@@ -111,6 +111,8 @@ public static IServiceCollection AddKubeClientOptionsFromKubeConfig(this IServic
111
111
KubeClientOptions optionsForTargetContext = config . ToKubeClientOptions ( kubeContextName , defaultKubeNamespace ) ;
112
112
113
113
optionsForTargetContext . CopyTo ( kubeClientOptions ) ;
114
+
115
+ kubeClientOptions . KubeNamespace = defaultKubeNamespace ;
114
116
} ) ;
115
117
116
118
return services ;
@@ -156,6 +158,8 @@ public static IServiceCollection AddKubeClientOptionsFromKubeConfig(this IServic
156
158
KubeClientOptions optionsForTargetContext = config . ToKubeClientOptions ( kubeContextName , defaultKubeNamespace ) ;
157
159
158
160
optionsForTargetContext . CopyTo ( kubeClientOptions ) ;
161
+
162
+ kubeClientOptions . KubeNamespace = defaultKubeNamespace ;
159
163
} ) ;
160
164
161
165
return services ;
@@ -186,25 +190,20 @@ public static IServiceCollection AddKubeClientOptionsFromKubeConfig(this IServic
186
190
187
191
FileInfo kubeConfigFile = GetKubeConfigFile ( kubeConfigFileName ) ;
188
192
193
+ // List of contexts is static for application lifetime...
189
194
K8sConfig config = K8sConfig . Load ( kubeConfigFile ) ;
190
- foreach ( Context targetContext in config . Contexts ) // AF: List of contexts is static for application lifetime, but config for those contexts is dynamic.
195
+
196
+ foreach ( Context targetContext in config . Contexts )
191
197
{
192
198
services . AddKubeClientOptions ( targetContext . Name , kubeClientOptions =>
193
199
{
194
- Cluster targetCluster = config . Clusters . Find ( cluster => cluster . Name == targetContext . Config . ClusterName ) ;
195
- if ( targetCluster == null )
196
- throw new InvalidOperationException ( $ "Cannot find a cluster in the Kubernetes client configuration named '{ targetContext . Config . ClusterName } '.") ;
200
+ // ...but config for those contexts is dynamic.
201
+ K8sConfig currentConfig = K8sConfig . Load ( kubeConfigFile ) ;
197
202
198
- UserIdentity targetUser = config . UserIdentities . Find ( user => user . Name == targetContext . Config . UserName ) ;
199
- if ( targetUser == null )
200
- throw new InvalidOperationException ( $ "Cannot find a user identity in the Kubernetes client configuration named '{ targetContext . Config . UserName } '.") ;
203
+ KubeClientOptions optionsForTargetContext = currentConfig . ToKubeClientOptions ( targetContext . Name , defaultKubeNamespace ) ;
204
+ optionsForTargetContext . CopyTo ( kubeClientOptions ) ;
201
205
202
- kubeClientOptions . ApiEndPoint = new Uri ( targetCluster . Config . Server ) ;
203
206
kubeClientOptions . KubeNamespace = defaultKubeNamespace ;
204
-
205
- kubeClientOptions . ClientCertificate = targetUser . Config . GetClientCertificate ( ) ;
206
- kubeClientOptions . CertificationAuthorityCertificate = targetCluster . Config . GetCACertificate ( ) ;
207
- kubeClientOptions . AccessToken = targetUser . Config . GetRawToken ( ) ;
208
207
} ) ;
209
208
}
210
209
0 commit comments