From d386e24df4db00a07d7d7da47da6624ac06d30d6 Mon Sep 17 00:00:00 2001 From: Jesse Suen Date: Wed, 27 Feb 2019 16:44:17 -0800 Subject: [PATCH] Rename excludedResources config key to resource.exclusions. Support hot reload (#1189) --- controller/appcontroller.go | 6 ++++++ docs/argocd-cm.yaml | 2 +- docs/declarative-setup.md | 6 +++--- util/settings/settings.go | 27 ++++++++++++++------------- util/settings/settings_test.go | 10 +++++----- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/controller/appcontroller.go b/controller/appcontroller.go index be506c54b620d..42383348e8c90 100644 --- a/controller/appcontroller.go +++ b/controller/appcontroller.go @@ -894,6 +894,7 @@ func (ctrl *ApplicationController) watchSettings(ctx context.Context) { updateCh := make(chan *settings_util.ArgoCDSettings, 1) ctrl.settingsMgr.Subscribe(updateCh) prevAppLabelKey := ctrl.settings.GetAppInstanceLabelKey() + prevResourceExclusions := ctrl.settings.ResourceExclusions done := false for !done { select { @@ -905,6 +906,11 @@ func (ctrl *ApplicationController) watchSettings(ctx context.Context) { ctrl.stateCache.Invalidate() prevAppLabelKey = newAppLabelKey } + if !reflect.DeepEqual(prevResourceExclusions, newSettings.ResourceExclusions) { + log.Infof("resource exclusions modified") + ctrl.stateCache.Invalidate() + prevResourceExclusions = newSettings.ResourceExclusions + } case <-ctx.Done(): done = true } diff --git a/docs/argocd-cm.yaml b/docs/argocd-cm.yaml index 3d69b2d227514..378cfb4bddf08 100644 --- a/docs/argocd-cm.yaml +++ b/docs/argocd-cm.yaml @@ -94,7 +94,7 @@ data: # These are globs, so a "*" will match all values. # If you omit groups/kinds/clusters then they will match all groups/kind/clusters. # NOTE: events.k8s.io and metrics.k8s.io are excluded by default - excludedResources: | + resource.exclusions: | - apiGroups: - repositories.stash.appscode.com kinds: diff --git a/docs/declarative-setup.md b/docs/declarative-setup.md index a73040b3f9a6d..ec91bb861bd63 100644 --- a/docs/declarative-setup.md +++ b/docs/declarative-setup.md @@ -234,12 +234,12 @@ To configure this, edit the `argcd-cm` config map: kubectl edit configmap argocd-cm -n argocdconfigmap/argocd-cm edited ``` -Add `excludedResources`, e.g.: +Add `resource.exclusions`, e.g.: ```yaml apiVersion: v1 data: - excludedResources: | + resource.exclusions: | - apiGroups: - "*" kinds: @@ -249,7 +249,7 @@ data: kind: ConfigMap ``` -The `excludedResources` node is a list of objects. Each object can have: +The `resource.exclusions` node is a list of objects. Each object can have: - `apiGroups` A list of globs to match the API group. - `kinds` A list of kinds to match. Can be "*" to match all. diff --git a/util/settings/settings.go b/util/settings/settings.go index ffc28da28c631..1cd6f63bfb925 100644 --- a/util/settings/settings.go +++ b/util/settings/settings.go @@ -21,7 +21,7 @@ import ( "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/selection" - "k8s.io/client-go/informers/core/v1" + v1 "k8s.io/client-go/informers/core/v1" "k8s.io/client-go/kubernetes" v1listers "k8s.io/client-go/listers/core/v1" "k8s.io/client-go/tools/cache" @@ -69,7 +69,8 @@ type ArgoCDSettings struct { // ResourceOverrides holds the overrides for specific resources. The keys are in the format of `group/kind` // (e.g. argoproj.io/rollout) for the resource that is being overridden ResourceOverrides map[string]ResourceOverride - ExcludedResources []ExcludedResource + // ResourceExclusions holds the api groups, kinds per cluster to exclude from Argo CD's watch + ResourceExclusions []ExcludedResource } type ResourceOverride struct { @@ -131,9 +132,9 @@ const ( // settingsApplicationInstanceLabelKey is the key to configure injected app instance label key settingsApplicationInstanceLabelKey = "application.instanceLabelKey" // resourcesCustomizationsKey is the key to the map of resource overrides - resourcesCustomizationsKey = "resource.customizations" - // excludedResourcesKey is the key to the list of excluded resourcese - excludedResourcesKey = "excludedResources" + resourceCustomizationsKey = "resource.customizations" + // resourceExclusions is the key to the list of excluded resources + resourceExclusionsKey = "resource.exclusions" // configManagementPluginsKey is the key to the list of config management plugins configManagementPluginsKey = "configManagementPlugins" ) @@ -345,7 +346,7 @@ func updateSettingsFromConfigMap(settings *ArgoCDSettings, argoCDCM *apiv1.Confi } } - if value, ok := argoCDCM.Data[resourcesCustomizationsKey]; ok { + if value, ok := argoCDCM.Data[resourceCustomizationsKey]; ok { resourceOverrides := map[string]ResourceOverride{} err := yaml.Unmarshal([]byte(value), &resourceOverrides) if err != nil { @@ -355,13 +356,13 @@ func updateSettingsFromConfigMap(settings *ArgoCDSettings, argoCDCM *apiv1.Confi } } - if value, ok := argoCDCM.Data[excludedResourcesKey]; ok { + if value, ok := argoCDCM.Data[resourceExclusionsKey]; ok { excludedResources := make([]ExcludedResource, 0) err := yaml.Unmarshal([]byte(value), &excludedResources) if err != nil { errors = append(errors, err) } else { - settings.ExcludedResources = excludedResources + settings.ResourceExclusions = excludedResources } } @@ -492,15 +493,15 @@ func (mgr *SettingsManager) SaveSettings(settings *ArgoCDSettings) error { if err != nil { return err } - argoCDCM.Data[resourcesCustomizationsKey] = string(yamlBytes) + argoCDCM.Data[resourceCustomizationsKey] = string(yamlBytes) } - if len(settings.ExcludedResources) > 0 { - yamlBytes, err := yaml.Marshal(settings.ExcludedResources) + if len(settings.ResourceExclusions) > 0 { + yamlBytes, err := yaml.Marshal(settings.ResourceExclusions) if err != nil { return err } - argoCDCM.Data[excludedResourcesKey] = string(yamlBytes) + argoCDCM.Data[resourceExclusionsKey] = string(yamlBytes) } @@ -818,7 +819,7 @@ func (a *ArgoCDSettings) getExcludedResources() []ExcludedResource { coreExcludedResources := []ExcludedResource{ {APIGroups: []string{"events.k8s.io", "metrics.k8s.io"}}, } - return append(coreExcludedResources, a.ExcludedResources...) + return append(coreExcludedResources, a.ResourceExclusions...) } func (a *ArgoCDSettings) IsExcludedResource(apiGroup, kind, cluster string) bool { diff --git a/util/settings/settings_test.go b/util/settings/settings_test.go index c490e27b095f5..033e6eeee691b 100644 --- a/util/settings/settings_test.go +++ b/util/settings/settings_test.go @@ -3,7 +3,7 @@ package settings import ( "testing" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "github.com/stretchr/testify/assert" ) @@ -15,21 +15,21 @@ func TestArgoCDSettings_IsExcludedResource(t *testing.T) { assert.False(t, settings.IsExcludedResource("rubbish.io", "", "")) } -func TestUpdateSettingsFromConfigMapExcludedResources(t *testing.T) { +func TestUpdateSettingsFromConfigMapResourceExclusions(t *testing.T) { settings := ArgoCDSettings{} configMap := v1.ConfigMap{} err := updateSettingsFromConfigMap(&settings, &configMap) assert.NoError(t, err) - assert.Nil(t, settings.ExcludedResources) + assert.Nil(t, settings.ResourceExclusions) configMap.Data = map[string]string{ - "excludedResources": "\n - apiGroups: []\n kinds: []\n clusters: []\n", + "resource.exclusions": "\n - apiGroups: []\n kinds: []\n clusters: []\n", } err = updateSettingsFromConfigMap(&settings, &configMap) assert.NoError(t, err) - assert.Equal(t, []ExcludedResource{{APIGroups: []string{}, Kinds: []string{}, Clusters: []string{}}}, settings.ExcludedResources) + assert.Equal(t, []ExcludedResource{{APIGroups: []string{}, Kinds: []string{}, Clusters: []string{}}}, settings.ResourceExclusions) }