Skip to content

Commit

Permalink
Issue argoproj#1167 - Controller should remove orphaned resources war…
Browse files Browse the repository at this point in the history
…ning if app has no orphaned resources
  • Loading branch information
Alexander Matyushentsev authored and Alexander Matyushentsev committed Aug 19, 2019
1 parent aa0f9a3 commit a3367a8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
6 changes: 4 additions & 2 deletions controller/appcontroller.go
Expand Up @@ -281,12 +281,14 @@ func (ctrl *ApplicationController) getResourceTree(a *appv1.Application, managed
}
}
}
var conditions []appv1.ApplicationCondition
if len(orphanedNodes) > 0 && warnOrphaned {
a.Status.SetConditions([]appv1.ApplicationCondition{{
conditions = []appv1.ApplicationCondition{{
Type: appv1.ApplicationConditionOrphanedResourceWarning,
Message: fmt.Sprintf("Application has %d orphaned resources", len(orphanedNodes)),
}}, map[appv1.ApplicationConditionType]bool{appv1.ApplicationConditionOrphanedResourceWarning: true})
}}
}
a.Status.SetConditions(conditions, map[appv1.ApplicationConditionType]bool{appv1.ApplicationConditionOrphanedResourceWarning: true})
return &appv1.ApplicationTree{Nodes: nodes, OrphanedNodes: orphanedNodes}, nil
}

Expand Down
15 changes: 14 additions & 1 deletion test/e2e/app_management_test.go
Expand Up @@ -768,5 +768,18 @@ func TestOrphanedResource(t *testing.T) {
}).
Refresh(RefreshTypeNormal).
Then().
Expect(Condition(ApplicationConditionOrphanedResourceWarning, "Application has 1 orphaned resources"))
Expect(Condition(ApplicationConditionOrphanedResourceWarning, "Application has 1 orphaned resources")).
Given().
ProjectSpec(AppProjectSpec{
SourceRepos: []string{"*"},
Destinations: []ApplicationDestination{{Namespace: "*", Server: "*"}},
OrphanedResources: nil,
}).
When().
Refresh(RefreshTypeNormal).
Then().
Expect(SyncStatusIs(SyncStatusCodeSynced)).
And(func(app *Application) {
assert.Len(t, app.Status.Conditions, 0)
})
}
8 changes: 3 additions & 5 deletions test/e2e/fixture/fixture.go
Expand Up @@ -2,7 +2,6 @@ package fixture

import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
Expand All @@ -12,8 +11,6 @@ import (
"testing"
"time"

"k8s.io/apimachinery/pkg/types"

"github.com/argoproj/pkg/errors"
jsonpatch "github.com/evanphx/json-patch"
"github.com/ghodss/yaml"
Expand Down Expand Up @@ -295,9 +292,10 @@ func SetHelmRepoCredential(creds settings.HelmRepoCredentials) {
}

func SetProjectSpec(project string, spec v1alpha1.AppProjectSpec) {
data, err := json.Marshal(spec)
proj, err := AppClientset.ArgoprojV1alpha1().AppProjects(ArgoCDNamespace).Get(project, v1.GetOptions{})
errors.CheckError(err)
_, err = AppClientset.ArgoprojV1alpha1().AppProjects(ArgoCDNamespace).Patch(project, types.MergePatchType, []byte(fmt.Sprintf(`{ "spec": %s }`, string(data))))
proj.Spec = spec
_, err = AppClientset.ArgoprojV1alpha1().AppProjects(ArgoCDNamespace).Update(proj)
errors.CheckError(err)
}

Expand Down

0 comments on commit a3367a8

Please sign in to comment.