Skip to content

Commit

Permalink
Merge pull request #3965 from csrwng/restore_ingresscontroller_rbac
Browse files Browse the repository at this point in the history
OCPBUGS-33132: Restore ingresscontroller rbac
  • Loading branch information
openshift-merge-bot[bot] committed May 1, 2024
2 parents a540b01 + 8d8586a commit 6bb55df
Showing 1 changed file with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,45 @@ func (r *HostedClusterReconciler) reconcileControlPlaneOperator(ctx context.Cont
return fmt.Errorf("failed to reconcile controlplane operator rolebinding: %w", err)
}

// TODO: Remove this block after initial merge of this feature. It is not needed for latest CPO version
if r.ManagementClusterCapabilities.Has(capabilities.CapabilityRoute) && releaseVersion.Major == 4 && releaseVersion.Minor <= 14 {
// Reconcile operator role - for ingress
controlPlaneOperatorIngressRole := controlplaneoperator.OperatorIngressRole("openshift-ingress", controlPlaneNamespace.Name)
_, err = createOrUpdate(ctx, r.Client, controlPlaneOperatorIngressRole, func() error {
return reconcileControlPlaneOperatorIngressRole(controlPlaneOperatorIngressRole)
})
if err != nil {
return fmt.Errorf("failed to reconcile controlplane operator ingress role: %w", err)
}

// Reconcile operator role binding - for ingress
controlPlaneOperatorIngressRoleBinding := controlplaneoperator.OperatorIngressRoleBinding("openshift-ingress", controlPlaneNamespace.Name)
_, err = createOrUpdate(ctx, r.Client, controlPlaneOperatorIngressRoleBinding, func() error {
return reconcileControlPlaneOperatorIngressRoleBinding(controlPlaneOperatorIngressRoleBinding, controlPlaneOperatorIngressRole, controlPlaneOperatorServiceAccount)
})
if err != nil {
return fmt.Errorf("failed to reconcile controlplane operator ingress rolebinding: %w", err)
}

// Reconcile operator role - for ingress operator
controlPlaneOperatorIngressOperatorRole := controlplaneoperator.OperatorIngressOperatorRole("openshift-ingress-operator", controlPlaneNamespace.Name)
_, err = createOrUpdate(ctx, r.Client, controlPlaneOperatorIngressOperatorRole, func() error {
return reconcilecontrolPlaneOperatorIngressOperatorRole(controlPlaneOperatorIngressOperatorRole)
})
if err != nil {
return fmt.Errorf("failed to reconcile controlplane operator ingress operator role: %w", err)
}

// Reconcile operator role binding - for ingress operator
controlPlaneOperatorIngressOperatorRoleBinding := controlplaneoperator.OperatorIngressOperatorRoleBinding("openshift-ingress-operator", controlPlaneNamespace.Name)
_, err = createOrUpdate(ctx, r.Client, controlPlaneOperatorIngressOperatorRoleBinding, func() error {
return reconcilecontrolPlaneOperatorIngressOperatorRoleBinding(controlPlaneOperatorIngressOperatorRoleBinding, controlPlaneOperatorIngressOperatorRole, controlPlaneOperatorServiceAccount)
})
if err != nil {
return fmt.Errorf("failed to reconcile controlplane operator ingress operator rolebinding: %w", err)
}
}

// Reconcile operator deployment
controlPlaneOperatorDeployment := controlplaneoperator.OperatorDeployment(controlPlaneNamespace.Name)
_, err = createOrUpdate(ctx, r.Client, controlPlaneOperatorDeployment, func() error {
Expand Down Expand Up @@ -2916,6 +2955,64 @@ func reconcileControlPlaneOperatorRoleBinding(binding *rbacv1.RoleBinding, role
return nil
}

func reconcileControlPlaneOperatorIngressRole(role *rbacv1.Role) error {
role.Rules = []rbacv1.PolicyRule{
{
APIGroups: []string{""},
Resources: []string{"services"},
Verbs: []string{"get", "list", "watch"},
},
}
return nil
}

func reconcileControlPlaneOperatorIngressRoleBinding(binding *rbacv1.RoleBinding, role *rbacv1.Role, sa *corev1.ServiceAccount) error {
binding.RoleRef = rbacv1.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Kind: "Role",
Name: role.Name,
}

binding.Subjects = []rbacv1.Subject{
{
Kind: "ServiceAccount",
Name: sa.Name,
Namespace: sa.Namespace,
},
}

return nil
}

func reconcilecontrolPlaneOperatorIngressOperatorRole(role *rbacv1.Role) error {
role.Rules = []rbacv1.PolicyRule{
{
APIGroups: []string{"operator.openshift.io"},
Resources: []string{"ingresscontrollers"},
Verbs: []string{"*"},
},
}
return nil
}

func reconcilecontrolPlaneOperatorIngressOperatorRoleBinding(binding *rbacv1.RoleBinding, role *rbacv1.Role, sa *corev1.ServiceAccount) error {
binding.RoleRef = rbacv1.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Kind: "Role",
Name: role.Name,
}

binding.Subjects = []rbacv1.Subject{
{
Kind: "ServiceAccount",
Name: sa.Name,
Namespace: sa.Namespace,
},
}

return nil
}

func reconcileCAPICluster(cluster *capiv1.Cluster, hcluster *hyperv1.HostedCluster, hcp *hyperv1.HostedControlPlane, infraCR client.Object) error {
// We only create this resource once and then let CAPI own it
if !cluster.CreationTimestamp.IsZero() {
Expand Down

1 comment on commit 6bb55df

@stevekuznetsov
Copy link
Contributor

Choose a reason for hiding this comment

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

/test

Please sign in to comment.