mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
go.mod still declared `module github.com/hanzoai/deploy` after the repo was renamed. A Go module path is not cosmetic — it is the resolvable location. So `go get github.com/hanzoai/cd` could not work, and anything importing this module had to spell a name that no longer exists at that address. The build log of v3.6.0 is where it surfaced: the compiler was still emitting github.com/hanzoai/deploy/cmd/cd/commands. 3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from the module path, replaced separately so neither could clobber the other. go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean. Co-authored-by: Hanzo Dev <[email protected]>
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
appv1 "github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
"github.com/hanzoai/cd/util/settings"
|
|
)
|
|
|
|
// ClusterSpecifier contains only the name and server URL of a cluster. We use this struct to avoid partially-populating
|
|
// the full Cluster struct, which would be misleading.
|
|
type ClusterSpecifier struct {
|
|
Name string
|
|
Server string
|
|
}
|
|
|
|
// SecretsContainInClusterCredentials checks if any of the provided secrets represent the in-cluster configuration.
|
|
func SecretsContainInClusterCredentials(secrets []corev1.Secret) bool {
|
|
for _, secret := range secrets {
|
|
if string(secret.Data["server"]) == appv1.KubernetesInternalAPIServerAddr {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// ListClusters returns a list of cluster specifiers using the ClusterInformer.
|
|
func ListClusters(clusterInformer *settings.ClusterInformer) ([]ClusterSpecifier, error) {
|
|
clusters, err := clusterInformer.ListClusters()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error listing clusters: %w", err)
|
|
}
|
|
// len of clusters +1 for the in cluster secret
|
|
clusterList := make([]ClusterSpecifier, 0, len(clusters)+1)
|
|
hasInCluster := false
|
|
|
|
for _, cluster := range clusters {
|
|
clusterList = append(clusterList, ClusterSpecifier{
|
|
Name: cluster.Name,
|
|
Server: cluster.Server,
|
|
})
|
|
if cluster.Server == appv1.KubernetesInternalAPIServerAddr {
|
|
hasInCluster = true
|
|
}
|
|
}
|
|
|
|
if !hasInCluster {
|
|
// There was no secret for the in-cluster config, so we add it here. We don't fully-populate the Cluster struct,
|
|
// since only the name and server fields are used by the generator.
|
|
clusterList = append(clusterList, ClusterSpecifier{
|
|
Name: appv1.KubernetesInClusterName,
|
|
Server: appv1.KubernetesInternalAPIServerAddr,
|
|
})
|
|
}
|
|
|
|
return clusterList, nil
|
|
}
|