Files
zeekayandHanzo Dev 1ab6e799c1 cd: the module is github.com/hanzoai/cd, where it is actually hosted
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]>
2026-07-28 21:16:24 -07:00

108 lines
3.8 KiB
Go

package diff
import (
"fmt"
"slices"
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
"github.com/hanzoai/cd/util/glob"
)
// IgnoreDiffConfig holds the ignore difference configurations defined in argo-cm
// as well as in the Application resource.
type IgnoreDiffConfig struct {
ignores []v1alpha1.ResourceIgnoreDifferences
overrides map[string]v1alpha1.ResourceOverride
}
// IgnoreDifference holds the configurations to be used while ignoring differences
// from live and desired states.
type IgnoreDifference struct {
// JSONPointers is a JSON path list following the format defined in RFC4627 (https://datatracker.ietf.org/doc/html/rfc6902#section-3)
JSONPointers []string
// JQPathExpressions is a JQ path list that will be evaludated during the diff process
JQPathExpressions []string
// ManagedFieldsManagers is a list of trusted managers. Fields mutated by those managers will take precedence over the
// desired state defined in the SCM and won't be displayed in diffs
ManagedFieldsManagers []string
}
// NewIgnoreDiffConfig creates a new NewIgnoreDiffConfig.
func NewIgnoreDiffConfig(ignores []v1alpha1.ResourceIgnoreDifferences, overrides map[string]v1alpha1.ResourceOverride) *IgnoreDiffConfig {
return &IgnoreDiffConfig{
ignores: ignores,
overrides: overrides,
}
}
// HasIgnoreDifference will verify if the provided resource identifiers have any ignore
// difference configurations associated with them. It will first check if there are
// system level ignore difference configurations for the current group/kind. If so, this
// will be returned taking precedence over Application specific ignore difference
// configurations.
func (i *IgnoreDiffConfig) HasIgnoreDifference(group, kind, name, namespace string) (bool, *IgnoreDifference) {
result := &IgnoreDifference{}
found := false
ro, ok := i.overrides[fmt.Sprintf("%s/%s", group, kind)]
if ok {
mergeIgnoreDifferences(overrideToIgnoreDifference(ro), result)
found = true
}
wildOverride, ok := i.overrides["*/*"]
if ok {
mergeIgnoreDifferences(overrideToIgnoreDifference(wildOverride), result)
found = true
}
for _, ignore := range i.ignores {
if glob.Match(ignore.Group, group) &&
glob.Match(ignore.Kind, kind) &&
(ignore.Name == "" || ignore.Name == name) &&
(ignore.Namespace == "" || ignore.Namespace == namespace) {
mergeIgnoreDifferences(resourceToIgnoreDifference(ignore), result)
found = true
}
}
if !found {
return found, nil
}
return found, result
}
func overrideToIgnoreDifference(override v1alpha1.ResourceOverride) *IgnoreDifference {
return &IgnoreDifference{
JSONPointers: override.IgnoreDifferences.JSONPointers,
JQPathExpressions: override.IgnoreDifferences.JQPathExpressions,
ManagedFieldsManagers: override.IgnoreDifferences.ManagedFieldsManagers,
}
}
func resourceToIgnoreDifference(resource v1alpha1.ResourceIgnoreDifferences) *IgnoreDifference {
return &IgnoreDifference{
JSONPointers: resource.JSONPointers,
JQPathExpressions: resource.JQPathExpressions,
ManagedFieldsManagers: resource.ManagedFieldsManagers,
}
}
// mergeIgnoreDifferences will merge all ignores in the given from in target
// skipping repeated configs.
func mergeIgnoreDifferences(from *IgnoreDifference, target *IgnoreDifference) {
for _, jqPath := range from.JQPathExpressions {
if !slices.Contains(target.JQPathExpressions, jqPath) {
target.JQPathExpressions = append(target.JQPathExpressions, jqPath)
}
}
for _, jsonPointer := range from.JSONPointers {
if !slices.Contains(target.JSONPointers, jsonPointer) {
target.JSONPointers = append(target.JSONPointers, jsonPointer)
}
}
for _, manager := range from.ManagedFieldsManagers {
if !slices.Contains(target.ManagedFieldsManagers, manager) {
target.ManagedFieldsManagers = append(target.ManagedFieldsManagers, manager)
}
}
}