Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiolor committed Feb 4, 2025
1 parent c8d585d commit 27640d4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion deployments/liqo/templates/liqo-peer-rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- $peeringroles := (merge (dict "name" "peering-token" "module" "peering-token") .) -}}
{{- $peeringroles := (merge (dict "name" "peering-user" "module" "peering-user") .) -}}

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand Down
38 changes: 19 additions & 19 deletions pkg/liqoctl/rest/peering-user/userfactory/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
"github.com/liqotech/liqo/pkg/consts"
)

var peeringTokenLabel = client.ListOptions{
var peeringUserLabel = client.ListOptions{
LabelSelector: labels.SelectorFromSet(labels.Set{
"app.kubernetes.io/component": "peering-token",
"app.kubernetes.io/component": "peering-user",
}),
}

Expand Down Expand Up @@ -143,27 +143,27 @@ func getUserLabelSelector(userName string) labels.Selector {
})
}

// ensureLiqoNsReaderRole ensures that the peering-token Role is bound to the user in the Liqo namespace.
// ensureLiqoNsReaderRole ensures that the peering-user Role is bound to the user in the Liqo namespace.
func ensureLiqoNsReaderRole(ctx context.Context, c client.Client, userCN string, clusterID liqov1beta1.ClusterID) error {
var peeringTokenRoleList rbacv1.RoleList
if err := c.List(ctx, &peeringTokenRoleList, &peeringTokenLabel); err != nil {
return fmt.Errorf("unable to get peering-token Role from liqo namespace: %w", err)
var peeringUserRoleList rbacv1.RoleList
if err := c.List(ctx, &peeringUserRoleList, &peeringUserLabel); err != nil {
return fmt.Errorf("unable to get peering-user Role from liqo namespace: %w", err)
}

if nRoles := len(peeringTokenRoleList.Items); nRoles == 0 {
return fmt.Errorf("no peering-token Role found in the Liqo namespace")
if nRoles := len(peeringUserRoleList.Items); nRoles == 0 {
return fmt.Errorf("no peering-user Role found in the Liqo namespace")
} else if nRoles > 1 {
return fmt.Errorf("multiple peering-token Roles found in the Liqo namespace")
return fmt.Errorf("multiple peering-user Roles found in the Liqo namespace")
}

peeringTokenRole := peeringTokenRoleList.Items[0]
peeringUserRole := peeringUserRoleList.Items[0]
userName := GetUserNameFromClusterID(clusterID)

// Bind the roles to operate on the liqo namespace
roleBinding := &rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-liqo-ns-reader", userName),
Namespace: peeringTokenRole.Namespace,
Namespace: peeringUserRole.Namespace,
Labels: map[string]string{
consts.PeeringUserNameLabelKey: userName,
},
Expand All @@ -178,32 +178,32 @@ func ensureLiqoNsReaderRole(ctx context.Context, c client.Client, userCN string,
RoleRef: rbacv1.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Kind: "Role",
Name: peeringTokenRole.Name,
Name: peeringUserRole.Name,
},
}

if err := c.Create(ctx, roleBinding); err != nil {
return fmt.Errorf("unable to create role binding in the %q namespace: %w", peeringTokenRole.Namespace, err)
return fmt.Errorf("unable to create role binding in the %q namespace: %w", peeringUserRole.Namespace, err)
}

return nil
}

func ensureTenantNsWriterRole(ctx context.Context, c client.Client, userCN string, clusterID liqov1beta1.ClusterID, tenantNsName string) error {
var peeringClusterRoles rbacv1.ClusterRoleList
if err := c.List(ctx, &peeringClusterRoles, &peeringTokenLabel); err != nil {
return fmt.Errorf("unable to get peering-token role from liqo namespace: %w", err)
if err := c.List(ctx, &peeringClusterRoles, &peeringUserLabel); err != nil {
return fmt.Errorf("unable to get peering-user role from liqo namespace: %w", err)
}

if nRoles := len(peeringClusterRoles.Items); nRoles == 0 {
return fmt.Errorf("no peering-token ClusterRole found")
return fmt.Errorf("no peering-user ClusterRole found")
} else if nRoles > 1 {
return fmt.Errorf("multiple peering-token ClusterRoles found ")
return fmt.Errorf("multiple peering-user ClusterRoles found ")
}

// bind the ClusterRole to the userName user
userName := GetUserNameFromClusterID(clusterID)
peeringTokenClusterRole := peeringClusterRoles.Items[0]
peeringUserClusterRole := peeringClusterRoles.Items[0]
clusterRoleBinding := &rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-tenant-ns-writer", userName),
Expand All @@ -222,7 +222,7 @@ func ensureTenantNsWriterRole(ctx context.Context, c client.Client, userCN strin
RoleRef: rbacv1.RoleRef{
APIGroup: "rbac.authorization.k8s.io",
Kind: "ClusterRole",
Name: peeringTokenClusterRole.Name,
Name: peeringUserClusterRole.Name,
},
}

Expand Down

0 comments on commit 27640d4

Please sign in to comment.