Skip to content

Commit

Permalink
Merge branch 'main' into golangci-lint-config
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 authored May 1, 2024
2 parents 151b622 + 4d48273 commit 9694a1b
Show file tree
Hide file tree
Showing 71 changed files with 1,600 additions and 365 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/crds-verify-kind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
${{ runner.os }}-go-
- name: Check out the code
uses: actions/checkout@v2
uses: actions/checkout@v4
if: steps.cache.outputs.cache-hit != 'true'

# If no binaries were built for this PR, build it now.
Expand All @@ -57,13 +57,13 @@ jobs:
matrix:
# Latest k8s versions. There's no series-based tag, nor is there a latest tag.
k8s:
- 1.19.7
- 1.20.2
- 1.21.1
- 1.22.0
- 1.23.6
- 1.24.2
- 1.25.3
- 1.23.17
- 1.24.17
- 1.25.16
- 1.26.13
- 1.27.10
- 1.28.6
- 1.29.1
# All steps run in parallel unless otherwise specified.
# See https://docs.github.com/en/actions/learn-github-actions/managing-complex-workflows#creating-dependent-jobs
steps:
Expand All @@ -81,7 +81,7 @@ jobs:
velero-${{ github.event.pull_request.number }}-
- uses: engineerd/[email protected]
with:
version: "v0.17.0"
version: "v0.21.0"
image: "kindest/node:v${{ matrix.k8s }}"
- name: Install CRDs
run: |
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/e2e-test-kind.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Check out the code
uses: actions/checkout@v2
uses: actions/checkout@v4
if: steps.cli-cache.outputs.cache-hit != 'true' || steps.image-cache.outputs.cache-hit != 'true'
# If no binaries were built for this PR, build it now.
- name: Build Velero CLI
Expand All @@ -60,13 +60,13 @@ jobs:
strategy:
matrix:
k8s:
- 1.19.16
- 1.20.15
- 1.21.12
- 1.22.9
- 1.23.6
- 1.24.0
- 1.25.3
- 1.23.17
- 1.24.17
- 1.25.16
- 1.26.13
- 1.27.10
- 1.28.6
- 1.29.1
focus:
# tests to focus on, use `|` to concatenate multiple regexes to run on the same job
# ordered according to e2e_suite_test.go order
Expand All @@ -85,13 +85,13 @@ jobs:
go-version: '1.22'
id: go
- name: Check out the code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install MinIO
run:
docker run -d --rm -p 9000:9000 -e "MINIO_ACCESS_KEY=minio" -e "MINIO_SECRET_KEY=minio123" -e "MINIO_DEFAULT_BUCKETS=bucket,additional-bucket" bitnami/minio:2021.6.17-debian-10-r7
- uses: engineerd/[email protected]
with:
version: "v0.17.0"
version: "v0.21.0"
image: "kindest/node:v${{ matrix.k8s }}"
- name: Fetch built CLI
id: cli-cache
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nightly-trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
Expand All @@ -31,6 +31,6 @@ jobs:
output: 'trivy-results.sarif'

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-results.sarif'
2 changes: 1 addition & 1 deletion .github/workflows/pr-changelog-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:

- name: Check out the code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Changelog check
if: ${{ !(contains(github.event.pull_request.labels.*.name, 'kind/changelog-not-required') || contains(github.event.pull_request.labels.*.name, 'Design') || contains(github.event.pull_request.labels.*.name, 'Website') || contains(github.event.pull_request.labels.*.name, 'Documentation'))}}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-ci-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
go-version: '1.22'
id: go
- name: Check out the code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Fetch cached go modules
uses: actions/cache@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-codespell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:

- name: Check out the code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Codespell
uses: codespell-project/actions-codespell@master
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-containers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
name: Checkout

- name: Set up QEMU
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
name: Checkout

- name: Verify .goreleaser.yml and try a dryrun release.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-linter-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
cache: false

- name: Linter check
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v5
with:
version: v1.57.2
args: --verbose --out-format=colored-line-number
2 changes: 1 addition & 1 deletion .github/workflows/prow-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
execute:
runs-on: ubuntu-latest
steps:
- uses: jpmcb/[email protected].2
- uses: jpmcb/[email protected].3
with:
# Only support /kind command for now.
# TODO: before allowing the /lgtm command, see if we can block merging if changelog labels are missing.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
# The default value is "1" which fetches only a single commit. If we merge PR without squash or rebase,
# there are at least two commits: the first one is the merge commit and the second one is the real commit
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
go-version: '1.22'
id: go

- uses: actions/checkout@v3
- uses: actions/checkout@v4

# Fix issue of setup-gcloud
- run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the latest code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Automatic Rebase
uses: cirrus-actions/rebase@1.3.1
uses: cirrus-actions/rebase@1.8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/stale-issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6.0.1
- uses: actions/stale@v9.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: "This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days. If a Velero team member has requested log or more information, please provide the output of the shared commands."
Expand Down
1 change: 1 addition & 0 deletions changelogs/unreleased/7664-shubham-pampattiwar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implementation for Extending VolumePolicies to support more actions
1 change: 1 addition & 0 deletions changelogs/unreleased/7702-reasonerjt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bump up the version of KinD and k8s in github actions
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/vmware-tanzu/velero

go 1.22
go 1.22.0

require (
cloud.google.com/go/storage v1.40.0
Expand Down
23 changes: 14 additions & 9 deletions internal/resourcepolicies/resource_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ type VolumeActionType string

const (
// currently only support configmap type of resource config
ConfigmapRefType string = "configmap"
Skip VolumeActionType = "skip"
ConfigmapRefType string = "configmap"
// skip action implies the volume would be skipped from the backup operation
Skip VolumeActionType = "skip"
// fs-backup action implies that the volume would be backed up via file system copy method using the uploader(kopia/restic) configured by the user
FSBackup VolumeActionType = "fs-backup"
// snapshot action can have 3 different meaning based on velero configuration and backup spec - cloud provider based snapshots, local csi snapshots and datamover snapshots
Snapshot VolumeActionType = "snapshot"
)

// Action defined as one action for a specific way of backup
Expand All @@ -40,16 +45,16 @@ type Action struct {
}

// volumePolicy defined policy to conditions to match Volumes and related action to handle matched Volumes
type volumePolicy struct {
type VolumePolicy struct {
// Conditions defined list of conditions to match Volumes
Conditions map[string]interface{} `yaml:"conditions"`
Action Action `yaml:"action"`
}

// resourcePolicies currently defined slice of volume policies to handle backup
type resourcePolicies struct {
type ResourcePolicies struct {
Version string `yaml:"version"`
VolumePolicies []volumePolicy `yaml:"volumePolicies"`
VolumePolicies []VolumePolicy `yaml:"volumePolicies"`
// we may support other resource policies in the future, and they could be added separately
// OtherResourcePolicies []OtherResourcePolicy
}
Expand All @@ -60,16 +65,16 @@ type Policies struct {
// OtherPolicies
}

func unmarshalResourcePolicies(yamlData *string) (*resourcePolicies, error) {
resPolicies := &resourcePolicies{}
func unmarshalResourcePolicies(yamlData *string) (*ResourcePolicies, error) {
resPolicies := &ResourcePolicies{}
err := decodeStruct(strings.NewReader(*yamlData), resPolicies)
if err != nil {
return nil, fmt.Errorf("failed to decode yaml data into resource policies %v", err)
}
return resPolicies, nil
}

func (p *Policies) buildPolicy(resPolicies *resourcePolicies) error {
func (p *Policies) BuildPolicy(resPolicies *ResourcePolicies) error {
for _, vp := range resPolicies.VolumePolicies {
con, err := unmarshalVolConditions(vp.Conditions)
if err != nil {
Expand Down Expand Up @@ -162,7 +167,7 @@ func GetResourcePoliciesFromConfig(cm *v1.ConfigMap) (*Policies, error) {
}

policies := &Policies{}
if err := policies.buildPolicy(resPolicies); err != nil {
if err := policies.BuildPolicy(resPolicies); err != nil {
return nil, errors.WithStack(err)
}

Expand Down
20 changes: 10 additions & 10 deletions internal/resourcepolicies/resource_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ func TestLoadResourcePolicies(t *testing.T) {
}

func TestGetResourceMatchedAction(t *testing.T) {
resPolicies := &resourcePolicies{
resPolicies := &ResourcePolicies{
Version: "v1",
VolumePolicies: []volumePolicy{
VolumePolicies: []VolumePolicy{
{
Action: Action{Type: "skip"},
Conditions: map[string]interface{}{
Expand All @@ -136,7 +136,7 @@ func TestGetResourceMatchedAction(t *testing.T) {
},
},
{
Action: Action{Type: "volume-snapshot"},
Action: Action{Type: "snapshot"},
Conditions: map[string]interface{}{
"capacity": "10,100Gi",
"storageClass": []string{"gp2", "ebs-sc"},
Expand All @@ -147,7 +147,7 @@ func TestGetResourceMatchedAction(t *testing.T) {
},
},
{
Action: Action{Type: "file-system-backup"},
Action: Action{Type: "fs-backup"},
Conditions: map[string]interface{}{
"storageClass": []string{"gp2", "ebs-sc"},
"csi": interface{}(
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestGetResourceMatchedAction(t *testing.T) {
storageClass: "ebs-sc",
csi: &csiVolumeSource{Driver: "aws.efs.csi.driver"},
},
expectedAction: &Action{Type: "volume-snapshot"},
expectedAction: &Action{Type: "snapshot"},
},
{
name: "dismatch all policies",
Expand All @@ -195,7 +195,7 @@ func TestGetResourceMatchedAction(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
policies := &Policies{}
err := policies.buildPolicy(resPolicies)
err := policies.BuildPolicy(resPolicies)
if err != nil {
t.Errorf("Failed to build policy with error %v", err)
}
Expand Down Expand Up @@ -237,9 +237,9 @@ func TestGetResourcePoliciesFromConfig(t *testing.T) {
// Check that the returned resourcePolicies object contains the expected data
assert.Equal(t, "v1", resPolicies.version)
assert.Len(t, resPolicies.volumePolicies, 1)
policies := resourcePolicies{
policies := ResourcePolicies{
Version: "v1",
VolumePolicies: []volumePolicy{
VolumePolicies: []VolumePolicy{
{
Conditions: map[string]interface{}{
"capacity": "0,10Gi",
Expand All @@ -251,7 +251,7 @@ func TestGetResourcePoliciesFromConfig(t *testing.T) {
},
}
p := &Policies{}
err = p.buildPolicy(&policies)
err = p.BuildPolicy(&policies)
if err != nil {
t.Fatalf("failed to build policy with error %v", err)
}
Expand Down Expand Up @@ -424,7 +424,7 @@ volumePolicies:
}
assert.Nil(t, err)
policies := &Policies{}
err = policies.buildPolicy(resPolicies)
err = policies.BuildPolicy(resPolicies)
assert.Nil(t, err)
action, err := policies.GetMatchAction(tc.vol)
assert.Nil(t, err)
Expand Down
6 changes: 5 additions & 1 deletion internal/resourcepolicies/volume_resources_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ func decodeStruct(r io.Reader, s interface{}) error {
// validate check action format
func (a *Action) validate() error {
// validate Type
if a.Type != Skip {
valid := false
if a.Type == Skip || a.Type == Snapshot || a.Type == FSBackup {
valid = true
}
if !valid {
return fmt.Errorf("invalid action type %s", a.Type)
}

Expand Down
Loading

0 comments on commit 9694a1b

Please sign in to comment.