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]>
56 lines
1.9 KiB
Go
56 lines
1.9 KiB
Go
package controller
|
|
|
|
import (
|
|
"maps"
|
|
|
|
gitopscommon "github.com/hanzoai/cd/gitops-engine/pkg/sync/common"
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
|
|
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
)
|
|
|
|
// syncNamespace determine if Hanzo CD should create and/or manage the namespace
|
|
// where the application will be deployed.
|
|
func syncNamespace(syncPolicy *v1alpha1.SyncPolicy) func(m *unstructured.Unstructured, l *unstructured.Unstructured) (bool, error) {
|
|
// This function must return true for the managed namespace to be synced.
|
|
return func(managedNs, liveNs *unstructured.Unstructured) (bool, error) {
|
|
if managedNs == nil {
|
|
return false, nil
|
|
}
|
|
|
|
isNewNamespace := liveNs == nil
|
|
isManagedNamespace := syncPolicy != nil && syncPolicy.ManagedNamespaceMetadata != nil
|
|
|
|
// should only sync the namespace if it doesn't exist in k8s or if
|
|
// syncPolicy is defined to manage the metadata
|
|
if !isManagedNamespace && !isNewNamespace {
|
|
return false, nil
|
|
}
|
|
|
|
if isManagedNamespace {
|
|
managedNamespaceMetadata := syncPolicy.ManagedNamespaceMetadata
|
|
managedNs.SetLabels(managedNamespaceMetadata.Labels)
|
|
// managedNamespaceMetadata relies on SSA in order to avoid overriding
|
|
// existing labels and annotations in namespaces
|
|
managedNs.SetAnnotations(appendSSAAnnotation(managedNamespaceMetadata.Annotations))
|
|
}
|
|
|
|
// TODO: https://github.com/argoproj/argo-cd/issues/11196
|
|
// err := resourceTracking.SetAppInstance(managedNs, appLabelKey, appName, "", trackingMethod)
|
|
// if err != nil {
|
|
// return false, fmt.Errorf("failed to set app instance tracking on the namespace %s: %s", managedNs.GetName(), err)
|
|
// }
|
|
|
|
return true, nil
|
|
}
|
|
}
|
|
|
|
// appendSSAAnnotation will set the managed namespace to be synced
|
|
// with server-side apply
|
|
func appendSSAAnnotation(in map[string]string) map[string]string {
|
|
r := map[string]string{}
|
|
maps.Copy(r, in)
|
|
r[gitopscommon.AnnotationSyncOptions] = gitopscommon.SyncOptionServerSideApply
|
|
return r
|
|
}
|