Skip to content

Commit

Permalink
fix(#3390): Fix Knative addressable resolver cluster role binding in …
Browse files Browse the repository at this point in the history
…global operator mode

Use proper operator namespace in the service account role binding subject for global operators. Was using empty global operator watch namespace before which caused errors in the cluster role binding.
  • Loading branch information
christophd authored and oscerd committed Jul 1, 2022
1 parent db22259 commit 2ffdcfa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
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).
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

0 comments on commit 2ffdcfa

Please sign in to comment.