diff --git a/cmd/flux/alert.go b/cmd/flux/alert.go index ea8012b968cab3be972d4a4af080934b9897e1b4..a0a5b0e6ad7c15a4f7933e2a818ec83db28b9434 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 fb7cb063ca6edcb23a3f3d21865b818a2f65fb86..d434ffacf60854555f386e2cbab7b532219f1279 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 c4ae564a7640782cd70d1c97f6b79744bec7b79f..81deb149d05e0aa77177653d24b68844f2dfce21 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 b54aa25de733338532073ce1da8612b156b2d49c..4659788bfa2c57a93bdc74dba3fd480d2b63c969 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 1151b7aa0ab322d923f31ac5956936c8994a9d26..0c13f7f5a175d6820092ab3f0b4169df7c41052d 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 0c68fcbab687f6f5847ecfc3f3eed1d1fd889215..26b3a0404776bd519af2e1a22afd2bd07e985835 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 9266e99a9d43a2c6c6db3fe4d581cd6cc7f5fe12..7fa5db77158f7d0b6d8e3f7b4a733c8d19c29f11 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 c3e53a73c80955898d6acc18da32e54731428b3b..5c56ea634f54e3cbaeea3b401b010fdb3f4dea4f 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 4eff1ee8a066d070d1a42d19bc81654bb8e3f86d..6186d5d6f1a012495f341ae8479b94f98a96599f 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 29dce7d5eb3539558be7583e7d8f90f22d770e64..d5c721bc69d1931686cfa1676c6b9cef013d345c 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 8ef80f6e3b842b32120e9c291dcc920a5b3bac06..f481ce670535d3a829ccd8bbfc35dafae6e61533 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 ad9727fe193ff42863dd06cf7ba929cefe63a4d3..38672988786da316ea15c7656a4c4732a07e7ae0 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 d2f36d247a76038ae2566fdc3c2b08db5fde7202..894a1ad2cfc5096d548ed23fac9bd529ec552259 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 2142286d370fac6af8bc4a6377effaf49ca5c068..d12a671f0c8b74c56fce4e90fce4436ac3d20ae0 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 e24cd12582a1c34f41f520d16f95b8ce30cf69e7..a59e904d50502ea10c570f0423b4e71bd5fdbd5d 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 8a30f2a4d4cf26e746d8dbf3ce3f46bce92cf41f..f82cd8acbc872e6de84e0ed88dd54d6249794ae5 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