From 0ec5ac18a307ae579787b974e17f3e4c0bf41cff Mon Sep 17 00:00:00 2001 From: RaviHari Date: Fri, 29 Jul 2022 21:22:52 +0530 Subject: [PATCH] fix: Failed to process: Object 'Kind' is missing in Errors with rollouts notification (#2150) * fix: update rolloutobject with gvk before writing to rollout informer Signed-off-by: Ravi Hari * fix: controller schema linting Signed-off-by: Ravi Hari * docs: comment the details on the change Signed-off-by: Ravi Hari * docs: comment the details on the change Signed-off-by: Ravi Hari --- rollout/controller.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rollout/controller.go b/rollout/controller.go index eaece46ce7..e314adf4af 100644 --- a/rollout/controller.go +++ b/rollout/controller.go @@ -8,6 +8,9 @@ import ( "strconv" "time" + "k8s.io/apimachinery/pkg/runtime/schema" + + "github.com/argoproj/argo-rollouts/pkg/apis/rollouts" smiclientset "github.com/servicemeshinterface/smi-sdk-go/pkg/gen/client/split/clientset/versioned" log "github.com/sirupsen/logrus" appsv1 "k8s.io/api/apps/v1" @@ -421,6 +424,19 @@ func (c *Controller) writeBackToInformer(ro *v1alpha1.Rollout) { return } un := unstructured.Unstructured{Object: obj} + // With code-gen tools the argoclientset is generated and the update method here is removing typemetafields + // which the notification controller expects when it converts rolloutobject to toUnstructured and if not present + // and that throws an error "Failed to process: Object 'Kind' is missing in ..." + // Fixing this here as the informer is shared by notification controller by updating typemetafileds. + // TODO: Need to revisit this in the future and maybe we should have a dedicated informer for notification + gvk := un.GetObjectKind().GroupVersionKind() + if len(gvk.Version) == 0 || len(gvk.Group) == 0 || len(gvk.Kind) == 0 { + un.GetObjectKind().SetGroupVersionKind(schema.GroupVersionKind{ + Group: v1alpha1.SchemeGroupVersion.Group, + Kind: rollouts.RolloutKind, + Version: v1alpha1.SchemeGroupVersion.Version, + }) + } err = c.rolloutsInformer.GetStore().Update(&un) if err != nil { logCtx.Errorf("failed to update informer store: %v", err)