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"
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"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"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
|
|
kubeinformers "k8s.io/client-go/informers"
|
|
|
|
kubernetesfake "k8s.io/client-go/kubernetes/fake"
|
|
|
|
coretesting "k8s.io/client-go/testing"
|
|
|
|
|
2020-09-18 19:56:24 +00:00
|
|
|
"go.pinniped.dev/internal/controllerlib"
|
|
|
|
"go.pinniped.dev/internal/testutil"
|
2020-08-11 01:53:53 +00:00
|
|
|
)
|
|
|
|
|
2020-08-11 17:14:57 +00:00
|
|
|
func TestManagerControllerOptions(t *testing.T) {
|
|
|
|
spec.Run(t, "options", func(t *testing.T, when spec.G, it spec.S) {
|
2020-08-11 01:53:53 +00:00
|
|
|
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-11 17:14:57 +00:00
|
|
|
var observableWithInitialEventOption *testutil.ObservableWithInitialEventOption
|
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()
|
2020-08-11 17:14:57 +00:00
|
|
|
observableWithInitialEventOption = testutil.NewObservableWithInitialEventOption()
|
2020-08-11 01:53:53 +00:00
|
|
|
secretsInformer := kubeinformers.NewSharedInformerFactory(nil, 0).Core().V1().Secrets()
|
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
|
|
|
_ = NewCertsManagerController(
|
|
|
|
installedInNamespace,
|
|
|
|
certsSecretResourceName,
|
2020-10-15 17:14:23 +00:00
|
|
|
make(map[string]string),
|
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
|
|
|
nil,
|
|
|
|
secretsInformer,
|
|
|
|
observableWithInformerOption.WithInformer,
|
|
|
|
observableWithInitialEventOption.WithInitialEvent,
|
|
|
|
0,
|
|
|
|
"Pinniped CA",
|
|
|
|
"pinniped-api",
|
|
|
|
)
|
2020-08-11 01:53:53 +00:00
|
|
|
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))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-08-11 17:14:57 +00:00
|
|
|
|
|
|
|
when("starting up", func() {
|
|
|
|
it("asks for an initial event because the Secret may not exist yet and it needs to run anyway", func() {
|
2020-09-24 20:54:20 +00:00
|
|
|
r.Equal(&controllerlib.Key{
|
2020-08-11 17:14:57 +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 17:14:57 +00:00
|
|
|
}, observableWithInitialEventOption.GetInitialEventKey())
|
|
|
|
})
|
|
|
|
})
|
2020-08-11 01:53:53 +00:00
|
|
|
}, spec.Parallel(), spec.Report(report.Terminal{}))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestManagerControllerSync(t *testing.T) {
|
|
|
|
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-20 19:17:18 +00:00
|
|
|
const certDuration = 12345678 * time.Second
|
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 kubeAPIClient *kubernetesfake.Clientset
|
|
|
|
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
|
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 = NewCertsManagerController(
|
|
|
|
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-10-15 17:14:23 +00:00
|
|
|
map[string]string{
|
|
|
|
"myLabelKey1": "myLabelValue1",
|
|
|
|
"myLabelKey2": "myLabelValue2",
|
|
|
|
},
|
2020-08-11 01:53:53 +00:00
|
|
|
kubeAPIClient,
|
|
|
|
kubeInformers.Core().V1().Secrets(),
|
2020-08-28 15:59:09 +00:00
|
|
|
controllerlib.WithInformer,
|
|
|
|
controllerlib.WithInitialEvent,
|
2020-08-20 19:17:18 +00:00
|
|
|
certDuration,
|
2020-09-08 23:36:49 +00:00
|
|
|
"Pinniped CA",
|
|
|
|
"pinniped-api",
|
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)
|
|
|
|
kubeAPIClient = kubernetesfake.NewSimpleClientset()
|
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
|
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
|
|
|
it("creates the serving cert Secret", func() {
|
2020-09-08 23:36:49 +00:00
|
|
|
startInformersAndController()
|
|
|
|
err := controllerlib.TestSync(t, subject, *syncContext)
|
|
|
|
r.NoError(err)
|
2020-08-11 01:53:53 +00:00
|
|
|
|
2020-09-08 23:36:49 +00:00
|
|
|
// Check all the relevant fields from the create Secret action
|
|
|
|
r.Len(kubeAPIClient.Actions(), 1)
|
|
|
|
actualAction := kubeAPIClient.Actions()[0].(coretesting.CreateActionImpl)
|
|
|
|
r.Equal(schema.GroupVersionResource{Group: "", Version: "v1", Resource: "secrets"}, actualAction.GetResource())
|
|
|
|
r.Equal(installedInNamespace, actualAction.GetNamespace())
|
|
|
|
actualSecret := actualAction.GetObject().(*corev1.Secret)
|
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
|
|
|
r.Equal(certsSecretResourceName, actualSecret.Name)
|
2020-09-08 23:36:49 +00:00
|
|
|
r.Equal(installedInNamespace, actualSecret.Namespace)
|
2020-10-15 17:14:23 +00:00
|
|
|
r.Equal(map[string]string{
|
|
|
|
"myLabelKey1": "myLabelValue1",
|
|
|
|
"myLabelKey2": "myLabelValue2",
|
|
|
|
}, actualSecret.Labels)
|
2020-09-08 23:36:49 +00:00
|
|
|
actualCACert := actualSecret.StringData["caCertificate"]
|
|
|
|
actualPrivateKey := actualSecret.StringData["tlsPrivateKey"]
|
|
|
|
actualCertChain := actualSecret.StringData["tlsCertificateChain"]
|
|
|
|
r.NotEmpty(actualCACert)
|
|
|
|
r.NotEmpty(actualPrivateKey)
|
|
|
|
r.NotEmpty(actualCertChain)
|
|
|
|
|
|
|
|
// Validate the created CA's lifetime.
|
|
|
|
validCACert := testutil.ValidateCertificate(t, actualCACert, actualCACert)
|
|
|
|
validCACert.RequireLifetime(time.Now(), time.Now().Add(certDuration), 6*time.Minute)
|
|
|
|
|
|
|
|
// Validate the created cert using the CA, and also validate the cert's hostname
|
|
|
|
validCert := testutil.ValidateCertificate(t, actualCACert, actualCertChain)
|
|
|
|
validCert.RequireDNSName("pinniped-api." + installedInNamespace + ".svc")
|
|
|
|
validCert.RequireLifetime(time.Now(), time.Now().Add(certDuration), 6*time.Minute)
|
|
|
|
validCert.RequireMatchesPrivateKey(actualPrivateKey)
|
2020-08-11 01:53:53 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
when("creating the Secret fails", func() {
|
|
|
|
it.Before(func() {
|
|
|
|
kubeAPIClient.PrependReactor(
|
|
|
|
"create",
|
|
|
|
"secrets",
|
|
|
|
func(_ coretesting.Action) (bool, runtime.Object, error) {
|
|
|
|
return true, nil, errors.New("create failed")
|
|
|
|
},
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2020-09-08 23:36:49 +00:00
|
|
|
it("returns the create error", func() {
|
2020-08-11 01:53:53 +00:00
|
|
|
startInformersAndController()
|
2020-08-28 15:59:09 +00:00
|
|
|
err := controllerlib.TestSync(t, subject, *syncContext)
|
2020-08-11 01:53:53 +00:00
|
|
|
r.EqualError(err, "could not create secret: create failed")
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
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 already in the installation namespace", 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,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
err := kubeInformerClient.Tracker().Add(apiServingCertSecret)
|
|
|
|
r.NoError(err)
|
|
|
|
})
|
|
|
|
|
2020-09-08 23:36:49 +00:00
|
|
|
it("does not need to make any API calls with its API client", func() {
|
2020-08-11 01:53:53 +00:00
|
|
|
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)
|
|
|
|
r.Empty(kubeAPIClient.Actions())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}, spec.Parallel(), spec.Report(report.Terminal{}))
|
|
|
|
}
|