Skip to content

Commit

Permalink
migrate management/auth from norman to wrangler (rancher#47954)
Browse files Browse the repository at this point in the history
* refact: move from norman to wrangler

Signed-off-by: Alessio Greggi <[email protected]>
  • Loading branch information
alegrey91 authored Nov 12, 2024
1 parent 186958f commit a9ec025
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 308 deletions.
1 change: 0 additions & 1 deletion pkg/auth/cleanup/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ func newMockCleanupService(t *testing.T,

func getSecretControllerMock(ctrl *gomock.Controller, store map[string]*corev1.Secret) wcorev1.SecretController {
secretController := wranglerfake.NewMockControllerInterface[*corev1.Secret, *corev1.SecretList](ctrl)

secretController.EXPECT().Create(gomock.Any()).DoAndReturn(func(secret *corev1.Secret) (*corev1.Secret, error) {
if secret.Name == "" {
uniqueIdentifier := md5.Sum([]byte(time.Now().String()))
Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/management/auth/legacy_grb_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (p *grbCleaner) sync(key string, obj *v3.GlobalRoleBinding) (runtime.Object
}

cleanedObj := gbrCleanUp(obj)
return p.mgmt.Management.GlobalRoleBindings("").Update(cleanedObj)
return p.mgmt.Wrangler.Mgmt.GlobalRoleBinding().Update(cleanedObj)
}

// gbrCleanUp returns a clean GlobalRoleBinding based on filters specified within the function
Expand Down
17 changes: 9 additions & 8 deletions pkg/controllers/management/auth/legacy_rt_cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ package auth

import (
"github.com/rancher/rancher/pkg/api/norman/store/roletemplate"
v3 "github.com/rancher/rancher/pkg/generated/norman/management.cattle.io/v3"
wv3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
v3 "github.com/rancher/rancher/pkg/generated/controllers/management.cattle.io/v3"
"github.com/rancher/rancher/pkg/types/config"
"k8s.io/apimachinery/pkg/runtime"
)

type rtCleaner struct {
clusterLister v3.ClusterLister
mgmt *config.ManagementContext
roleTemplates v3.RoleTemplateController
clusterLister v3.ClusterController
}

func newLegacyRTCleaner(mgmt *config.ManagementContext) *rtCleaner {
return &rtCleaner{
mgmt: mgmt,
clusterLister: mgmt.Management.Clusters("").Controller().Lister(),
roleTemplates: mgmt.Wrangler.Mgmt.RoleTemplate(),
clusterLister: mgmt.Wrangler.Mgmt.Cluster(),
}
}

// sync cleans up all roleTemplates to drop cluster-scoped lifecycle handler finalizers
func (p *rtCleaner) sync(key string, obj *v3.RoleTemplate) (runtime.Object, error) {
func (p *rtCleaner) sync(key string, obj *wv3.RoleTemplate) (runtime.Object, error) {
if key == "" || obj == nil {
return nil, nil
}
Expand All @@ -29,11 +30,11 @@ func (p *rtCleaner) sync(key string, obj *v3.RoleTemplate) (runtime.Object, erro
}

cleanedObj := rtCleanUp(obj)
return p.mgmt.Management.RoleTemplates("").Update(cleanedObj)
return p.roleTemplates.Update(cleanedObj)
}

// rtCleanUp returns a clean RoleTemplate based on filters specified within the function
func rtCleanUp(obj *v3.RoleTemplate) *v3.RoleTemplate {
func rtCleanUp(obj *wv3.RoleTemplate) *wv3.RoleTemplate {
obj.SetFinalizers(cleanFinalizers(obj.GetFinalizers(), "clusterscoped.controller.cattle.io/cluster-roletemplate-sync_"))
cleanAnnotations := cleanAnnotations(obj.GetAnnotations(), "lifecycle.cattle.io/create.cluster-roletemplate-sync_")

Expand Down
19 changes: 10 additions & 9 deletions pkg/controllers/management/auth/token.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package auth

import (
v3 "github.com/rancher/rancher/pkg/apis/management.cattle.io/v3"
tokenUtil "github.com/rancher/rancher/pkg/auth/tokens"
"github.com/rancher/rancher/pkg/features"
v3 "github.com/rancher/rancher/pkg/generated/norman/management.cattle.io/v3"
wrangmgmtv3 "github.com/rancher/rancher/pkg/generated/controllers/management.cattle.io/v3"
"github.com/rancher/rancher/pkg/types/config"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -14,16 +15,16 @@ const (
)

type TokenController struct {
tokens v3.TokenInterface
userAttributes v3.UserAttributeInterface
userAttributesLister v3.UserAttributeLister
tokens wrangmgmtv3.TokenController
userAttributes wrangmgmtv3.UserAttributeController
userAttributesLister wrangmgmtv3.UserAttributeCache
}

func newTokenController(mgmt *config.ManagementContext) *TokenController {
n := &TokenController{
tokens: mgmt.Management.Tokens(""),
userAttributes: mgmt.Management.UserAttributes(""),
userAttributesLister: mgmt.Management.UserAttributes("").Controller().Lister(),
tokens: mgmt.Wrangler.Mgmt.Token(),
userAttributes: mgmt.Wrangler.Mgmt.UserAttribute(),
userAttributesLister: mgmt.Wrangler.Mgmt.UserAttribute().Cache(),
}
return n
}
Expand Down Expand Up @@ -104,7 +105,7 @@ func (t *TokenController) userAttributesNeedsRefresh(user string) (bool, error)
return false, nil
}

userAttribute, err := t.userAttributesLister.Get("", user)
userAttribute, err := t.userAttributesLister.Get(user)
if err != nil {
if errors.IsNotFound(err) {
return false, nil
Expand All @@ -115,7 +116,7 @@ func (t *TokenController) userAttributesNeedsRefresh(user string) (bool, error)
}

func (t *TokenController) triggerUserAttributesRefresh(user string) error {
userAttribute, err := t.userAttributesLister.Get("", user)
userAttribute, err := t.userAttributesLister.Get(user)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit a9ec025

Please sign in to comment.