Skip to content

Commit

Permalink
[2.6] fix branch and rev info of Flux v2
Browse files Browse the repository at this point in the history
Signed-off-by: Chanwit Kaewkasi <chanwit@gmail.com>
  • Loading branch information
chanwit committed May 13, 2023
1 parent ad214a4 commit 04f9c84
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ argo-cd/
gitops-engine/

VERSION
patches-argo-cd
patches-argo-cd
patches-gitops-engine
86 changes: 86 additions & 0 deletions patches-argo-cd-v2.6/15-fix-branch-and-rev-info-of.patch
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]})
+ }
+ }
}
}
}
1 change: 1 addition & 0 deletions patches-argo-cd-v2.6/series
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
12-change-logo-to-flamingo.patch
13-add-open-in-weave-gitops.patch
14-upgrade-to-flux-v2-0-0-rc-1.patch
15-fix-branch-and-rev-info-of.patch

0 comments on commit 04f9c84

Please sign in to comment.