From 3341e0f106db1ba1316cc95f342045e8c9dd99aa Mon Sep 17 00:00:00 2001 From: Sedef Date: Thu, 28 Jan 2021 11:59:25 -0500 Subject: [PATCH] Fix cluster resource set not getting Secret/Configmap TypeMeta with live client --- .../clusterresourceset_controller.go | 6 +++--- .../clusterresourceset_controller_test.go | 20 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/exp/addons/controllers/clusterresourceset_controller.go b/exp/addons/controllers/clusterresourceset_controller.go index 72a374b62b74..2ae2f19b37f9 100644 --- a/exp/addons/controllers/clusterresourceset_controller.go +++ b/exp/addons/controllers/clusterresourceset_controller.go @@ -386,16 +386,16 @@ func (r *ClusterResourceSetReconciler) getResource(resourceRef addonsv1.Resource if resourceSecret.Type != addonsv1.ClusterResourceSetSecretType { return nil, ErrSecretTypeNotSupported } - resourceInterface = resourceSecret.DeepCopyObject() } - raw, err := runtime.DefaultUnstructuredConverter.ToUnstructured(resourceInterface) + raw := &unstructured.Unstructured{} + err := r.scheme.Convert(resourceInterface, raw, nil) if err != nil { return nil, err } - return &unstructured.Unstructured{Object: raw}, nil + return raw, nil } // patchOwnerRefToResource adds the ClusterResourceSet as a OwnerReference to the resource. diff --git a/exp/addons/controllers/clusterresourceset_controller_test.go b/exp/addons/controllers/clusterresourceset_controller_test.go index 671a7d228b82..56759d9ff11a 100644 --- a/exp/addons/controllers/clusterresourceset_controller_test.go +++ b/exp/addons/controllers/clusterresourceset_controller_test.go @@ -18,6 +18,7 @@ package controllers import ( "fmt" + apierrors "k8s.io/apimachinery/pkg/api/errors" "time" "sigs.k8s.io/cluster-api/util" @@ -27,7 +28,6 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3" addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1alpha3" @@ -44,7 +44,7 @@ var _ = Describe("ClusterResourceSet Reconciler", func() { var clusterName string var configmapName = "test-configmap" - var configmap2Name = "test-configmap2" + var secretName = "test-secret" BeforeEach(func() { clusterName = fmt.Sprintf("cluster-%s", util.RandomString(6)) @@ -54,7 +54,6 @@ var _ = Describe("ClusterResourceSet Reconciler", func() { Expect(testEnv.Create(ctx, testCluster)).To(Succeed()) By("Creating the remote Cluster kubeconfig") Expect(testEnv.CreateKubeconfigSecret(testCluster)).To(Succeed()) - testConfigmap := &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ Name: configmapName, @@ -68,13 +67,14 @@ kind: ConfigMap apiVersion: v1`, }, } - - testConfigmap2 := &corev1.ConfigMap{ + testEnv.Create(ctx, testConfigmap) + testSecret := &corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ - Name: configmap2Name, + Name: secretName, Namespace: defaultNamespaceName, }, - Data: map[string]string{ + Type: "addons.cluster.x-k8s.io/resource-set", + StringData: map[string]string{ "cm": `metadata: kind: ConfigMap apiVersion: v1 @@ -85,7 +85,7 @@ metadata: } By("Creating 2 ConfigMaps with ConfigMap in their data field") testEnv.Create(ctx, testConfigmap) - testEnv.Create(ctx, testConfigmap2) + testEnv.Create(ctx, testSecret) }) AfterEach(func() { By("Deleting the Kubeconfigsecret") @@ -136,7 +136,7 @@ metadata: ClusterSelector: metav1.LabelSelector{ MatchLabels: labels, }, - Resources: []addonsv1.ResourceRef{{Name: configmapName, Kind: "ConfigMap"}, {Name: configmap2Name, Kind: "ConfigMap"}}, + Resources: []addonsv1.ResourceRef{{Name: configmapName, Kind: "ConfigMap"}, {Name: secretName, Kind: "Secret"}}, }, } // Create the ClusterResourceSet. @@ -340,7 +340,7 @@ metadata: ClusterSelector: metav1.LabelSelector{ MatchLabels: labels, }, - Resources: []addonsv1.ResourceRef{{Name: configmapName, Kind: "ConfigMap"}, {Name: configmap2Name, Kind: "ConfigMap"}}, + Resources: []addonsv1.ResourceRef{{Name: configmapName, Kind: "ConfigMap"}, {Name: secretName, Kind: "Secret"}}, }, } // Create the ClusterResourceSet.