From 9c1c760f561163f34aef3333698890cf72111569 Mon Sep 17 00:00:00 2001 From: Ryan Richard Date: Wed, 3 Mar 2021 16:23:07 -0800 Subject: [PATCH] Always clean up the ConfigMap at the end of the impersonator int test Signed-off-by: Margo Crawford --- .../concierge_impersonation_proxy_test.go | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/test/integration/concierge_impersonation_proxy_test.go b/test/integration/concierge_impersonation_proxy_test.go index d4b6bb50..b52c662f 100644 --- a/test/integration/concierge_impersonation_proxy_test.go +++ b/test/integration/concierge_impersonation_proxy_test.go @@ -94,6 +94,28 @@ func TestImpersonationProxy(t *testing.T) { t.Logf("stashing a pre-existing configmap %s", oldConfigMap.Name) require.NoError(t, adminClient.CoreV1().ConfigMaps(env.ConciergeNamespace).Delete(ctx, impersonationProxyConfigMapName(env), metav1.DeleteOptions{})) } + // At the end of the test, clean up the ConfigMap. + t.Cleanup(func() { + ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + // Delete any version that was created by this test. + t.Logf("cleaning up configmap at end of test %s", impersonationProxyConfigMapName(env)) + err = adminClient.CoreV1().ConfigMaps(env.ConciergeNamespace).Delete(ctx, impersonationProxyConfigMapName(env), metav1.DeleteOptions{}) + if !k8serrors.IsNotFound(err) { + require.NoError(t, err) // only not found errors are acceptable + } + + // Only recreate it if it already existed at the start of this test. + if len(oldConfigMap.Data) != 0 { + t.Log(oldConfigMap) + oldConfigMap.UID = "" // cant have a UID yet + oldConfigMap.ResourceVersion = "" + t.Logf("restoring a pre-existing configmap %s", oldConfigMap.Name) + _, err = adminClient.CoreV1().ConfigMaps(env.ConciergeNamespace).Create(ctx, oldConfigMap, metav1.CreateOptions{}) + require.NoError(t, err) + } + }) if env.HasCapability(library.HasExternalLoadBalancerProvider) { //nolint:nestif // come on... it's just a test // Check that load balancer has been automatically created by the impersonator's "auto" mode. @@ -122,24 +144,6 @@ func TestImpersonationProxy(t *testing.T) { t.Logf("creating configmap %s", configMap.Name) _, err = adminClient.CoreV1().ConfigMaps(env.ConciergeNamespace).Create(ctx, &configMap, metav1.CreateOptions{}) require.NoError(t, err) - - // At the end of the test, clean up the ConfigMap. - t.Cleanup(func() { - ctx, cancel = context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - t.Logf("cleaning up configmap at end of test %s", impersonationProxyConfigMapName(env)) - err = adminClient.CoreV1().ConfigMaps(env.ConciergeNamespace).Delete(ctx, impersonationProxyConfigMapName(env), metav1.DeleteOptions{}) - require.NoError(t, err) - - if len(oldConfigMap.Data) != 0 { - t.Log(oldConfigMap) - oldConfigMap.UID = "" // cant have a UID yet - oldConfigMap.ResourceVersion = "" - t.Logf("restoring a pre-existing configmap %s", oldConfigMap.Name) - _, err = adminClient.CoreV1().ConfigMaps(env.ConciergeNamespace).Create(ctx, oldConfigMap, metav1.CreateOptions{}) - require.NoError(t, err) - } - }) } // At this point the impersonator should be starting/running. When it is ready, the CredentialIssuer's