| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /*
- Copyright © The ESO Authors
- 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
- https://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 common
- import (
- "context"
- "fmt"
- "time"
- . "github.com/onsi/ginkgo/v2"
- . "github.com/onsi/gomega"
- corev1 "k8s.io/api/core/v1"
- apierrors "k8s.io/apimachinery/pkg/api/errors"
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
- "k8s.io/apimachinery/pkg/util/wait"
- "github.com/external-secrets/external-secrets-e2e/framework"
- )
- func CreateProviderCaseNamespace(f *framework.Framework, prefix string, pollInterval time.Duration) string {
- if pollInterval <= 0 {
- pollInterval = 5 * time.Second
- }
- namespace := &corev1.Namespace{
- ObjectMeta: metav1.ObjectMeta{
- GenerateName: fmt.Sprintf("e2e-tests-%s-", prefix),
- },
- }
- Expect(f.CRClient.Create(context.Background(), namespace)).To(Succeed())
- DeferCleanup(func() {
- ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
- defer cancel()
- err := f.CRClient.Delete(ctx, namespace)
- if err != nil && !apierrors.IsNotFound(err) {
- Expect(err).ToNot(HaveOccurred())
- }
- err = wait.PollUntilContextTimeout(ctx, pollInterval, 2*time.Minute, true, func(ctx context.Context) (bool, error) {
- _, err := f.KubeClientSet.CoreV1().Namespaces().Get(ctx, namespace.Name, metav1.GetOptions{})
- if apierrors.IsNotFound(err) {
- return true, nil
- }
- if err != nil {
- return false, err
- }
- return false, nil
- })
- Expect(err).To(Succeed())
- })
- return namespace.Name
- }
|