diff --git a/docs/configuration-reference/components/velero.md b/docs/configuration-reference/components/velero.md index 533f1e2e0..ad6fc27b6 100644 --- a/docs/configuration-reference/components/velero.md +++ b/docs/configuration-reference/components/velero.md @@ -104,50 +104,51 @@ component "velero" { Table of all the arguments accepted by the component. -| Argument | Description | Default | Type | Required | -|------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|--------|----------| -| `namespace` | Namespace to install Velero. | "velero" | string | false | -| `provider` | Provider sets which provider block to use for the configuration. Supported values are: `azure`, `openebs` and `restic`. | - | string | true | -| `metrics` | Configure Prometheus to scrape Velero metrics. Needs the [Prometheus Operator component](prometheus-operator.md) installed. | - | object | false | -| `metrics.enabled` | Adds Prometheus annotations to Velero deployment if enabled. | false | bool | false | -| `metrics.service_monitor` | Adds ServiceMonitor resource for Prometheus. Requires `metrics.enabled` as true. | false | bool | false | -| `azure` | Configure Azure provider for Velero. | - | object | false | -| `azure.subscription_id` | Azure Subscription ID where client application is created. Can be obtained with `az account list`. | - | string | true | -| `azure.tenant_id` | Azure Tenant ID where your subscription is created. Can be obtained with `az account list`. | - | string | true | -| `azure.client_id` | Azure Application Client ID to perform Azure operations. | - | string | true | -| `azure.client_secret` | Azure Application Client secret. | - | string | true | -| `azure.resource_group` | Azure resource group, where PVC Disks are created. If this argument is wrong, Velero will fail to create PVC snapshots. | - | string | true | -| `azure.backup_storage_location` | Configure backup storage location and metadata. | - | object | true | -| `azure.backup_storage_location.resource_group` | Name of the resource group containing the storage account for this backup storage location. | - | string | true | -| `azure.backup_storage_location.storage_account` | Name of the storage account for this backup storage location. | - | string | true | -| `azure.backup_storage_location.bucket` | Name of the storage container to store backups. | - | string | true | -| `azure.volume_snapshot_location` | Configure PVC snapshot location. | - | object | false | -| `azure.volume_snapshot_location.resource_group` | Azure Resource Group where snapshots will be stored. | Stored in the same resource group as the cluster. | string | false | -| `azure.volume_snapshot_location.api_timeout` | Azure API timeout. | "10m" | string | false | -| `openebs` | Configure OpenEBS provider for Velero. | - | object | false | -| `openebs.credentials` | Content of cloud provider credentials. | - | string | true | -| `openebs.provider` | Cloud provider to use for backup and snapshot storage. Supported values are `gcp` and `aws`. | - | string | false | -| `openebs.backup_storage_location` | Configure backup storage location. | - | object | true | -| `openebs.backup_storage_location.region` | Cloud provider region for storing backups. | - | string | true | -| `openebs.backup_storage_location.bucket` | Cloud storage bucket name for storing backups. | - | string | true | -| `openebs.backup_storage_location.provider` | Cloud provider name for storing backups. Overrides `openebs.provider` field for backup storage. | - | string | false | -| `openebs.backup_storage_location.name` | Name for backup location object on the cluster. | - | string | false | -| `openebs.volume_snapshot_location` | Configure volume snapshot location. | - | object | true | -| `openebs.volume_snapshot_location.bucket` | Cloud storage bucket name for storing volume snapshots. | - | string | true | -| `openebs.volume_snapshot_location.region` | Cloud provider region for storing snapshots. | | string | true | -| `openebs.volume_snapshot_location.provider` | Cloud provider name for storing snapshots. Overrides `openebs.provider` field for backup storage. | - | string | false | -| `openebs.volume_snapshot_location.name` | Name for snapshot location object on the cluster. | - | string | false | -| `openebs.volume_snapshot_location.prefix` | Prefix for snapshot names. | - | string | false | -| `openebs.volume_snapshot_location.local` | If `true`, backups won't be copied to cloud storage. | false | bool | false | -| `openebs.volume_snapshot_location.openebs_namespace` | Name of the namespace where OpenEBS runs. | - | string | true | -| `openebs.volume_snapshot_location.s3_url` | S3 API URL. | - | string | false | -| `restic` | Configure Restic provider for Velero. | - | object | false | -| `restic.credentials` | Content of cloud provider credentials. | - | string | true | -| `restic.require_volume_annotation` | Backup all pod volumes without having to apply annotation on the pod when using restic. To exclude volumes add the annotation `backup.velero.io/backup-volumes-excludes` on the pod. | false | bool | false -| `restic.backup_storage_location.provider` | Cloud provider name for storing backups. | - | string | false | -| `restic.backup_storage_location.bucket` | Cloud storage bucket name for storing backups. | - | string | true | -| `restic.backup_storage_location.name` | Name for backup location object on the cluster. | "default" | string | false | -| `restic.backup_storage_location.region` | Cloud provider region for storing snapshots. Required if `restic.backup_storage_location.provider = aws`. | - | string | false | +| Argument | Description | Default | Type | Required | +|------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------|----------------------------------------------------------------------------------------------------------------|----------| +| `namespace` | Namespace to install Velero. | "velero" | string | false | +| `provider` | Provider sets which provider block to use for the configuration. Supported values are: `azure`, `openebs` and `restic`. | - | string | true | +| `metrics` | Configure Prometheus to scrape Velero metrics. Needs the [Prometheus Operator component](prometheus-operator.md) installed. | - | object | false | +| `metrics.enabled` | Adds Prometheus annotations to Velero deployment if enabled. | false | bool | false | +| `metrics.service_monitor` | Adds ServiceMonitor resource for Prometheus. Requires `metrics.enabled` as true. | false | bool | false | +| `azure` | Configure Azure provider for Velero. | - | object | false | +| `azure.subscription_id` | Azure Subscription ID where client application is created. Can be obtained with `az account list`. | - | string | true | +| `azure.tenant_id` | Azure Tenant ID where your subscription is created. Can be obtained with `az account list`. | - | string | true | +| `azure.client_id` | Azure Application Client ID to perform Azure operations. | - | string | true | +| `azure.client_secret` | Azure Application Client secret. | - | string | true | +| `azure.resource_group` | Azure resource group, where PVC Disks are created. If this argument is wrong, Velero will fail to create PVC snapshots. | - | string | true | +| `azure.backup_storage_location` | Configure backup storage location and metadata. | - | object | true | +| `azure.backup_storage_location.resource_group` | Name of the resource group containing the storage account for this backup storage location. | - | string | true | +| `azure.backup_storage_location.storage_account` | Name of the storage account for this backup storage location. | - | string | true | +| `azure.backup_storage_location.bucket` | Name of the storage container to store backups. | - | string | true | +| `azure.volume_snapshot_location` | Configure PVC snapshot location. | - | object | false | +| `azure.volume_snapshot_location.resource_group` | Azure Resource Group where snapshots will be stored. | Stored in the same resource group as the cluster. | string | false | +| `azure.volume_snapshot_location.api_timeout` | Azure API timeout. | "10m" | string | false | +| `openebs` | Configure OpenEBS provider for Velero. | - | object | false | +| `openebs.credentials` | Content of cloud provider credentials. | - | string | true | +| `openebs.provider` | Cloud provider to use for backup and snapshot storage. Supported values are `gcp` and `aws`. | - | string | false | +| `openebs.backup_storage_location` | Configure backup storage location. | - | object | true | +| `openebs.backup_storage_location.region` | Cloud provider region for storing backups. | - | string | true | +| `openebs.backup_storage_location.bucket` | Cloud storage bucket name for storing backups. | - | string | true | +| `openebs.backup_storage_location.provider` | Cloud provider name for storing backups. Overrides `openebs.provider` field for backup storage. | - | string | false | +| `openebs.backup_storage_location.name` | Name for backup location object on the cluster. | - | string | false | +| `openebs.volume_snapshot_location` | Configure volume snapshot location. | - | object | true | +| `openebs.volume_snapshot_location.bucket` | Cloud storage bucket name for storing volume snapshots. | - | string | true | +| `openebs.volume_snapshot_location.region` | Cloud provider region for storing snapshots. | | string | true | +| `openebs.volume_snapshot_location.provider` | Cloud provider name for storing snapshots. Overrides `openebs.provider` field for backup storage. | - | string | false | +| `openebs.volume_snapshot_location.name` | Name for snapshot location object on the cluster. | - | string | false | +| `openebs.volume_snapshot_location.prefix` | Prefix for snapshot names. | - | string | false | +| `openebs.volume_snapshot_location.local` | If `true`, backups won't be copied to cloud storage. | false | bool | false | +| `openebs.volume_snapshot_location.openebs_namespace` | Name of the namespace where OpenEBS runs. | - | string | true | +| `openebs.volume_snapshot_location.s3_url` | S3 API URL. | - | string | false | +| `restic` | Configure Restic provider for Velero. | - | object | false | +| `restic.credentials` | Content of cloud provider credentials. | - | string | true | +| `restic.require_volume_annotation` | Backup all pod volumes without having to apply annotation on the pod when using restic. To exclude volumes add the annotation `backup.velero.io/backup-volumes-excludes` on the pod. | false | bool | false | +| `restic.backup_storage_location.provider` | Cloud provider name for storing backups. | - | string | false | +| `restic.backup_storage_location.bucket` | Cloud storage bucket name for storing backups. | - | string | true | +| `restic.backup_storage_location.name` | Name for backup location object on the cluster. | "default" | string | false | +| `restic.backup_storage_location.region` | Cloud provider region for storing snapshots. Required if `restic.backup_storage_location.provider = aws`. | - | string | false | +| `restic.tolerations` | Tolerations that the Restic provider installation daemonset will tolerate. | - | list(object({key = string, effect = string, operator = string, value = string, toleration_seconds = string })) | false | ## Applying diff --git a/pkg/components/velero/component_test.go b/pkg/components/velero/component_test.go index fee1fa586..a928da68c 100644 --- a/pkg/components/velero/component_test.go +++ b/pkg/components/velero/component_test.go @@ -19,6 +19,7 @@ import ( "github.com/hashicorp/hcl/v2" + "github.com/kinvolk/lokomotive/pkg/components/internal/testutil" "github.com/kinvolk/lokomotive/pkg/components/util" ) @@ -195,3 +196,46 @@ component "velero" { t.Fatalf("Rendered manifests shouldn't be empty") } } + +func TestRenderManifestResticToleration(t *testing.T) { + configHCL := ` +component "velero" { + provider = "restic" + restic { + credentials = "foo" + + backup_storage_location { + bucket = "foo" + provider = "aws" + } + + tolerations { + key = "TestResticToletrationKey" + value = "TestResticToletrationValue" + operator = "Equal" + effect = "NoSchedule" + toleration_seconds = "1" + } + } +} +` + + component := NewConfig() + + body, d := util.GetComponentBody(configHCL, Name) + if d.HasErrors() { + t.Fatalf("Error getting component body: %v", d) + } + + if d = component.LoadConfig(body, &hcl.EvalContext{}); d.HasErrors() { + t.Fatalf("Valid config should not return error, got: %v", d) + } + + m := testutil.RenderManifests(t, component, Name, configHCL) + jsonPath := "{.spec.template.spec.tolerations[0].key}" + expected := "TestResticToletrationKey" + + gotConfig := testutil.ConfigFromMap(t, m, "velero/templates/restic-daemonset.yaml") + + testutil.MatchJSONPathStringValue(t, gotConfig, jsonPath, expected) +} diff --git a/pkg/components/velero/restic/restic.go b/pkg/components/velero/restic/restic.go index 298267bdf..38491d112 100644 --- a/pkg/components/velero/restic/restic.go +++ b/pkg/components/velero/restic/restic.go @@ -23,6 +23,7 @@ import ( "github.com/hashicorp/hcl/v2" "github.com/kinvolk/lokomotive/internal" + "github.com/kinvolk/lokomotive/pkg/components/util" ) const indentation = 6 @@ -32,6 +33,8 @@ type Configuration struct { Credentials string `hcl:"credentials"` RequireVolumeAnnotation bool `hcl:"require_volume_annotation,optional"` BackupStorageLocation *BackupStorageLocation `hcl:"backup_storage_location,block"` + Tolerations []util.Toleration `hcl:"tolerations,block"` + TolerationsRaw string } // BackupStorageLocation configures the backup storage location. @@ -55,6 +58,13 @@ func (c *Configuration) Values() (string, error) { var buf bytes.Buffer + var err error + + c.TolerationsRaw, err = util.RenderTolerations(c.Tolerations) + if err != nil { + return "", fmt.Errorf("rendering tolerations: %w", err) + } + v := struct { Configuration *Configuration CredentialsIndented string diff --git a/pkg/components/velero/restic/template.go b/pkg/components/velero/restic/template.go index f69b22f14..7c3ccaded 100644 --- a/pkg/components/velero/restic/template.go +++ b/pkg/components/velero/restic/template.go @@ -34,6 +34,9 @@ deployRestic: true snapshotsEnabled: false restic: privileged: true + {{- if .Configuration.Tolerations }} + tolerations: {{ .Configuration.TolerationsRaw }} + {{- end }} credentials: secretContents: {{- if .Configuration.Credentials }}