mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
e2e framework: remove last dependency to k/k/pkg/util
Copied and modified RemoveString function from k/k/pkg/util/slice/slice.go to e2e/framework/pod/pod_client.go This is the last dependency from e2e framework to k/k/pkg/util
This commit is contained in:
parent
6e541a6da7
commit
dc4f6f9da6
@ -38,7 +38,6 @@ import (
|
||||
"github.com/onsi/ginkgo/v2"
|
||||
"github.com/onsi/gomega"
|
||||
|
||||
"k8s.io/kubernetes/pkg/util/slice"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
)
|
||||
|
||||
@ -313,10 +312,29 @@ func (c *PodClient) PodIsReady(ctx context.Context, name string) bool {
|
||||
return podutils.IsPodReady(pod)
|
||||
}
|
||||
|
||||
// RemoveString returns a newly created []string that contains all items from slice
|
||||
// that are not equal to s.
|
||||
// This code is taken from k/k/pkg/util/slice/slice.go to remove
|
||||
// e2e/framework/pod -> k/k/pkg/util/slice dependency.
|
||||
func removeString(slice []string, s string) []string {
|
||||
newSlice := make([]string, 0)
|
||||
for _, item := range slice {
|
||||
if item != s {
|
||||
newSlice = append(newSlice, item)
|
||||
}
|
||||
}
|
||||
if len(newSlice) == 0 {
|
||||
// Sanitize for unit tests so we don't need to distinguish empty array
|
||||
// and nil.
|
||||
return nil
|
||||
}
|
||||
return newSlice
|
||||
}
|
||||
|
||||
// RemovePodFinalizer removes the pod's finalizer
|
||||
func (c *PodClient) RemoveFinalizer(ctx context.Context, podName string, finalizerName string) {
|
||||
framework.Logf("Removing pod's %q finalizer: %q", podName, finalizerName)
|
||||
c.Update(ctx, podName, func(pod *v1.Pod) {
|
||||
pod.ObjectMeta.Finalizers = slice.RemoveString(pod.ObjectMeta.Finalizers, finalizerName, nil)
|
||||
pod.ObjectMeta.Finalizers = removeString(pod.ObjectMeta.Finalizers, finalizerName)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user