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

Added function to get the csm namespaces from the cluster. #581

Merged
merged 5 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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
23 changes: 23 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1175,3 +1175,26 @@ 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{})

list := &csmv1.ContainerStorageModuleList{}

if err := ctrlClient.List(ctx, list); err != nil {
return nil, fmt.Errorf("list csm resources: %w", err)
}
for _, csmResource := range list.Items {
namespaceMap[csmResource.Namespace] = struct{}{}
fmt.Printf("namespace is %s\n", csmResource.Namespace)
}

// Convert set to slice
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we converting the map to a slice? why not just use the slice from the beginning and append to it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to make sure only unique namespace entries are added. Using a map will ensure that. Duplicates will be removed

var namespaces []string
for namespace := range namespaceMap {
namespaces = append(namespaces, namespace)
}

return namespaces, nil
}
Loading