Add dynamic certificate feature to controller
This commit is contained in:
parent
b4942ccd03
commit
7faf089082
12 changed files with 342 additions and 29 deletions
|
|
@ -98,11 +98,18 @@ func (s k8sStore) getPemCertificate(secretName string) (*ingress.SSLCert, error)
|
|||
return nil, fmt.Errorf("key 'tls.key' missing from Secret %q", secretName)
|
||||
}
|
||||
|
||||
// If 'ca.crt' is also present, it will allow this secret to be used in the
|
||||
// 'nginx.ingress.kubernetes.io/auth-tls-secret' annotation
|
||||
sslCert, err = ssl.AddOrUpdateCertAndKey(nsSecName, cert, key, ca, s.filesystem)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if s.isDynamicCertificatesEnabled {
|
||||
sslCert, err = ssl.CreateSSLCert(nsSecName, cert, key, ca)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unexpected error creating SSL Cert: %v", err)
|
||||
}
|
||||
} else {
|
||||
// If 'ca.crt' is also present, it will allow this secret to be used in the
|
||||
// 'nginx.ingress.kubernetes.io/auth-tls-secret' annotation
|
||||
sslCert, err = ssl.AddOrUpdateCertAndKey(nsSecName, cert, key, ca, s.filesystem)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unexpected error creating pem file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
msg := fmt.Sprintf("Configuring Secret %q for TLS encryption (CN: %v)", secretName, sslCert.CN)
|
||||
|
|
|
|||
|
|
@ -212,6 +212,8 @@ type k8sStore struct {
|
|||
mu *sync.Mutex
|
||||
|
||||
defaultSSLCertificate string
|
||||
|
||||
isDynamicCertificatesEnabled bool
|
||||
}
|
||||
|
||||
// New creates a new object store to be used in the ingress controller
|
||||
|
|
@ -220,19 +222,21 @@ func New(checkOCSP bool,
|
|||
resyncPeriod time.Duration,
|
||||
client clientset.Interface,
|
||||
fs file.Filesystem,
|
||||
updateCh *channels.RingChannel) Storer {
|
||||
updateCh *channels.RingChannel,
|
||||
isDynamicCertificatesEnabled bool) Storer {
|
||||
|
||||
store := &k8sStore{
|
||||
isOCSPCheckEnabled: checkOCSP,
|
||||
informers: &Informer{},
|
||||
listers: &Lister{},
|
||||
sslStore: NewSSLCertTracker(),
|
||||
filesystem: fs,
|
||||
updateCh: updateCh,
|
||||
backendConfig: ngx_config.NewDefault(),
|
||||
mu: &sync.Mutex{},
|
||||
secretIngressMap: NewObjectRefMap(),
|
||||
defaultSSLCertificate: defaultSSLCertificate,
|
||||
isOCSPCheckEnabled: checkOCSP,
|
||||
informers: &Informer{},
|
||||
listers: &Lister{},
|
||||
sslStore: NewSSLCertTracker(),
|
||||
filesystem: fs,
|
||||
updateCh: updateCh,
|
||||
backendConfig: ngx_config.NewDefault(),
|
||||
mu: &sync.Mutex{},
|
||||
secretIngressMap: NewObjectRefMap(),
|
||||
defaultSSLCertificate: defaultSSLCertificate,
|
||||
isDynamicCertificatesEnabled: isDynamicCertificatesEnabled,
|
||||
}
|
||||
|
||||
eventBroadcaster := record.NewBroadcaster()
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ func TestStore(t *testing.T) {
|
|||
10*time.Minute,
|
||||
clientSet,
|
||||
fs,
|
||||
updateCh)
|
||||
updateCh,
|
||||
false)
|
||||
|
||||
storer.Run(stopCh)
|
||||
|
||||
|
|
@ -155,7 +156,8 @@ func TestStore(t *testing.T) {
|
|||
10*time.Minute,
|
||||
clientSet,
|
||||
fs,
|
||||
updateCh)
|
||||
updateCh,
|
||||
false)
|
||||
|
||||
storer.Run(stopCh)
|
||||
|
||||
|
|
@ -302,7 +304,8 @@ func TestStore(t *testing.T) {
|
|||
10*time.Minute,
|
||||
clientSet,
|
||||
fs,
|
||||
updateCh)
|
||||
updateCh,
|
||||
false)
|
||||
|
||||
storer.Run(stopCh)
|
||||
|
||||
|
|
@ -390,7 +393,8 @@ func TestStore(t *testing.T) {
|
|||
10*time.Minute,
|
||||
clientSet,
|
||||
fs,
|
||||
updateCh)
|
||||
updateCh,
|
||||
false)
|
||||
|
||||
storer.Run(stopCh)
|
||||
|
||||
|
|
@ -501,7 +505,8 @@ func TestStore(t *testing.T) {
|
|||
10*time.Minute,
|
||||
clientSet,
|
||||
fs,
|
||||
updateCh)
|
||||
updateCh,
|
||||
false)
|
||||
|
||||
storer.Run(stopCh)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue