Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/9800-immanuwell
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix test delete wait helpers to poll the requested object name.
2 changes: 1 addition & 1 deletion test/util/k8s/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func WaitForConfigmapDelete(c clientset.Interface, ns, name string) error {

return waitutil.PollImmediateInfinite(5*time.Second,
func() (bool, error) {
if _, err := c.CoreV1().ConfigMaps(ns).Get(context.TODO(), ns, metav1.GetOptions{}); err != nil {
if _, err := c.CoreV1().ConfigMaps(ns).Get(context.TODO(), name, metav1.GetOptions{}); err != nil {
if apierrors.IsNotFound(err) {
return true, nil
}
Expand Down
98 changes: 98 additions & 0 deletions test/util/k8s/delete_wait_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Copyright the Velero contributors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package k8s

import (
"testing"

corev1api "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/fake"
kubetesting "k8s.io/client-go/testing"
)

func TestWaitForServiceDeletePollsRequestedService(t *testing.T) {
const namespace = "test-ns"
const name = "test-service"

client := fake.NewSimpleClientset(&corev1api.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
})

if err := WaitForServiceDelete(TestClient{ClientGo: client}, namespace, name, true); err != nil {
t.Fatalf("WaitForServiceDelete returned error: %v", err)
}

assertGetActionName(t, client.Actions(), "services", name)
}

func TestWaitForSecretDeletePollsRequestedSecret(t *testing.T) {
const namespace = "test-ns"
const name = "test-secret"

client := fake.NewSimpleClientset(&corev1api.Secret{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
})

if err := WaitForSecretDelete(client, namespace, name); err != nil {
t.Fatalf("WaitForSecretDelete returned error: %v", err)
}

assertGetActionName(t, client.Actions(), "secrets", name)
}

func TestWaitForConfigmapDeletePollsRequestedConfigMap(t *testing.T) {
const namespace = "test-ns"
const name = "test-configmap"

client := fake.NewSimpleClientset(&corev1api.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
})

if err := WaitForConfigmapDelete(client, namespace, name); err != nil {
t.Fatalf("WaitForConfigmapDelete returned error: %v", err)
}

assertGetActionName(t, client.Actions(), "configmaps", name)
}

func assertGetActionName(t *testing.T, actions []kubetesting.Action, resource, expectedName string) {
t.Helper()

for _, action := range actions {
getAction, ok := action.(kubetesting.GetAction)
if !ok || getAction.GetVerb() != "get" || getAction.GetResource().Resource != resource {
continue
}

if getAction.GetName() != expectedName {
t.Fatalf("expected get action for %q, got %q", expectedName, getAction.GetName())
}
return
}

t.Fatalf("expected get action for resource %q", resource)
}
2 changes: 1 addition & 1 deletion test/util/k8s/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func WaitForSecretDelete(c clientset.Interface, ns, name string) error {
}
return waitutil.PollImmediateInfinite(5*time.Second,
func() (bool, error) {
if _, err := c.CoreV1().Secrets(ns).Get(context.TODO(), ns, metav1.GetOptions{}); err != nil {
if _, err := c.CoreV1().Secrets(ns).Get(context.TODO(), name, metav1.GetOptions{}); err != nil {
if apierrors.IsNotFound(err) {
return true, nil
}
Expand Down
2 changes: 1 addition & 1 deletion test/util/k8s/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func WaitForServiceDelete(client TestClient, ns, name string, deleteFirst bool)
}
return waitutil.PollImmediateInfinite(5*time.Second,
func() (bool, error) {
if _, err := client.ClientGo.CoreV1().Services(ns).Get(context.TODO(), ns, metav1.GetOptions{}); err != nil {
if _, err := client.ClientGo.CoreV1().Services(ns).Get(context.TODO(), name, metav1.GetOptions{}); err != nil {
if apierrors.IsNotFound(err) {
return true, nil
}
Expand Down
Loading