Skip to content

Commit a836b12

Browse files
committed
targetconfigcontroller: make sure extension-apiserver-authentication has necessary annotations
configmap kube-system/extension-apiserver-authentication is created by kube-apiserver, but it doesn't have ownership metadata. This commit updates target config controller to set necessary metadata (ownership and description)
1 parent 0bec046 commit a836b12

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# NOTE: This asset defines the required annotations for the live
2+
# kube-system/extension-apiserver-authentication ConfigMap. It is not
3+
# applied directly; the operator reads these annotations and reconciles
4+
# them on the existing ConfigMap created by kube-apiserver.
5+
apiVersion: v1
6+
kind: ConfigMap
7+
metadata:
8+
name: extension-apiserver-authentication
9+
namespace: kube-system
10+
annotations:
11+
"openshift.io/owning-component": "kube-apiserver"
12+
"openshift.io/description": "CA holding the root certificate bundle used to verify client certificates on incoming requests"

pkg/operator/targetconfigcontroller/targetconfigcontroller.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ func createTargetConfig(ctx context.Context, c TargetConfigController, recorder
237237
errors = append(errors, fmt.Errorf("%q: %v", "configmap/trusted-ca-bundle", err))
238238
}
239239

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+
240245
err = ensureLocalhostRecoverySAToken(ctx, c.kubeClient.CoreV1(), recorder)
241246
if err != nil {
242247
errors = append(errors, fmt.Errorf("%q: %v", "serviceaccount/localhost-recovery-client", err))
@@ -507,6 +512,37 @@ func ensureKubeAPIServerTrustedCA(ctx context.Context, client coreclientv1.CoreV
507512
return err
508513
}
509514

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+
if apierrors.IsNotFound(err) {
523+
return nil
524+
}
525+
return err
526+
}
527+
528+
// Ensure that the config map is updated with the required annotations
529+
modified := false
530+
for key, value := range required.Annotations {
531+
if cm.Annotations[key] != value {
532+
cm.Annotations[key] = value
533+
modified = true
534+
}
535+
}
536+
537+
if modified {
538+
updatedCM, err := cmCLient.Update(ctx, cm, metav1.UpdateOptions{})
539+
resourcehelper.ReportUpdateEvent(recorder, updatedCM, err)
540+
return err
541+
}
542+
543+
return err
544+
}
545+
510546
func ensureLocalhostRecoverySAToken(ctx context.Context, client coreclientv1.CoreV1Interface, recorder events.Recorder) error {
511547
requiredSA := resourceread.ReadServiceAccountV1OrDie(bindata.MustAsset("assets/kube-apiserver/localhost-recovery-sa.yaml"))
512548
requiredToken := resourceread.ReadSecretV1OrDie(bindata.MustAsset("assets/kube-apiserver/localhost-recovery-token.yaml"))

0 commit comments

Comments
 (0)