Skip to content

Commit 34cf002

Browse files
Merge pull request #508 from sector2000/fix-app-reconcile
Fixed reconciliation conditions
2 parents e070b60 + 93ee57b commit 34cf002

2 files changed

Lines changed: 242 additions & 126 deletions

File tree

internal/controller/argo.go

Lines changed: 112 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,87 @@ 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+
if goal.AllowEmpty != actual.AllowEmpty {
982+
log.Printf("SyncPolicy AllowEmpty changed %t -> %t\n", actual.AllowEmpty, goal.AllowEmpty)
983+
return false
984+
}
985+
if goal.SelfHeal != actual.SelfHeal {
986+
log.Printf("SyncPolicy SelfHeal changed %t -> %t\n", actual.SelfHeal, goal.SelfHeal)
987+
return false
988+
}
989+
return true
990+
}
991+
992+
func compareSyncOptions(goal, actual argoapi.SyncOptions) bool {
993+
if goal == nil && actual == nil {
994+
return true
995+
}
996+
if (goal == nil) != (actual == nil) {
997+
return false
998+
}
999+
if len(goal) != len(actual) {
1000+
return false
1001+
}
1002+
for i, gS := range goal {
1003+
if gS != actual[i] {
1004+
log.Printf("SyncOption at position %d changed: %s -> %s\n", i, actual[i], gS)
1005+
return false
1006+
}
1007+
}
1008+
return true
1009+
}
1010+
9411011
func compareSource(goal, actual *argoapi.ApplicationSource) bool {
942-
if goal == nil || actual == nil {
1012+
if goal == nil && actual == nil {
1013+
return true
1014+
}
1015+
if (goal == nil) != (actual == nil) {
9431016
return false
9441017
}
9451018
if goal.RepoURL != actual.RepoURL {
@@ -971,7 +1044,10 @@ func compareSource(goal, actual *argoapi.ApplicationSource) bool {
9711044
}
9721045

9731046
func compareSources(goal, actual argoapi.ApplicationSources) bool {
974-
if actual == nil || goal == nil {
1047+
if goal == nil && actual == nil {
1048+
return true
1049+
}
1050+
if (goal == nil) != (actual == nil) {
9751051
return false
9761052
}
9771053
if len(actual) != len(goal) {
@@ -1000,49 +1076,46 @@ func compareHelmSource(goal, actual *argoapi.ApplicationSourceHelm) bool {
10001076
return true
10011077
}
10021078

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-
10171079
func compareHelmParameters(goal, actual []argoapi.HelmParameter) bool {
1080+
if goal == nil && actual == nil {
1081+
return true
1082+
}
1083+
if (goal == nil) != (actual == nil) {
1084+
return false
1085+
}
10181086
if len(goal) != len(actual) {
10191087
return false
10201088
}
1021-
1022-
for _, gP := range goal {
1023-
if !compareHelmParameter(gP, actual) {
1089+
for i, gP := range goal {
1090+
if gP.Name != actual[i].Name {
1091+
log.Printf("Helm parameter at position %d changed: %s -> %s\n", i, actual[i].Name, gP.Name)
10241092
return false
10251093
}
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
1094+
if gP.Value != actual[i].Value {
1095+
log.Printf("Helm parameter %s changed: %s -> %s\n", actual[i].Name, actual[i].Value, gP.Value)
1096+
return false
1097+
}
1098+
if gP.ForceString != actual[i].ForceString {
1099+
log.Printf("ForceString for Helm parameter %s changed: %t -> %t\n", actual[i].Name, actual[i].ForceString, gP.ForceString)
1100+
return false
10341101
}
10351102
}
1036-
log.Printf("Values file %q not found", goal)
1037-
return false
1103+
return true
10381104
}
10391105

10401106
func compareHelmValueFiles(goal, actual []string) bool {
1107+
if goal == nil && actual == nil {
1108+
return true
1109+
}
1110+
if (goal == nil) != (actual == nil) {
1111+
return false
1112+
}
10411113
if len(goal) != len(actual) {
10421114
return false
10431115
}
1044-
for _, gV := range goal {
1045-
if !compareHelmValueFile(gV, actual) {
1116+
for i, gV := range goal {
1117+
if gV != actual[i] {
1118+
log.Printf("ValueFile at position %d changed: %s -> %s\n", i, actual[i], gV)
10461119
return false
10471120
}
10481121
}

0 commit comments

Comments
 (0)