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(#3390): Fix Knative addressable resolver cluster role binding #3400

Merged
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
16 changes: 8 additions & 8 deletions pkg/install/knative.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ import (

const knativeAddressableResolverClusterRoleName = "addressable-resolver"

// BindKnativeAddressableResolverClusterRole binds the Knative Addressable resolver aggregated ClusterRole
// BindKnativeAddressableResolverClusterRole binds the Knative addressable resolver aggregated ClusterRole
// to the operator ServiceAccount.
func BindKnativeAddressableResolverClusterRole(ctx context.Context, c kubernetes.Interface, namespace string) error {
func BindKnativeAddressableResolverClusterRole(ctx context.Context, c kubernetes.Interface, namespace string, operatorNamespace string) error {
if isKnative, err := knative.IsInstalled(ctx, c); err != nil {
return err
} else if !isKnative {
return nil
}
if namespace != "" {
return applyAddressableResolverRoleBinding(ctx, c, namespace)
return applyAddressableResolverRoleBinding(ctx, c, namespace, operatorNamespace)
}
return applyAddressableResolverClusterRoleBinding(ctx, c, namespace)
return applyAddressableResolverClusterRoleBinding(ctx, c, operatorNamespace)
}

func applyAddressableResolverRoleBinding(ctx context.Context, c kubernetes.Interface, namespace string) error {
func applyAddressableResolverRoleBinding(ctx context.Context, c kubernetes.Interface, namespace string, operatorNamespace string) error {
rb := rbacv1ac.RoleBinding(fmt.Sprintf("%s-addressable-resolver", serviceAccountName), namespace).
christophd marked this conversation as resolved.
Show resolved Hide resolved
WithSubjects(
rbacv1ac.Subject().
WithKind("ServiceAccount").
WithNamespace(namespace).
WithNamespace(operatorNamespace).
WithName(serviceAccountName),
).
WithRoleRef(rbacv1ac.RoleRef().
Expand All @@ -65,12 +65,12 @@ func applyAddressableResolverRoleBinding(ctx context.Context, c kubernetes.Inter
return err
}

func applyAddressableResolverClusterRoleBinding(ctx context.Context, c kubernetes.Interface, namespace string) error {
func applyAddressableResolverClusterRoleBinding(ctx context.Context, c kubernetes.Interface, operatorNamespace string) error {
crb := rbacv1ac.ClusterRoleBinding(fmt.Sprintf("%s-addressable-resolver", serviceAccountName)).
WithSubjects(
rbacv1ac.Subject().
WithKind("ServiceAccount").
WithNamespace(namespace).
WithNamespace(operatorNamespace).
WithName(serviceAccountName),
).
WithRoleRef(rbacv1ac.RoleRef().
Expand Down
2 changes: 1 addition & 1 deletion pkg/install/optional.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func OperatorStartupOptionalTools(ctx context.Context, c client.Client, namespac
}

// Try to bind the Knative Addressable resolver aggregated ClusterRole to the operator ServiceAccount
if err := BindKnativeAddressableResolverClusterRole(ctx, c, namespace); err != nil {
if err := BindKnativeAddressableResolverClusterRole(ctx, c, namespace, operatorNamespace); err != nil {
log.Info("Cannot bind the Knative Addressable resolver aggregated ClusterRole: skipping.")
log.V(8).Info("Error while binding the Knative Addressable resolver aggregated ClusterRole", "error", err)
}
Expand Down