From 8ddc1a1e929feb3cc6487ad1108f982b5671999a Mon Sep 17 00:00:00 2001 From: Andrew Keesler Date: Thu, 27 Aug 2020 10:43:13 -0400 Subject: [PATCH] internal/controller/issuerconfig: add missing invalid kubeconfig test? Signed-off-by: Andrew Keesler --- internal/controller/issuerconfig/publisher.go | 6 +++++- .../controller/issuerconfig/publisher_test.go | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/controller/issuerconfig/publisher.go b/internal/controller/issuerconfig/publisher.go index 0098df02..7d1b862f 100644 --- a/internal/controller/issuerconfig/publisher.go +++ b/internal/controller/issuerconfig/publisher.go @@ -94,7 +94,11 @@ func (c *publisherController) Sync(ctx controller.Context) error { return nil } - config, _ := clientcmd.Load([]byte(kubeConfig)) + config, err := clientcmd.Load([]byte(kubeConfig)) + if err != nil { + klog.InfoS("could not load kubeconfig configmap key") + return nil + } var certificateAuthorityData, server string for _, v := range config.Clusters { diff --git a/internal/controller/issuerconfig/publisher_test.go b/internal/controller/issuerconfig/publisher_test.go index efce518d..79fd87cd 100644 --- a/internal/controller/issuerconfig/publisher_test.go +++ b/internal/controller/issuerconfig/publisher_test.go @@ -436,6 +436,26 @@ func TestSync(t *testing.T) { r.Empty(pinnipedAPIClient.Actions()) }) }) + + when("the ConfigMap does not have a valid kubeconfig", func() { + it.Before(func() { + clusterInfoConfigMap := &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{Name: "cluster-info", Namespace: "kube-public"}, + Data: map[string]string{ + "kubeconfig": "this is an invalid kubeconfig", + }, + } + err := kubeInformerClient.Tracker().Add(clusterInfoConfigMap) + r.NoError(err) + }) + + it("keeps waiting for it to be properly formatted", func() { + startInformersAndController() + err := controller.TestSync(t, subject, *syncContext) + r.NoError(err) + r.Empty(pinnipedAPIClient.Actions()) + }) + }) }) when("there is not a cluster-info ConfigMap in the kube-public namespace", func() {