Skip to content

DEBUG: Mount /etc/kubernetes #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bindata/oauth-apiserver/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ spec:
name: serving-cert
- mountPath: /var/run/secrets/encryption-config
name: encryption-config
- mountPath: /var/run/secrets/loopback/apiserver-loopback-client__.crt
name: loopback-cert
subPath: "tls.crt"
- mountPath: /var/run/secrets/loopback/apiserver-loopback-client__.key
name: loopback-cert
subPath: "tls.key"
- mountPath: /var/log/oauth-apiserver
name: audit-dir
livenessProbe:
Expand Down Expand Up @@ -174,6 +180,9 @@ spec:
- hostPath:
path: /var/log/oauth-apiserver
name: audit-dir
- name: loopback-cert
secret:
secretName: loopback
nodeSelector:
node-role.kubernetes.io/master: ""
tolerations:
Expand Down
111 changes: 111 additions & 0 deletions pkg/controllers/certrotationcontroller/certrotationcontroller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package certrotationcontroller

import (
"context"
"fmt"
"time"

operatorv1 "github.com/openshift/api/operator/v1"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"

"github.com/openshift/library-go/pkg/controller/factory"
"github.com/openshift/library-go/pkg/operator/certrotation"
"github.com/openshift/library-go/pkg/operator/condition"
"github.com/openshift/library-go/pkg/operator/events"
"github.com/openshift/library-go/pkg/operator/v1helpers"
)

type OperatorConditionStatusReporter struct {
// Plumbing:
OperatorClient v1helpers.OperatorClient
}

func (s *OperatorConditionStatusReporter) Report(ctx context.Context, controllerName string, syncErr error) (bool, error) {
newCondition := operatorv1.OperatorCondition{
Type: fmt.Sprintf(condition.CertRotationDegradedConditionTypeFmt, controllerName),
Status: operatorv1.ConditionFalse,
}
if syncErr != nil {
newCondition.Status = operatorv1.ConditionTrue
newCondition.Reason = "CertificateRotationError"
newCondition.Message = syncErr.Error()
}
_, updated, updateErr := v1helpers.UpdateStatus(ctx, s.OperatorClient, v1helpers.UpdateConditionFn(newCondition))
return updated, updateErr
}

type CertRotationController struct {
certRotators []factory.Controller
}

func NewCertRotationController(
secretsGetter corev1client.SecretsGetter,
configMapsGetter corev1client.ConfigMapsGetter,
operatorClient v1helpers.OperatorClient,
kubeInformersForNamespaces v1helpers.KubeInformersForNamespaces,
eventRecorder events.Recorder,
day time.Duration,
) (*CertRotationController, error) {
ret := &CertRotationController{}

targetNS := "openshift-oauth-apiserver"

certRotator := certrotation.NewCertRotationController(
"OAuthLoopbackCert",
certrotation.RotatedSigningCASecret{
Namespace: targetNS,
Name: "loopback-signer",
AdditionalAnnotations: certrotation.AdditionalAnnotations{
JiraComponent: "oauth-apiserver",
},
Validity: 60 * day,
Refresh: 30 * day,
RefreshOnlyWhenExpired: false,
Informer: kubeInformersForNamespaces.InformersFor(targetNS).Core().V1().Secrets(),
Lister: kubeInformersForNamespaces.InformersFor(targetNS).Core().V1().Secrets().Lister(),
Client: secretsGetter,
EventRecorder: eventRecorder,
},
certrotation.CABundleConfigMap{
Namespace: targetNS,
Name: "loopback-ca",
AdditionalAnnotations: certrotation.AdditionalAnnotations{
JiraComponent: "oauth-apiserver",
},
Informer: kubeInformersForNamespaces.InformersFor(targetNS).Core().V1().ConfigMaps(),
Lister: kubeInformersForNamespaces.InformersFor(targetNS).Core().V1().ConfigMaps().Lister(),
Client: configMapsGetter,
EventRecorder: eventRecorder,
},
certrotation.RotatedSelfSignedCertKeySecret{
Namespace: targetNS,
Name: "loopback",
AdditionalAnnotations: certrotation.AdditionalAnnotations{
JiraComponent: "oauth-apiserver",
},
Validity: 30 * day,
Refresh: 15 * day,
RefreshOnlyWhenExpired: false,
CertCreator: &certrotation.ServingRotation{
Hostnames: func() []string { return []string{"apiserver-loopback-client"} },
},
Informer: kubeInformersForNamespaces.InformersFor(targetNS).Core().V1().Secrets(),
Lister: kubeInformersForNamespaces.InformersFor(targetNS).Core().V1().Secrets().Lister(),
Client: secretsGetter,
EventRecorder: eventRecorder,
},
eventRecorder,
&OperatorConditionStatusReporter{OperatorClient: operatorClient},
)

ret.certRotators = append(ret.certRotators, certRotator)

return ret, nil
}

func (c *CertRotationController) Run(ctx context.Context, workers int) {
syncCtx := context.WithValue(ctx, certrotation.RunOnceContextKey, false)
for _, certRotator := range c.certRotators {
go certRotator.Run(syncCtx, workers)
}
}
14 changes: 14 additions & 0 deletions pkg/operator/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
routev1 "github.com/openshift/api/route/v1"
applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"
"github.com/openshift/cluster-authentication-operator/bindata"
"github.com/openshift/cluster-authentication-operator/pkg/controllers/certrotationcontroller"
"github.com/openshift/cluster-authentication-operator/pkg/controllers/configobservation/configobservercontroller"
componentroutesecretsync "github.com/openshift/cluster-authentication-operator/pkg/controllers/customroute"
"github.com/openshift/cluster-authentication-operator/pkg/controllers/deployment"
Expand Down Expand Up @@ -652,6 +653,18 @@ func prepareOauthAPIServerOperator(
eventRecorder,
)

certRotationController, err := certrotationcontroller.NewCertRotationController(
v1helpers.CachedSecretGetter(authOperatorInput.kubeClient.CoreV1(), informerFactories.kubeInformersForNamespaces),
v1helpers.CachedConfigMapGetter(authOperatorInput.kubeClient.CoreV1(), informerFactories.kubeInformersForNamespaces),
authOperatorInput.authenticationOperatorClient,
informerFactories.kubeInformersForNamespaces,
authOperatorInput.eventRecorder,
time.Hour*24,
)
if err != nil {
return nil, nil, err
}

runOnceFns := []libraryapplyconfiguration.NamedRunOnce{
libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, "TODO-other-configObserver", configObserver.Sync),
libraryapplyconfiguration.AdaptSyncFn(authOperatorInput.eventRecorder, "TODO-authenticatorCertRequester", authenticatorCertRequester.Sync),
Expand All @@ -668,6 +681,7 @@ func prepareOauthAPIServerOperator(
libraryapplyconfiguration.AdaptRunFn(webhookAuthController.Run),
libraryapplyconfiguration.AdaptRunFn(webhookCertsApprover.Run),
libraryapplyconfiguration.AdaptRunFn(func(ctx context.Context, _ int) { apiServerControllers.Run(ctx) }),
libraryapplyconfiguration.AdaptRunFn(certRotationController.Run),
}

return runOnceFns, runFns, nil
Expand Down