diff --git a/cmd/flux/get_kustomization.go b/cmd/flux/get_kustomization.go index a6f1eb6a..d2991e93 100644 --- a/cmd/flux/get_kustomization.go +++ b/cmd/flux/get_kustomization.go @@ -18,10 +18,12 @@ package main import ( "fmt" + "regexp" "strconv" "strings" "github.com/spf13/cobra" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" kustomizev1 "github.com/fluxcd/kustomize-controller/api/v1beta2" @@ -78,6 +80,10 @@ func (a kustomizationListAdapter) summariseItem(i int, includeNamespace bool, in item := a.Items[i] revision := item.Status.LastAppliedRevision status, msg := statusAndMessage(item.Status.Conditions) + if status == string(metav1.ConditionTrue) { + revision = shortenCommitSha(revision) + msg = shortenCommitSha(msg) + } return append(nameColumns(&item, includeNamespace, includeKind), status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend))) } @@ -94,3 +100,13 @@ func (a kustomizationListAdapter) statusSelectorMatches(i int, conditionType, co item := a.Items[i] return statusMatches(conditionType, conditionStatus, item.Status.Conditions) } + +func shortenCommitSha(msg string) string { + r := regexp.MustCompile("/([a-f0-9]{40})$") + sha := r.FindString(msg) + if sha != "" { + msg = strings.Replace(msg, sha, string([]rune(sha)[:8]), -1) + } + + return msg +} diff --git a/cmd/flux/get_source_git.go b/cmd/flux/get_source_git.go index 31a8e5bd..95b8ab4f 100644 --- a/cmd/flux/get_source_git.go +++ b/cmd/flux/get_source_git.go @@ -22,6 +22,7 @@ import ( "strings" "github.com/spf13/cobra" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" sourcev1 "github.com/fluxcd/source-controller/api/v1beta1" @@ -80,6 +81,10 @@ func (a *gitRepositoryListAdapter) summariseItem(i int, includeNamespace bool, i revision = item.GetArtifact().Revision } status, msg := statusAndMessage(item.Status.Conditions) + if status == string(metav1.ConditionTrue) { + revision = shortenCommitSha(revision) + msg = shortenCommitSha(msg) + } return append(nameColumns(&item, includeNamespace, includeKind), status, msg, revision, strings.Title(strconv.FormatBool(item.Spec.Suspend))) } diff --git a/cmd/flux/testdata/kustomization/get_kustomization_from_git.golden b/cmd/flux/testdata/kustomization/get_kustomization_from_git.golden index 3c21df33..a613aa34 100644 --- a/cmd/flux/testdata/kustomization/get_kustomization_from_git.golden +++ b/cmd/flux/testdata/kustomization/get_kustomization_from_git.golden @@ -1,2 +1,2 @@ -NAME READY MESSAGE REVISION SUSPENDED -tkfg True Applied revision: 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 False +NAME READY MESSAGE REVISION SUSPENDED +tkfg True Applied revision: 6.0.0/627d5c4 6.0.0/627d5c4 False