Skip to content

Commit

Permalink
Minor change to clusterrole (#63)
Browse files Browse the repository at this point in the history
* Minor change to clusterrole

* Update clusterrole.go

* Update clusterrole.go

* clusterole changes

* Adding namespace kind

* reverting back change
  • Loading branch information
ChristianAtDell committed Oct 15, 2024
1 parent 73f6fc0 commit 59d9999
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions controllers/csm_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,11 @@ func (r *ContainerStorageModuleReconciler) SyncCSM(ctx context.Context, cr csmv1
}

// Create/Update ClusterRoles
if _, err = rbac.SyncClusterRole(ctx, &node.Rbac.ClusterRole, r.Client); err != nil {
if err = rbac.SyncClusterRole(ctx, &node.Rbac.ClusterRole, r.Client); err != nil {
return err
}

if _, err = rbac.SyncClusterRole(ctx, &controller.Rbac.ClusterRole, r.Client); err != nil {
if err = rbac.SyncClusterRole(ctx, &controller.Rbac.ClusterRole, r.Client); err != nil {
return err
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/resources/rbac/clusterrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ import (
)

// SyncClusterRole - Syncs a ClusterRole
func SyncClusterRole(ctx context.Context, clusterRole *rbacv1.ClusterRole, client client.Client) (*rbacv1.ClusterRole, error) {
func SyncClusterRole(ctx context.Context, clusterRole *rbacv1.ClusterRole, client client.Client) error {
log := logger.GetLogger(ctx)
found := &rbacv1.ClusterRole{}
err := client.Get(ctx, types.NamespacedName{Name: clusterRole.Name, Namespace: clusterRole.Namespace}, found)
if err != nil && errors.IsNotFound(err) {
log.Info("Creating a new ClusterRole", "Name", clusterRole.Name)
err = client.Create(ctx, clusterRole)
if err != nil {
return nil, err
return err
}
// we need to return found object
err := client.Get(ctx, types.NamespacedName{Name: clusterRole.Name, Namespace: clusterRole.Namespace}, found)
if err != nil {
return nil, err
return err
}
} else if err != nil {
log.Info("Unknown error.", "Error", err.Error())
return nil, err
return err
} else {
log.Info("Updating ClusterRole", "Name:", clusterRole.Name)
err = client.Update(ctx, clusterRole)
if err != nil {
return nil, err
return err
}
}

return found, nil
return nil
}

0 comments on commit 59d9999

Please sign in to comment.