Skip to content

Commit

Permalink
Fix cluster resource set not getting Secret/Configmap TypeMeta with l…
Browse files Browse the repository at this point in the history
…ive client
  • Loading branch information
Sedef committed Jan 28, 2021
1 parent fccc84c commit 3341e0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions exp/addons/controllers/clusterresourceset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 10 additions & 10 deletions exp/addons/controllers/clusterresourceset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controllers

import (
"fmt"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"time"

"sigs.k8s.io/cluster-api/util"
Expand All @@ -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"
Expand All @@ -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))
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3341e0f

Please sign in to comment.