Skip to content

Commit

Permalink
fix: kb install panic when user have no permission
Browse files Browse the repository at this point in the history
  • Loading branch information
ldming committed Dec 11, 2023
1 parent 7f2fbab commit 5a52d50
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
40 changes: 23 additions & 17 deletions pkg/cmd/kubeblocks/kubeblocks_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,27 @@ func getKBObjects(dynamic dynamic.Interface, namespace string, addons []*extensi
crds, err := dynamic.Resource(types.CRDGVR()).List(ctx, metav1.ListOptions{})
appendErr(err)
kbObjs[types.CRDGVR()] = &unstructured.UnstructuredList{}
for i, crd := range crds.Items {
if !strings.Contains(crd.GetName(), constant.APIGroup) {
continue
}
crdObjs := kbObjs[types.CRDGVR()]
crdObjs.Items = append(crdObjs.Items, crds.Items[i])

// get built-in CRs belonging to this CRD
gvr, err := getGVRByCRD(&crd)
if err != nil {
appendErr(err)
continue
}
if crs, err := dynamic.Resource(*gvr).List(ctx, metav1.ListOptions{}); err != nil {
appendErr(err)
continue
} else {
kbObjs[*gvr] = crs
if crds != nil {
for i, crd := range crds.Items {
if !strings.Contains(crd.GetName(), constant.APIGroup) {
continue
}
crdObjs := kbObjs[types.CRDGVR()]
crdObjs.Items = append(crdObjs.Items, crds.Items[i])

// get built-in CRs belonging to this CRD
gvr, err := getGVRByCRD(&crd)
if err != nil {
appendErr(err)
continue
}
if crs, err := dynamic.Resource(*gvr).List(ctx, metav1.ListOptions{}); err != nil {
appendErr(err)
continue
} else {
kbObjs[*gvr] = crs
}
}
}

Expand Down Expand Up @@ -147,15 +150,18 @@ func getKBObjects(dynamic dynamic.Interface, namespace string, addons []*extensi
target.Items = append(target.Items, *obj)
klog.V(1).Infof("\tget object: %s, %s, %s", obj.GetNamespace(), obj.GetKind(), obj.GetName())
}

// get RBAC resources, such as ClusterRole, ClusterRoleBinding, Role, RoleBinding, ServiceAccount
getObjectsByLabels(buildKubeBlocksSelectorLabels(), types.ClusterRoleGVR(), ResourceScopeGlobal)
getObjectsByLabels(buildKubeBlocksSelectorLabels(), types.ClusterRoleBindingGVR(), ResourceScopeGlobal)
getObjectsByLabels(buildKubeBlocksSelectorLabels(), types.RoleGVR(), ResourceScopeLocal)
getObjectsByLabels(buildKubeBlocksSelectorLabels(), types.RoleBindingGVR(), ResourceScopeLocal)
getObjectsByLabels(buildKubeBlocksSelectorLabels(), types.ServiceAccountGVR(), ResourceScopeLocal)

// get webhooks
getObjectsByLabels(buildKubeBlocksSelectorLabels(), types.ValidatingWebhookConfigurationGVR(), ResourceScopeGlobal)
getObjectsByLabels(buildKubeBlocksSelectorLabels(), types.MutatingWebhookConfigurationGVR(), ResourceScopeGlobal)

// get configmap for config template
getObjectsByLabels(buildConfigTypeSelectorLabels(), types.ConfigmapGVR(), ResourceScopeLocal)
getObjectsByLabels(buildKubeBlocksSelectorLabels(), types.ConfigmapGVR(), ResourceScopeLocal)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/kubeblocks/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import (
func getGVRByCRD(crd *unstructured.Unstructured) (*schema.GroupVersionResource, error) {
group, _, err := unstructured.NestedString(crd.Object, "spec", "group")
if err != nil {
return nil, nil
return nil, err
}
return &schema.GroupVersionResource{
Group: group,
Expand Down

0 comments on commit 5a52d50

Please sign in to comment.