Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/changing tracking method #250

Open
wants to merge 2 commits into
base: release-2.8
Choose a base branch
from
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
19 changes: 19 additions & 0 deletions util/argo/diff/diff_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package diff_test

import (
"github.com/argoproj/argo-cd/v2/common"
argo2 "github.com/argoproj/argo-cd/v2/util/argo"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -154,6 +156,23 @@ func TestStateDiff(t *testing.T) {
assert.Equal(t, float64(tc.expectedPredictedReplicas), predictedReplicas)
})
}

t.Run("will find diff while moving from label tracking to annotation+label", func(t *testing.T) {
// given
params := defaultDiffConfigParams()
params.trackingMethod = string(argo2.TrackingMethodAnnotationAndLabel)
params.label = common.LabelKeyAppInstance
dc := diffConfig(t, params)

// when
result, err := argo.StateDiff(testutil.YamlToUnstructured(testdata.LiveAppWithOldLabelTrackingYaml), testutil.YamlToUnstructured(testdata.DesiredAppMixedTrackingYaml), dc)

// then
assert.NoError(t, err)
assert.NotNil(t, result)
assert.True(t, result.Modified)
})

}
func TestDiffConfigBuilder(t *testing.T) {
type fixture struct {
Expand Down
6 changes: 6 additions & 0 deletions util/argo/resource_tracking.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ func (rt *resourceTracking) Normalize(config, live *unstructured.Unstructured, l
return nil
}

liveInstanceAnnotation, err := argokube.GetAppInstanceAnnotation(live, common.AnnotationKeyAppInstance)

if err == nil && liveInstanceAnnotation == "" && trackingMethod != string(TrackingMethodLabel) {
return nil
}

annotation, err := argokube.GetAppInstanceAnnotation(config, common.AnnotationKeyAppInstance)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions util/argo/testdata/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ var (

//go:embed desired_validating_webhook.yaml
DesiredValidatingWebhookYaml string

//go:embed live_app_with_old_label_tracking.yaml
LiveAppWithOldLabelTrackingYaml string

//go:embed desired_app_mixed_tracking.yaml
DesiredAppMixedTrackingYaml string
)
26 changes: 26 additions & 0 deletions util/argo/testdata/desired_app_mixed_tracking.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
argocd.argoproj.io/tracking-id: 'parent:argoproj.io/Application:argo/child'
some-annotation: 'some'
labels:
app.kubernetes.io/instance: parent
name: child
namespace: argo
spec:
destination:
name: in-cluster
namespace: argo
project: default
source:
path: empty
repoURL: 'https://github.com/argoproj/argocd-example-apps'
targetRevision: main
syncPolicy:
automated:
allowEmpty: true
prune: true
selfHeal: false
syncOptions:
- CreateNamespace=true
25 changes: 25 additions & 0 deletions util/argo/testdata/live_app_with_old_label_tracking.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
some-annotation: 'some'
labels:
app.kubernetes.io/instance: parent
name: child
namespace: argo
spec:
destination:
name: in-cluster
namespace: argo
project: default
source:
path: empty
repoURL: 'https://github.com/argoproj/argocd-example-apps'
targetRevision: main
syncPolicy:
automated:
allowEmpty: true
prune: true
selfHeal: false
syncOptions:
- CreateNamespace=true
Loading