-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[2.6] fix branch and rev info of Flux v2
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
- Loading branch information
Showing
3 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ argo-cd/ | |
gitops-engine/ | ||
|
||
VERSION | ||
patches-argo-cd | ||
patches-argo-cd | ||
patches-gitops-engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
fix branch and rev info of flux v2 | ||
|
||
From: Chanwit Kaewkasi <chanwit@gmail.com> | ||
|
||
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com> | ||
--- | ||
controller/cache/info.go | 58 ++++++++++++++++++++++++++++++++++++---------- | ||
1 file changed, 45 insertions(+), 13 deletions(-) | ||
|
||
diff --git a/controller/cache/info.go b/controller/cache/info.go | ||
index f97b04b4c..d9dbfa6e3 100644 | ||
--- a/controller/cache/info.go | ||
+++ b/controller/cache/info.go | ||
@@ -57,15 +57,31 @@ func populateNodeInfo(un *unstructured.Unstructured, res *ResourceInfo, customLa | ||
// TODO add Flux here | ||
case "source.toolkit.fluxcd.io": | ||
if revision, found, err := unstructured.NestedString(un.Object, "status", "artifact", "revision"); found && err == nil { | ||
- parts := strings.SplitN(revision, "/", 2) | ||
- if len(parts) == 1 { | ||
- if len(parts[0]) >= 8 { | ||
- res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Revision", Value: parts[0][0:8]}) | ||
+ if strings.Contains(revision, "/") { | ||
+ parts := strings.SplitN(revision, "/", 2) | ||
+ if len(parts) == 1 { | ||
+ if len(parts[0]) >= 8 { | ||
+ res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Revision", Value: parts[0][0:8]}) | ||
+ } | ||
+ } else if len(parts) == 2 { | ||
+ res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Branch", Value: parts[0]}) | ||
+ if len(parts[1]) >= 8 { | ||
+ res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Revision", Value: parts[1][0:8]}) | ||
+ } | ||
} | ||
- } else if len(parts) == 2 { | ||
- res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Branch", Value: parts[0]}) | ||
- if len(parts[1]) >= 8 { | ||
- res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Revision", Value: parts[1][0:8]}) | ||
+ } else if strings.Contains(revision, "@") { | ||
+ parts := strings.SplitN(revision, "@", 2) | ||
+ // v2.6@sha256:c7fd0cc69b924aa5f9a6928477311737e439ca1b9e444855b0377e8a8ec65bb5 | ||
+ if len(parts) == 2 { | ||
+ res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Tag", Value: parts[0]}) | ||
+ // split at : so => sha256 and c7fd0cc69b924aa5f9a6928477311737e439ca1b9e444855b0377e8a8ec65bb5 | ||
+ split := strings.SplitN(parts[1], ":", 2) | ||
+ if len(split) == 2 { | ||
+ // we discard the sha256 and only take the first 8 chars | ||
+ if len(split[1]) >= 8 { | ||
+ res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Revision", Value: split[1][0:8]}) | ||
+ } | ||
+ } | ||
} | ||
} | ||
} | ||
@@ -82,11 +98,27 @@ func populateNodeInfo(un *unstructured.Unstructured, res *ResourceInfo, customLa | ||
switch gvk.Kind { | ||
case "Kustomization", "Terraform": | ||
if revision, found, err := unstructured.NestedString(un.Object, "status", "lastAppliedRevision"); found && err == nil { | ||
- parts := strings.SplitN(revision, "/", 2) | ||
- if len(parts) == 2 { | ||
- res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Branch", Value: parts[0]}) | ||
- if len(parts[1]) >= 8 { | ||
- res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Revision", Value: parts[1][0:8]}) | ||
+ if strings.Contains(revision, "/") { | ||
+ parts := strings.SplitN(revision, "/", 2) | ||
+ if len(parts) == 2 { | ||
+ res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Branch", Value: parts[0]}) | ||
+ if len(parts[1]) >= 8 { | ||
+ res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Revision", Value: parts[1][0:8]}) | ||
+ } | ||
+ } | ||
+ } else if strings.Contains(revision, "@") { | ||
+ parts := strings.SplitN(revision, "@", 2) | ||
+ // v2.6@sha256:c7fd0cc69b924aa5f9a6928477311737e439ca1b9e444855b0377e8a8ec65bb5 | ||
+ if len(parts) == 2 { | ||
+ res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Tag", Value: parts[0]}) | ||
+ // split at : so => sha256 and c7fd0cc69b924aa5f9a6928477311737e439ca1b9e444855b0377e8a8ec65bb5 | ||
+ split := strings.SplitN(parts[1], ":", 2) | ||
+ if len(split) == 2 { | ||
+ // we discard the sha256 and only take the first 8 chars | ||
+ if len(split[1]) >= 8 { | ||
+ res.Info = append(res.Info, v1alpha1.InfoItem{Name: "Revision", Value: split[1][0:8]}) | ||
+ } | ||
+ } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters