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 <moyerm@vmware.com>
This commit is contained in:
parent
7be8927d5e
commit
4dbde4cf7f
@ -180,18 +180,21 @@ func TestImpersonationProxy(t *testing.T) {
|
|||||||
informerFactory.WaitForCacheSync(ctx.Done())
|
informerFactory.WaitForCacheSync(ctx.Done())
|
||||||
|
|
||||||
// Test "create" verb through the impersonation proxy.
|
// 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,
|
_, 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{},
|
metav1.CreateOptions{},
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = impersonationProxyClient.CoreV1().ConfigMaps(namespace.Name).Create(ctx,
|
_, 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{},
|
metav1.CreateOptions{},
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
_, err = impersonationProxyClient.CoreV1().ConfigMaps(namespace.Name).Create(ctx,
|
_, 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{},
|
metav1.CreateOptions{},
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -210,7 +213,9 @@ func TestImpersonationProxy(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Test "list" verb through the impersonation proxy.
|
// 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.NoError(t, err)
|
||||||
require.Len(t, listResult.Items, 3)
|
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.
|
// demonstrate that the informer's "watch" verb is working through the impersonation proxy.
|
||||||
require.Eventually(t, func() bool {
|
require.Eventually(t, func() bool {
|
||||||
_, getErr := informer.Lister().ConfigMaps(namespace.Name).Get("configmap-3")
|
_, 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
|
return k8serrors.IsNotFound(getErr) && listErr == nil && len(list) == 2
|
||||||
}, 10*time.Second, 50*time.Millisecond)
|
}, 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
|
// 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.
|
// demonstrate that the informer's "watch" verb is working through the impersonation proxy.
|
||||||
require.Eventually(t, func() bool {
|
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
|
return listErr == nil && len(list) == 0
|
||||||
}, 10*time.Second, 50*time.Millisecond)
|
}, 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.NoError(t, err)
|
||||||
require.Len(t, listResult.Items, 0)
|
require.Len(t, listResult.Items, 0)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user