Skip to content

Commit 02f0adc

Browse files
committed
Fixed reconciliation conditions:
- when syncPolicy changes - when order of helm parameters changes - when order of helm valueFiles changes
1 parent e070b60 commit 02f0adc

2 files changed

Lines changed: 212 additions & 126 deletions

File tree

internal/controller/argo.go

Lines changed: 104 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -916,14 +916,8 @@ func updateApplication(client argoclient.Interface, target, current *argoapi.App
916916
} else if target == nil {
917917
return false, fmt.Errorf("target application was nil")
918918
}
919-
if current.Spec.Sources == nil {
920-
if compareSource(target.Spec.Source, current.Spec.Source) {
921-
return false, nil
922-
}
923-
} else {
924-
if compareSources(target.Spec.Sources, current.Spec.Sources) {
925-
return false, nil
926-
}
919+
if compareApplication(current, target) {
920+
return false, nil
927921
}
928922

929923
spec := current.Spec.DeepCopy()
@@ -938,8 +932,79 @@ func removeApplication(client argoclient.Interface, name, namespace string) erro
938932
return client.ArgoprojV1alpha1().Applications(namespace).Delete(context.Background(), name, metav1.DeleteOptions{})
939933
}
940934

935+
func compareApplication(goal, actual *argoapi.Application) bool {
936+
if goal == nil && actual == nil {
937+
return true
938+
}
939+
if (goal == nil) != (actual == nil) {
940+
return false
941+
}
942+
if !compareSource(goal.Spec.Source, actual.Spec.Source) {
943+
return false
944+
}
945+
if !compareSources(goal.Spec.Sources, actual.Spec.Sources) {
946+
return false
947+
}
948+
if !compareSyncPolicy(goal.Spec.SyncPolicy, actual.Spec.SyncPolicy) {
949+
return false
950+
}
951+
return true
952+
}
953+
954+
func compareSyncPolicy(goal, actual *argoapi.SyncPolicy) bool {
955+
if goal == nil && actual == nil {
956+
return true
957+
}
958+
if (goal == nil) != (actual == nil) {
959+
return false
960+
}
961+
if !compareAutomatedSyncPolicy(goal.Automated, actual.Automated) {
962+
return false
963+
}
964+
if !compareSyncOptions(goal.SyncOptions, actual.SyncOptions) {
965+
return false
966+
}
967+
return true
968+
}
969+
970+
func compareAutomatedSyncPolicy(goal, actual *argoapi.SyncPolicyAutomated) bool {
971+
if goal == nil && actual == nil {
972+
return true
973+
}
974+
if (goal == nil) != (actual == nil) {
975+
return false
976+
}
977+
if goal.Prune != actual.Prune {
978+
log.Printf("SyncPolicy Prune changed %t -> %t\n", actual.Prune, goal.Prune)
979+
return false
980+
}
981+
return true
982+
}
983+
984+
func compareSyncOptions(goal, actual argoapi.SyncOptions) bool {
985+
if goal == nil && actual == nil {
986+
return true
987+
}
988+
if (goal == nil) != (actual == nil) {
989+
return false
990+
}
991+
if len(goal) != len(actual) {
992+
return false
993+
}
994+
for i, gS := range goal {
995+
if gS != actual[i] {
996+
log.Printf("SyncOption at position %d changed: %s -> %s\n", i, actual[i], gS)
997+
return false
998+
}
999+
}
1000+
return true
1001+
}
1002+
9411003
func compareSource(goal, actual *argoapi.ApplicationSource) bool {
942-
if goal == nil || actual == nil {
1004+
if goal == nil && actual == nil {
1005+
return true
1006+
}
1007+
if (goal == nil) != (actual == nil) {
9431008
return false
9441009
}
9451010
if goal.RepoURL != actual.RepoURL {
@@ -971,7 +1036,10 @@ func compareSource(goal, actual *argoapi.ApplicationSource) bool {
9711036
}
9721037

9731038
func compareSources(goal, actual argoapi.ApplicationSources) bool {
974-
if actual == nil || goal == nil {
1039+
if goal == nil && actual == nil {
1040+
return true
1041+
}
1042+
if (goal == nil) != (actual == nil) {
9751043
return false
9761044
}
9771045
if len(actual) != len(goal) {
@@ -1000,49 +1068,46 @@ func compareHelmSource(goal, actual *argoapi.ApplicationSourceHelm) bool {
10001068
return true
10011069
}
10021070

1003-
func compareHelmParameter(goal argoapi.HelmParameter, actual []argoapi.HelmParameter) bool {
1004-
for _, param := range actual {
1005-
if goal.Name == param.Name {
1006-
if goal.Value == param.Value {
1007-
return true
1008-
}
1009-
log.Printf("Parameter %q changed: %q -> %q", goal.Name, param.Value, goal.Value)
1010-
return false
1011-
}
1012-
}
1013-
log.Printf("Parameter %q not found", goal.Name)
1014-
return false
1015-
}
1016-
10171071
func compareHelmParameters(goal, actual []argoapi.HelmParameter) bool {
1072+
if goal == nil && actual == nil {
1073+
return true
1074+
}
1075+
if (goal == nil) != (actual == nil) {
1076+
return false
1077+
}
10181078
if len(goal) != len(actual) {
10191079
return false
10201080
}
1021-
1022-
for _, gP := range goal {
1023-
if !compareHelmParameter(gP, actual) {
1081+
for i, gP := range goal {
1082+
if gP.Name != actual[i].Name {
1083+
log.Printf("Helm parameter at position %d changed: %s -> %s\n", i, actual[i].Name, gP.Name)
10241084
return false
10251085
}
1026-
}
1027-
return true
1028-
}
1029-
1030-
func compareHelmValueFile(goal string, actual []string) bool {
1031-
for _, value := range actual {
1032-
if goal == value {
1033-
return true
1086+
if gP.Value != actual[i].Value {
1087+
log.Printf("Helm parameter %s changed: %s -> %s\n", actual[i].Name, actual[i].Value, gP.Value)
1088+
return false
1089+
}
1090+
if gP.ForceString != actual[i].ForceString {
1091+
log.Printf("ForceString for Helm parameter %s changed: %t -> %t\n", actual[i].Name, actual[i].ForceString, gP.ForceString)
1092+
return false
10341093
}
10351094
}
1036-
log.Printf("Values file %q not found", goal)
1037-
return false
1095+
return true
10381096
}
10391097

10401098
func compareHelmValueFiles(goal, actual []string) bool {
1099+
if goal == nil && actual == nil {
1100+
return true
1101+
}
1102+
if (goal == nil) != (actual == nil) {
1103+
return false
1104+
}
10411105
if len(goal) != len(actual) {
10421106
return false
10431107
}
1044-
for _, gV := range goal {
1045-
if !compareHelmValueFile(gV, actual) {
1108+
for i, gV := range goal {
1109+
if gV != actual[i] {
1110+
log.Printf("ValueFile at position %d changed: %s -> %s\n", i, actual[i], gV)
10461111
return false
10471112
}
10481113
}

0 commit comments

Comments
 (0)