2021-03-05 01:25:43 +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-11 01:53:53 +00:00
package apicerts
import (
"context"
2021-03-11 21:20:25 +00:00
"strings"
2020-08-11 01:53:53 +00:00
"testing"
2021-03-11 21:20:25 +00:00
"time"
2020-08-11 01:53:53 +00:00
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeinformers "k8s.io/client-go/informers"
kubernetesfake "k8s.io/client-go/kubernetes/fake"
2021-03-15 16:24:07 +00:00
"go.pinniped.dev/internal/certauthority"
2020-09-18 19:56:24 +00:00
"go.pinniped.dev/internal/controllerlib"
2020-09-23 12:26:59 +00:00
"go.pinniped.dev/internal/dynamiccert"
2020-09-18 19:56:24 +00:00
"go.pinniped.dev/internal/testutil"
2020-08-11 01:53:53 +00:00
)
func TestObserverControllerInformerFilters ( t * testing . T ) {
spec . Run ( t , "informer filters" , func ( t * testing . T , when spec . G , it spec . S ) {
const installedInNamespace = "some-namespace"
Rename many of resources that are created in Kubernetes by Pinniped
New resource naming conventions:
- Do not repeat the Kind in the name,
e.g. do not call it foo-cluster-role-binding, just call it foo
- Names will generally start with a prefix to identify our component,
so when a user lists all objects of that kind, they can tell to which
component it is related,
e.g. `kubectl get configmaps` would list one named "pinniped-config"
- It should be possible for an operator to make the word "pinniped"
mostly disappear if they choose, by specifying the app_name in
values.yaml, to the extent that is practical (but not from APIService
names because those are hardcoded in golang)
- Each role/clusterrole and its corresponding binding have the same name
- Pinniped resource names that must be known by the server golang code
are passed to the code at run time via ConfigMap, rather than
hardcoded in the golang code. This also allows them to be prepended
with the app_name from values.yaml while creating the ConfigMap.
- Since the CLI `get-kubeconfig` command cannot guess the name of the
CredentialIssuerConfig resource in advance anymore, it lists all
CredentialIssuerConfig in the app's namespace and returns an error
if there is not exactly one found, and then uses that one regardless
of its name
2020-09-18 22:56:50 +00:00
const certsSecretResourceName = "some-resource-name"
2020-08-11 01:53:53 +00:00
var r * require . Assertions
var observableWithInformerOption * testutil . ObservableWithInformerOption
2020-08-28 15:59:09 +00:00
var secretsInformerFilter controllerlib . Filter
2020-08-11 01:53:53 +00:00
it . Before ( func ( ) {
r = require . New ( t )
observableWithInformerOption = testutil . NewObservableWithInformerOption ( )
secretsInformer := kubeinformers . NewSharedInformerFactory ( nil , 0 ) . Core ( ) . V1 ( ) . Secrets ( )
_ = NewCertsObserverController (
installedInNamespace ,
Rename many of resources that are created in Kubernetes by Pinniped
New resource naming conventions:
- Do not repeat the Kind in the name,
e.g. do not call it foo-cluster-role-binding, just call it foo
- Names will generally start with a prefix to identify our component,
so when a user lists all objects of that kind, they can tell to which
component it is related,
e.g. `kubectl get configmaps` would list one named "pinniped-config"
- It should be possible for an operator to make the word "pinniped"
mostly disappear if they choose, by specifying the app_name in
values.yaml, to the extent that is practical (but not from APIService
names because those are hardcoded in golang)
- Each role/clusterrole and its corresponding binding have the same name
- Pinniped resource names that must be known by the server golang code
are passed to the code at run time via ConfigMap, rather than
hardcoded in the golang code. This also allows them to be prepended
with the app_name from values.yaml while creating the ConfigMap.
- Since the CLI `get-kubeconfig` command cannot guess the name of the
CredentialIssuerConfig resource in advance anymore, it lists all
CredentialIssuerConfig in the app's namespace and returns an error
if there is not exactly one found, and then uses that one regardless
of its name
2020-09-18 22:56:50 +00:00
certsSecretResourceName ,
2020-08-11 01:53:53 +00:00
nil ,
secretsInformer ,
observableWithInformerOption . WithInformer , // make it possible to observe the behavior of the Filters
)
secretsInformerFilter = observableWithInformerOption . GetFilterForInformer ( secretsInformer )
} )
when ( "watching Secret objects" , func ( ) {
2020-08-28 15:59:09 +00:00
var subject controllerlib . Filter
2020-08-11 01:53:53 +00:00
var target , wrongNamespace , wrongName , unrelated * corev1 . Secret
it . Before ( func ( ) {
subject = secretsInformerFilter
Rename many of resources that are created in Kubernetes by Pinniped
New resource naming conventions:
- Do not repeat the Kind in the name,
e.g. do not call it foo-cluster-role-binding, just call it foo
- Names will generally start with a prefix to identify our component,
so when a user lists all objects of that kind, they can tell to which
component it is related,
e.g. `kubectl get configmaps` would list one named "pinniped-config"
- It should be possible for an operator to make the word "pinniped"
mostly disappear if they choose, by specifying the app_name in
values.yaml, to the extent that is practical (but not from APIService
names because those are hardcoded in golang)
- Each role/clusterrole and its corresponding binding have the same name
- Pinniped resource names that must be known by the server golang code
are passed to the code at run time via ConfigMap, rather than
hardcoded in the golang code. This also allows them to be prepended
with the app_name from values.yaml while creating the ConfigMap.
- Since the CLI `get-kubeconfig` command cannot guess the name of the
CredentialIssuerConfig resource in advance anymore, it lists all
CredentialIssuerConfig in the app's namespace and returns an error
if there is not exactly one found, and then uses that one regardless
of its name
2020-09-18 22:56:50 +00:00
target = & corev1 . Secret { ObjectMeta : metav1 . ObjectMeta { Name : certsSecretResourceName , Namespace : installedInNamespace } }
wrongNamespace = & corev1 . Secret { ObjectMeta : metav1 . ObjectMeta { Name : certsSecretResourceName , Namespace : "wrong-namespace" } }
2020-08-11 01:53:53 +00:00
wrongName = & corev1 . Secret { ObjectMeta : metav1 . ObjectMeta { Name : "wrong-name" , Namespace : installedInNamespace } }
unrelated = & corev1 . Secret { ObjectMeta : metav1 . ObjectMeta { Name : "wrong-name" , Namespace : "wrong-namespace" } }
} )
when ( "the target Secret changes" , func ( ) {
it ( "returns true to trigger the sync method" , func ( ) {
r . True ( subject . Add ( target ) )
r . True ( subject . Update ( target , unrelated ) )
r . True ( subject . Update ( unrelated , target ) )
r . True ( subject . Delete ( target ) )
} )
} )
when ( "a Secret from another namespace changes" , func ( ) {
it ( "returns false to avoid triggering the sync method" , func ( ) {
r . False ( subject . Add ( wrongNamespace ) )
r . False ( subject . Update ( wrongNamespace , unrelated ) )
r . False ( subject . Update ( unrelated , wrongNamespace ) )
r . False ( subject . Delete ( wrongNamespace ) )
} )
} )
when ( "a Secret with a different name changes" , func ( ) {
it ( "returns false to avoid triggering the sync method" , func ( ) {
r . False ( subject . Add ( wrongName ) )
r . False ( subject . Update ( wrongName , unrelated ) )
r . False ( subject . Update ( unrelated , wrongName ) )
r . False ( subject . Delete ( wrongName ) )
} )
} )
when ( "a Secret with a different name and a different namespace changes" , func ( ) {
it ( "returns false to avoid triggering the sync method" , func ( ) {
r . False ( subject . Add ( unrelated ) )
r . False ( subject . Update ( unrelated , unrelated ) )
r . False ( subject . Delete ( unrelated ) )
} )
} )
} )
} , spec . Parallel ( ) , spec . Report ( report . Terminal { } ) )
}
func TestObserverControllerSync ( t * testing . T ) {
2021-03-11 21:20:25 +00:00
name := t . Name ( )
2020-08-11 01:53:53 +00:00
spec . Run ( t , "Sync" , func ( t * testing . T , when spec . G , it spec . S ) {
const installedInNamespace = "some-namespace"
Rename many of resources that are created in Kubernetes by Pinniped
New resource naming conventions:
- Do not repeat the Kind in the name,
e.g. do not call it foo-cluster-role-binding, just call it foo
- Names will generally start with a prefix to identify our component,
so when a user lists all objects of that kind, they can tell to which
component it is related,
e.g. `kubectl get configmaps` would list one named "pinniped-config"
- It should be possible for an operator to make the word "pinniped"
mostly disappear if they choose, by specifying the app_name in
values.yaml, to the extent that is practical (but not from APIService
names because those are hardcoded in golang)
- Each role/clusterrole and its corresponding binding have the same name
- Pinniped resource names that must be known by the server golang code
are passed to the code at run time via ConfigMap, rather than
hardcoded in the golang code. This also allows them to be prepended
with the app_name from values.yaml while creating the ConfigMap.
- Since the CLI `get-kubeconfig` command cannot guess the name of the
CredentialIssuerConfig resource in advance anymore, it lists all
CredentialIssuerConfig in the app's namespace and returns an error
if there is not exactly one found, and then uses that one regardless
of its name
2020-09-18 22:56:50 +00:00
const certsSecretResourceName = "some-resource-name"
2020-08-11 01:53:53 +00:00
var r * require . Assertions
2020-08-28 15:59:09 +00:00
var subject controllerlib . Controller
2020-08-11 01:53:53 +00:00
var kubeInformerClient * kubernetesfake . Clientset
var kubeInformers kubeinformers . SharedInformerFactory
2021-03-05 01:25:43 +00:00
var cancelContext context . Context
var cancelContextCancelFunc context . CancelFunc
2020-08-28 15:59:09 +00:00
var syncContext * controllerlib . Context
2021-03-15 16:24:07 +00:00
var dynamicCertProvider dynamiccert . Private
2020-08-11 01:53:53 +00:00
// Defer starting the informers until the last possible moment so that the
// nested Before's can keep adding things to the informer caches.
var startInformersAndController = func ( ) {
// Set this at the last second to allow for injection of server override.
subject = NewCertsObserverController (
installedInNamespace ,
Rename many of resources that are created in Kubernetes by Pinniped
New resource naming conventions:
- Do not repeat the Kind in the name,
e.g. do not call it foo-cluster-role-binding, just call it foo
- Names will generally start with a prefix to identify our component,
so when a user lists all objects of that kind, they can tell to which
component it is related,
e.g. `kubectl get configmaps` would list one named "pinniped-config"
- It should be possible for an operator to make the word "pinniped"
mostly disappear if they choose, by specifying the app_name in
values.yaml, to the extent that is practical (but not from APIService
names because those are hardcoded in golang)
- Each role/clusterrole and its corresponding binding have the same name
- Pinniped resource names that must be known by the server golang code
are passed to the code at run time via ConfigMap, rather than
hardcoded in the golang code. This also allows them to be prepended
with the app_name from values.yaml while creating the ConfigMap.
- Since the CLI `get-kubeconfig` command cannot guess the name of the
CredentialIssuerConfig resource in advance anymore, it lists all
CredentialIssuerConfig in the app's namespace and returns an error
if there is not exactly one found, and then uses that one regardless
of its name
2020-09-18 22:56:50 +00:00
certsSecretResourceName ,
2020-08-11 01:53:53 +00:00
dynamicCertProvider ,
kubeInformers . Core ( ) . V1 ( ) . Secrets ( ) ,
2020-08-28 15:59:09 +00:00
controllerlib . WithInformer ,
2020-08-11 01:53:53 +00:00
)
// Set this at the last second to support calling subject.Name().
2020-08-28 15:59:09 +00:00
syncContext = & controllerlib . Context {
2021-03-05 01:25:43 +00:00
Context : cancelContext ,
2020-08-11 01:53:53 +00:00
Name : subject . Name ( ) ,
2020-08-28 15:59:09 +00:00
Key : controllerlib . Key {
2020-08-11 01:53:53 +00:00
Namespace : installedInNamespace ,
Rename many of resources that are created in Kubernetes by Pinniped
New resource naming conventions:
- Do not repeat the Kind in the name,
e.g. do not call it foo-cluster-role-binding, just call it foo
- Names will generally start with a prefix to identify our component,
so when a user lists all objects of that kind, they can tell to which
component it is related,
e.g. `kubectl get configmaps` would list one named "pinniped-config"
- It should be possible for an operator to make the word "pinniped"
mostly disappear if they choose, by specifying the app_name in
values.yaml, to the extent that is practical (but not from APIService
names because those are hardcoded in golang)
- Each role/clusterrole and its corresponding binding have the same name
- Pinniped resource names that must be known by the server golang code
are passed to the code at run time via ConfigMap, rather than
hardcoded in the golang code. This also allows them to be prepended
with the app_name from values.yaml while creating the ConfigMap.
- Since the CLI `get-kubeconfig` command cannot guess the name of the
CredentialIssuerConfig resource in advance anymore, it lists all
CredentialIssuerConfig in the app's namespace and returns an error
if there is not exactly one found, and then uses that one regardless
of its name
2020-09-18 22:56:50 +00:00
Name : certsSecretResourceName ,
2020-08-11 01:53:53 +00:00
} ,
}
// Must start informers before calling TestRunSynchronously()
2021-03-05 01:25:43 +00:00
kubeInformers . Start ( cancelContext . Done ( ) )
2020-08-28 15:59:09 +00:00
controllerlib . TestRunSynchronously ( t , subject )
2020-08-11 01:53:53 +00:00
}
it . Before ( func ( ) {
r = require . New ( t )
2021-03-05 01:25:43 +00:00
cancelContext , cancelContextCancelFunc = context . WithCancel ( context . Background ( ) )
2020-08-11 01:53:53 +00:00
kubeInformerClient = kubernetesfake . NewSimpleClientset ( )
kubeInformers = kubeinformers . NewSharedInformerFactory ( kubeInformerClient , 0 )
2021-03-15 16:24:07 +00:00
dynamicCertProvider = dynamiccert . NewServingCert ( name )
2020-08-11 01:53:53 +00:00
} )
it . After ( func ( ) {
2021-03-05 01:25:43 +00:00
cancelContextCancelFunc ( )
2020-08-11 01:53:53 +00:00
} )
Rename many of resources that are created in Kubernetes by Pinniped
New resource naming conventions:
- Do not repeat the Kind in the name,
e.g. do not call it foo-cluster-role-binding, just call it foo
- Names will generally start with a prefix to identify our component,
so when a user lists all objects of that kind, they can tell to which
component it is related,
e.g. `kubectl get configmaps` would list one named "pinniped-config"
- It should be possible for an operator to make the word "pinniped"
mostly disappear if they choose, by specifying the app_name in
values.yaml, to the extent that is practical (but not from APIService
names because those are hardcoded in golang)
- Each role/clusterrole and its corresponding binding have the same name
- Pinniped resource names that must be known by the server golang code
are passed to the code at run time via ConfigMap, rather than
hardcoded in the golang code. This also allows them to be prepended
with the app_name from values.yaml while creating the ConfigMap.
- Since the CLI `get-kubeconfig` command cannot guess the name of the
CredentialIssuerConfig resource in advance anymore, it lists all
CredentialIssuerConfig in the app's namespace and returns an error
if there is not exactly one found, and then uses that one regardless
of its name
2020-09-18 22:56:50 +00:00
when ( "there is not yet a serving cert Secret in the installation namespace or it was deleted" , func ( ) {
2020-08-11 01:53:53 +00:00
it . Before ( func ( ) {
unrelatedSecret := & corev1 . Secret {
ObjectMeta : metav1 . ObjectMeta {
Name : "some other secret" ,
Namespace : installedInNamespace ,
} ,
}
err := kubeInformerClient . Tracker ( ) . Add ( unrelatedSecret )
r . NoError ( err )
2021-03-15 16:24:07 +00:00
caCrt , caKey , err := testutil . CreateCertificate (
2021-03-11 21:20:25 +00:00
time . Now ( ) . Add ( - time . Hour ) ,
time . Now ( ) . Add ( time . Hour ) ,
)
require . NoError ( t , err )
2021-03-15 16:24:07 +00:00
ca , err := certauthority . Load ( string ( caCrt ) , string ( caKey ) )
require . NoError ( t , err )
crt , key , err := ca . IssueServerCertPEM ( nil , nil , time . Hour )
require . NoError ( t , err )
2021-03-11 21:20:25 +00:00
err = dynamicCertProvider . SetCertKeyContent ( crt , key )
r . NoError ( err )
2020-08-11 01:53:53 +00:00
} )
it ( "sets the dynamicCertProvider's cert and key to nil" , func ( ) {
startInformersAndController ( )
2020-08-28 15:59:09 +00:00
err := controllerlib . TestSync ( t , subject , * syncContext )
2020-08-11 01:53:53 +00:00
r . NoError ( err )
actualCertChain , actualKey := dynamicCertProvider . CurrentCertKeyContent ( )
r . Nil ( actualCertChain )
r . Nil ( actualKey )
} )
} )
Rename many of resources that are created in Kubernetes by Pinniped
New resource naming conventions:
- Do not repeat the Kind in the name,
e.g. do not call it foo-cluster-role-binding, just call it foo
- Names will generally start with a prefix to identify our component,
so when a user lists all objects of that kind, they can tell to which
component it is related,
e.g. `kubectl get configmaps` would list one named "pinniped-config"
- It should be possible for an operator to make the word "pinniped"
mostly disappear if they choose, by specifying the app_name in
values.yaml, to the extent that is practical (but not from APIService
names because those are hardcoded in golang)
- Each role/clusterrole and its corresponding binding have the same name
- Pinniped resource names that must be known by the server golang code
are passed to the code at run time via ConfigMap, rather than
hardcoded in the golang code. This also allows them to be prepended
with the app_name from values.yaml while creating the ConfigMap.
- Since the CLI `get-kubeconfig` command cannot guess the name of the
CredentialIssuerConfig resource in advance anymore, it lists all
CredentialIssuerConfig in the app's namespace and returns an error
if there is not exactly one found, and then uses that one regardless
of its name
2020-09-18 22:56:50 +00:00
when ( "there is a serving cert Secret with the expected keys already in the installation namespace" , func ( ) {
2020-08-11 01:53:53 +00:00
it . Before ( func ( ) {
2021-03-15 16:24:07 +00:00
caCrt , caKey , err := testutil . CreateCertificate (
2021-03-11 21:20:25 +00:00
time . Now ( ) . Add ( - time . Hour ) ,
time . Now ( ) . Add ( time . Hour ) ,
)
require . NoError ( t , err )
2021-03-15 16:24:07 +00:00
ca , err := certauthority . Load ( string ( caCrt ) , string ( caKey ) )
require . NoError ( t , err )
crt , key , err := ca . IssueServerCertPEM ( nil , nil , time . Hour )
require . NoError ( t , err )
2020-08-11 01:53:53 +00:00
apiServingCertSecret := & corev1 . Secret {
ObjectMeta : metav1 . ObjectMeta {
Rename many of resources that are created in Kubernetes by Pinniped
New resource naming conventions:
- Do not repeat the Kind in the name,
e.g. do not call it foo-cluster-role-binding, just call it foo
- Names will generally start with a prefix to identify our component,
so when a user lists all objects of that kind, they can tell to which
component it is related,
e.g. `kubectl get configmaps` would list one named "pinniped-config"
- It should be possible for an operator to make the word "pinniped"
mostly disappear if they choose, by specifying the app_name in
values.yaml, to the extent that is practical (but not from APIService
names because those are hardcoded in golang)
- Each role/clusterrole and its corresponding binding have the same name
- Pinniped resource names that must be known by the server golang code
are passed to the code at run time via ConfigMap, rather than
hardcoded in the golang code. This also allows them to be prepended
with the app_name from values.yaml while creating the ConfigMap.
- Since the CLI `get-kubeconfig` command cannot guess the name of the
CredentialIssuerConfig resource in advance anymore, it lists all
CredentialIssuerConfig in the app's namespace and returns an error
if there is not exactly one found, and then uses that one regardless
of its name
2020-09-18 22:56:50 +00:00
Name : certsSecretResourceName ,
2020-08-11 01:53:53 +00:00
Namespace : installedInNamespace ,
} ,
Data : map [ string ] [ ] byte {
"caCertificate" : [ ] byte ( "fake cert" ) ,
2021-03-11 21:20:25 +00:00
"tlsPrivateKey" : key ,
"tlsCertificateChain" : crt ,
2020-08-11 01:53:53 +00:00
} ,
}
2021-03-11 21:20:25 +00:00
err = kubeInformerClient . Tracker ( ) . Add ( apiServingCertSecret )
2020-08-11 01:53:53 +00:00
r . NoError ( err )
2021-03-11 21:20:25 +00:00
dynamicCertProvider . UnsetCertKeyContent ( )
2020-08-11 01:53:53 +00:00
} )
it ( "updates the dynamicCertProvider's cert and key" , func ( ) {
startInformersAndController ( )
2021-03-11 21:20:25 +00:00
actualCertChain , actualKey := dynamicCertProvider . CurrentCertKeyContent ( )
r . Nil ( actualCertChain )
r . Nil ( actualKey )
2020-08-28 15:59:09 +00:00
err := controllerlib . TestSync ( t , subject , * syncContext )
2020-08-11 01:53:53 +00:00
r . NoError ( err )
2021-03-11 21:20:25 +00:00
actualCertChain , actualKey = dynamicCertProvider . CurrentCertKeyContent ( )
r . True ( strings . HasPrefix ( string ( actualCertChain ) , ` -----BEGIN CERTIFICATE----- ` ) , "not a cert:\n%s" , string ( actualCertChain ) )
r . True ( strings . HasPrefix ( string ( actualKey ) , ` -----BEGIN PRIVATE KEY----- ` ) , "not a key:\n%s" , string ( actualKey ) )
2020-08-11 01:53:53 +00:00
} )
} )
Rename many of resources that are created in Kubernetes by Pinniped
New resource naming conventions:
- Do not repeat the Kind in the name,
e.g. do not call it foo-cluster-role-binding, just call it foo
- Names will generally start with a prefix to identify our component,
so when a user lists all objects of that kind, they can tell to which
component it is related,
e.g. `kubectl get configmaps` would list one named "pinniped-config"
- It should be possible for an operator to make the word "pinniped"
mostly disappear if they choose, by specifying the app_name in
values.yaml, to the extent that is practical (but not from APIService
names because those are hardcoded in golang)
- Each role/clusterrole and its corresponding binding have the same name
- Pinniped resource names that must be known by the server golang code
are passed to the code at run time via ConfigMap, rather than
hardcoded in the golang code. This also allows them to be prepended
with the app_name from values.yaml while creating the ConfigMap.
- Since the CLI `get-kubeconfig` command cannot guess the name of the
CredentialIssuerConfig resource in advance anymore, it lists all
CredentialIssuerConfig in the app's namespace and returns an error
if there is not exactly one found, and then uses that one regardless
of its name
2020-09-18 22:56:50 +00:00
when ( "the serving cert Secret exists but is missing the expected keys" , func ( ) {
2020-08-11 01:53:53 +00:00
it . Before ( func ( ) {
apiServingCertSecret := & corev1 . Secret {
ObjectMeta : metav1 . ObjectMeta {
Rename many of resources that are created in Kubernetes by Pinniped
New resource naming conventions:
- Do not repeat the Kind in the name,
e.g. do not call it foo-cluster-role-binding, just call it foo
- Names will generally start with a prefix to identify our component,
so when a user lists all objects of that kind, they can tell to which
component it is related,
e.g. `kubectl get configmaps` would list one named "pinniped-config"
- It should be possible for an operator to make the word "pinniped"
mostly disappear if they choose, by specifying the app_name in
values.yaml, to the extent that is practical (but not from APIService
names because those are hardcoded in golang)
- Each role/clusterrole and its corresponding binding have the same name
- Pinniped resource names that must be known by the server golang code
are passed to the code at run time via ConfigMap, rather than
hardcoded in the golang code. This also allows them to be prepended
with the app_name from values.yaml while creating the ConfigMap.
- Since the CLI `get-kubeconfig` command cannot guess the name of the
CredentialIssuerConfig resource in advance anymore, it lists all
CredentialIssuerConfig in the app's namespace and returns an error
if there is not exactly one found, and then uses that one regardless
of its name
2020-09-18 22:56:50 +00:00
Name : certsSecretResourceName ,
2020-08-11 01:53:53 +00:00
Namespace : installedInNamespace ,
} ,
Data : map [ string ] [ ] byte { } ,
}
err := kubeInformerClient . Tracker ( ) . Add ( apiServingCertSecret )
r . NoError ( err )
2021-03-11 21:20:25 +00:00
dynamicCertProvider . UnsetCertKeyContent ( )
2020-08-11 01:53:53 +00:00
} )
2021-03-11 21:20:25 +00:00
it ( "returns an error and does not change the dynamicCertProvider" , func ( ) {
2020-08-11 01:53:53 +00:00
startInformersAndController ( )
actualCertChain , actualKey := dynamicCertProvider . CurrentCertKeyContent ( )
r . Nil ( actualCertChain )
r . Nil ( actualKey )
2021-03-11 21:20:25 +00:00
err := controllerlib . TestSync ( t , subject , * syncContext )
r . EqualError ( err , "failed to set serving cert/key content from secret some-namespace/some-resource-name: TestObserverControllerSync: attempt to set invalid key pair: tls: failed to find any PEM data in certificate input" )
actualCertChain , actualKey = dynamicCertProvider . CurrentCertKeyContent ( )
r . Nil ( actualCertChain )
r . Nil ( actualKey )
2020-08-11 01:53:53 +00:00
} )
} )
} , spec . Parallel ( ) , spec . Report ( report . Terminal { } ) )
}