mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-19 22:44:21 +00:00
This change adds an E2E test which exercises the mulitple credentials feature added in #3489. The test creates a secret from the given credentials and creates a BackupStorageLocation which uses those credentials. A backup and restore is then performed to the default BSL and to the newly created BSL. This change adds new flags to the E2E test suite to configure the BSL created and used in the test. Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package e2e
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os/exec"
|
|
"time"
|
|
|
|
"github.com/pkg/errors"
|
|
"golang.org/x/net/context"
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
|
"k8s.io/client-go/kubernetes"
|
|
|
|
"github.com/vmware-tanzu/velero/pkg/builder"
|
|
)
|
|
|
|
// EnsureClusterExists returns whether or not a kubernetes cluster exists for tests to be run on.
|
|
func EnsureClusterExists(ctx context.Context) error {
|
|
return exec.CommandContext(ctx, "kubectl", "cluster-info").Run()
|
|
}
|
|
|
|
// CreateNamespace creates a kubernetes namespace
|
|
func CreateNamespace(ctx context.Context, client *kubernetes.Clientset, namespace string) error {
|
|
ns := builder.ForNamespace(namespace).Result()
|
|
_, err := client.CoreV1().Namespaces().Create(ctx, ns, metav1.CreateOptions{})
|
|
if apierrors.IsAlreadyExists(err) {
|
|
return nil
|
|
}
|
|
return err
|
|
}
|
|
|
|
// WaitForNamespaceDeletion Waits for namespace to be deleted.
|
|
func WaitForNamespaceDeletion(interval, timeout time.Duration, client *kubernetes.Clientset, ns string) error {
|
|
err := wait.PollImmediate(interval, timeout, func() (bool, error) {
|
|
_, err := client.CoreV1().Namespaces().Get(context.TODO(), ns, metav1.GetOptions{})
|
|
if err != nil {
|
|
if apierrors.IsNotFound(err) {
|
|
return true, nil
|
|
}
|
|
return false, err
|
|
}
|
|
fmt.Printf("Namespace %s is still being deleted...\n", ns)
|
|
return false, nil
|
|
})
|
|
return err
|
|
}
|
|
|
|
func CreateSecretFromFiles(ctx context.Context, client *kubernetes.Clientset, namespace string, name string, files map[string]string) error {
|
|
data := make(map[string][]byte)
|
|
|
|
for key, filePath := range files {
|
|
contents, err := ioutil.ReadFile(filePath)
|
|
if err != nil {
|
|
return errors.WithMessagef(err, "Failed to read secret file %q", filePath)
|
|
}
|
|
|
|
data[key] = contents
|
|
}
|
|
|
|
secret := builder.ForSecret(namespace, name).Data(data).Result()
|
|
_, err := client.CoreV1().Secrets(namespace).Create(ctx, secret, metav1.CreateOptions{})
|
|
return err
|
|
}
|