diff --git a/cmd/flux/alert.go b/cmd/flux/alert.go index ea8012b9..a0a5b0e6 100644 --- a/cmd/flux/alert.go +++ b/cmd/flux/alert.go @@ -25,8 +25,9 @@ import ( // notificationv1.Alert var alertType = apiType{ - kind: notificationv1.AlertKind, - humanKind: "alert", + kind: notificationv1.AlertKind, + humanKind: "alert", + groupVersion: notificationv1.GroupVersion, } type alertAdapter struct { diff --git a/cmd/flux/alert_provider.go b/cmd/flux/alert_provider.go index fb7cb063..d434ffac 100644 --- a/cmd/flux/alert_provider.go +++ b/cmd/flux/alert_provider.go @@ -25,8 +25,9 @@ import ( // notificationv1.Provider var alertProviderType = apiType{ - kind: notificationv1.ProviderKind, - humanKind: "alert provider", + kind: notificationv1.ProviderKind, + humanKind: "alert provider", + groupVersion: notificationv1.GroupVersion, } type alertProviderAdapter struct { diff --git a/cmd/flux/helmrelease.go b/cmd/flux/helmrelease.go index c4ae564a..81deb149 100644 --- a/cmd/flux/helmrelease.go +++ b/cmd/flux/helmrelease.go @@ -25,8 +25,9 @@ import ( // helmv2.HelmRelease var helmReleaseType = apiType{ - kind: helmv2.HelmReleaseKind, - humanKind: "helmreleases", + kind: helmv2.HelmReleaseKind, + humanKind: "helmrelease", + groupVersion: helmv2.GroupVersion, } type helmReleaseAdapter struct { diff --git a/cmd/flux/image.go b/cmd/flux/image.go index b54aa25d..4659788b 100644 --- a/cmd/flux/image.go +++ b/cmd/flux/image.go @@ -30,8 +30,9 @@ import ( // imagev1.ImageRepository var imageRepositoryType = apiType{ - kind: imagev1.ImageRepositoryKind, - humanKind: "image repository", + kind: imagev1.ImageRepositoryKind, + humanKind: "image repository", + groupVersion: imagev1.GroupVersion, } type imageRepositoryAdapter struct { @@ -63,8 +64,9 @@ func (a imageRepositoryListAdapter) len() int { // imagev1.ImagePolicy var imagePolicyType = apiType{ - kind: imagev1.ImagePolicyKind, - humanKind: "image policy", + kind: imagev1.ImagePolicyKind, + humanKind: "image policy", + groupVersion: imagev1.GroupVersion, } type imagePolicyAdapter struct { @@ -92,8 +94,9 @@ func (a imagePolicyListAdapter) len() int { // autov1.ImageUpdateAutomation var imageUpdateAutomationType = apiType{ - kind: autov1.ImageUpdateAutomationKind, - humanKind: "image update automation", + kind: autov1.ImageUpdateAutomationKind, + humanKind: "image update automation", + groupVersion: autov1.GroupVersion, } type imageUpdateAutomationAdapter struct { diff --git a/cmd/flux/kustomization.go b/cmd/flux/kustomization.go index 1151b7aa..0c13f7f5 100644 --- a/cmd/flux/kustomization.go +++ b/cmd/flux/kustomization.go @@ -25,8 +25,9 @@ import ( // kustomizev1.Kustomization var kustomizationType = apiType{ - kind: kustomizev1.KustomizationKind, - humanKind: "kustomizations", + kind: kustomizev1.KustomizationKind, + humanKind: "kustomization", + groupVersion: kustomizev1.GroupVersion, } type kustomizationAdapter struct { diff --git a/cmd/flux/object.go b/cmd/flux/object.go index 0c68fcba..26b3a040 100644 --- a/cmd/flux/object.go +++ b/cmd/flux/object.go @@ -28,6 +28,7 @@ import ( // implementation can pick whichever it wants to use. type apiType struct { kind, humanKind string + groupVersion schema.GroupVersion } // adapter is an interface for a wrapper or alias from which we can diff --git a/cmd/flux/receiver.go b/cmd/flux/receiver.go index 9266e99a..7fa5db77 100644 --- a/cmd/flux/receiver.go +++ b/cmd/flux/receiver.go @@ -25,8 +25,9 @@ import ( // notificationv1.Receiver var receiverType = apiType{ - kind: notificationv1.ReceiverKind, - humanKind: "receiver", + kind: notificationv1.ReceiverKind, + humanKind: "receiver", + groupVersion: notificationv1.GroupVersion, } type receiverAdapter struct { diff --git a/cmd/flux/reconcile.go b/cmd/flux/reconcile.go index c3e53a73..5c56ea63 100644 --- a/cmd/flux/reconcile.go +++ b/cmd/flux/reconcile.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/cobra" apimeta "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/util/retry" @@ -95,7 +96,8 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error { } logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, *kubeconfigArgs.Namespace) - if err := requestReconciliation(ctx, kubeClient, namespacedName, reconcile.object); err != nil { + if err := requestReconciliation(ctx, kubeClient, namespacedName, + reconcile.groupVersion.WithKind(reconcile.kind)); err != nil { return err } logger.Successf("%s annotated", reconcile.kind) @@ -142,21 +144,25 @@ func reconciliationHandled(ctx context.Context, kubeClient client.Client, } func requestReconciliation(ctx context.Context, kubeClient client.Client, - namespacedName types.NamespacedName, obj reconcilable) error { + namespacedName types.NamespacedName, gvk schema.GroupVersionKind) error { return retry.RetryOnConflict(retry.DefaultBackoff, func() (err error) { - if err := kubeClient.Get(ctx, namespacedName, obj.asClientObject()); err != nil { + object := &metav1.PartialObjectMetadata{} + object.SetGroupVersionKind(gvk) + object.SetName(namespacedName.Name) + object.SetNamespace(namespacedName.Namespace) + if err := kubeClient.Get(ctx, namespacedName, object); err != nil { return err } - patch := client.MergeFrom(obj.deepCopyClientObject()) - if ann := obj.GetAnnotations(); ann == nil { - obj.SetAnnotations(map[string]string{ + patch := client.MergeFrom(object.DeepCopy()) + if ann := object.GetAnnotations(); ann == nil { + object.SetAnnotations(map[string]string{ meta.ReconcileRequestAnnotation: time.Now().Format(time.RFC3339Nano), }) } else { ann[meta.ReconcileRequestAnnotation] = time.Now().Format(time.RFC3339Nano) - obj.SetAnnotations(ann) + object.SetAnnotations(ann) } - return kubeClient.Patch(ctx, obj.asClientObject(), patch) + return kubeClient.Patch(ctx, object, patch) }) } diff --git a/cmd/flux/reconcile_with_source.go b/cmd/flux/reconcile_with_source.go index 4eff1ee8..6186d5d6 100644 --- a/cmd/flux/reconcile_with_source.go +++ b/cmd/flux/reconcile_with_source.go @@ -71,7 +71,8 @@ func (reconcile reconcileWithSourceCommand) run(cmd *cobra.Command, args []strin lastHandledReconcileAt := reconcile.object.lastHandledReconcileRequest() logger.Actionf("annotating %s %s in %s namespace", reconcile.kind, name, *kubeconfigArgs.Namespace) - if err := requestReconciliation(ctx, kubeClient, namespacedName, reconcile.object); err != nil { + if err := requestReconciliation(ctx, kubeClient, namespacedName, + reconcile.groupVersion.WithKind(reconcile.kind)); err != nil { return err } logger.Successf("%s annotated", reconcile.kind) diff --git a/cmd/flux/source.go b/cmd/flux/source.go index 29dce7d5..d5c721bc 100644 --- a/cmd/flux/source.go +++ b/cmd/flux/source.go @@ -29,8 +29,9 @@ import ( // sourcev1.Bucket var bucketType = apiType{ - kind: sourcev1.BucketKind, - humanKind: "source bucket", + kind: sourcev1.BucketKind, + humanKind: "source bucket", + groupVersion: sourcev1.GroupVersion, } type bucketAdapter struct { @@ -62,8 +63,9 @@ func (a bucketListAdapter) len() int { // sourcev1.HelmChart var helmChartType = apiType{ - kind: sourcev1.HelmChartKind, - humanKind: "source chart", + kind: sourcev1.HelmChartKind, + humanKind: "source chart", + groupVersion: sourcev1.GroupVersion, } type helmChartAdapter struct { @@ -95,8 +97,9 @@ func (a helmChartListAdapter) len() int { // sourcev1.GitRepository var gitRepositoryType = apiType{ - kind: sourcev1.GitRepositoryKind, - humanKind: "source git", + kind: sourcev1.GitRepositoryKind, + humanKind: "source git", + groupVersion: sourcev1.GroupVersion, } type gitRepositoryAdapter struct { @@ -128,8 +131,9 @@ func (a gitRepositoryListAdapter) len() int { // sourcev1.HelmRepository var helmRepositoryType = apiType{ - kind: sourcev1.HelmRepositoryKind, - humanKind: "source helm", + kind: sourcev1.HelmRepositoryKind, + humanKind: "source helm", + groupVersion: sourcev1.GroupVersion, } type helmRepositoryAdapter struct { diff --git a/cmd/flux/testdata/helmrelease/delete_helmrelease_from_git.golden b/cmd/flux/testdata/helmrelease/delete_helmrelease_from_git.golden index 8ef80f6e..f481ce67 100644 --- a/cmd/flux/testdata/helmrelease/delete_helmrelease_from_git.golden +++ b/cmd/flux/testdata/helmrelease/delete_helmrelease_from_git.golden @@ -1,2 +1,2 @@ -► deleting helmreleases thrfg in {{ .ns }} namespace -✔ helmreleases deleted +► deleting helmrelease thrfg in {{ .ns }} namespace +✔ helmrelease deleted diff --git a/cmd/flux/testdata/helmrelease/resume_helmrelease_from_git.golden b/cmd/flux/testdata/helmrelease/resume_helmrelease_from_git.golden index ad9727fe..38672988 100644 --- a/cmd/flux/testdata/helmrelease/resume_helmrelease_from_git.golden +++ b/cmd/flux/testdata/helmrelease/resume_helmrelease_from_git.golden @@ -1,5 +1,5 @@ -► resuming helmreleases thrfg in {{ .ns }} namespace -✔ helmreleases resumed +► resuming helmrelease thrfg in {{ .ns }} namespace +✔ helmrelease resumed ◎ waiting for HelmRelease reconciliation ✔ HelmRelease reconciliation completed ✔ applied revision 6.0.0 diff --git a/cmd/flux/testdata/helmrelease/suspend_helmrelease_from_git.golden b/cmd/flux/testdata/helmrelease/suspend_helmrelease_from_git.golden index d2f36d24..894a1ad2 100644 --- a/cmd/flux/testdata/helmrelease/suspend_helmrelease_from_git.golden +++ b/cmd/flux/testdata/helmrelease/suspend_helmrelease_from_git.golden @@ -1,2 +1,2 @@ -► suspending helmreleases thrfg in {{ .ns }} namespace -✔ helmreleases suspended +► suspending helmrelease thrfg in {{ .ns }} namespace +✔ helmrelease suspended diff --git a/cmd/flux/testdata/kustomization/delete_kustomization_from_git.golden b/cmd/flux/testdata/kustomization/delete_kustomization_from_git.golden index 2142286d..d12a671f 100644 --- a/cmd/flux/testdata/kustomization/delete_kustomization_from_git.golden +++ b/cmd/flux/testdata/kustomization/delete_kustomization_from_git.golden @@ -1,2 +1,2 @@ -► deleting kustomizations tkfg in {{ .ns }} namespace -✔ kustomizations deleted +► deleting kustomization tkfg in {{ .ns }} namespace +✔ kustomization deleted diff --git a/cmd/flux/testdata/kustomization/resume_kustomization_from_git.golden b/cmd/flux/testdata/kustomization/resume_kustomization_from_git.golden index e24cd125..a59e904d 100644 --- a/cmd/flux/testdata/kustomization/resume_kustomization_from_git.golden +++ b/cmd/flux/testdata/kustomization/resume_kustomization_from_git.golden @@ -1,5 +1,5 @@ -► resuming kustomizations tkfg in {{ .ns }} namespace -✔ kustomizations resumed +► resuming kustomization tkfg in {{ .ns }} namespace +✔ kustomization resumed ◎ waiting for Kustomization reconciliation ✔ Kustomization reconciliation completed ✔ applied revision 6.0.0/627d5c4bb67b77185f37e31d734b085019ff2951 diff --git a/cmd/flux/testdata/kustomization/suspend_kustomization_from_git.golden b/cmd/flux/testdata/kustomization/suspend_kustomization_from_git.golden index 8a30f2a4..f82cd8ac 100644 --- a/cmd/flux/testdata/kustomization/suspend_kustomization_from_git.golden +++ b/cmd/flux/testdata/kustomization/suspend_kustomization_from_git.golden @@ -1,2 +1,2 @@ -► suspending kustomizations tkfg in {{ .ns }} namespace -✔ kustomizations suspended +► suspending kustomization tkfg in {{ .ns }} namespace +✔ kustomization suspended