Rename excludedResources config key to resource.exclusions. Support hot reload (#1189)

This commit is contained in:
Jesse Suen 2019-02-27 16:44:17 -08:00 committed by GitHub
parent a9d352efb2
commit d386e24df4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 22 deletions

View file

@ -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
}

View file

@ -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:

View file

@ -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.

View file

@ -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 {

View file

@ -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)
}