Skip to content

Commit

Permalink
flag: add context flag to switch between clusters
Browse files Browse the repository at this point in the history
we missed adding `--context` flag when migrating
to golang. Adding the flag back.

Signed-off-by: subhamkrai <srai@redhat.com>
  • Loading branch information
subhamkrai committed Jul 6, 2023
1 parent c0f9f1d commit efd2c38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ jobs:
set -ex
kubectl rook-ceph ceph status
- name: Ceph status using context
run: |
set -ex
kubectl rook-ceph --context=$(kubectl config current-context) ceph status
- name: Mon restore
env:
ROOK_PLUGIN_SKIP_PROMPTS: true
Expand Down Expand Up @@ -148,6 +153,11 @@ jobs:
set -ex
kubectl rook-ceph --operator-namespace test-operator -n test-cluster ceph status
- name: Ceph status using context
run: |
set -ex
kubectl rook-ceph --operator-namespace test-operator -n test-cluster --context=$(kubectl config current-context) ceph status
- name: Mon restore
env:
ROOK_PLUGIN_SKIP_PROMPTS: true
Expand Down
9 changes: 8 additions & 1 deletion cmd/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
KubeConfig string
OperatorNamespace string
CephClusterNamespace string
KubeContext string
)

// rookCmd represents the rook command
Expand Down Expand Up @@ -67,17 +68,23 @@ func init() {
RootCmd.PersistentFlags().StringVar(&KubeConfig, "kubeconfig", "", "kubernetes config path")
RootCmd.PersistentFlags().StringVar(&OperatorNamespace, "operator-namespace", "", "Kubernetes namespace where rook operator is running")
RootCmd.PersistentFlags().StringVarP(&CephClusterNamespace, "namespace", "n", "rook-ceph", "Kubernetes namespace where CephCluster is created")
RootCmd.PersistentFlags().StringVar(&KubeContext, "context", "", "Kubernetes context to use")
}

func GetClientsets(ctx context.Context) *k8sutil.Clientsets {
var err error

clientsets := &k8sutil.Clientsets{}

congfigOverride := &clientcmd.ConfigOverrides{}
if KubeContext != "" {
congfigOverride = &clientcmd.ConfigOverrides{CurrentContext: KubeContext}
}

// 1. Create Kubernetes Client
kubeconfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(),
&clientcmd.ConfigOverrides{},
congfigOverride,
)

clientsets.KubeConfig, err = kubeconfig.ClientConfig()
Expand Down

0 comments on commit efd2c38

Please sign in to comment.