@@ -237,6 +237,11 @@ func createTargetConfig(ctx context.Context, c TargetConfigController, recorder
237
237
errors = append (errors , fmt .Errorf ("%q: %v" , "configmap/trusted-ca-bundle" , err ))
238
238
}
239
239
240
+ err = ensureKubeAPIServerExtensionAuthenticationCA (ctx , c .kubeClient .CoreV1 (), recorder )
241
+ if err != nil {
242
+ errors = append (errors , fmt .Errorf ("%q: %v" , "configmap/extension-apiserver-authentication" , err ))
243
+ }
244
+
240
245
err = ensureLocalhostRecoverySAToken (ctx , c .kubeClient .CoreV1 (), recorder )
241
246
if err != nil {
242
247
errors = append (errors , fmt .Errorf ("%q: %v" , "serviceaccount/localhost-recovery-client" , err ))
@@ -507,6 +512,38 @@ func ensureKubeAPIServerTrustedCA(ctx context.Context, client coreclientv1.CoreV
507
512
return err
508
513
}
509
514
515
+ func ensureKubeAPIServerExtensionAuthenticationCA (ctx context.Context , client coreclientv1.CoreV1Interface , recorder events.Recorder ) error {
516
+ required := resourceread .ReadConfigMapV1OrDie (bindata .MustAsset ("assets/kube-apiserver/extension-apiserver-authentication-cm.yaml" ))
517
+ cmClient := client .ConfigMaps ("kube-system" )
518
+
519
+ cm , err := cmClient .Get (ctx , "extension-apiserver-authentication" , metav1.GetOptions {})
520
+ if err != nil {
521
+ // kube-apiserver creates this CM; don't degrade while waiting.
522
+ return nil
523
+ }
524
+
525
+ // Ensure that the config map is updated with the required annotations
526
+ modified := false
527
+ if cm .Annotations == nil {
528
+ cm .Annotations = make (map [string ]string )
529
+ }
530
+
531
+ for key , expected := range required .Annotations {
532
+ if actual , ok := cm .Annotations [key ]; ! ok || actual != expected {
533
+ cm .Annotations [key ] = expected
534
+ modified = true
535
+ }
536
+ }
537
+
538
+ if modified {
539
+ cmClient .Update (ctx , cm , metav1.UpdateOptions {})
540
+ // Setting annotations is a best-effort operation, so ignore errors.
541
+ return nil
542
+ }
543
+
544
+ return nil
545
+ }
546
+
510
547
func ensureLocalhostRecoverySAToken (ctx context.Context , client coreclientv1.CoreV1Interface , recorder events.Recorder ) error {
511
548
requiredSA := resourceread .ReadServiceAccountV1OrDie (bindata .MustAsset ("assets/kube-apiserver/localhost-recovery-sa.yaml" ))
512
549
requiredToken := resourceread .ReadSecretV1OrDie (bindata .MustAsset ("assets/kube-apiserver/localhost-recovery-token.yaml" ))
0 commit comments