kubeplus icon indicating copy to clipboard operation
kubeplus copied to clipboard

[WIP] Refactoring the provider-kubeconfig.py

Open chiukapoor opened this issue 1 year ago • 7 comments
trafficstars

Issue

  • Fixes: https://github.com/cloud-ark/kubeplus/issues/1325

Updates

  • Use python kube-client
  • Modularize delete functionality
  • Add -n, --namespace parameter for namespace
  • Error handling

TODO

  • [x] Test UPDATE functionality
  • [ ] Use logger
  • [ ] Need refactor the below code blocks once the JSON format is provided by @devdattakulkarni https://github.com/cloud-ark/kubeplus/blob/d4d61ce4d28c9a8609377d4dc60e76242174dfc8/provider-kubeconfig.py#L346-L391 https://github.com/cloud-ark/kubeplus/blob/d4d61ce4d28c9a8609377d4dc60e76242174dfc8/provider-kubeconfig.py#L421-L439

chiukapoor avatar Jul 04 '24 12:07 chiukapoor

Looks like CI has failed: https://github.com/cloud-ark/kubeplus/actions/runs/9838082051/job/27157203380?pr=1326#step:5:1896

devdattakulkarni avatar Jul 08 '24 10:07 devdattakulkarni

https://github.com/cloud-ark/kubeplus/actions/runs/9838401881/job/27158227902?pr=1326#step:5:1901

Need to add kubernetes to requirements.txt.

devdattakulkarni avatar Jul 08 '24 11:07 devdattakulkarni

@devdattakulkarni I would like to propose that we move the provider-kubeconfig.py and requirements.txt to a new folder (ex kubeconfig-generator)?

chiukapoor avatar Jul 08 '24 13:07 chiukapoor

Rebased with master

chiukapoor avatar Jul 10 '24 11:07 chiukapoor

@chiukapoor I have started testing the changes. Here is a gist with early results.

https://gist.github.com/devdattakulkarni/bb3833c9589ca3139c971da43ac2fa62

I would suggest you try all the flags with all the commands to verify whether all combinations of commands and flags are working correctly.

devdattakulkarni avatar Aug 03 '24 21:08 devdattakulkarni

@devdattakulkarni

Test 2: "Namespace does not exist" is working fine for me.

❯ kubectl get namespaces -A
NAME                 STATUS   AGE
default              Active   7m7s
kube-node-lease      Active   7m7s
kube-public          Active   7m7s
kube-system          Active   7m7s
local-path-storage   Active   7m4s
testkubeconfig2      Active   53s
❯ python3 provider-kubeconfig.py create -n testkubeconfig3 -s $apiserver
API Server IP: https://127.0.0.1:36921
Namespace 'testkubeconfig3' created successfully.
Namespace 'testkubeconfig3' labeled successfully.
ServiceAccount 'kubeplus-saas-provider' created successfully.
Secret 'kubeplus-saas-provider' created successfully.
Kubeconfig file 'kubeplus-saas-provider.json' created successfully.
ClusterRole 'kubeplus-saas-provider' replaced successfully.
ClusterRole 'kubeplus-saas-provider' replaced successfully.
Provider kubeconfig created: kubeplus-saas-provider.json

Rest of the issues are resolved in latest commit.

chiukapoor avatar Aug 06 '24 18:08 chiukapoor

Rebased the PR @devdattakulkarni

chiukapoor avatar Sep 11 '24 16:09 chiukapoor