This repository has been archived by the owner on Jun 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
velero: add velero restic plugin for Packet
This commit adds support for using restic plugin for Packet platform when the underlying storage is Rook or node storage. Signed-off-by: Imran Pochi <imran@kinvolk.io>
- Loading branch information
Showing
5 changed files
with
257 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Copyright 2020 The Lokomotive Authors | ||
// | ||
// 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 restic deals with configuring restic plugin. | ||
package restic | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"text/template" | ||
|
||
"github.com/hashicorp/hcl/v2" | ||
|
||
"github.com/kinvolk/lokomotive/internal" | ||
) | ||
|
||
const indentation = 6 | ||
|
||
// Configuration contains Restic specific parameters. | ||
type Configuration struct { | ||
Credentials string `hcl:"credentials"` | ||
BackupStorageLocation *BackupStorageLocation `hcl:"backup_storage_location,block"` | ||
} | ||
|
||
// BackupStorageLocation configures the backup storage location. | ||
type BackupStorageLocation struct { | ||
Provider string `hcl:"provider"` | ||
Bucket string `hcl:"bucket"` | ||
Name string `hcl:"name,optional"` | ||
} | ||
|
||
// NewConfiguration returns the default restic configuration. | ||
func NewConfiguration() *Configuration { | ||
return &Configuration{ | ||
BackupStorageLocation: &BackupStorageLocation{ | ||
Provider: "aws", | ||
Name: "default", | ||
}, | ||
} | ||
} | ||
|
||
// Values returns plugin-specific value for Velero Helm chart. | ||
func (c *Configuration) Values() (string, error) { | ||
t := template.Must(template.New("values").Parse(chartValuesTmpl)) | ||
|
||
var buf bytes.Buffer | ||
|
||
v := struct { | ||
Configuration *Configuration | ||
CredentialsIndented string | ||
}{ | ||
Configuration: c, | ||
CredentialsIndented: internal.Indent(c.Credentials, indentation), | ||
} | ||
|
||
if err := t.Execute(&buf, v); err != nil { | ||
return "", fmt.Errorf("executing values template: %w", err) | ||
} | ||
|
||
return buf.String(), nil | ||
} | ||
|
||
// Validate validates the restic configuration. | ||
func (c *Configuration) Validate() hcl.Diagnostics { | ||
var diagnostics hcl.Diagnostics | ||
|
||
if c.BackupStorageLocation == nil { | ||
c.BackupStorageLocation = &BackupStorageLocation{} | ||
|
||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "'restic.backup_storage_location' block must be specified", | ||
Detail: "Make sure to the set the field to valid non-empty value", | ||
}) | ||
} | ||
|
||
if c.BackupStorageLocation.Bucket == "" { | ||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "restic.backup_storage_location.bucket must not be empty", | ||
Detail: "Make sure `bucket` value is set", | ||
}) | ||
} | ||
|
||
if !isSupportedProvider(c.BackupStorageLocation.Provider) { | ||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: fmt.Sprintf("restic.backup_storage_location.provider must be one of: '%s'", | ||
resticSupportedProviders()), | ||
Detail: "Make sure to set provider to one of supported values", | ||
}) | ||
} | ||
|
||
return diagnostics | ||
} | ||
|
||
// isSupportedProvider checks if the provider is supported or not. | ||
func isSupportedProvider(provider string) bool { | ||
for _, p := range resticSupportedProviders() { | ||
if provider == p { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
|
||
// resticSupportedProviders returns the list of supported providers. | ||
func resticSupportedProviders() []string { | ||
return []string{"aws", "gcp", "azure"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2020 The Lokomotive Authors | ||
// | ||
// 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 restic | ||
|
||
const chartValuesTmpl = ` | ||
configuration: | ||
provider: {{ .Configuration.BackupStorageLocation.Provider }} | ||
backupStorageLocation: | ||
{{- if .Configuration.BackupStorageLocation.Provider}} | ||
provider: {{ .Configuration.BackupStorageLocation.Provider }} | ||
{{- end }} | ||
{{- if .Configuration.BackupStorageLocation.Name}} | ||
name: {{ .Configuration.BackupStorageLocation.Name }} | ||
{{- end }} | ||
bucket: {{ .Configuration.BackupStorageLocation.Bucket }} | ||
config: | ||
region: eu-west-1 | ||
deployRestic: true | ||
snapshotsEnabled: false | ||
restic: | ||
privileged: true | ||
credentials: | ||
secretContents: | ||
{{- if .Configuration.Credentials }} | ||
cloud: | | ||
{{ .CredentialsIndented }} | ||
{{- end }} | ||
initContainers: | ||
{{- if eq .Configuration.BackupStorageLocation.Provider "aws" }} | ||
- image: velero/velero-plugin-for-aws:v1.1.0 | ||
imagePullPolicy: IfNotPresent | ||
name: velero-plugin-for-aws | ||
resources: {} | ||
terminationMessagePath: /dev/termination-log | ||
terminationMessagePolicy: File | ||
volumeMounts: | ||
- mountPath: /target | ||
name: plugins | ||
{{- end }} | ||
{{- if eq .Configuration.BackupStorageLocation.Provider "gcp" }} | ||
- image: velero/velero-plugin-for-gcp:v1.1.0 | ||
imagePullPolicy: IfNotPresent | ||
name: velero-plugin-for-gcp | ||
resources: {} | ||
terminationMessagePath: /dev/termination-log | ||
terminationMessagePolicy: File | ||
volumeMounts: | ||
- mountPath: /target | ||
name: plugins | ||
{{- end }} | ||
{{- if eq .Configuration.BackupStorageLocation.Provider "azure" }} | ||
- image: velero/velero-plugin-for-microsoft-azure:v1.1.0 | ||
imagePullPolicy: IfNotPresent | ||
name: velero-plugin-for-azure | ||
resources: {} | ||
terminationMessagePath: /dev/termination-log | ||
terminationMessagePolicy: File | ||
volumeMounts: | ||
- mountPath: /target | ||
name: plugins | ||
{{- end }} | ||
` |