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

Implement support for Azure velero operations #9

Merged
merged 1 commit into from
Mar 2, 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tmp/

# Secret files
credentials-velero
credentials-velero-az

# Release generated
out
28 changes: 28 additions & 0 deletions api/v1alpha1/veleroinstallation_operations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright 2024.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

func (p Provider) Name() string {
switch {
case p.AWS != nil:
return "aws"
case p.Azure != nil:
return "azure"
default:
panic("Unknown type of provider supplied")
}
}
37 changes: 36 additions & 1 deletion api/v1alpha1/veleroinstallation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,36 @@ type VeleroInstallationSpec struct {
}

type Provider struct {
AWS *AWS `json:"aws,omitempty"`
AWS *AWS `json:"aws,omitempty"`
Azure *Azure `json:"azure,omitempty"`
}

type AWS struct {
// +optional
PluginURL string `json:"pluginURL"`

// +optional
PluginTag string `json:"pluginTag"`

CredentialMap CredentialMap `json:"credentialMap,omitempty"`

// +optional
Config AWSConfig `json:"config,omitempty"`
}

type Azure struct {
// +optional
PluginURL string `json:"pluginURL"`

// +optional
PluginTag string `json:"pluginTag"`

CredentialMap CredentialMap `json:"credentialMap,omitempty"`

// +optional
Config AzureConfig `json:"config,omitempty"`
}

type AWSConfig struct {
// +optional
Region string `json:"region,omitempty"`
Expand All @@ -65,6 +85,21 @@ type AWSConfig struct {
S3Url string `json:"s3Url,omitempty"`
}

type AzureConfig struct {
// AZURE_BACKUP_RESOURCE_GROUP
ResourceGroup string `json:"resourceGroup"`

// AZURE_STORAGE_ACCOUNT_ID
StorageAccount string `json:"storageAccount"`

// AZURE_STORAGE_ACCOUNT_ACCESS_KEY
// +optional
StorageAccountKeyEnvVar string `json:"storageAccountKeyEnvVar"`

// AZURE_BACKUP_SUBSCRIPTION_ID
// +optional
SubscriptionId string `json:"subscriptionId"`
}
type VeleroHelmState struct {
DeployNodeAgent bool `json:"deployNodeAgent"`
CleanUpCRDs bool `json:"cleanUpCRDs"`
Expand Down
37 changes: 37 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions config/crd/bases/addons.cluster.x-k8s.io_veleroinstallations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,52 @@ spec:
to:
type: string
type: object
pluginTag:
type: string
pluginURL:
type: string
type: object
azure:
properties:
config:
properties:
resourceGroup:
description: AZURE_BACKUP_RESOURCE_GROUP
type: string
storageAccount:
description: AZURE_STORAGE_ACCOUNT_ID
type: string
storageAccountKeyEnvVar:
description: AZURE_STORAGE_ACCOUNT_ACCESS_KEY
type: string
subscriptionId:
description: AZURE_BACKUP_SUBSCRIPTION_ID
type: string
required:
- resourceGroup
- storageAccount
type: object
credentialMap:
properties:
from:
type: string
namespaceName:
properties:
name:
type: string
namespace:
type: string
required:
- name
- namespace
type: object
to:
type: string
type: object
pluginTag:
type: string
pluginURL:
type: string
type: object
type: object
state:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ spec:
deployNodeAgent: true
cleanUpCRDs: true
credentials: {}
# TODO(user): Add fields here
17 changes: 17 additions & 0 deletions config/samples/azure/_v1alpha1_velerobackup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: addons.cluster.x-k8s.io/v1alpha1
kind: VeleroBackup
metadata:
labels:
app.kubernetes.io/name: velerobackup
app.kubernetes.io/instance: azbackup-sample
app.kubernetes.io/part-of: cluster-api-addon-provider-velero
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: cluster-api-addon-provider-velero
name: azbackup-sample
namespace: creategitops-me7ee7
spec:
installation:
ref:
kind: VeleroInstallation
name: sample-az
namespace: creategitops-me7ee7
28 changes: 28 additions & 0 deletions config/samples/azure/_v1alpha1_veleroinstallation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: addons.cluster.x-k8s.io/v1alpha1
kind: VeleroInstallation
metadata:
labels:
app.kubernetes.io/name: veleroinstallation
app.kubernetes.io/instance: sample-az
app.kubernetes.io/part-of: cluster-api-addon-provider-velero
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: cluster-api-addon-provider-velero
name: sample-az
namespace: creategitops-me7ee7
spec:
bucket: velero-dgrigore
namespace: velero-az
provider:
azure:
credentialMap:
namespaceName:
name: az-credentials
namespace: default
config:
resourceGroup: dgrigore_backups
storageAccount: velerodgrigorev
state:
deployNodeAgent: true
cleanUpCRDs: true
credentials: {}

18 changes: 18 additions & 0 deletions config/samples/azure/_v1alpha1_velerorestore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: addons.cluster.x-k8s.io/v1alpha1
kind: VeleroRestore
metadata:
labels:
app.kubernetes.io/name: velerorestore
app.kubernetes.io/instance: azrestore-sample
app.kubernetes.io/part-of: cluster-api-addon-provider-velero
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: cluster-api-addon-provider-velero
name: azrestore-sample
namespace: creategitops-me7ee7
spec:
backupName: azbackup-sample
installation:
ref:
kind: VeleroInstallation
name: sample-az
namespace: creategitops-me7ee7
19 changes: 19 additions & 0 deletions config/samples/azure/_v1alpha1_velerorestoreschedule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: addons.cluster.x-k8s.io/v1alpha1
kind: VeleroRestore
metadata:
labels:
app.kubernetes.io/name: velerorestore
app.kubernetes.io/instance: velerorestore-sample
app.kubernetes.io/part-of: cluster-api-addon-provider-velero
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: cluster-api-addon-provider-velero
name: azrestoreshedule-sample
namespace: creategitops-me7ee7
spec:
backupName: ""
scheduleName: azschedule-sample
installation:
ref:
kind: VeleroInstallation
name: sample-az
namespace: creategitops-me7ee7
19 changes: 19 additions & 0 deletions config/samples/azure/_v1alpha1_veleroschedule.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: addons.cluster.x-k8s.io/v1alpha1
kind: VeleroSchedule
metadata:
labels:
app.kubernetes.io/name: veleroschedule
app.kubernetes.io/instance: veleroschedule-sample
app.kubernetes.io/part-of: cluster-api-addon-provider-velero
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: cluster-api-addon-provider-velero
name: azschedule-sample
namespace: creategitops-me7ee7
spec:
template: {}
schedule: "* * * * *"
installation:
ref:
kind: VeleroInstallation
name: sample-az
namespace: creategitops-me7ee7
26 changes: 26 additions & 0 deletions hack/setup-velero-bucket-az.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
AZURE_BACKUP_RESOURCE_GROUP=dgrigore_backups
az group create -n $AZURE_BACKUP_RESOURCE_GROUP --location francecentral

AZURE_STORAGE_ACCOUNT_ID="velerodgrigorev" #-$(uuidgen | cut -d '-' -f5 | tr '[A-Z]' '[a-z]')"
az storage account create \
--name $AZURE_STORAGE_ACCOUNT_ID \
--resource-group $AZURE_BACKUP_RESOURCE_GROUP \
--sku Standard_GRS \
--encryption-services blob \
--https-only true \
--min-tls-version TLS1_2 \
--kind BlobStorage \
--access-tier Hot

BLOB_CONTAINER=velero-dgrigore
az storage container create -n $BLOB_CONTAINER --public-access off --account-name $AZURE_STORAGE_ACCOUNT_ID

AZURE_STORAGE_ACCOUNT_ACCESS_KEY=`az storage account keys list --account-name $AZURE_STORAGE_ACCOUNT_ID --query "[?keyName == 'key1'].value" -o tsv`
cat << EOF > ./credentials-velero-az
AZURE_STORAGE_ACCOUNT_ACCESS_KEY=${AZURE_STORAGE_ACCOUNT_ACCESS_KEY}
AZURE_CLOUD_NAME=AzurePublicCloud
EOF

kubectl create secret generic -n default az-credentials --from-file=azure=credentials-velero-az

rm credentials-velero-az
Loading
Loading