diff --git a/pkg/controllers/dataexport/reconcile.go b/pkg/controllers/dataexport/reconcile.go index 9c5fe5fff..c764df49a 100644 --- a/pkg/controllers/dataexport/reconcile.go +++ b/pkg/controllers/dataexport/reconcile.go @@ -2260,6 +2260,7 @@ func createAzureSecret(secretName string, backupLocation *storkapi.BackupLocatio credentialData["path"] = []byte(backupLocation.Location.Path) credentialData["storageaccountname"] = []byte(backupLocation.Location.AzureConfig.StorageAccountName) credentialData["storageaccountkey"] = []byte(backupLocation.Location.AzureConfig.StorageAccountKey) + credentialData["environment"] = []byte(backupLocation.Location.AzureConfig.Environment) err := utils.CreateJobSecret(secretName, namespace, credentialData, labels) return err diff --git a/pkg/executor/common.go b/pkg/executor/common.go index 7ff5ab76b..b0a6e9922 100644 --- a/pkg/executor/common.go +++ b/pkg/executor/common.go @@ -46,6 +46,7 @@ const ( projectIDKeypath = "/etc/cred-secret/projectid" storageAccountNamePath = "/etc/cred-secret/storageaccountname" storageAccountKeyPath = "/etc/cred-secret/storageaccountkey" + environmentPath = "/etc/cred-secret/environment" // ServerAddr & SubPath needed for NFS based backuplocation serverAddr = "/etc/cred-secret/serverAddr" subPath = "/etc/cred-secret/subPath" @@ -98,6 +99,7 @@ type S3Config struct { type AzureConfig struct { StorageAccountName string StorageAccountKey string + Environment string } // GoogleConfig specifies the config required to connect to Google Cloud Storage @@ -242,6 +244,9 @@ func parseAzure(repoName string, backupLocation storkapi.BackupLocationItem) (*R Name: repoName, Path: "azure:" + repoName + "/", AuthEnv: envs, + AzureConfig: &AzureConfig{ + Environment: string(backupLocation.AzureConfig.Environment), + }, }, nil } @@ -454,9 +459,17 @@ func parseAzureCreds() (*Repository, error) { return nil, fmt.Errorf(errMsg) } + environment, err := os.ReadFile(environmentPath) + if err != nil { + errMsg := fmt.Sprintf("failed reading data from file %s: %s", environmentPath, err) + logrus.Errorf("%v", errMsg) + return nil, fmt.Errorf(errMsg) + } + repository.Type = storkapi.BackupLocationAzure repository.AzureConfig.StorageAccountName = string(storageAccountName) repository.AzureConfig.StorageAccountKey = string(storageAccountKey) + repository.AzureConfig.Environment = string(environment) return repository, nil } diff --git a/pkg/executor/kopia/kopiabackup.go b/pkg/executor/kopia/kopiabackup.go index 83355e131..ea59d1a3c 100644 --- a/pkg/executor/kopia/kopiabackup.go +++ b/pkg/executor/kopia/kopiabackup.go @@ -20,15 +20,17 @@ import ( ) const ( - progressCheckInterval = 5 * time.Second - genericBackupDir = "generic-backup" - kopiaRepositoryFile = "kopia.repository" - annualSnapshots = "2147483647" - monthlySnapshots = "2147483647" - weeklySnapshots = "2147483647" - dailySnapshots = "2147483647" - hourlySnapshots = "2147483647" - latestSnapshots = "2147483647" + progressCheckInterval = 5 * time.Second + genericBackupDir = "generic-backup" + kopiaRepositoryFile = "kopia.repository" + annualSnapshots = "2147483647" + monthlySnapshots = "2147483647" + weeklySnapshots = "2147483647" + dailySnapshots = "2147483647" + hourlySnapshots = "2147483647" + latestSnapshots = "2147483647" + azureChinaStorageDomain = "blob.core.chinacloudapi.cn" + azurePublicStorageDomain = "blob.core.windows.net" ) var ( @@ -211,12 +213,22 @@ func populateGCEAccessDetails(initCmd *kopia.Command, repository *executor.Repos } func populateAzureccessDetails(initCmd *kopia.Command, repository *executor.Repository) *kopia.Command { + //Construct Azure storage Domain + var storageDomain string + switch repository.AzureConfig.Environment { + case "AzureChinaCloud": + storageDomain = azureChinaStorageDomain + case "AzurePublicCloud": + storageDomain = azurePublicStorageDomain + } initCmd.AddArg("--container") initCmd.AddArg(repository.Path) initCmd.AddArg("--storage-account") initCmd.AddArg(repository.AzureConfig.StorageAccountName) initCmd.AddArg("--storage-key") initCmd.AddArg(repository.AzureConfig.StorageAccountKey) + initCmd.AddArg("--storage-domain") + initCmd.AddArg(storageDomain) return initCmd } @@ -600,6 +612,7 @@ func buildStorkBackupLocation(repository *executor.Repository) (*storkv1.BackupL backupLocation.Location.AzureConfig = &storkv1.AzureConfig{ StorageAccountName: repository.AzureConfig.StorageAccountName, StorageAccountKey: repository.AzureConfig.StorageAccountKey, + Environment: storkv1.AzureEnvironment(repository.AzureConfig.Environment), } }