Skip to content

Commit

Permalink
Issue argoproj#1621 - Proper handling of an excluded resource in an a…
Browse files Browse the repository at this point in the history
…pplication (argoproj#1862)
  • Loading branch information
Alexander Matyushentsev authored Jul 2, 2019
1 parent 5ee346c commit 9f8693a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions controller/appcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@ func (ctrl *ApplicationController) refreshAppConditions(app *appv1.Application)
appv1.ApplicationConditionSharedResourceWarning: true,
appv1.ApplicationConditionSyncError: true,
appv1.ApplicationConditionRepeatedResourceWarning: true,
appv1.ApplicationConditionExcludedResourceWarning: true,
}
appConditions := make([]appv1.ApplicationCondition, 0)
for i := 0; i < len(app.Status.Conditions); i++ {
Expand Down
17 changes: 17 additions & 0 deletions controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,23 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, revision st
}
conditions = append(conditions, dedupConditions...)

resFilter, err := m.settingsMgr.GetResourcesFilter()
if err != nil {
conditions = append(conditions, v1alpha1.ApplicationCondition{Type: v1alpha1.ApplicationConditionComparisonError, Message: err.Error()})
} else {
for i := len(targetObjs) - 1; i >= 0; i-- {
targetObj := targetObjs[i]
gvk := targetObj.GroupVersionKind()
if resFilter.IsExcludedResource(gvk.Group, gvk.Kind, app.Spec.Destination.Server) {
targetObjs = append(targetObjs[:i], targetObjs[i+1:]...)
conditions = append(conditions, v1alpha1.ApplicationCondition{
Type: v1alpha1.ApplicationConditionExcludedResourceWarning,
Message: fmt.Sprintf("Resource %s/%s %s is excluded in the settings", gvk.Group, gvk.Kind, targetObj.GetName()),
})
}
}
}

logCtx.Debugf("Generated config manifests")
liveObjByKey, err := m.liveStateCache.GetManagedLiveObjs(app, targetObjs)
dedupLiveResources(targetObjs, liveObjByKey)
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ const (
ApplicationConditionSharedResourceWarning = "SharedResourceWarning"
// ApplicationConditionRepeatedResourceWarning indicates that application source has resource with same Group, Kind, Name, Namespace multiple times
ApplicationConditionRepeatedResourceWarning = "RepeatedResourceWarning"
// ApplicationConditionExcludedResourceWarning indicates that application has resource which is configured to be excluded
ApplicationConditionExcludedResourceWarning = "ExcludedResourceWarning"
)

// ApplicationCondition contains details about current application condition
Expand Down
16 changes: 16 additions & 0 deletions test/e2e/app_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"testing"
"time"

"github.com/argoproj/argo-cd/util/settings"

"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -683,3 +685,17 @@ func TestSelfManagedApps(t *testing.T) {
assert.True(t, reconciledCount < 3, "Application was reconciled too many times")
})
}

func TestExcludedResource(t *testing.T) {
Given(t).
ResourceOverrides(map[string]ResourceOverride{"apps/Deployment": {Actions: actionsConfig}}).
Path(guestbookPath).
ResourceFilter(settings.ResourcesFilter{
ResourceExclusions: []settings.FilteredResource{{Kinds: []string{kube.DeploymentKind}}},
}).
When().
Create().
Sync().
Then().
Expect(Condition(ApplicationConditionExcludedResourceWarning, "Resource apps/Deployment guestbook-ui is excluded in the settings"))
}
5 changes: 5 additions & 0 deletions test/e2e/fixture/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func (c *Context) ResourceOverrides(overrides map[string]v1alpha1.ResourceOverri
return c
}

func (c *Context) ResourceFilter(filter settings.ResourcesFilter) *Context {
fixture.SetResourceFilter(filter)
return c
}

// this both configures the plugin, but forces use of it
func (c *Context) ConfigManagementPlugin(plugin v1alpha1.ConfigManagementPlugin) *Context {
fixture.SetConfigManagementPlugins(plugin)
Expand Down
17 changes: 17 additions & 0 deletions test/e2e/fixture/fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,22 @@ func SetConfigManagementPlugins(plugin ...v1alpha1.ConfigManagementPlugin) {
})
}

func SetResourceFilter(filters settings.ResourcesFilter) {
updateSettingConfigMap(func(cm *corev1.ConfigMap) error {
exclusions, err := yaml.Marshal(filters.ResourceExclusions)
if err != nil {
return err
}
inclusions, err := yaml.Marshal(filters.ResourceInclusions)
if err != nil {
return err
}
cm.Data["resource.exclusions"] = string(exclusions)
cm.Data["resource.inclusions"] = string(inclusions)
return nil
})
}

func SetRepos(repos ...settings.RepoCredentials) {
updateSettingConfigMap(func(cm *corev1.ConfigMap) error {
yamlBytes, err := yaml.Marshal(repos)
Expand Down Expand Up @@ -253,6 +269,7 @@ func EnsureCleanState(t *testing.T) {
SetConfigManagementPlugins()
SetRepoCredentials()
SetRepos()
SetResourceFilter(settings.ResourcesFilter{})

// remove tmp dir
CheckError(os.RemoveAll(tmpDir))
Expand Down

0 comments on commit 9f8693a

Please sign in to comment.