From 0ba9db560bff5f9ee7de240b3b55e57eecf5df6f Mon Sep 17 00:00:00 2001 From: Travis Mattera Date: Wed, 13 Sep 2023 11:00:51 -0700 Subject: [PATCH] Sets the flux cli `suspend` command `--reason` flag to an empty string as default and changes the flux resource suspend behavior to only apply the suspend reason annotation when a non-empty reason is provided. Signed-off-by: Travis Mattera --- cmd/flux/suspend.go | 2 +- cmd/flux/suspend_alert.go | 4 +++- cmd/flux/suspend_helmrelease.go | 4 +++- cmd/flux/suspend_image_repository.go | 4 +++- cmd/flux/suspend_image_updateauto.go | 4 +++- cmd/flux/suspend_kustomization.go | 4 +++- cmd/flux/suspend_receiver.go | 4 +++- cmd/flux/suspend_source_bucket.go | 4 +++- cmd/flux/suspend_source_chart.go | 4 +++- cmd/flux/suspend_source_git.go | 4 +++- cmd/flux/suspend_source_helm.go | 4 +++- cmd/flux/suspend_source_oci.go | 4 +++- 12 files changed, 34 insertions(+), 12 deletions(-) diff --git a/cmd/flux/suspend.go b/cmd/flux/suspend.go index 0ab7a917..5ac2ac37 100644 --- a/cmd/flux/suspend.go +++ b/cmd/flux/suspend.go @@ -43,7 +43,7 @@ var suspendArgs SuspendFlags func init() { suspendCmd.PersistentFlags().BoolVarP(&suspendArgs.all, "all", "", false, "suspend all resources in that namespace") - suspendCmd.PersistentFlags().StringVarP(&suspendArgs.reason, "reason", "r", "suspended", + suspendCmd.PersistentFlags().StringVarP(&suspendArgs.reason, "reason", "r", "", "set a reason for why the resource is suspended, the reason will show up under the suspend.toolkit.fluxcd.io/reason annotation") rootCmd.AddCommand(suspendCmd) } diff --git a/cmd/flux/suspend_alert.go b/cmd/flux/suspend_alert.go index 87262765..be750c9f 100644 --- a/cmd/flux/suspend_alert.go +++ b/cmd/flux/suspend_alert.go @@ -49,7 +49,9 @@ func (obj alertAdapter) isSuspended() bool { func (obj alertAdapter) setSuspended(reason string) { obj.Alert.Spec.Suspend = true - obj.Alert.Annotations[SuspendReasonAnnotation] = reason + if reason != "" { + obj.Alert.Annotations[SuspendReasonAnnotation] = reason + } } func (a alertListAdapter) item(i int) suspendable { diff --git a/cmd/flux/suspend_helmrelease.go b/cmd/flux/suspend_helmrelease.go index 88d78742..8bfd3731 100644 --- a/cmd/flux/suspend_helmrelease.go +++ b/cmd/flux/suspend_helmrelease.go @@ -50,7 +50,9 @@ func (obj helmReleaseAdapter) isSuspended() bool { func (obj helmReleaseAdapter) setSuspended(reason string) { obj.HelmRelease.Spec.Suspend = true - obj.HelmRelease.Annotations[SuspendReasonAnnotation] = reason + if reason != "" { + obj.HelmRelease.Annotations[SuspendReasonAnnotation] = reason + } } func (a helmReleaseListAdapter) item(i int) suspendable { diff --git a/cmd/flux/suspend_image_repository.go b/cmd/flux/suspend_image_repository.go index 3b9f901c..83cdd127 100644 --- a/cmd/flux/suspend_image_repository.go +++ b/cmd/flux/suspend_image_repository.go @@ -49,7 +49,9 @@ func (obj imageRepositoryAdapter) isSuspended() bool { func (obj imageRepositoryAdapter) setSuspended(reason string) { obj.ImageRepository.Spec.Suspend = true - obj.ImageRepository.Annotations[SuspendReasonAnnotation] = reason + if reason != "" { + obj.ImageRepository.Annotations[SuspendReasonAnnotation] = reason + } } func (a imageRepositoryListAdapter) item(i int) suspendable { diff --git a/cmd/flux/suspend_image_updateauto.go b/cmd/flux/suspend_image_updateauto.go index 5649fa4e..89295b5b 100644 --- a/cmd/flux/suspend_image_updateauto.go +++ b/cmd/flux/suspend_image_updateauto.go @@ -49,7 +49,9 @@ func (update imageUpdateAutomationAdapter) isSuspended() bool { func (update imageUpdateAutomationAdapter) setSuspended(reason string) { update.ImageUpdateAutomation.Spec.Suspend = true - update.ImageUpdateAutomation.Annotations[SuspendReasonAnnotation] = reason + if reason != "" { + update.ImageUpdateAutomation.Annotations[SuspendReasonAnnotation] = reason + } } func (a imageUpdateAutomationListAdapter) item(i int) suspendable { diff --git a/cmd/flux/suspend_kustomization.go b/cmd/flux/suspend_kustomization.go index 7689c904..b0ec1b8b 100644 --- a/cmd/flux/suspend_kustomization.go +++ b/cmd/flux/suspend_kustomization.go @@ -50,7 +50,9 @@ func (obj kustomizationAdapter) isSuspended() bool { func (obj kustomizationAdapter) setSuspended(reason string) { obj.Kustomization.Spec.Suspend = true - obj.Kustomization.Annotations[SuspendReasonAnnotation] = reason + if reason != "" { + obj.Kustomization.Annotations[SuspendReasonAnnotation] = reason + } } func (a kustomizationListAdapter) item(i int) suspendable { diff --git a/cmd/flux/suspend_receiver.go b/cmd/flux/suspend_receiver.go index b512238b..57ceb1d0 100644 --- a/cmd/flux/suspend_receiver.go +++ b/cmd/flux/suspend_receiver.go @@ -49,7 +49,9 @@ func (obj receiverAdapter) isSuspended() bool { func (obj receiverAdapter) setSuspended(reason string) { obj.Receiver.Spec.Suspend = true - obj.Receiver.Annotations[SuspendReasonAnnotation] = reason + if reason != "" { + obj.Receiver.Annotations[SuspendReasonAnnotation] = reason + } } func (a receiverListAdapter) item(i int) suspendable { diff --git a/cmd/flux/suspend_source_bucket.go b/cmd/flux/suspend_source_bucket.go index 1a625f3f..55eef2c4 100644 --- a/cmd/flux/suspend_source_bucket.go +++ b/cmd/flux/suspend_source_bucket.go @@ -49,7 +49,9 @@ func (obj bucketAdapter) isSuspended() bool { func (obj bucketAdapter) setSuspended(reason string) { obj.Bucket.Spec.Suspend = true - obj.Bucket.Annotations[SuspendReasonAnnotation] = reason + if reason != "" { + obj.Bucket.Annotations[SuspendReasonAnnotation] = reason + } } func (a bucketListAdapter) item(i int) suspendable { diff --git a/cmd/flux/suspend_source_chart.go b/cmd/flux/suspend_source_chart.go index aeccf034..f8d471ed 100644 --- a/cmd/flux/suspend_source_chart.go +++ b/cmd/flux/suspend_source_chart.go @@ -49,7 +49,9 @@ func (obj helmChartAdapter) isSuspended() bool { func (obj helmChartAdapter) setSuspended(reason string) { obj.HelmChart.Spec.Suspend = true - obj.HelmChart.Annotations[SuspendReasonAnnotation] = reason + if reason != "" { + obj.HelmChart.Annotations[SuspendReasonAnnotation] = reason + } } func (a helmChartListAdapter) item(i int) suspendable { diff --git a/cmd/flux/suspend_source_git.go b/cmd/flux/suspend_source_git.go index a40cdb05..f379ab8e 100644 --- a/cmd/flux/suspend_source_git.go +++ b/cmd/flux/suspend_source_git.go @@ -49,7 +49,9 @@ func (obj gitRepositoryAdapter) isSuspended() bool { func (obj gitRepositoryAdapter) setSuspended(reason string) { obj.GitRepository.Spec.Suspend = true - obj.GitRepository.Annotations[SuspendReasonAnnotation] = reason + if reason != "" { + obj.GitRepository.Annotations[SuspendReasonAnnotation] = reason + } } func (a gitRepositoryListAdapter) item(i int) suspendable { diff --git a/cmd/flux/suspend_source_helm.go b/cmd/flux/suspend_source_helm.go index 6b7a7669..56e883ed 100644 --- a/cmd/flux/suspend_source_helm.go +++ b/cmd/flux/suspend_source_helm.go @@ -49,7 +49,9 @@ func (obj helmRepositoryAdapter) isSuspended() bool { func (obj helmRepositoryAdapter) setSuspended(reason string) { obj.HelmRepository.Spec.Suspend = true - obj.HelmRepository.Annotations[SuspendReasonAnnotation] = reason + if reason != "" { + obj.HelmRepository.Annotations[SuspendReasonAnnotation] = reason + } } func (a helmRepositoryListAdapter) item(i int) suspendable { diff --git a/cmd/flux/suspend_source_oci.go b/cmd/flux/suspend_source_oci.go index e756b06f..07fa2a4f 100644 --- a/cmd/flux/suspend_source_oci.go +++ b/cmd/flux/suspend_source_oci.go @@ -49,7 +49,9 @@ func (obj ociRepositoryAdapter) isSuspended() bool { func (obj ociRepositoryAdapter) setSuspended(reason string) { obj.OCIRepository.Spec.Suspend = true - obj.OCIRepository.Annotations[SuspendReasonAnnotation] = reason + if reason != "" { + obj.OCIRepository.Annotations[SuspendReasonAnnotation] = reason + } } func (a ociRepositoryListAdapter) item(i int) suspendable {