2021-01-07 22:58:09 +00:00
|
|
|
// Copyright 2020-2021 the Pinniped contributors. All Rights Reserved.
|
2020-09-16 14:19:51 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-08-07 21:49:04 +00:00
|
|
|
|
2020-09-21 18:16:14 +00:00
|
|
|
// Package controllermanager provides an entrypoint into running all of the controllers that run as
|
|
|
|
// a part of Pinniped.
|
2020-08-09 17:04:05 +00:00
|
|
|
package controllermanager
|
2020-08-07 21:49:04 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-02-12 01:22:47 +00:00
|
|
|
"crypto/tls"
|
2020-08-07 21:49:04 +00:00
|
|
|
"fmt"
|
2021-02-12 01:22:47 +00:00
|
|
|
"net/http"
|
2020-08-07 21:49:04 +00:00
|
|
|
"time"
|
|
|
|
|
2021-02-15 23:00:10 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
2020-09-23 15:01:41 +00:00
|
|
|
"k8s.io/apimachinery/pkg/util/clock"
|
2020-08-07 21:49:04 +00:00
|
|
|
k8sinformers "k8s.io/client-go/informers"
|
|
|
|
"k8s.io/client-go/kubernetes"
|
2020-09-14 15:47:16 +00:00
|
|
|
"k8s.io/klog/v2/klogr"
|
2020-08-07 21:49:04 +00:00
|
|
|
|
2021-01-07 22:58:09 +00:00
|
|
|
loginv1alpha1 "go.pinniped.dev/generated/1.20/apis/concierge/login/v1alpha1"
|
|
|
|
pinnipedclientset "go.pinniped.dev/generated/1.20/client/concierge/clientset/versioned"
|
|
|
|
pinnipedinformers "go.pinniped.dev/generated/1.20/client/concierge/informers/externalversions"
|
2021-02-10 16:12:03 +00:00
|
|
|
"go.pinniped.dev/internal/apiserviceref"
|
2021-02-12 01:22:47 +00:00
|
|
|
"go.pinniped.dev/internal/concierge/impersonator"
|
2020-10-15 19:40:56 +00:00
|
|
|
"go.pinniped.dev/internal/config/concierge"
|
2020-09-18 19:56:24 +00:00
|
|
|
"go.pinniped.dev/internal/controller/apicerts"
|
2020-10-30 19:02:21 +00:00
|
|
|
"go.pinniped.dev/internal/controller/authenticator/authncache"
|
2020-12-08 01:39:51 +00:00
|
|
|
"go.pinniped.dev/internal/controller/authenticator/cachecleaner"
|
|
|
|
"go.pinniped.dev/internal/controller/authenticator/jwtcachefiller"
|
2020-10-30 19:02:21 +00:00
|
|
|
"go.pinniped.dev/internal/controller/authenticator/webhookcachefiller"
|
2021-02-12 01:22:47 +00:00
|
|
|
"go.pinniped.dev/internal/controller/impersonatorconfig"
|
2020-09-18 19:56:24 +00:00
|
|
|
"go.pinniped.dev/internal/controller/issuerconfig"
|
2020-09-21 18:16:14 +00:00
|
|
|
"go.pinniped.dev/internal/controller/kubecertagent"
|
2020-09-18 19:56:24 +00:00
|
|
|
"go.pinniped.dev/internal/controllerlib"
|
2021-01-05 22:07:33 +00:00
|
|
|
"go.pinniped.dev/internal/deploymentref"
|
|
|
|
"go.pinniped.dev/internal/downward"
|
2020-09-23 12:26:59 +00:00
|
|
|
"go.pinniped.dev/internal/dynamiccert"
|
2021-01-13 01:27:41 +00:00
|
|
|
"go.pinniped.dev/internal/groupsuffix"
|
2021-01-05 22:07:33 +00:00
|
|
|
"go.pinniped.dev/internal/kubeclient"
|
2020-08-07 21:49:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
singletonWorker = 1
|
|
|
|
defaultResyncInterval = 3 * time.Minute
|
|
|
|
)
|
|
|
|
|
2020-09-21 18:16:14 +00:00
|
|
|
// Config holds all the input parameters to the set of controllers run as a part of Pinniped.
|
|
|
|
//
|
|
|
|
// It is used to inject parameters into PrepareControllers.
|
|
|
|
type Config struct {
|
2021-01-05 22:07:33 +00:00
|
|
|
// ServerInstallationInfo provides the name of the pod in which Pinniped is running and the namespace in which Pinniped is deployed.
|
|
|
|
ServerInstallationInfo *downward.PodInfo
|
2020-09-21 18:16:14 +00:00
|
|
|
|
2021-01-19 15:52:12 +00:00
|
|
|
// APIGroupSuffix is the suffix of the Pinniped API that should be targeted by these controllers.
|
|
|
|
APIGroupSuffix string
|
|
|
|
|
2020-09-21 18:16:14 +00:00
|
|
|
// NamesConfig comes from the Pinniped config API (see api.Config). It specifies how Kubernetes
|
|
|
|
// objects should be named.
|
2020-10-15 19:40:56 +00:00
|
|
|
NamesConfig *concierge.NamesConfigSpec
|
2020-09-21 18:16:14 +00:00
|
|
|
|
2020-09-24 00:30:22 +00:00
|
|
|
// KubeCertAgentConfig comes from the Pinniped config API (see api.Config). It configures how
|
|
|
|
// the kubecertagent package's controllers should manage the agent pods.
|
2020-10-15 19:40:56 +00:00
|
|
|
KubeCertAgentConfig *concierge.KubeCertAgentSpec
|
2020-09-24 00:30:22 +00:00
|
|
|
|
2020-09-21 18:16:14 +00:00
|
|
|
// DiscoveryURLOverride allows a caller to inject a hardcoded discovery URL into Pinniped
|
|
|
|
// discovery document.
|
|
|
|
DiscoveryURLOverride *string
|
|
|
|
|
2020-09-23 13:53:21 +00:00
|
|
|
// DynamicServingCertProvider provides a setter and a getter to the Pinniped API's serving cert.
|
|
|
|
DynamicServingCertProvider dynamiccert.Provider
|
2020-09-23 15:01:41 +00:00
|
|
|
// DynamicSigningCertProvider provides a setter and a getter to the Pinniped API's
|
|
|
|
// signing cert, i.e., the cert that it uses to sign certs for Pinniped clients wishing to login.
|
|
|
|
DynamicSigningCertProvider dynamiccert.Provider
|
2020-09-21 18:16:14 +00:00
|
|
|
|
|
|
|
// ServingCertDuration is the validity period, in seconds, of the API serving certificate.
|
|
|
|
ServingCertDuration time.Duration
|
|
|
|
// ServingCertRenewBefore is the period of time, in seconds, that pinniped will wait before
|
|
|
|
// rotating the serving certificate. This period of time starts upon issuance of the serving
|
|
|
|
// certificate.
|
|
|
|
ServingCertRenewBefore time.Duration
|
|
|
|
|
2020-10-30 19:02:21 +00:00
|
|
|
// AuthenticatorCache is a cache of authenticators shared amongst various authenticated-related controllers.
|
|
|
|
AuthenticatorCache *authncache.Cache
|
2020-10-15 17:14:23 +00:00
|
|
|
|
2021-02-15 23:00:10 +00:00
|
|
|
// LoginJSONDecoder can decode login.concierge.pinniped.dev types (e.g., TokenCredentialRequest)
|
|
|
|
// into their internal representation.
|
|
|
|
LoginJSONDecoder runtime.Decoder
|
|
|
|
|
2020-10-15 17:14:23 +00:00
|
|
|
// Labels are labels that should be added to any resources created by the controllers.
|
|
|
|
Labels map[string]string
|
2020-09-21 18:16:14 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 21:49:04 +00:00
|
|
|
// Prepare the controllers and their informers and return a function that will start them when called.
|
2020-09-21 18:16:14 +00:00
|
|
|
//nolint:funlen // Eh, fair, it is a really long function...but it is wiring the world...so...
|
|
|
|
func PrepareControllers(c *Config) (func(ctx context.Context), error) {
|
2021-02-10 16:12:03 +00:00
|
|
|
groupName, ok := groupsuffix.Replace(loginv1alpha1.GroupName, c.APIGroupSuffix)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("cannot make api group from %s/%s", loginv1alpha1.GroupName, c.APIGroupSuffix)
|
|
|
|
}
|
|
|
|
apiServiceName := loginv1alpha1.SchemeGroupVersion.Version + "." + groupName
|
|
|
|
|
2021-01-05 22:07:33 +00:00
|
|
|
dref, _, err := deploymentref.New(c.ServerInstallationInfo)
|
2020-09-23 15:01:41 +00:00
|
|
|
if err != nil {
|
2021-01-05 22:07:33 +00:00
|
|
|
return nil, fmt.Errorf("cannot create deployment ref: %w", err)
|
2020-09-23 15:01:41 +00:00
|
|
|
}
|
2021-01-05 22:07:33 +00:00
|
|
|
|
2021-02-10 16:12:03 +00:00
|
|
|
apiServiceRef, err := apiserviceref.New(apiServiceName)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot create API service ref: %w", err)
|
|
|
|
}
|
|
|
|
|
2021-01-13 01:27:41 +00:00
|
|
|
client, err := kubeclient.New(
|
2021-02-10 16:12:03 +00:00
|
|
|
dref, // first try to use the deployment as an owner ref (for namespace scoped resources)
|
|
|
|
apiServiceRef, // fallback to our API service (for everything else we create)
|
2021-01-13 01:27:41 +00:00
|
|
|
kubeclient.WithMiddleware(groupsuffix.New(c.APIGroupSuffix)),
|
|
|
|
)
|
2020-08-07 21:49:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not create clients for the controllers: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-08-09 17:04:05 +00:00
|
|
|
// Create informers. Don't forget to make sure they get started in the function returned below.
|
2021-01-05 22:07:33 +00:00
|
|
|
informers := createInformers(c.ServerInstallationInfo.Namespace, client.Kubernetes, client.PinnipedConcierge)
|
2020-08-07 21:49:04 +00:00
|
|
|
|
2020-09-24 00:30:22 +00:00
|
|
|
// Configuration for the kubecertagent controllers created below.
|
|
|
|
agentPodConfig := &kubecertagent.AgentPodConfig{
|
2021-01-05 22:07:33 +00:00
|
|
|
Namespace: c.ServerInstallationInfo.Namespace,
|
2020-09-24 19:52:05 +00:00
|
|
|
ContainerImage: *c.KubeCertAgentConfig.Image,
|
|
|
|
PodNamePrefix: *c.KubeCertAgentConfig.NamePrefix,
|
|
|
|
ContainerImagePullSecrets: c.KubeCertAgentConfig.ImagePullSecrets,
|
2020-10-15 17:14:23 +00:00
|
|
|
AdditionalLabels: c.Labels,
|
2020-09-24 00:30:22 +00:00
|
|
|
}
|
2020-11-02 21:39:43 +00:00
|
|
|
credentialIssuerLocationConfig := &kubecertagent.CredentialIssuerLocationConfig{
|
2021-02-09 18:59:32 +00:00
|
|
|
Name: c.NamesConfig.CredentialIssuer,
|
2020-09-24 00:30:22 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 21:49:04 +00:00
|
|
|
// Create controller manager.
|
2020-08-28 15:59:09 +00:00
|
|
|
controllerManager := controllerlib.
|
2020-08-07 21:49:04 +00:00
|
|
|
NewManager().
|
2020-09-24 00:30:22 +00:00
|
|
|
|
|
|
|
// KubeConfig info publishing controller is responsible for writing the KubeConfig information to the
|
2020-11-02 21:39:43 +00:00
|
|
|
// CredentialIssuer resource and keeping that information up to date.
|
2020-08-07 21:49:04 +00:00
|
|
|
WithController(
|
2020-09-23 11:58:01 +00:00
|
|
|
issuerconfig.NewKubeConfigInfoPublisherController(
|
2020-11-02 21:39:43 +00:00
|
|
|
c.NamesConfig.CredentialIssuer,
|
2020-10-15 17:14:23 +00:00
|
|
|
c.Labels,
|
2020-09-21 18:16:14 +00:00
|
|
|
c.DiscoveryURLOverride,
|
2021-01-05 22:07:33 +00:00
|
|
|
client.PinnipedConcierge,
|
2020-09-21 18:16:14 +00:00
|
|
|
informers.kubePublicNamespaceK8s.Core().V1().ConfigMaps(),
|
2020-08-28 15:59:09 +00:00
|
|
|
controllerlib.WithInformer,
|
2020-08-09 17:04:05 +00:00
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
2020-09-24 00:30:22 +00:00
|
|
|
|
|
|
|
// API certs controllers are responsible for managing the TLS certificates used to serve Pinniped's API.
|
2020-08-09 17:04:05 +00:00
|
|
|
WithController(
|
|
|
|
apicerts.NewCertsManagerController(
|
2021-01-05 22:07:33 +00:00
|
|
|
c.ServerInstallationInfo.Namespace,
|
2020-09-21 18:16:14 +00:00
|
|
|
c.NamesConfig.ServingCertificateSecret,
|
2020-10-15 17:14:23 +00:00
|
|
|
c.Labels,
|
2021-01-05 22:07:33 +00:00
|
|
|
client.Kubernetes,
|
2020-09-21 18:16:14 +00:00
|
|
|
informers.installationNamespaceK8s.Core().V1().Secrets(),
|
2020-08-28 15:59:09 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
controllerlib.WithInitialEvent,
|
2020-09-21 18:16:14 +00:00
|
|
|
c.ServingCertDuration,
|
2020-09-08 23:36:49 +00:00
|
|
|
"Pinniped CA",
|
2020-09-21 18:16:14 +00:00
|
|
|
c.NamesConfig.APIService,
|
2020-09-08 23:36:49 +00:00
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
2020-09-16 20:00:03 +00:00
|
|
|
WithController(
|
|
|
|
apicerts.NewAPIServiceUpdaterController(
|
2021-01-05 22:07:33 +00:00
|
|
|
c.ServerInstallationInfo.Namespace,
|
2020-09-21 18:16:14 +00:00
|
|
|
c.NamesConfig.ServingCertificateSecret,
|
2021-01-19 15:52:12 +00:00
|
|
|
apiServiceName,
|
2021-01-05 22:07:33 +00:00
|
|
|
client.Aggregation,
|
2020-09-21 18:16:14 +00:00
|
|
|
informers.installationNamespaceK8s.Core().V1().Secrets(),
|
2020-09-16 20:00:03 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
2020-08-09 17:04:05 +00:00
|
|
|
WithController(
|
|
|
|
apicerts.NewCertsObserverController(
|
2021-01-05 22:07:33 +00:00
|
|
|
c.ServerInstallationInfo.Namespace,
|
2020-09-21 18:16:14 +00:00
|
|
|
c.NamesConfig.ServingCertificateSecret,
|
2020-09-23 13:53:21 +00:00
|
|
|
c.DynamicServingCertProvider,
|
2020-09-21 18:16:14 +00:00
|
|
|
informers.installationNamespaceK8s.Core().V1().Secrets(),
|
2020-08-28 15:59:09 +00:00
|
|
|
controllerlib.WithInformer,
|
2020-08-07 21:49:04 +00:00
|
|
|
),
|
|
|
|
singletonWorker,
|
2020-08-19 20:15:45 +00:00
|
|
|
).
|
|
|
|
WithController(
|
|
|
|
apicerts.NewCertsExpirerController(
|
2021-01-05 22:07:33 +00:00
|
|
|
c.ServerInstallationInfo.Namespace,
|
2020-09-21 18:16:14 +00:00
|
|
|
c.NamesConfig.ServingCertificateSecret,
|
2021-01-05 22:07:33 +00:00
|
|
|
client.Kubernetes,
|
2020-09-21 18:16:14 +00:00
|
|
|
informers.installationNamespaceK8s.Core().V1().Secrets(),
|
2020-08-28 15:59:09 +00:00
|
|
|
controllerlib.WithInformer,
|
2020-09-21 18:16:14 +00:00
|
|
|
c.ServingCertRenewBefore,
|
2020-08-19 20:15:45 +00:00
|
|
|
),
|
|
|
|
singletonWorker,
|
2020-09-14 15:47:16 +00:00
|
|
|
).
|
2020-09-24 00:30:22 +00:00
|
|
|
|
|
|
|
// Kube cert agent controllers are responsible for finding the cluster's signing keys and keeping them
|
|
|
|
// up to date in memory, as well as reporting status on this cluster integration strategy.
|
2020-09-14 15:47:16 +00:00
|
|
|
WithController(
|
2020-09-24 00:30:22 +00:00
|
|
|
kubecertagent.NewCreaterController(
|
|
|
|
agentPodConfig,
|
2020-11-02 21:39:43 +00:00
|
|
|
credentialIssuerLocationConfig,
|
2020-10-15 17:14:23 +00:00
|
|
|
c.Labels,
|
2020-09-24 14:40:50 +00:00
|
|
|
clock.RealClock{},
|
2021-01-05 22:07:33 +00:00
|
|
|
client.Kubernetes,
|
|
|
|
client.PinnipedConcierge,
|
2020-09-24 00:30:22 +00:00
|
|
|
informers.kubeSystemNamespaceK8s.Core().V1().Pods(),
|
|
|
|
informers.installationNamespaceK8s.Core().V1().Pods(),
|
|
|
|
controllerlib.WithInformer,
|
2020-09-24 20:54:20 +00:00
|
|
|
controllerlib.WithInitialEvent,
|
2020-09-14 15:47:16 +00:00
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
|
|
|
WithController(
|
2020-09-24 00:30:22 +00:00
|
|
|
kubecertagent.NewAnnotaterController(
|
|
|
|
agentPodConfig,
|
2020-11-02 21:39:43 +00:00
|
|
|
credentialIssuerLocationConfig,
|
2020-09-24 14:40:50 +00:00
|
|
|
clock.RealClock{},
|
2021-01-05 22:07:33 +00:00
|
|
|
client.Kubernetes,
|
|
|
|
client.PinnipedConcierge,
|
2020-09-24 00:30:22 +00:00
|
|
|
informers.kubeSystemNamespaceK8s.Core().V1().Pods(),
|
|
|
|
informers.installationNamespaceK8s.Core().V1().Pods(),
|
|
|
|
controllerlib.WithInformer,
|
2020-09-14 15:47:16 +00:00
|
|
|
),
|
|
|
|
singletonWorker,
|
2020-09-21 18:16:14 +00:00
|
|
|
).
|
|
|
|
WithController(
|
2020-09-24 00:30:22 +00:00
|
|
|
kubecertagent.NewExecerController(
|
2020-11-02 21:39:43 +00:00
|
|
|
credentialIssuerLocationConfig,
|
2020-09-24 00:30:22 +00:00
|
|
|
c.DynamicSigningCertProvider,
|
2021-01-05 22:07:33 +00:00
|
|
|
kubecertagent.NewPodCommandExecutor(client.JSONConfig, client.Kubernetes),
|
|
|
|
client.PinnipedConcierge,
|
2020-09-24 00:30:22 +00:00
|
|
|
clock.RealClock{},
|
2020-09-21 23:37:22 +00:00
|
|
|
informers.installationNamespaceK8s.Core().V1().Pods(),
|
2020-09-21 18:16:14 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
|
|
|
WithController(
|
|
|
|
kubecertagent.NewDeleterController(
|
2020-09-24 00:30:22 +00:00
|
|
|
agentPodConfig,
|
2021-01-05 22:07:33 +00:00
|
|
|
client.Kubernetes,
|
2020-09-21 18:16:14 +00:00
|
|
|
informers.kubeSystemNamespaceK8s.Core().V1().Pods(),
|
2020-09-21 23:37:22 +00:00
|
|
|
informers.installationNamespaceK8s.Core().V1().Pods(),
|
2020-09-21 18:16:14 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
2020-09-24 00:30:22 +00:00
|
|
|
|
2020-10-30 19:02:21 +00:00
|
|
|
// The cache filler/cleaner controllers are responsible for keep an in-memory representation of active
|
|
|
|
// authenticators up to date.
|
2020-09-21 18:16:14 +00:00
|
|
|
WithController(
|
2020-09-24 00:30:22 +00:00
|
|
|
webhookcachefiller.New(
|
2020-10-30 19:02:21 +00:00
|
|
|
c.AuthenticatorCache,
|
2021-02-09 18:59:32 +00:00
|
|
|
informers.pinniped.Authentication().V1alpha1().WebhookAuthenticators(),
|
2020-09-24 00:30:22 +00:00
|
|
|
klogr.New(),
|
2020-09-21 18:16:14 +00:00
|
|
|
),
|
|
|
|
singletonWorker,
|
2020-09-23 15:01:41 +00:00
|
|
|
).
|
|
|
|
WithController(
|
2020-12-08 01:39:51 +00:00
|
|
|
jwtcachefiller.New(
|
|
|
|
c.AuthenticatorCache,
|
2021-02-09 18:59:32 +00:00
|
|
|
informers.pinniped.Authentication().V1alpha1().JWTAuthenticators(),
|
2020-12-08 01:39:51 +00:00
|
|
|
klogr.New(),
|
|
|
|
),
|
|
|
|
singletonWorker,
|
|
|
|
).
|
|
|
|
WithController(
|
|
|
|
cachecleaner.New(
|
2020-10-30 19:02:21 +00:00
|
|
|
c.AuthenticatorCache,
|
2021-02-09 18:59:32 +00:00
|
|
|
informers.pinniped.Authentication().V1alpha1().WebhookAuthenticators(),
|
|
|
|
informers.pinniped.Authentication().V1alpha1().JWTAuthenticators(),
|
2020-09-24 00:30:22 +00:00
|
|
|
klogr.New(),
|
2020-09-23 15:01:41 +00:00
|
|
|
),
|
|
|
|
singletonWorker,
|
2021-02-12 01:22:47 +00:00
|
|
|
).
|
|
|
|
|
|
|
|
// The impersonation proxy configuration controllers dynamically configure the impersonation proxy feature.
|
|
|
|
WithController(
|
|
|
|
impersonatorconfig.NewImpersonatorConfigController(
|
|
|
|
c.ServerInstallationInfo.Namespace,
|
|
|
|
"pinniped-concierge-impersonation-proxy-config", // TODO this string should come from `c.NamesConfig`
|
|
|
|
client.Kubernetes,
|
|
|
|
informers.installationNamespaceK8s.Core().V1().ConfigMaps(),
|
2021-02-18 01:22:13 +00:00
|
|
|
informers.installationNamespaceK8s.Core().V1().Services(),
|
2021-02-12 01:22:47 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
controllerlib.WithInitialEvent,
|
|
|
|
"pinniped-concierge-impersonation-proxy-load-balancer", // TODO this string should come from `c.NamesConfig`
|
2021-02-16 23:57:02 +00:00
|
|
|
c.Labels,
|
2021-02-12 01:22:47 +00:00
|
|
|
tls.Listen,
|
|
|
|
func() (http.Handler, error) {
|
2021-02-15 23:00:10 +00:00
|
|
|
impersonationProxyHandler, err := impersonator.New(c.AuthenticatorCache, c.LoginJSONDecoder, klogr.New().WithName("impersonation-proxy"))
|
2021-02-12 01:22:47 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not create impersonation proxy: %w", err)
|
|
|
|
}
|
|
|
|
return impersonationProxyHandler, nil
|
|
|
|
},
|
|
|
|
),
|
|
|
|
singletonWorker,
|
2020-08-07 21:49:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Return a function which starts the informers and controllers.
|
|
|
|
return func(ctx context.Context) {
|
2020-09-21 18:16:14 +00:00
|
|
|
informers.startAndWaitForSync(ctx)
|
2020-08-07 21:49:04 +00:00
|
|
|
go controllerManager.Start(ctx)
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-09-21 18:16:14 +00:00
|
|
|
type informers struct {
|
2021-02-09 18:59:32 +00:00
|
|
|
kubePublicNamespaceK8s k8sinformers.SharedInformerFactory
|
|
|
|
kubeSystemNamespaceK8s k8sinformers.SharedInformerFactory
|
|
|
|
installationNamespaceK8s k8sinformers.SharedInformerFactory
|
|
|
|
pinniped pinnipedinformers.SharedInformerFactory
|
2020-09-21 18:16:14 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 21:49:04 +00:00
|
|
|
// Create the informers that will be used by the controllers.
|
|
|
|
func createInformers(
|
|
|
|
serverInstallationNamespace string,
|
2021-01-05 22:07:33 +00:00
|
|
|
k8sClient kubernetes.Interface,
|
|
|
|
pinnipedClient pinnipedclientset.Interface,
|
2020-09-21 18:16:14 +00:00
|
|
|
) *informers {
|
|
|
|
return &informers{
|
|
|
|
kubePublicNamespaceK8s: k8sinformers.NewSharedInformerFactoryWithOptions(
|
|
|
|
k8sClient,
|
|
|
|
defaultResyncInterval,
|
|
|
|
k8sinformers.WithNamespace(issuerconfig.ClusterInfoNamespace),
|
|
|
|
),
|
|
|
|
kubeSystemNamespaceK8s: k8sinformers.NewSharedInformerFactoryWithOptions(
|
|
|
|
k8sClient,
|
|
|
|
defaultResyncInterval,
|
|
|
|
k8sinformers.WithNamespace(kubecertagent.ControllerManagerNamespace),
|
|
|
|
),
|
|
|
|
installationNamespaceK8s: k8sinformers.NewSharedInformerFactoryWithOptions(
|
|
|
|
k8sClient,
|
|
|
|
defaultResyncInterval,
|
|
|
|
k8sinformers.WithNamespace(serverInstallationNamespace),
|
|
|
|
),
|
2021-02-09 18:59:32 +00:00
|
|
|
pinniped: pinnipedinformers.NewSharedInformerFactoryWithOptions(
|
2020-09-21 18:16:14 +00:00
|
|
|
pinnipedClient,
|
|
|
|
defaultResyncInterval,
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i *informers) startAndWaitForSync(ctx context.Context) {
|
|
|
|
i.kubePublicNamespaceK8s.Start(ctx.Done())
|
|
|
|
i.kubeSystemNamespaceK8s.Start(ctx.Done())
|
|
|
|
i.installationNamespaceK8s.Start(ctx.Done())
|
2021-02-09 18:59:32 +00:00
|
|
|
i.pinniped.Start(ctx.Done())
|
2020-09-21 18:16:14 +00:00
|
|
|
|
|
|
|
i.kubePublicNamespaceK8s.WaitForCacheSync(ctx.Done())
|
|
|
|
i.kubeSystemNamespaceK8s.WaitForCacheSync(ctx.Done())
|
|
|
|
i.installationNamespaceK8s.WaitForCacheSync(ctx.Done())
|
2021-02-09 18:59:32 +00:00
|
|
|
i.pinniped.WaitForCacheSync(ctx.Done())
|
2020-08-07 21:49:04 +00:00
|
|
|
}
|