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 Feb 1, 2021
1 parent 5815384 commit f1cdf7b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
7 changes: 3 additions & 4 deletions exp/addons/controllers/clusterresourceset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
kerrors "k8s.io/apimachinery/pkg/util/errors"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
Expand Down Expand Up @@ -386,16 +385,16 @@ func (r *ClusterResourceSetReconciler) getResource(ctx context.Context, resource
if resourceSecret.Type != addonsv1.ClusterResourceSetSecretType {
return nil, ErrSecretTypeNotSupported
}

resourceInterface = resourceSecret.DeepCopyObject()
}

raw, err := runtime.DefaultUnstructuredConverter.ToUnstructured(resourceInterface)
raw := &unstructured.Unstructured{}
err := r.Client.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
25 changes: 12 additions & 13 deletions exp/addons/controllers/clusterresourceset_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ import (
"fmt"
"time"

"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/controller-runtime/pkg/client"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

Expand All @@ -31,6 +28,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
addonsv1 "sigs.k8s.io/cluster-api/exp/addons/api/v1alpha4"
"sigs.k8s.io/cluster-api/util"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
Expand All @@ -46,7 +45,7 @@ var _ = Describe("ClusterResourceSet Reconciler", func() {
var clusterName string

var configmapName = "test-configmap"
var configmap2Name = "test-configmap2"
var secretName = "test-secret"

BeforeEach(func() {
clusterResourceSetName = fmt.Sprintf("clusterresourceset-%s", util.RandomString(6))
Expand All @@ -58,7 +57,6 @@ var _ = Describe("ClusterResourceSet Reconciler", func() {
Expect(testEnv.Create(ctx, testCluster)).To(Succeed())
By("Creating the remote Cluster kubeconfig")
Expect(testEnv.CreateKubeconfigSecret(ctx, testCluster)).To(Succeed())

testConfigmap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: configmapName,
Expand All @@ -72,13 +70,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 @@ -87,9 +86,9 @@ metadata:
namespace: default`,
},
}
By("Creating 2 ConfigMaps with ConfigMap in their data field")
By("Creating a Secret and a ConfigMap 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 @@ -140,7 +139,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 @@ -353,7 +352,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 f1cdf7b

Please sign in to comment.