Merge pull request #2766 from wansir/tenant

fix kubectl pod owner reference
This commit is contained in:
KubeSphere CI Bot
2020-08-04 17:35:52 +08:00
committed by GitHub
2 changed files with 7 additions and 7 deletions

View File

@@ -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

View File

@@ -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