@@ -30,6 +30,12 @@ import (
3030 operatorv1alpha1 "github.com/kcp-dev/kcp-operator/sdk/apis/operator/v1alpha1"
3131)
3232
33+ const (
34+ baseContext string = "base"
35+ shardBaseContext string = "shard-base"
36+ defaultContext string = "default"
37+ )
38+
3339func KubeconfigSecretReconciler (
3440 kubeconfig * operatorv1alpha1.Kubeconfig ,
3541 rootShard * operatorv1alpha1.RootShard ,
@@ -72,12 +78,12 @@ func KubeconfigSecretReconciler(
7278 return nil , err
7379 }
7480
75- addCluster ("default" , defaultURL )
76- addContext ("default" , "default" )
77- addCluster ("base" , serverURL )
78- addContext ("base" , "base" )
79- addContext ("shard-base" , "base" )
80- config .CurrentContext = "default"
81+ addCluster (defaultContext , defaultURL )
82+ addContext (defaultContext , defaultContext )
83+ addCluster (baseContext , serverURL )
84+ addContext (baseContext , baseContext )
85+ addContext (shardBaseContext , baseContext )
86+ config .CurrentContext = defaultContext
8187
8288 case kubeconfig .Spec .Target .ShardRef != nil :
8389 if shard == nil {
@@ -90,12 +96,12 @@ func KubeconfigSecretReconciler(
9096 return nil , err
9197 }
9298
93- addCluster ("default" , defaultURL )
94- addContext ("default" , "default" )
95- addCluster ("base" , serverURL )
96- addContext ("base" , "base" )
97- addContext ("shard-base" , "base" )
98- config .CurrentContext = "default"
99+ addCluster (defaultContext , defaultURL )
100+ addContext (defaultContext , defaultContext )
101+ addCluster (baseContext , serverURL )
102+ addContext (baseContext , baseContext )
103+ addContext (shardBaseContext , baseContext )
104+ config .CurrentContext = defaultContext
99105
100106 case kubeconfig .Spec .Target .FrontProxyRef != nil :
101107 if rootShard == nil {
@@ -108,11 +114,11 @@ func KubeconfigSecretReconciler(
108114 return nil , err
109115 }
110116
111- addCluster ("base" , serverURL )
112- addCluster ("default" , defaultURL )
113- addContext ("default" , "default" )
114- addContext ("base" , "base" )
115- config .CurrentContext = "default"
117+ addCluster (baseContext , serverURL )
118+ addCluster (defaultContext , defaultURL )
119+ addContext (defaultContext , defaultContext )
120+ addContext (baseContext , baseContext )
121+ config .CurrentContext = defaultContext
116122
117123 default :
118124 panic ("Called reconciler for an invalid kubeconfig, this should not have happened." )
0 commit comments