Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor change to clusterrole #63

Merged
merged 6 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}