Skip to content

Commit

Permalink
Merge pull request #361 from portworx/PB-6677
Browse files Browse the repository at this point in the history
Pb-6677: Add storage domain for azure cloud provider
  • Loading branch information
shkumari-px authored May 7, 2024
2 parents 1398689 + 03c9b95 commit f411395
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions pkg/controllers/dataexport/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions pkg/executor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
31 changes: 22 additions & 9 deletions pkg/executor/kopia/kopiabackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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),
}
}

Expand Down

0 comments on commit f411395

Please sign in to comment.