Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi cloud e2e master rebase #568

Merged
Merged
71 changes: 58 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
OADP_TEST_NAMESPACE ?= openshift-adp
REGION ?= us-east-1
PROVIDER ?= aws
CLUSTER_PROFILE ?= aws
CLUSTER_TYPE ?= aws

# CONFIGS FOR CLOUD
# bsl / blob storage cred dir
OADP_CRED_DIR ?= /var/run/oadp-credentials
# vsl / volume/cluster cred dir
CLUSTER_PROFILE_DIR ?= /Users/drajds/.aws

# bsl cred file
OADP_CRED_FILE ?= ${OADP_CRED_DIR}/new-aws-credentials
# vsl cred file
CI_CRED_FILE ?= ${CLUSTER_PROFILE_DIR}/.awscred
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After much confusion debugging ci.. this probably should've been called VSL_CRED_FILE


# aws configs - default
BSL_REGION ?= us-east-1
VSL_REGION ?= ${LEASED_RESOURCE}
# BSL_AWS_PROFILE ?= default
BSL_AWS_PROFILE ?= migration-engineering

# vsl secret
CREDS_SECRET_REF ?= cloud-credentials
OADP_AWS_CRED_FILE ?= /var/run/oadp-credentials/aws-credentials
OADP_S3_BUCKET ?= /var/run/oadp-credentials/velero-bucket-name
# bucket file
OADP_BUCKET_FILE ?= ${OADP_CRED_DIR}/new-velero-bucket-name
# azure cluster resource file - only in CI
AZURE_RESOURCE_FILE ?= /var/run/secrets/ci.openshift.io/multi-stage/metadata.json

# Misc
OPENSHIFT_CI ?= true
VELERO_INSTANCE_NAME ?= velero-sample
E2E_TIMEOUT_MULTIPLIER ?= 1

ifeq ($(CLUSTER_TYPE), gcp)
CI_CRED_FILE = ${CLUSTER_PROFILE_DIR}/gce.json
OADP_CRED_FILE = ${OADP_CRED_DIR}/gcp-credentials
CREDS_SECRET_REF = cloud-credentials-gcp
OADP_BUCKET_FILE = ${OADP_CRED_DIR}/gcp-velero-bucket-name
else ifeq ($(CLUSTER_TYPE), azure4)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

azure4, is that the real cluster type or typo?

Copy link
Contributor Author

@deepakraj1997 deepakraj1997 Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thats the real cluster type @weshayutin. Changing it on the next line to a proper one.

CLUSTER_TYPE = azure
CI_CRED_FILE = ${CLUSTER_PROFILE_DIR}/osServicePrincipal.json
OADP_CRED_FILE = ${OADP_CRED_DIR}/azure-credentials
CREDS_SECRET_REF = cloud-credentials-azure
OADP_BUCKET_FILE = ${OADP_CRED_DIR}/azure-velero-bucket-name
endif

# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.21

Expand Down Expand Up @@ -290,18 +325,28 @@ catalog-build: opm ## Build a catalog image.
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

S3_BUCKET := $(shell cat $(OADP_S3_BUCKET) | awk '/velero-bucket-name/ {gsub(/"/, "", $$2);gsub(/}/,""); print $$2}')
TEST_FILTER := $(shell echo '! aws && ! gcp && ! azure' | sed -r "s/[&]* [!] $(CLUSTER_PROFILE)|[!] $(CLUSTER_PROFILE) [&]*//")
OADP_BUCKET := $(shell cat $(OADP_BUCKET_FILE))
TEST_FILTER := $(shell echo '! aws && ! gcp && ! azure' | sed -r "s/[&]* [!] $(CLUSTER_TYPE)|[!] $(CLUSTER_TYPE) [&]*//")
SETTINGS_TMP=/tmp/test-settings
test-e2e:

test-e2e-setup:
mkdir -p $(SETTINGS_TMP)
PROVIDER="$(PROVIDER)" BUCKET="$(S3_BUCKET)" REGION="$(REGION)" SECRET="$(CREDS_SECRET_REF)" TMP_DIR=$(SETTINGS_TMP) /bin/bash tests/e2e/scripts/aws_settings.sh
ginkgo run -mod=mod tests/e2e/ -- -cloud=$(OADP_AWS_CRED_FILE) \
PROVIDER="$(CLUSTER_TYPE)" BUCKET="$(OADP_BUCKET)" BSL_REGION="$(BSL_REGION)" SECRET="$(CREDS_SECRET_REF)" TMP_DIR=$(SETTINGS_TMP) \
VSL_REGION="$(VSL_REGION)" BSL_AWS_PROFILE="$(BSL_AWS_PROFILE)" BSL_REGION="$(BSL_REGION)" /bin/bash "tests/e2e/scripts/$(CLUSTER_TYPE)_settings.sh"

test-e2e: test-e2e-setup
ginkgo run -mod=mod tests/e2e/ -- -credentials=$(OADP_CRED_FILE) \
-velero_namespace=$(OADP_TEST_NAMESPACE) \
-settings=$(SETTINGS_TMP)/awscreds \
-settings=$(SETTINGS_TMP)/oadpcreds \
-velero_instance_name=$(VELERO_INSTANCE_NAME) \
-timeout_multiplier=$(E2E_TIMEOUT_MULTIPLIER) \
-cluster_profile=$(CLUSTER_PROFILE) \
--ginkgo.label-filter="$(TEST_FILTER)"
-cluster_profile=$(CLUSTER_TYPE) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to feed all platform specific info to the json file instead? better to keep it platform agnostic...

--ginkgo.label-filter="$(TEST_FILTER)" \
-openshift_ci=$(OPENSHIFT_CI) \
-ci_cred_file=$(CI_CRED_FILE) \
-azure_resource_file=$(AZURE_RESOURCE_FILE) \
-provider=$(CLUSTER_TYPE) \
-creds_secret_ref=$(CREDS_SECRET_REF)

test-e2e-cleanup:
rm -rf $(SETTINGS_TMP)
2 changes: 1 addition & 1 deletion controllers/bsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func (r *DPAReconciler) validateProviderPluginAndSecret(bslSpec velerov1.BackupS
r.Log.Info(fmt.Sprintf("%s backupstoragelocation is configured but velero plugin for %s is not present", bslSpec.Provider, bslSpec.Provider))
//TODO: set warning condition on Velero CR
}
secretName, _ := r.getSecretNameAndKey(bslSpec.Credential, oadpv1alpha1.DefaultPlugin(bslSpec.Provider))
secretName, _ := r.getSecretNameAndKey(&bslSpec, oadpv1alpha1.DefaultPlugin(bslSpec.Provider))

_, err := r.getProviderSecret(secretName)

Expand Down
39 changes: 30 additions & 9 deletions controllers/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,29 @@ func (r *DPAReconciler) buildRegistryDeployment(registryDeployment *appsv1.Deplo
},
}

// attach gcp secret volume if provider is gcp
if bsl.Spec.Provider == GCPProvider {
// attach secret volume for cloud providers
if _, ok := bsl.Spec.Config["credentialsFile"]; ok {
if cloudProviderMap, bslCredOk := credentials.PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bsl.Spec.Provider)]; bslCredOk {
registryDeployment.Spec.Template.Spec.Volumes = append(
registryDeployment.Spec.Template.Spec.Volumes,
corev1.Volume{
Name: cloudProviderMap.SecretName,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: cloudProviderMap.BslSecretName,
},
},
},
)
}
} else if bsl.Spec.Provider == GCPProvider {
cloudProviderMap := credentials.PluginSpecificFields[oadpv1alpha1.DefaultPluginGCP]
registryDeployment.Spec.Template.Spec.Volumes = []corev1.Volume{
{
Name: credentials.PluginSpecificFields[oadpv1alpha1.DefaultPluginGCP].SecretName,
Name: cloudProviderMap.SecretName,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: credentials.PluginSpecificFields[oadpv1alpha1.DefaultPluginGCP].SecretName,
SecretName: cloudProviderMap.SecretName,
},
},
},
Expand Down Expand Up @@ -540,18 +555,24 @@ func (r *DPAReconciler) getSecretNameAndKeyforBackupLocation(bslspec oadpv1alpha
}
}
if bslspec.Velero != nil {
return r.getSecretNameAndKey(bslspec.Velero.Credential, oadpv1alpha1.DefaultPlugin(bslspec.Velero.Provider))
return r.getSecretNameAndKey(bslspec.Velero, oadpv1alpha1.DefaultPlugin(bslspec.Velero.Provider))
}

return "", ""
}

func (r *DPAReconciler) getSecretNameAndKey(credential *corev1.SecretKeySelector, plugin oadpv1alpha1.DefaultPlugin) (string, string) {
func (r *DPAReconciler) getSecretNameAndKey(bslSpec *velerov1.BackupStorageLocationSpec, plugin oadpv1alpha1.DefaultPlugin) (string, string) {
// Assume default values unless user has overriden them
secretName := credentials.PluginSpecificFields[plugin].SecretName
secretKey := credentials.PluginSpecificFields[plugin].PluginSecretKey

if _, ok := bslSpec.Config["credentialsFile"]; ok {
secretName = credentials.PluginSpecificFields[plugin].BslSecretName
secretKey = credentials.PluginSpecificFields[plugin].PluginSecretKey
}
r.Log.Info(fmt.Sprintf("secret: %s", secretName))
r.Log.Info(fmt.Sprintf("key: %s", secretKey))
// check if user specified the Credential Name and Key
credential := bslSpec.Credential
if credential != nil {
if len(credential.Name) > 0 {
secretName = credential.Name
Expand Down Expand Up @@ -1138,7 +1159,7 @@ func (r *DPAReconciler) updateRegistrySecret(secret *corev1.Secret, bsl *velerov

func (r *DPAReconciler) populateAWSRegistrySecret(bsl *velerov1.BackupStorageLocation, registrySecret *corev1.Secret) error {
// Check for secret name
secretName, secretKey := r.getSecretNameAndKey(bsl.Spec.Credential, oadpv1alpha1.DefaultPluginAWS)
secretName, secretKey := r.getSecretNameAndKey(&bsl.Spec, oadpv1alpha1.DefaultPluginAWS)

// fetch secret and error
secret, err := r.getProviderSecret(secretName)
Expand Down Expand Up @@ -1167,7 +1188,7 @@ func (r *DPAReconciler) populateAWSRegistrySecret(bsl *velerov1.BackupStorageLoc

func (r *DPAReconciler) populateAzureRegistrySecret(bsl *velerov1.BackupStorageLocation, registrySecret *corev1.Secret) error {
// Check for secret name
secretName, secretKey := r.getSecretNameAndKey(bsl.Spec.Credential, oadpv1alpha1.DefaultPluginMicrosoftAzure)
secretName, secretKey := r.getSecretNameAndKey(&bsl.Spec, oadpv1alpha1.DefaultPluginMicrosoftAzure)
r.Log.Info(fmt.Sprintf("Azure secret name: %s and secret key: %s", secretName, secretKey))

// fetch secret and error
Expand Down
49 changes: 49 additions & 0 deletions pkg/credentials/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type DefaultPluginFields struct {
IsCloudProvider bool
SecretName string
MountPath string
BslSecretName string
BSlMountPath string
EnvCredentialsFile string
PluginImage string
PluginSecretKey string
Expand All @@ -32,6 +34,8 @@ var (
IsCloudProvider: true,
SecretName: "cloud-credentials",
MountPath: "/credentials",
BslSecretName: "bsl-cloud-credentials-aws",
BSlMountPath: "/bsl-cloud-credentials-aws",
EnvCredentialsFile: common.AWSSharedCredentialsFileEnvKey,
PluginName: common.VeleroPluginForAWS,
PluginSecretKey: "cloud",
Expand All @@ -40,6 +44,8 @@ var (
IsCloudProvider: true,
SecretName: "cloud-credentials-gcp",
MountPath: "/credentials-gcp",
BslSecretName: "bsl-cloud-credentials-gcp",
BSlMountPath: "/bsl-cloud-credentials-gcp",
EnvCredentialsFile: common.GCPCredentialsEnvKey,
PluginName: common.VeleroPluginForGCP,
PluginSecretKey: "cloud",
Expand All @@ -48,6 +54,8 @@ var (
IsCloudProvider: true,
SecretName: "cloud-credentials-azure",
MountPath: "/credentials-azure",
BslSecretName: "bsl-cloud-credentials-azure",
BSlMountPath: "/bsl-cloud-credentials-azure",
EnvCredentialsFile: common.AzureCredentialsFileEnvKey,
PluginName: common.VeleroPluginForAzure,
PluginSecretKey: "cloud",
Expand Down Expand Up @@ -212,6 +220,23 @@ func AppendCloudProviderVolumes(dpa *oadpv1alpha1.DataProtectionApplication, ds

}
}
for _, bslSpec := range dpa.Spec.BackupLocations {
if _, ok := bslSpec.Velero.Config["credentialsFile"]; ok {
if cloudProviderMap, bslCredOk := PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bslSpec.Velero.Provider)]; bslCredOk {
ds.Spec.Template.Spec.Volumes = append(
ds.Spec.Template.Spec.Volumes,
corev1.Volume{
Name: cloudProviderMap.BslSecretName,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: cloudProviderMap.BslSecretName,
},
},
},
)
}
}
}
return nil
}

Expand Down Expand Up @@ -277,6 +302,30 @@ func AppendPluginSpecificSpecs(dpa *oadpv1alpha1.DataProtectionApplication, vele
},
})

// append bsl volume secret
for _, bslSpec := range dpa.Spec.BackupLocations {
if _, ok := bslSpec.Velero.Config["credentialsFile"]; ok {
if cloudProviderMap, bslCredOk := PluginSpecificFields[oadpv1alpha1.DefaultPlugin(bslSpec.Velero.Provider)]; bslCredOk {
veleroContainer.VolumeMounts = append(
veleroContainer.VolumeMounts,
corev1.VolumeMount{
Name: cloudProviderMap.BslSecretName,
MountPath: pluginSpecificMap.BSlMountPath,
})
veleroDeployment.Spec.Template.Spec.Volumes = append(
veleroDeployment.Spec.Template.Spec.Volumes,
corev1.Volume{
Name: cloudProviderMap.BslSecretName,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: cloudProviderMap.BslSecretName,
},
},
},
)
}
}
}
}
}
// append custom plugin init containers
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/backup_restore_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var _ = Describe("AWS backup restore tests", func() {
testSuiteInstanceName := "ts-" + instanceName
dpaCR.Name = testSuiteInstanceName

credData, err := utils.ReadFile(cloud)
credData, err := utils.ReadFile(credFile)
Expect(err).NotTo(HaveOccurred())
err = CreateCredentialsSecret(credData, namespace, GetSecretRef(credSecretRef))
Expect(err).NotTo(HaveOccurred())
Expand Down
Loading