@@ -146,13 +146,10 @@ def auth(kube_config: str) -> None:
146
146
os .environ ["KUBECONFIG" ] = combined_kubeconfig
147
147
with open (kube_config ) as file :
148
148
content = yaml .safe_load (file )
149
- for elem in content :
150
- print (elem )
151
- content ["clusters" ][0 ]
152
149
user = content ["users" ][0 ]
153
150
user_name = user ["name" ]
154
151
user_token = user ["user" ]["token" ]
155
- content ["contexts" ][ 0 ]
152
+ current_context = content ["current-context" ]
156
153
flatten_cmd = "kubectl config view --flatten"
157
154
result_flatten = subprocess .run (
158
155
flatten_cmd , shell = True , check = True , capture_output = True , text = True
@@ -187,11 +184,14 @@ def auth(kube_config: str) -> None:
187
184
188
185
with open (current_kubeconfig ) as file :
189
186
contents = yaml .safe_load (file )
190
- print ("\n Use the following command to switch to a new user:" )
191
- print (" kubectl config use-context [user]\n " )
192
- print ("Available users:" )
193
- for c in contents ["contexts" ]:
194
- print (f" { c ['name' ]} " )
187
+
188
+ with open (current_kubeconfig , "w" ) as file :
189
+ contents ["current-context" ] = current_context
190
+ yaml .safe_dump (contents , file )
191
+
192
+ with open (current_kubeconfig ) as file :
193
+ contents = yaml .safe_load (file )
194
+ print (f"\n Warcli's current context is now set to: { contents ['current-context' ]} " )
195
195
196
196
197
197
if __name__ == "__main__" :
0 commit comments