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

Pb-6677: Add storage domain for azure cloud provider #361

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading