未验证 提交 fd4790a6 编写于 作者: K KubeSphere CI Bot 提交者: GitHub

Merge pull request #2766 from wansir/tenant

fix kubectl pod owner reference
......@@ -213,11 +213,10 @@ func (c *Controller) reconcile(key string) error {
return err
}
isClusterAdmin := clusterRoleBinding.RoleRef.Name == iamv1alpha2.ClusterAdmin
if isClusterAdmin {
if clusterRoleBinding.RoleRef.Name == iamv1alpha2.ClusterAdmin {
for _, subject := range clusterRoleBinding.Subjects {
if subject.Kind == iamv1alpha2.ResourceKindUser {
err = c.kubectlOperator.CreateKubectlDeploy(subject.Name)
err = c.kubectlOperator.CreateKubectlDeploy(subject.Name, clusterRoleBinding)
if err != nil {
klog.Error(err)
return err
......
......@@ -43,7 +43,7 @@ const (
type Interface interface {
GetKubectlPod(username string) (models.PodInfo, error)
CreateKubectlDeploy(username string) error
CreateKubectlDeploy(username string, owner metav1.Object) error
}
type operator struct {
......@@ -108,10 +108,10 @@ func selectCorrectPod(namespace string, pods []*v1.Pod) (kubectlPod *v1.Pod, err
return kubectlPodList[random], nil
}
func (o *operator) CreateKubectlDeploy(username string) error {
func (o *operator) CreateKubectlDeploy(username string, owner metav1.Object) error {
deployName := fmt.Sprintf(deployNameFormat, username)
user, err := o.userInformer.Lister().Get(username)
_, err := o.userInformer.Lister().Get(username)
if err != nil {
klog.Error(err)
// ignore if user not exist
......@@ -165,7 +165,8 @@ func (o *operator) CreateKubectlDeploy(username string) error {
},
}
err = controllerutil.SetControllerReference(user, deployment, scheme.Scheme)
// bind the lifecycle of role binding
err = controllerutil.SetControllerReference(owner, deployment, scheme.Scheme)
if err != nil {
klog.Errorln(err)
return err
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册