Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
caliskanugur committed Oct 28, 2024
1 parent 8ea8a1f commit 04a346f
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions extensions/users/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"strings"
"time"

"github.com/pkg/errors"
"github.com/rancher/norman/types"
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
"github.com/sirupsen/logrus"
authzv1 "k8s.io/api/authorization/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -91,7 +93,7 @@ func AddProjectMember(rancherClient *rancher.Client, project *management.Project

adminClient, err := rancher.NewClient(rancherClient.RancherConfig.AdminToken, rancherClient.Session)
if err != nil {
return err
return errors.Wrap(err, "admin client instantiation")
}

opts := metav1.ListOptions{
Expand All @@ -100,16 +102,18 @@ func AddProjectMember(rancherClient *rancher.Client, project *management.Project
}
watchInterface, err := adminClient.GetManagementWatchInterface(management.ProjectType, opts)
if err != nil {
return err
return errors.Wrap(err, "watcher interface instantiation")
}

checkFunc := func(event watch.Event) (ready bool, err error) {
projectUnstructured := event.Object.(*unstructured.Unstructured)
project := &v3.Project{}
logrus.Infof("project found: [%v]", project.Name)
err = scheme.Scheme.Convert(projectUnstructured, project, projectUnstructured.GroupVersionKind())
if err != nil {
return false, err
return false, errors.Wrap(err, "scheme convert in watcher")
}
logrus.Infof("namespaced backed resource: [%v]", v3.NamespaceBackedResource.IsTrue(project))
if v3.NamespaceBackedResource.IsTrue(project) {
return true, nil
}
Expand All @@ -119,19 +123,25 @@ func AddProjectMember(rancherClient *rancher.Client, project *management.Project

err = wait.WatchWait(watchInterface, checkFunc)
if err != nil {
return err
return errors.Wrap(err, "watcher to make sure namespaced backed resource is true")
}

roleTemplateResp, err := rancherClient.Management.ProjectRoleTemplateBinding.Create(role)
if err != nil {
return err
return errors.Wrap(err, "role template create")
}

var prtb *management.ProjectRoleTemplateBinding
err = kwait.Poll(500*time.Millisecond, 2*time.Minute, func() (done bool, err error) {
prtb, err = rancherClient.Management.ProjectRoleTemplateBinding.ByID(roleTemplateResp.ID)
if err != nil {
return false, err
return false, errors.Wrap(err, "prtb get in poll")
}
if prtb != nil {
logrus.Infof("prtb: [%v]", prtb.Name)
} else {

logrus.Infof("prtb is nil")
}
if prtb != nil && prtb.UserID == user.ID && prtb.ProjectID == project.ID {
return true, nil
Expand All @@ -140,12 +150,12 @@ func AddProjectMember(rancherClient *rancher.Client, project *management.Project
return false, nil
})
if err != nil {
return err
return errors.Wrap(err, "prtb get poll")
}

err = waitForPRTBRollout(adminClient, prtb, createOp)
if err != nil {
return err
return errors.Wrap(err, "watcher for PRTB rollout")
}

err = waitForAllowed(rancherClient, project.ClusterID, user, attrs)
Expand Down

0 comments on commit 04a346f

Please sign in to comment.