Skip to content

Commit

Permalink
feat: merge self heal logic with oss (#345)
Browse files Browse the repository at this point in the history
* merge self heal logic with oss

* merge self heal logic with oss

* merge self heal logic with oss

* merge self heal logic with oss
  • Loading branch information
pasha-codefresh authored Oct 17, 2024
1 parent 55633e5 commit 36fb3f0
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 60 deletions.
25 changes: 12 additions & 13 deletions controller/appcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"encoding/json"
"errors"
"os"
"testing"
"time"

Expand Down Expand Up @@ -553,7 +552,7 @@ func TestAutoSync(t *testing.T) {
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
}
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}})
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}, true)
assert.Nil(t, cond)
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
require.NoError(t, err)
Expand All @@ -570,7 +569,7 @@ func TestAutoSyncNotAllowEmpty(t *testing.T) {
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
}
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{})
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}, true)
assert.NotNil(t, cond)
}

Expand All @@ -583,7 +582,7 @@ func TestAutoSyncAllowEmpty(t *testing.T) {
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
}
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{})
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}, false)
assert.Nil(t, cond)
}

Expand All @@ -597,7 +596,7 @@ func TestSkipAutoSync(t *testing.T) {
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
}
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{})
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}, false)
assert.Nil(t, cond)
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
require.NoError(t, err)
Expand All @@ -612,7 +611,7 @@ func TestSkipAutoSync(t *testing.T) {
Status: v1alpha1.SyncStatusCodeSynced,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
}
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{})
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}, false)
assert.Nil(t, cond)
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
require.NoError(t, err)
Expand All @@ -628,7 +627,7 @@ func TestSkipAutoSync(t *testing.T) {
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
}
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{})
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}, false)
assert.Nil(t, cond)
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
require.NoError(t, err)
Expand All @@ -645,7 +644,7 @@ func TestSkipAutoSync(t *testing.T) {
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
}
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{})
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{}, false)
assert.Nil(t, cond)
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
require.NoError(t, err)
Expand All @@ -671,7 +670,7 @@ func TestSkipAutoSync(t *testing.T) {
Status: v1alpha1.SyncStatusCodeOutOfSync,
Revision: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
}
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}})
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}, false)
assert.NotNil(t, cond)
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
require.NoError(t, err)
Expand All @@ -687,7 +686,7 @@ func TestSkipAutoSync(t *testing.T) {
}
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{
{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync, RequiresPruning: true},
})
}, false)
assert.Nil(t, cond)
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
require.NoError(t, err)
Expand Down Expand Up @@ -723,7 +722,7 @@ func TestAutoSyncIndicateError(t *testing.T) {
Source: *app.Spec.Source.DeepCopy(),
},
}
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}})
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}, false)
assert.NotNil(t, cond)
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
require.NoError(t, err)
Expand Down Expand Up @@ -766,7 +765,7 @@ func TestAutoSyncParameterOverrides(t *testing.T) {
Revision: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
},
}
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}})
cond, _ := ctrl.autoSync(app, &syncStatus, []v1alpha1.ResourceStatus{{Name: "guestbook", Kind: kube.DeploymentKind, Status: v1alpha1.SyncStatusCodeOutOfSync}}, false)
assert.Nil(t, cond)
app, err := ctrl.applicationClientset.ArgoprojV1alpha1().Applications(test.FakeArgoCDNamespace).Get(context.Background(), "my-app", metav1.GetOptions{})
require.NoError(t, err)
Expand Down Expand Up @@ -2169,4 +2168,4 @@ func TestAlreadyAttemptSync(t *testing.T) {
attempted, _ := alreadyAttemptedSync(app, "sha", []string{}, false, true)
assert.False(t, attempted)
})
}
}
25 changes: 12 additions & 13 deletions controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type comparisonResult struct {
timings map[string]time.Duration
diffResultList *diff.DiffResultList
hasPostDeleteHooks bool
revisionUpdated bool
revisionUpdated bool
}

func (res *comparisonResult) GetSyncStatus() *v1alpha1.SyncStatus {
Expand Down Expand Up @@ -182,13 +182,13 @@ func (m *appStateManager) GetRepoObjs(app *v1alpha1.Application, sources []v1alp
if err != nil {
return nil, nil, false, fmt.Errorf("failed to get ref sources: %w", err)
}

revisionUpdated := false

atLeastOneRevisionIsNotPossibleToBeUpdated := false

keyManifestGenerateAnnotationVal, keyManifestGenerateAnnotationExists := app.Annotations[v1alpha1.AnnotationKeyManifestGeneratePaths]

for i, source := range sources {
if len(revisions) < len(sources) || revisions[i] == "" {
revisions[i] = source.TargetRevision
Expand Down Expand Up @@ -232,7 +232,6 @@ func (m *appStateManager) GetRepoObjs(app *v1alpha1.Application, sources []v1alp
RefSources: refSources,
HasMultipleSources: app.Spec.HasMultipleSources(),
})

if err != nil {
return nil, nil, false, fmt.Errorf("failed to compare revisions for source %d of %d: %w", i+1, len(sources), err)
}
Expand All @@ -244,7 +243,7 @@ func (m *appStateManager) GetRepoObjs(app *v1alpha1.Application, sources []v1alp
if updateRevisionResult.Revision != "" {
revision = updateRevisionResult.Revision
}
} else {
} else {
// revisionUpdated is set to true if at least one revision is not possible to be updated,
atLeastOneRevisionIsNotPossibleToBeUpdated = true
}
Expand All @@ -254,7 +253,7 @@ func (m *appStateManager) GetRepoObjs(app *v1alpha1.Application, sources []v1alp
manifestInfo, err := repoClient.GenerateManifest(context.Background(), &apiclient.ManifestRequest{
Repo: repo,
Repos: permittedHelmRepos,
Revision: revisions[i],
Revision: revision,
NoCache: noCache,
NoRevisionCache: noRevisionCache,
AppLabelKey: appLabelKey,
Expand Down Expand Up @@ -468,7 +467,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
targetNsExists := false

var revisionUpdated bool

if len(localManifests) == 0 {
// If the length of revisions is not same as the length of sources,
// we take the revisions from the sources directly for all the sources.
Expand Down Expand Up @@ -850,8 +849,8 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
Sources: sources,
IgnoreDifferences: app.Spec.IgnoreDifferences,
},
Status: syncCode,
Revisions: manifestRevisions,
Status: syncCode,
Revisions: manifestRevisions,
}
} else {
syncStatus = v1alpha1.SyncStatus{
Expand All @@ -860,8 +859,8 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
Source: app.Spec.GetSource(),
IgnoreDifferences: app.Spec.IgnoreDifferences,
},
Status: syncCode,
Revision: revision,
Status: syncCode,
Revision: revision,
}
}

Expand Down Expand Up @@ -890,7 +889,7 @@ func (m *appStateManager) CompareAppState(app *v1alpha1.Application, project *v1
diffConfig: diffConfig,
diffResultList: diffResults,
hasPostDeleteHooks: hasPostDeleteHooks,
revisionUpdated: revisionUpdated,
revisionUpdated: revisionUpdated,
}

if hasMultipleSources {
Expand Down
2 changes: 1 addition & 1 deletion controller/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1781,4 +1781,4 @@ func TestCompareAppStateRevisionUpdatedWithHelmSource(t *testing.T) {
assert.NotNil(t, compRes)
assert.NotNil(t, compRes.syncStatus)
assert.True(t, compRes.revisionUpdated)
}
}
2 changes: 1 addition & 1 deletion manifests/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ kind: Kustomization
images:
- name: quay.io/argoproj/argocd
newName: quay.io/codefresh/argocd
newTag: v2.12-2024.10.16-ae9bb9622
newTag: latest
resources:
- ./application-controller
- ./dex
Expand Down
8 changes: 4 additions & 4 deletions manifests/core-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21543,7 +21543,7 @@ spec:
- argocd
- admin
- redis-initial-password
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: IfNotPresent
name: secret-init
securityContext:
Expand Down Expand Up @@ -21796,7 +21796,7 @@ spec:
value: /helm-working-dir
- name: HELM_DATA_HOME
value: /helm-working-dir
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
Expand Down Expand Up @@ -21848,7 +21848,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /var/run/argocd/argocd-cmp-server
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
name: copyutil
securityContext:
allowPrivilegeEscalation: false
Expand Down Expand Up @@ -22119,7 +22119,7 @@ spec:
key: controller.ignore.normalizer.jq.timeout
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: argocd-application-controller
ports:
Expand Down
2 changes: 1 addition & 1 deletion manifests/core-install/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ resources:
images:
- name: quay.io/argoproj/argocd
newName: quay.io/codefresh/argocd
newTag: v2.12-2024.10.16-ae9bb9622
newTag: latest
2 changes: 1 addition & 1 deletion manifests/ha/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ patches:
images:
- name: quay.io/argoproj/argocd
newName: quay.io/codefresh/argocd
newTag: v2.12-2024.10.16-ae9bb9622
newTag: latest
resources:
- ../../base/application-controller
- ../../base/applicationset-controller
Expand Down
12 changes: 6 additions & 6 deletions manifests/ha/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22785,7 +22785,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /shared/argocd-dex
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: copyutil
securityContext:
Expand Down Expand Up @@ -22900,7 +22900,7 @@ spec:
- argocd
- admin
- redis-initial-password
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: IfNotPresent
name: secret-init
securityContext:
Expand Down Expand Up @@ -23183,7 +23183,7 @@ spec:
value: /helm-working-dir
- name: HELM_DATA_HOME
value: /helm-working-dir
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
Expand Down Expand Up @@ -23235,7 +23235,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /var/run/argocd/argocd-cmp-server
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
name: copyutil
securityContext:
allowPrivilegeEscalation: false
Expand Down Expand Up @@ -23565,7 +23565,7 @@ spec:
key: server.api.content.types
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -23864,7 +23864,7 @@ spec:
key: controller.ignore.normalizer.jq.timeout
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: argocd-application-controller
ports:
Expand Down
12 changes: 6 additions & 6 deletions manifests/ha/namespace-install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /shared/argocd-dex
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: copyutil
securityContext:
Expand Down Expand Up @@ -1812,7 +1812,7 @@ spec:
- argocd
- admin
- redis-initial-password
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: IfNotPresent
name: secret-init
securityContext:
Expand Down Expand Up @@ -2095,7 +2095,7 @@ spec:
value: /helm-working-dir
- name: HELM_DATA_HOME
value: /helm-working-dir
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
Expand Down Expand Up @@ -2147,7 +2147,7 @@ spec:
- -n
- /usr/local/bin/argocd
- /var/run/argocd/argocd-cmp-server
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
name: copyutil
securityContext:
allowPrivilegeEscalation: false
Expand Down Expand Up @@ -2477,7 +2477,7 @@ spec:
key: server.api.content.types
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
livenessProbe:
httpGet:
Expand Down Expand Up @@ -2776,7 +2776,7 @@ spec:
key: controller.ignore.normalizer.jq.timeout
name: argocd-cmd-params-cm
optional: true
image: quay.io/codefresh/argocd:v2.12-2024.10.16-ae9bb9622
image: quay.io/codefresh/argocd:latest
imagePullPolicy: Always
name: argocd-application-controller
ports:
Expand Down
Loading

0 comments on commit 36fb3f0

Please sign in to comment.