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

Fix incorrect rolebinding error message and improve logging #2564

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func main() {
os.Exit(1)
}

setupLog.Info("platform", "type", clusterConfig.Platform())

// Checking if required files exist before starting the operator
requiredFiles := []string{
payload.HostLocalCNIPlugin,
Expand Down
13 changes: 8 additions & 5 deletions controllers/configmap_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,17 +600,19 @@ func (r *ConfigMapReconciler) ensureWICDRoleBinding(ctx context.Context) error {
return fmt.Errorf("unable to delete RoleBinding %s/%s: %w", r.watchNamespace, wicdRBACResourceName, err)
}
r.log.Info("Deleted malformed resource", "RoleBinding",
kubeTypes.NamespacedName{Namespace: r.watchNamespace, Name: existingRB.Name},
kubeTypes.NamespacedName{Namespace: existingRB.Namespace, Name: existingRB.Name},
"RoleRef", existingRB.RoleRef.Name, "Subjects", existingRB.Subjects)
}
// create proper resource if it does not exist
_, err = r.k8sclientset.RbacV1().RoleBindings(r.watchNamespace).Create(ctx, expectedRB,
createdRB, err := r.k8sclientset.RbacV1().RoleBindings(r.watchNamespace).Create(ctx, expectedRB,
meta.CreateOptions{})
if err != nil {
return fmt.Errorf("unable to create RoleBinding %s/%s: %w", r.watchNamespace, wicdRBACResourceName, err)
}
r.log.Info("Created resource", "RoleBinding",
kubeTypes.NamespacedName{Namespace: r.watchNamespace, Name: expectedRB.Name})
kubeTypes.NamespacedName{Namespace: createdRB.Namespace, Name: createdRB.Name},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this be same as expectedRB?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, with namespaced resources isn't a big deal. I made this change to better align with the ClusterRoleBinding log messages.

"RoleRef", createdRB.RoleRef.Name, "Subjects", createdRB.Subjects)

return nil
}

Expand Down Expand Up @@ -653,9 +655,10 @@ func (r *ConfigMapReconciler) ensureWICDClusterRoleBinding(ctx context.Context)
"RoleRef", existingCRB.RoleRef.Name, "Subjects", existingCRB.Subjects)
}
// create proper resource if it does not exist
_, err = r.k8sclientset.RbacV1().ClusterRoleBindings().Create(ctx, expectedCRB, meta.CreateOptions{})
createdCRB, err := r.k8sclientset.RbacV1().ClusterRoleBindings().Create(ctx, expectedCRB, meta.CreateOptions{})
if err == nil {
r.log.Info("Created resource", "ClusterRoleBinding", expectedCRB.Name)
r.log.Info("Created resource", "ClusterRoleBinding", createdCRB.Name,
"RoleRef", createdCRB.RoleRef.Name, "Subjects", createdCRB.Subjects)
}
return err
}