-
Notifications
You must be signed in to change notification settings - Fork 207
/
simple_clientcert_controller.go
50 lines (45 loc) · 1.48 KB
/
simple_clientcert_controller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package csr
import (
"crypto/x509/pkix"
"fmt"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"github.com/openshift/library-go/pkg/controller/factory"
"github.com/openshift/library-go/pkg/operator/events"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// NewSimpleClientCertificateController creates a controller that keeps a secret up to date with a client-cert
// valid against the kube-apiserver. This version only works in a single cluster. The base library allows
// the secret in one cluster and the CSR in another.
func NewSimpleClientCertificateController(
secretNamespace, secretName string,
commonName string, groups []string,
kubeInformers informers.SharedInformerFactory,
kubeClient kubernetes.Interface,
recorder events.Recorder,
) (factory.Controller, error) {
certOptions := ClientCertOption{
SecretNamespace: secretNamespace,
SecretName: secretName,
}
csrOptions := CSROption{
ObjectMeta: metav1.ObjectMeta{},
Subject: &pkix.Name{
Organization: groups,
CommonName: commonName,
},
SignerName: "kubernetes.io/kube-apiserver-client",
EventFilterFunc: nil,
}
controllerName := fmt.Sprintf("client-cert-%s[%s]", secretName, secretNamespace)
return NewClientCertificateController(
certOptions,
csrOptions,
kubeInformers.Certificates().V1().CertificateSigningRequests(),
kubeClient.CertificatesV1().CertificateSigningRequests(),
kubeInformers.Core().V1().Secrets(),
kubeClient.CoreV1(),
recorder,
controllerName,
)
}