Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"runtime/debug"
"sort"
"strconv"
"path/filepath"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -637,6 +638,9 @@ func (ctrl *ApplicationController) getResourceTree(destCluster *appv1.Cluster, a
orphanedNodesKeys := make([]kube.ResourceKey, 0)
for k := range orphanedNodesMap {
if k.Namespace != "" && proj.IsGroupKindNamePermitted(k.GroupKind(), k.Name, true) && !isKnownOrphanedResourceExclusion(k, proj) {
if ctrl.isOrphanedResourceIgnored(k) {
continue
}
orphanedNodesKeys = append(orphanedNodesKeys, k)
}
}
Expand Down Expand Up @@ -2778,3 +2782,19 @@ func (ctrl *ApplicationController) applyImpersonationConfig(config *rest.Config,
}

type ClusterFilterFunction func(c *appv1.Cluster, distributionFunction sharding.DistributionFunction) bool

// isOrphanedResourceIgnored returns true if the given resource key matches
// any name pattern defined in resource.orphaned.ignore.namePatterns in argocd-cm
func (ctrl *ApplicationController) isOrphanedResourceIgnored(key kube.ResourceKey) bool {
config, err := ctrl.settingsMgr.GetOrphanedIgnoreConfig()
if err != nil || config == nil {
return false
}
for _, pattern := range config.NamePatterns {
matched, err := filepath.Match(pattern, key.Name)
if err == nil && matched {
return true
}
}
return false
}
29 changes: 28 additions & 1 deletion util/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,10 @@ const (
resourceInclusionsKey = "resource.inclusions"
// resourceIgnoreResourceUpdatesEnabledKey is the key to a boolean determining whether the resourceIgnoreUpdates feature is enabled
resourceIgnoreResourceUpdatesEnabledKey = "resource.ignoreResourceUpdatesEnabled"
// resourceOrphanedIgnorePatternsKey is the key to a list of name patterns for orphaned resources to ignore
resourceOrphanedIgnorePatternsKey = "resource.orphaned.ignore.namePatterns"
// resourceSensitiveAnnotationsKey is the key to list of annotations to mask in secret resource
// resourceSensitiveAnnotationsKey is the key to list of annotations to mask
resourceSensitiveAnnotationsKey = "resource.sensitive.mask.annotations"
// resourceCustomLabelKey is the key to a custom label to show in node info, if present
resourceCustomLabelsKey = "resource.customLabels"
Expand Down Expand Up @@ -2769,7 +2772,6 @@ func (m myFeatureGates) Enabled(f clientgofeatures.Feature) bool {
return m.parent.Enabled(f)
}

// FIXME: remove when we have proper WatchListClient and InOrderInformers support
func ConfigureGoClientFeatures() {
gates := clientgofeatures.FeatureGates()
isWatchListEnabled := gates.Enabled(clientgofeatures.WatchListClient)
Expand All @@ -2780,3 +2782,28 @@ func ConfigureGoClientFeatures() {
clientgofeatures.ReplaceFeatureGates(wrapper)
}
}
// OrphanedResourceIgnoreConfig holds name patterns for orphaned resources
// that should be ignored during reconciliation

type OrphanedResourceIgnoreConfig struct {
NamePatterns []string `json:"namePatterns,omitempty"`
}

// GetOrphanedIgnoreConfig returns the config for ignoring orphaned
// resources by name pattern, read from argocd-cm
func (mgr *SettingsManager) GetOrphanedIgnoreConfig() (*OrphanedResourceIgnoreConfig, error) {
argoCDCM, err := mgr.getConfigMap()
if err != nil {
return nil, err
}
val, ok := argoCDCM.Data[resourceOrphanedIgnorePatternsKey]
if !ok || val == "" {
return &OrphanedResourceIgnoreConfig{}, nil
}
config := &OrphanedResourceIgnoreConfig{}
err = yaml.Unmarshal([]byte(val), config)
if err != nil {
return nil, fmt.Errorf("failed to parse %s: %w", resourceOrphanedIgnorePatternsKey, err)
}
return config, nil
}
24 changes: 24 additions & 0 deletions util/settings/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2944,7 +2944,31 @@
})
}


func TestGetOrphanedIgnoreConfig_NoConfig(t *testing.T) {
_, settingsManager := fixtures(t.Context(), nil)
config, err := settingsManager.GetOrphanedIgnoreConfig()
require.NoError(t, err)
assert.Empty(t, config.NamePatterns)
}

func TestGetOrphanedIgnoreConfig_WithPatterns(t *testing.T) {
_, settingsManager := fixtures(t.Context(), map[string]string{
"resource.orphaned.ignore.namePatterns": "namePatterns:\n - \"*-cluster-config-map\"\n - \"*-config-map\"\n",
})
config, err := settingsManager.GetOrphanedIgnoreConfig()
require.NoError(t, err)
assert.Equal(t, []string{"*-cluster-config-map", "*-config-map"}, config.NamePatterns)
}

func TestGetOrphanedIgnoreConfig_NoMatch(t *testing.T) {
_, settingsManager := fixtures(t.Context(), map[string]string{
"resource.orphaned.ignore.namePatterns": "namePatterns:\n - \"*-cluster-config-map\"\n",
})
config, err := settingsManager.GetOrphanedIgnoreConfig()
require.NoError(t, err)
assert.NotContains(t, config.NamePatterns, "some-other-resource")
func TestSettingsManager_GetWebhookRefreshJitter(t *testing.T) {

Check failure on line 2971 in util/settings/settings_test.go

View workflow job for this annotation

GitHub Actions / Lint Go code

expected '(', found TestSettingsManager_GetWebhookRefreshJitter (typecheck)

Check failure on line 2971 in util/settings/settings_test.go

View workflow job for this annotation

GitHub Actions / Lint Go code

syntax error: unexpected name TestSettingsManager_GetWebhookRefreshJitter, expected ( (typecheck)

Check failure on line 2971 in util/settings/settings_test.go

View workflow job for this annotation

GitHub Actions / Run unit tests for Go packages

expected '(', found TestSettingsManager_GetWebhookRefreshJitter

Check failure on line 2971 in util/settings/settings_test.go

View workflow job for this annotation

GitHub Actions / Run unit tests with -race for Go packages

expected '(', found TestSettingsManager_GetWebhookRefreshJitter
tests := []struct {
name string
input string
Expand Down Expand Up @@ -2988,4 +3012,4 @@
assert.Equal(t, tt.output, jitter)
})
}
}

Check failure on line 3015 in util/settings/settings_test.go

View workflow job for this annotation

GitHub Actions / Lint Go code

expected '}', found 'EOF' (typecheck)
Loading