2020-07-30 00:22:25 +00:00
|
|
|
/*
|
|
|
|
Copyright 2020 VMware, Inc.
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
package logindiscovery
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-07-30 14:39:15 +00:00
|
|
|
"errors"
|
2020-07-30 00:22:25 +00:00
|
|
|
"strings"
|
|
|
|
"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"
|
2020-07-30 14:39:15 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
2020-07-30 00:22:25 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
2020-07-30 21:34:13 +00:00
|
|
|
kubeinformers "k8s.io/client-go/informers"
|
2020-07-30 00:22:25 +00:00
|
|
|
kubernetesfake "k8s.io/client-go/kubernetes/fake"
|
|
|
|
coretesting "k8s.io/client-go/testing"
|
|
|
|
|
|
|
|
"github.com/suzerain-io/controller-go"
|
|
|
|
placeholderv1alpha1 "github.com/suzerain-io/placeholder-name-api/pkg/apis/placeholder/v1alpha1"
|
|
|
|
placeholderfake "github.com/suzerain-io/placeholder-name-client-go/pkg/generated/clientset/versioned/fake"
|
2020-07-30 21:34:13 +00:00
|
|
|
placeholderinformers "github.com/suzerain-io/placeholder-name-client-go/pkg/generated/informers/externalversions"
|
2020-07-30 00:22:25 +00:00
|
|
|
)
|
|
|
|
|
2020-07-31 00:16:09 +00:00
|
|
|
type ObservableWithInformerOption struct {
|
|
|
|
InformerToFilterMap map[controller.InformerGetter]controller.Filter
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewObservableWithInformerOption() *ObservableWithInformerOption {
|
|
|
|
return &ObservableWithInformerOption{
|
|
|
|
InformerToFilterMap: make(map[controller.InformerGetter]controller.Filter),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (owi *ObservableWithInformerOption) WithInformer(
|
|
|
|
getter controller.InformerGetter,
|
|
|
|
filter controller.Filter,
|
|
|
|
opt controller.InformerOption) controller.Option {
|
|
|
|
owi.InformerToFilterMap[getter] = filter
|
|
|
|
return controller.WithInformer(getter, filter, opt)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestInformerFilters(t *testing.T) {
|
|
|
|
spec.Run(t, "informer filters", func(t *testing.T, when spec.G, it spec.S) {
|
|
|
|
const installedInNamespace = "some-namespace"
|
|
|
|
|
|
|
|
var r *require.Assertions
|
|
|
|
var observableWithInformerOption *ObservableWithInformerOption
|
|
|
|
var configMapInformerFilter controller.Filter
|
|
|
|
var loginDiscoveryConfigInformerFilter controller.Filter
|
|
|
|
|
|
|
|
it.Before(func() {
|
|
|
|
r = require.New(t)
|
|
|
|
observableWithInformerOption = NewObservableWithInformerOption()
|
|
|
|
configMapInformer := kubeinformers.NewSharedInformerFactory(nil, 0).Core().V1().ConfigMaps()
|
|
|
|
loginDiscoveryConfigInformer := placeholderinformers.NewSharedInformerFactory(nil, 0).Placeholder().V1alpha1().LoginDiscoveryConfigs()
|
|
|
|
_ = NewPublisherController(
|
|
|
|
installedInNamespace,
|
|
|
|
nil,
|
|
|
|
configMapInformer,
|
|
|
|
loginDiscoveryConfigInformer,
|
|
|
|
observableWithInformerOption.WithInformer, // make it possible to observe the behavior of the Filters
|
|
|
|
)
|
|
|
|
configMapInformerFilter = observableWithInformerOption.InformerToFilterMap[configMapInformer]
|
|
|
|
loginDiscoveryConfigInformerFilter = observableWithInformerOption.InformerToFilterMap[loginDiscoveryConfigInformer]
|
|
|
|
})
|
|
|
|
|
|
|
|
when("watching ConfigMap objects", func() {
|
|
|
|
var subject controller.Filter
|
|
|
|
var target, wrongNamespace, wrongName, unrelated *corev1.ConfigMap
|
|
|
|
|
|
|
|
it.Before(func() {
|
|
|
|
subject = configMapInformerFilter
|
|
|
|
target = &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "cluster-info", Namespace: "kube-public"}}
|
|
|
|
wrongNamespace = &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "cluster-info", Namespace: "wrong-namespace"}}
|
|
|
|
wrongName = &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "wrong-name", Namespace: "kube-public"}}
|
|
|
|
unrelated = &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "wrong-name", Namespace: "wrong-namespace"}}
|
|
|
|
})
|
|
|
|
|
|
|
|
when("the target ConfigMap 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 ConfigMap 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 ConfigMap 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 ConfigMap 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))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
when("watching LoginDiscoveryConfig objects", func() {
|
|
|
|
var subject controller.Filter
|
|
|
|
var target, wrongNamespace, wrongName, unrelated *placeholderv1alpha1.LoginDiscoveryConfig
|
|
|
|
|
|
|
|
it.Before(func() {
|
|
|
|
subject = loginDiscoveryConfigInformerFilter
|
|
|
|
target = &placeholderv1alpha1.LoginDiscoveryConfig{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "placeholder-name-config", Namespace: installedInNamespace},
|
|
|
|
}
|
|
|
|
wrongNamespace = &placeholderv1alpha1.LoginDiscoveryConfig{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "placeholder-name-config", Namespace: "wrong-namespace"},
|
|
|
|
}
|
|
|
|
wrongName = &placeholderv1alpha1.LoginDiscoveryConfig{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "wrong-name", Namespace: installedInNamespace},
|
|
|
|
}
|
|
|
|
unrelated = &placeholderv1alpha1.LoginDiscoveryConfig{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "wrong-name", Namespace: "wrong-namespace"},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
when("the target LoginDiscoveryConfig 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 LoginDiscoveryConfig 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 LoginDiscoveryConfig 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 LoginDiscoveryConfig 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 TestSync(t *testing.T) {
|
|
|
|
spec.Run(t, "Sync", func(t *testing.T, when spec.G, it spec.S) {
|
2020-07-30 00:22:25 +00:00
|
|
|
const installedInNamespace = "some-namespace"
|
|
|
|
|
|
|
|
var r *require.Assertions
|
|
|
|
|
|
|
|
var subject controller.Controller
|
2020-07-30 21:34:13 +00:00
|
|
|
var kubeInformerClient *kubernetesfake.Clientset
|
|
|
|
var placeholderInformerClient *placeholderfake.Clientset
|
|
|
|
var kubeInformers kubeinformers.SharedInformerFactory
|
|
|
|
var placeholderInformers placeholderinformers.SharedInformerFactory
|
|
|
|
var placeholderAPIClient *placeholderfake.Clientset
|
2020-07-30 00:22:25 +00:00
|
|
|
var timeoutContext context.Context
|
|
|
|
var timeoutContextCancel context.CancelFunc
|
2020-07-30 21:34:13 +00:00
|
|
|
var syncContext *controller.Context
|
2020-07-30 00:22:25 +00:00
|
|
|
|
|
|
|
var expectedLoginDiscoveryConfig = func(expectedNamespace, expectedServerURL, expectedCAData string) (schema.GroupVersionResource, *placeholderv1alpha1.LoginDiscoveryConfig) {
|
|
|
|
expectedLoginDiscoveryConfigGVR := schema.GroupVersionResource{
|
|
|
|
Group: placeholderv1alpha1.GroupName,
|
|
|
|
Version: "v1alpha1",
|
|
|
|
Resource: "logindiscoveryconfigs",
|
|
|
|
}
|
|
|
|
expectedLoginDiscoveryConfig := &placeholderv1alpha1.LoginDiscoveryConfig{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "placeholder-name-config",
|
|
|
|
Namespace: expectedNamespace,
|
|
|
|
},
|
|
|
|
Spec: placeholderv1alpha1.LoginDiscoveryConfigSpec{
|
|
|
|
Server: expectedServerURL,
|
|
|
|
CertificateAuthorityData: expectedCAData,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return expectedLoginDiscoveryConfigGVR, expectedLoginDiscoveryConfig
|
|
|
|
}
|
|
|
|
|
2020-07-30 21:34:13 +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() {
|
|
|
|
// Must start informers before calling TestRunSynchronously()
|
|
|
|
kubeInformers.Start(timeoutContext.Done())
|
|
|
|
placeholderInformers.Start(timeoutContext.Done())
|
|
|
|
controller.TestRunSynchronously(t, subject)
|
|
|
|
}
|
|
|
|
|
2020-07-30 00:22:25 +00:00
|
|
|
it.Before(func() {
|
|
|
|
r = require.New(t)
|
2020-07-30 21:34:13 +00:00
|
|
|
|
2020-07-30 00:22:25 +00:00
|
|
|
timeoutContext, timeoutContextCancel = context.WithTimeout(context.Background(), time.Second*3)
|
2020-07-30 21:34:13 +00:00
|
|
|
|
|
|
|
kubeInformerClient = kubernetesfake.NewSimpleClientset()
|
|
|
|
kubeInformers = kubeinformers.NewSharedInformerFactory(kubeInformerClient, 0)
|
|
|
|
placeholderAPIClient = placeholderfake.NewSimpleClientset()
|
|
|
|
placeholderInformerClient = placeholderfake.NewSimpleClientset()
|
|
|
|
placeholderInformers = placeholderinformers.NewSharedInformerFactory(placeholderInformerClient, 0)
|
|
|
|
|
|
|
|
subject = NewPublisherController(
|
|
|
|
installedInNamespace,
|
|
|
|
placeholderAPIClient,
|
|
|
|
kubeInformers.Core().V1().ConfigMaps(),
|
|
|
|
placeholderInformers.Placeholder().V1alpha1().LoginDiscoveryConfigs(),
|
2020-07-31 00:16:09 +00:00
|
|
|
controller.WithInformer,
|
2020-07-30 21:34:13 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
syncContext = &controller.Context{
|
2020-07-30 00:22:25 +00:00
|
|
|
Context: timeoutContext,
|
|
|
|
Name: subject.Name(),
|
|
|
|
Key: controller.Key{
|
|
|
|
Namespace: "kube-public",
|
|
|
|
Name: "cluster-info",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-07-30 21:34:13 +00:00
|
|
|
it.After(func() {
|
|
|
|
timeoutContextCancel()
|
|
|
|
})
|
|
|
|
|
2020-07-30 01:18:42 +00:00
|
|
|
when("there is a cluster-info ConfigMap in the kube-public namespace", func() {
|
2020-07-30 00:22:25 +00:00
|
|
|
const caData = "c29tZS1jZXJ0aWZpY2F0ZS1hdXRob3JpdHktZGF0YQo=" // "some-certificate-authority-data" base64 encoded
|
|
|
|
const kubeServerURL = "https://some-server"
|
2020-07-30 01:18:42 +00:00
|
|
|
|
|
|
|
when("the ConfigMap has the expected `kubeconfig` top-level data key", func() {
|
|
|
|
it.Before(func() {
|
2020-07-30 21:34:13 +00:00
|
|
|
clusterInfoConfigMap := &corev1.ConfigMap{
|
2020-07-30 01:18:42 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "cluster-info", Namespace: "kube-public"},
|
|
|
|
// Note that go fmt puts tabs in our file, which we must remove from our configmap yaml below.
|
|
|
|
Data: map[string]string{
|
|
|
|
"kubeconfig": strings.ReplaceAll(`
|
2020-07-30 00:22:25 +00:00
|
|
|
kind: Config
|
|
|
|
apiVersion: v1
|
|
|
|
clusters:
|
|
|
|
- name: ""
|
|
|
|
cluster:
|
|
|
|
certificate-authority-data: "`+caData+`"
|
|
|
|
server: "`+kubeServerURL+`"`, "\t", " "),
|
2020-07-30 01:18:42 +00:00
|
|
|
"uninteresting-key": "uninteresting-value",
|
|
|
|
},
|
|
|
|
}
|
2020-07-30 21:34:13 +00:00
|
|
|
err := kubeInformerClient.Tracker().Add(clusterInfoConfigMap)
|
2020-07-30 01:18:42 +00:00
|
|
|
r.NoError(err)
|
|
|
|
})
|
2020-07-30 00:22:25 +00:00
|
|
|
|
2020-07-30 01:18:42 +00:00
|
|
|
when("the LoginDiscoveryConfig does not already exist", func() {
|
2020-07-31 00:16:09 +00:00
|
|
|
it("creates a LoginDiscoveryConfig", func() {
|
2020-07-30 21:34:13 +00:00
|
|
|
startInformersAndController()
|
|
|
|
err := controller.TestSync(t, subject, *syncContext)
|
2020-07-30 01:18:42 +00:00
|
|
|
r.NoError(err)
|
|
|
|
|
2020-07-30 14:39:15 +00:00
|
|
|
expectedLoginDiscoveryConfigGVR, expectedLoginDiscoveryConfig := expectedLoginDiscoveryConfig(
|
|
|
|
installedInNamespace,
|
|
|
|
kubeServerURL,
|
|
|
|
caData,
|
|
|
|
)
|
2020-07-30 21:34:13 +00:00
|
|
|
|
|
|
|
r.Equal(
|
|
|
|
[]coretesting.Action{
|
|
|
|
coretesting.NewCreateAction(
|
|
|
|
expectedLoginDiscoveryConfigGVR,
|
|
|
|
installedInNamespace,
|
|
|
|
expectedLoginDiscoveryConfig,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
placeholderAPIClient.Actions(),
|
|
|
|
)
|
2020-07-30 01:18:42 +00:00
|
|
|
})
|
2020-07-30 14:39:15 +00:00
|
|
|
|
|
|
|
when("creating the LoginDiscoveryConfig fails", func() {
|
|
|
|
it.Before(func() {
|
2020-07-30 21:34:13 +00:00
|
|
|
placeholderAPIClient.PrependReactor(
|
2020-07-30 14:39:15 +00:00
|
|
|
"create",
|
|
|
|
"logindiscoveryconfigs",
|
|
|
|
func(_ coretesting.Action) (bool, runtime.Object, error) {
|
|
|
|
return true, nil, errors.New("create failed")
|
|
|
|
},
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("returns the create error", func() {
|
2020-07-30 21:34:13 +00:00
|
|
|
startInformersAndController()
|
|
|
|
err := controller.TestSync(t, subject, *syncContext)
|
2020-07-30 14:39:15 +00:00
|
|
|
r.EqualError(err, "could not create logindiscoveryconfig: create failed")
|
|
|
|
})
|
|
|
|
})
|
2020-07-30 01:18:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
when("the LoginDiscoveryConfig already exists", func() {
|
|
|
|
when("the LoginDiscoveryConfig is already up to date according to the data in the ConfigMap", func() {
|
|
|
|
it.Before(func() {
|
2020-07-30 14:39:15 +00:00
|
|
|
_, expectedLoginDiscoveryConfig := expectedLoginDiscoveryConfig(
|
|
|
|
installedInNamespace,
|
|
|
|
kubeServerURL,
|
|
|
|
caData,
|
|
|
|
)
|
2020-07-30 21:34:13 +00:00
|
|
|
err := placeholderInformerClient.Tracker().Add(expectedLoginDiscoveryConfig)
|
2020-07-30 14:39:15 +00:00
|
|
|
r.NoError(err)
|
2020-07-30 01:18:42 +00:00
|
|
|
})
|
|
|
|
|
2020-07-30 14:39:15 +00:00
|
|
|
it("does not update the LoginDiscoveryConfig to avoid unnecessary etcd writes/api calls", func() {
|
2020-07-30 21:34:13 +00:00
|
|
|
startInformersAndController()
|
|
|
|
err := controller.TestSync(t, subject, *syncContext)
|
2020-07-30 01:18:42 +00:00
|
|
|
r.NoError(err)
|
2020-07-30 14:39:15 +00:00
|
|
|
|
2020-07-30 21:34:13 +00:00
|
|
|
r.Empty(placeholderAPIClient.Actions())
|
2020-07-30 01:18:42 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
when("the LoginDiscoveryConfig is stale compared to the data in the ConfigMap", func() {
|
|
|
|
it.Before(func() {
|
2020-07-30 14:39:15 +00:00
|
|
|
_, expectedLoginDiscoveryConfig := expectedLoginDiscoveryConfig(
|
|
|
|
installedInNamespace,
|
|
|
|
kubeServerURL,
|
|
|
|
caData,
|
|
|
|
)
|
|
|
|
expectedLoginDiscoveryConfig.Spec.Server = "https://some-other-server"
|
2020-07-30 21:34:13 +00:00
|
|
|
r.NoError(placeholderInformerClient.Tracker().Add(expectedLoginDiscoveryConfig))
|
|
|
|
r.NoError(placeholderAPIClient.Tracker().Add(expectedLoginDiscoveryConfig))
|
2020-07-30 01:18:42 +00:00
|
|
|
})
|
|
|
|
|
2020-07-30 14:39:15 +00:00
|
|
|
it("updates the existing LoginDiscoveryConfig", func() {
|
2020-07-30 21:34:13 +00:00
|
|
|
startInformersAndController()
|
|
|
|
err := controller.TestSync(t, subject, *syncContext)
|
2020-07-30 14:39:15 +00:00
|
|
|
r.NoError(err)
|
|
|
|
|
|
|
|
expectedLoginDiscoveryConfigGVR, expectedLoginDiscoveryConfig := expectedLoginDiscoveryConfig(
|
|
|
|
installedInNamespace,
|
|
|
|
kubeServerURL,
|
|
|
|
caData,
|
|
|
|
)
|
|
|
|
expectedActions := []coretesting.Action{
|
|
|
|
coretesting.NewUpdateAction(
|
|
|
|
expectedLoginDiscoveryConfigGVR,
|
|
|
|
installedInNamespace,
|
|
|
|
expectedLoginDiscoveryConfig,
|
|
|
|
),
|
|
|
|
}
|
2020-07-30 21:34:13 +00:00
|
|
|
r.Equal(expectedActions, placeholderAPIClient.Actions())
|
2020-07-30 14:39:15 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
when("updating the LoginDiscoveryConfig fails", func() {
|
|
|
|
it.Before(func() {
|
2020-07-30 21:34:13 +00:00
|
|
|
placeholderAPIClient.PrependReactor(
|
2020-07-30 14:39:15 +00:00
|
|
|
"update",
|
|
|
|
"logindiscoveryconfigs",
|
|
|
|
func(_ coretesting.Action) (bool, runtime.Object, error) {
|
|
|
|
return true, nil, errors.New("update failed")
|
|
|
|
},
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("returns the update error", func() {
|
2020-07-30 21:34:13 +00:00
|
|
|
startInformersAndController()
|
|
|
|
err := controller.TestSync(t, subject, *syncContext)
|
2020-07-30 14:39:15 +00:00
|
|
|
r.EqualError(err, "could not update logindiscoveryconfig: update failed")
|
|
|
|
})
|
2020-07-30 01:18:42 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2020-07-30 00:22:25 +00:00
|
|
|
|
2020-07-30 01:18:42 +00:00
|
|
|
when("the ConfigMap is missing the expected `kubeconfig` top-level data key", func() {
|
|
|
|
it.Before(func() {
|
2020-07-30 21:34:13 +00:00
|
|
|
clusterInfoConfigMap := &corev1.ConfigMap{
|
2020-07-30 01:18:42 +00:00
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "cluster-info", Namespace: "kube-public"},
|
|
|
|
Data: map[string]string{
|
|
|
|
"these are not the droids you're looking for": "uninteresting-value",
|
|
|
|
},
|
2020-07-30 00:22:25 +00:00
|
|
|
}
|
2020-07-30 21:34:13 +00:00
|
|
|
err := kubeInformerClient.Tracker().Add(clusterInfoConfigMap)
|
2020-07-30 01:18:42 +00:00
|
|
|
r.NoError(err)
|
|
|
|
})
|
2020-07-30 00:22:25 +00:00
|
|
|
|
2020-07-30 01:18:42 +00:00
|
|
|
it("keeps waiting for it to exist", func() {
|
2020-07-30 21:34:13 +00:00
|
|
|
startInformersAndController()
|
|
|
|
err := controller.TestSync(t, subject, *syncContext)
|
2020-07-30 01:18:42 +00:00
|
|
|
r.NoError(err)
|
2020-07-30 21:34:13 +00:00
|
|
|
r.Empty(placeholderAPIClient.Actions())
|
2020-07-30 00:22:25 +00:00
|
|
|
})
|
2020-07-30 01:18:42 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
when("there is not a cluster-info ConfigMap in the kube-public namespace", func() {
|
|
|
|
it.Before(func() {
|
|
|
|
unrelatedConfigMap := &corev1.ConfigMap{
|
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
|
|
Name: "oops this is not the cluster-info ConfigMap",
|
|
|
|
Namespace: "kube-public",
|
|
|
|
},
|
|
|
|
}
|
2020-07-30 21:34:13 +00:00
|
|
|
err := kubeInformerClient.Tracker().Add(unrelatedConfigMap)
|
2020-07-30 01:18:42 +00:00
|
|
|
r.NoError(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
it("keeps waiting for one", func() {
|
2020-07-30 21:34:13 +00:00
|
|
|
startInformersAndController()
|
|
|
|
err := controller.TestSync(t, subject, *syncContext)
|
2020-07-30 01:18:42 +00:00
|
|
|
r.NoError(err)
|
2020-07-30 21:34:13 +00:00
|
|
|
r.Empty(placeholderAPIClient.Actions())
|
2020-07-30 01:18:42 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}, spec.Parallel(), spec.Report(report.Terminal{}))
|
2020-07-30 00:22:25 +00:00
|
|
|
}
|