diff --git a/pkg/cmd/kubeblocks/kubeblocks_objects.go b/pkg/cmd/kubeblocks/kubeblocks_objects.go index b1f70b252..ca4bdc5e2 100644 --- a/pkg/cmd/kubeblocks/kubeblocks_objects.go +++ b/pkg/cmd/kubeblocks/kubeblocks_objects.go @@ -22,6 +22,7 @@ package kubeblocks import ( "context" "encoding/json" + "fmt" "strings" corev1 "k8s.io/api/core/v1" @@ -82,7 +83,9 @@ func getKBObjects(dynamic dynamic.Interface, namespace string, addons []*extensi ctx := context.TODO() // get CRDs - crds, err := dynamic.Resource(types.CRDGVR()).List(ctx, metav1.ListOptions{}) + crds, err := dynamic.Resource(types.CRDGVR()).List(ctx, metav1.ListOptions{ + LabelSelector: fmt.Sprintf("%s=%s", constant.AppNameLabelKey, types.KubeBlocksChartName), + }) appendErr(err) kbObjs[types.CRDGVR()] = &unstructured.UnstructuredList{} diff --git a/pkg/cmd/kubeblocks/kubeblocks_objects_test.go b/pkg/cmd/kubeblocks/kubeblocks_objects_test.go index b5c6624b3..4f6b5afc1 100644 --- a/pkg/cmd/kubeblocks/kubeblocks_objects_test.go +++ b/pkg/cmd/kubeblocks/kubeblocks_objects_test.go @@ -155,13 +155,15 @@ func mockName() string { } func mockCRD() []runtime.Object { + label := map[string]string{constant.AppNameLabelKey: types.KubeBlocksChartName} clusterCRD := v1.CustomResourceDefinition{ TypeMeta: metav1.TypeMeta{ Kind: "CustomResourceDefinition", APIVersion: "apiextensions.k8s.io/v1", }, ObjectMeta: metav1.ObjectMeta{ - Name: "clusters.apps.kubeblocks.io", + Name: "clusters.apps.kubeblocks.io", + Labels: label, }, Spec: v1.CustomResourceDefinitionSpec{ Group: types.AppsAPIGroup, @@ -174,7 +176,8 @@ func mockCRD() []runtime.Object { APIVersion: "apiextensions.k8s.io/v1", }, ObjectMeta: metav1.ObjectMeta{ - Name: "clusterdefinitions.apps.kubeblocks.io", + Name: "clusterdefinitions.apps.kubeblocks.io", + Labels: label, }, Spec: v1.CustomResourceDefinitionSpec{ Group: types.AppsAPIGroup, @@ -188,7 +191,8 @@ func mockCRD() []runtime.Object { APIVersion: "apiextensions.k8s.io/v1", }, ObjectMeta: metav1.ObjectMeta{ - Name: "actionsets.dataprotection.kubeblocks.io", + Name: "actionsets.dataprotection.kubeblocks.io", + Labels: label, }, Spec: v1.CustomResourceDefinitionSpec{ Group: types.DPAPIGroup,