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
Ability to use to CSI plugin for Velero. Supports AWS EBS CSI driver. #1285
Open
ipochi
wants to merge
2
commits into
master
Choose a base branch
from
imran/velero-csi-driver
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,56 @@ | ||
// 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 csi deals with configuring Velero CSI plugin. | ||
package csi | ||
|
||
import ( | ||
"github.com/hashicorp/hcl/v2" | ||
|
||
"github.com/kinvolk/lokomotive/pkg/components/velero/csi/drivers/aws" | ||
) | ||
|
||
// Configuration contains various CSI driver specific sub block. | ||
type Configuration struct { | ||
// AWSDriver represents the AWS EBS CSI driver component. | ||
AWSDriver *aws.Configuration `hcl:"aws,block"` | ||
} | ||
|
||
// Values returns the plugin specific values for Velero Helm chart. | ||
func (c *Configuration) Values() (string, error) { | ||
return c.AWSDriver.Values() | ||
} | ||
|
||
// Validate validates CSI driver specific parts in the configuration. | ||
func (c *Configuration) Validate() hcl.Diagnostics { | ||
return c.validate() | ||
} | ||
|
||
// validate validates component configuration. | ||
func (c *Configuration) validate() hcl.Diagnostics { | ||
diagnostics := hcl.Diagnostics{} | ||
// Since the only supported driver currently is AWS EBS CSI driver, currently we | ||
// don't deal with checks such as only one driver should be configured, based on | ||
// the driver configured, its configuration should be validated. | ||
// This absraction would be needed once more CSI drivers are supported. | ||
if c.AWSDriver == nil { | ||
return append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "CSI driver for AWS not configured", | ||
Detail: "Make sure to configure the `aws` sub block under `csi`", | ||
}) | ||
} | ||
|
||
return append(diagnostics, c.AWSDriver.Validate()...) | ||
} |
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,149 @@ | ||
// 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 aws deals with configuring Velero aws plugin. | ||
package aws | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"text/template" | ||
|
||
"github.com/hashicorp/hcl/v2" | ||
|
||
"github.com/kinvolk/lokomotive/internal" | ||
) | ||
|
||
const indentation = 6 | ||
|
||
// Configuration contains AWS specific parameters. | ||
type Configuration struct { | ||
Credentials string `hcl:"credentials"` | ||
BackupStorageLocation *BackupStorageLocation `hcl:"backup_storage_location,block"` | ||
VolumeSnapshotLocation *VolumeSnapshotLocation `hcl:"volume_snapshot_location,block"` | ||
} | ||
|
||
// BackupStorageLocation configures the backup storage location for AWS plugin. | ||
type BackupStorageLocation struct { | ||
Region string `hcl:"region"` | ||
Bucket string `hcl:"bucket"` | ||
Name string `hcl:"name,optional"` | ||
Prefix string `hcl:"prefix,optional"` | ||
S3ForcePathStyle bool `hcl:"s3_force_path_style,optional"` | ||
S3URL string `hcl:"s3_url,optional"` | ||
PublicURL string `hcl:"public_url,optional"` | ||
} | ||
|
||
// validate validates BackupStorageLocation struct fields. | ||
func (b *BackupStorageLocation) validate() hcl.Diagnostics { | ||
var diagnostics hcl.Diagnostics | ||
|
||
if b == nil { | ||
b = &BackupStorageLocation{} | ||
|
||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "'csi.aws.backup_storage_location' block must be specified", | ||
Detail: "Make sure to set the field to valid non-empty value", | ||
}) | ||
} | ||
|
||
if b.Bucket == "" { | ||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "'csi.aws.backup_storage_location.bucket' cannot be empty", | ||
Detail: "Make sure to set the field to valid non-empty value", | ||
}) | ||
} | ||
|
||
if b.Region == "" { | ||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "'csi.aws.backup_storage_location.region' cannot be empty", | ||
Detail: "Make sure to set the field to valid non-empty value", | ||
}) | ||
} | ||
|
||
return diagnostics | ||
} | ||
|
||
// VolumeSnapshotLocation configures the volume snapshot location for the AWS plugin. | ||
type VolumeSnapshotLocation struct { | ||
Region string `hcl:"region"` | ||
Name string `hcl:"name,optional"` | ||
} | ||
|
||
// validate validates VolumeSnapshotLocation struct fields. | ||
func (v *VolumeSnapshotLocation) validate() hcl.Diagnostics { | ||
var diagnostics hcl.Diagnostics | ||
|
||
if v == nil { | ||
v = &VolumeSnapshotLocation{} | ||
|
||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "'csi.aws.volume_snapshot_location' block must be specified", | ||
Detail: "Make sure to set the field to valid non-empty value", | ||
}) | ||
} | ||
|
||
if v.Region == "" { | ||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "'csi.aws.volume_snapshot_location.region' cannot be empty", | ||
Detail: "Make sure to set the field to valid non-empty value", | ||
}) | ||
} | ||
|
||
return diagnostics | ||
} | ||
|
||
// Values returns the plugin specific values 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 AWS plugin specific parts in the configuration. | ||
func (c *Configuration) Validate() hcl.Diagnostics { | ||
var diagnostics hcl.Diagnostics | ||
|
||
if c.Credentials == "" { | ||
diagnostics = append(diagnostics, &hcl.Diagnostic{ | ||
Severity: hcl.DiagError, | ||
Summary: "'credentials' cannot be empty", | ||
Detail: "No credentials found", | ||
}) | ||
} | ||
|
||
diagnostics = append(diagnostics, c.BackupStorageLocation.validate()...) | ||
diagnostics = append(diagnostics, c.VolumeSnapshotLocation.validate()...) | ||
|
||
return diagnostics | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use
template.Must
we need to have unit tests to validate the template.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pkg/components/velero/component_test.go
has the tests for each provider.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh.. Can we have a tests locally to the package? Otherwise changing code in one package breaks tests in other, this is not nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added unit tests.