From 4dbde4cf7f62f5f4e77c3b8318881326457abbbc Mon Sep 17 00:00:00 2001 From: Matt Moyer Date: Wed, 24 Feb 2021 12:08:41 -0600 Subject: [PATCH] Fix TestImpersonationProxy on Kubernetes 1.20 with RootCAConfigMap. There is a new feature in 1.20 that creates a ConfigMap by default in each namespace: https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.20.md#introducing-rootcaconfigmap This broke this test because it assumed that all the ConfigMaps in the ephemeral test namespace were those created by the test code. The fix is to add a test label and rewrite our assertions to filter with it. Signed-off-by: Matt Moyer --- .../concierge_impersonation_proxy_test.go | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/test/integration/concierge_impersonation_proxy_test.go b/test/integration/concierge_impersonation_proxy_test.go index 08101533..1ec2fc08 100644 --- a/test/integration/concierge_impersonation_proxy_test.go +++ b/test/integration/concierge_impersonation_proxy_test.go @@ -180,18 +180,21 @@ func TestImpersonationProxy(t *testing.T) { informerFactory.WaitForCacheSync(ctx.Done()) // Test "create" verb through the impersonation proxy. + configMapLabels := labels.Set{ + "pinniped.dev/testConfigMap": library.RandHex(t, 8), + } _, err = impersonationProxyClient.CoreV1().ConfigMaps(namespace.Name).Create(ctx, - &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "configmap-1"}}, + &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "configmap-1", Labels: configMapLabels}}, metav1.CreateOptions{}, ) require.NoError(t, err) _, err = impersonationProxyClient.CoreV1().ConfigMaps(namespace.Name).Create(ctx, - &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "configmap-2"}}, + &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "configmap-2", Labels: configMapLabels}}, metav1.CreateOptions{}, ) require.NoError(t, err) _, err = impersonationProxyClient.CoreV1().ConfigMaps(namespace.Name).Create(ctx, - &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "configmap-3"}}, + &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "configmap-3", Labels: configMapLabels}}, metav1.CreateOptions{}, ) require.NoError(t, err) @@ -210,7 +213,9 @@ func TestImpersonationProxy(t *testing.T) { require.NoError(t, err) // Test "list" verb through the impersonation proxy. - listResult, err := impersonationProxyClient.CoreV1().ConfigMaps(namespace.Name).List(ctx, metav1.ListOptions{}) + listResult, err := impersonationProxyClient.CoreV1().ConfigMaps(namespace.Name).List(ctx, metav1.ListOptions{ + LabelSelector: configMapLabels.String(), + }) require.NoError(t, err) require.Len(t, listResult.Items, 3) @@ -253,7 +258,7 @@ func TestImpersonationProxy(t *testing.T) { // demonstrate that the informer's "watch" verb is working through the impersonation proxy. require.Eventually(t, func() bool { _, getErr := informer.Lister().ConfigMaps(namespace.Name).Get("configmap-3") - list, listErr := informer.Lister().ConfigMaps(namespace.Name).List(labels.Everything()) + list, listErr := informer.Lister().ConfigMaps(namespace.Name).List(configMapLabels.AsSelector()) return k8serrors.IsNotFound(getErr) && listErr == nil && len(list) == 2 }, 10*time.Second, 50*time.Millisecond) @@ -264,11 +269,13 @@ func TestImpersonationProxy(t *testing.T) { // Make sure that the deleted ConfigMaps shows up in the informer's cache to // demonstrate that the informer's "watch" verb is working through the impersonation proxy. require.Eventually(t, func() bool { - list, listErr := informer.Lister().ConfigMaps(namespace.Name).List(labels.Everything()) + list, listErr := informer.Lister().ConfigMaps(namespace.Name).List(configMapLabels.AsSelector()) return listErr == nil && len(list) == 0 }, 10*time.Second, 50*time.Millisecond) - listResult, err = impersonationProxyClient.CoreV1().ConfigMaps(namespace.Name).List(ctx, metav1.ListOptions{}) + listResult, err = impersonationProxyClient.CoreV1().ConfigMaps(namespace.Name).List(ctx, metav1.ListOptions{ + LabelSelector: configMapLabels.String(), + }) require.NoError(t, err) require.Len(t, listResult.Items, 0) })