Skip to content

Commit

Permalink
Added function to get the csm namespaces from the cluster. (#581)
Browse files Browse the repository at this point in the history
* function to get the csm namespaces from the cluster

* change the function to unexported type for time being

* refactor variablename and error message

* refactor variablename and error message

* fix yaml lint
  • Loading branch information
ChristianAtDell committed Oct 15, 2024
1 parent 9471039 commit 9411d40
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: connectivity-client-docker-k8s
namespace: <ExistingNameSpace>
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["list","get", "create", "update", "delete","watch"]
- apiGroups: ["storage.dell.com"]
resources: ["containerstoragemodules"]
verbs: ["create", "delete"]
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "create", "delete", "update"]
- apiGroups: ["mobility.storage.dell.com"]
resources: ["backups"]
verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: connectivity-client-docker-k8s
namespace: <ExistingNameSpace>
subjects:
- kind: ServiceAccount
name: connectivity-client-docker-k8s
namespace: <ClientNameSpace>
roleRef:
kind: Role
name: connectivity-client-docker-k8s
apiGroup: rbac.authorization.k8s.io
22 changes: 22 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,3 +1175,25 @@ func getUpgradeInfo[T csmv1.CSMComponentType](ctx context.Context, operatorConfi
// Example return value: "v2.2.0"
return upgradePath.MinUpgradePath, nil
}

func getNamespaces(ctx context.Context, ctrlClient crclient.Client) ([]string, error) {
// Set to store unique namespaces
namespaceMap := make(map[string]struct{})

csmList := &csmv1.ContainerStorageModuleList{}

if err := ctrlClient.List(ctx, csmList); err != nil {
return nil, fmt.Errorf("error listing csm resources: %w", err)
}
for _, csmResource := range csmList.Items {
namespaceMap[csmResource.Namespace] = struct{}{}
}

// Convert set to slice
var namespaces []string
for namespace := range namespaceMap {
namespaces = append(namespaces, namespace)
}

return namespaces, nil
}

0 comments on commit 9411d40

Please sign in to comment.