From 05d97aec2d8b11c064c74ce52c1cb0031b8cb339 Mon Sep 17 00:00:00 2001 From: Ganesh Hubale Date: Tue, 8 Mar 2022 14:26:52 +0530 Subject: [PATCH 1/7] Fixed start contributing link (#4723) Signed-off-by: Ganesh Hubale Signed-off-by: Hoang, Phuong --- site/content/docs/v1.8/_index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/content/docs/v1.8/_index.md b/site/content/docs/v1.8/_index.md index 74eece82f..d4a88da6a 100644 --- a/site/content/docs/v1.8/_index.md +++ b/site/content/docs/v1.8/_index.md @@ -33,7 +33,7 @@ If you encounter issues, review the [troubleshooting docs][30], [file an issue][ ## Contributing -If you are ready to jump in and test, add code, or help with documentation, follow the instructions on our [Start contributing](https://velero.io/docs/v1.8.0/start-contributing/) documentation for guidance on how to setup Velero for development. +If you are ready to jump in and test, add code, or help with documentation, follow the instructions on our [Start contributing](https://velero.io/docs/v1.8/start-contributing/) documentation for guidance on how to setup Velero for development. ## Changelog From 291f0c17e869ec431ae6bfbfdd3484e342a288d4 Mon Sep 17 00:00:00 2001 From: Xun Jiang Date: Tue, 8 Mar 2022 17:04:32 +0800 Subject: [PATCH 2/7] Support multiple skip option for E2E test The GINKGO_SKIP option is updated to string that can be separated by "." for "make test-e2e". Signed-off-by: Xun Jiang Signed-off-by: Hoang, Phuong --- changelogs/unreleased/4725-jxun | 1 + test/e2e/Makefile | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/4725-jxun diff --git a/changelogs/unreleased/4725-jxun b/changelogs/unreleased/4725-jxun new file mode 100644 index 000000000..f9e0e4d94 --- /dev/null +++ b/changelogs/unreleased/4725-jxun @@ -0,0 +1 @@ +Support multiple skip option for E2E test \ No newline at end of file diff --git a/test/e2e/Makefile b/test/e2e/Makefile index b49829ab6..01099282d 100644 --- a/test/e2e/Makefile +++ b/test/e2e/Makefile @@ -47,6 +47,7 @@ KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize OUTPUT_DIR := _output/$(GOOS)/$(GOARCH)/bin GINKGO_FOCUS ?= GINKGO_SKIP ?= +SKIP_STR := $(foreach var, $(subst ., ,$(GINKGO_SKIP)),-skip "$(var)") VELERO_CLI ?=$$(pwd)/../../_output/bin/$(GOOS)/$(GOARCH)/velero VELERO_IMAGE ?= velero/velero:main VELERO_VERSION ?= $(VERSION) @@ -86,7 +87,7 @@ run: ginkgo (echo "Bucket to store the backups from E2E tests is required, please re-run with BSL_BUCKET="; exit 1 ) @[ "${CLOUD_PROVIDER}" ] && echo "Using cloud provider ${CLOUD_PROVIDER}" || \ (echo "Cloud provider for target cloud/plug-in provider is required, please rerun with CLOUD_PROVIDER="; exit 1) - @$(GINKGO) -v -focus="$(GINKGO_FOCUS)" -skip="$(GINKGO_SKIP)" . -- -velerocli=$(VELERO_CLI) \ + @$(GINKGO) -v -focus="$(GINKGO_FOCUS)" $(SKIP_STR) . -- -velerocli=$(VELERO_CLI) \ -velero-image=$(VELERO_IMAGE) \ -plugins=$(PLUGINS) \ -velero-version=$(VELERO_VERSION) \ From 0741360050b6ad51392c5c28c678dd960a142949 Mon Sep 17 00:00:00 2001 From: "Hoang, Phuong" Date: Mon, 14 Mar 2022 17:10:54 -0400 Subject: [PATCH 3/7] Adding PriorityClass to backup podAction and restore podAction. Signed-off-by: Hoang, Phuong --- pkg/backup/pod_action.go | 16 ++++++++++++---- pkg/kuberesource/kuberesource.go | 1 + pkg/restore/pod_action.go | 10 ++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/pkg/backup/pod_action.go b/pkg/backup/pod_action.go index be43c24ed..0fd479a71 100644 --- a/pkg/backup/pod_action.go +++ b/pkg/backup/pod_action.go @@ -56,12 +56,20 @@ func (a *PodAction) Execute(item runtime.Unstructured, backup *v1.Backup) (runti return nil, nil, errors.WithStack(err) } - if len(pod.Spec.Volumes) == 0 { - a.log.Info("pod has no volumes") - return item, nil, nil + var additionalItems []velero.ResourceIdentifier + if pod.Spec.PriorityClassName > "" { + a.log.Infof("Adding priorityclass %s to additionalItems", pod.Spec.PriorityClassName) + additionalItems = append(additionalItems, velero.ResourceIdentifier{ + GroupResource: kuberesource.PriorityClasses, + Name: pod.Spec.PriorityClassName, + }) + } + + if len(pod.Spec.Volumes) == 0 { + a.log.Info("pod has no volumes") + return item, additionalItems, nil } - var additionalItems []velero.ResourceIdentifier for _, volume := range pod.Spec.Volumes { if volume.PersistentVolumeClaim != nil && volume.PersistentVolumeClaim.ClaimName != "" { a.log.Infof("Adding pvc %s to additionalItems", volume.PersistentVolumeClaim.ClaimName) diff --git a/pkg/kuberesource/kuberesource.go b/pkg/kuberesource/kuberesource.go index a515a70ff..c6dd36a05 100644 --- a/pkg/kuberesource/kuberesource.go +++ b/pkg/kuberesource/kuberesource.go @@ -34,4 +34,5 @@ var ( VolumeSnapshotClasses = schema.GroupResource{Group: "snapshot.storage.k8s.io", Resource: "volumesnapshotclasses"} VolumeSnapshots = schema.GroupResource{Group: "snapshot.storage.k8s.io", Resource: "volumesnapshots"} VolumeSnapshotContents = schema.GroupResource{Group: "snapshot.storage.k8s.io", Resource: "volumesnapshotcontents"} + PriorityClasses = schema.GroupResource{Group: "scheduling.k8s.io", Resource: "priorityclasses"} ) diff --git a/pkg/restore/pod_action.go b/pkg/restore/pod_action.go index 2086954ae..4db9da722 100644 --- a/pkg/restore/pod_action.go +++ b/pkg/restore/pod_action.go @@ -25,6 +25,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" + "github.com/vmware-tanzu/velero/pkg/kuberesource" "github.com/vmware-tanzu/velero/pkg/plugin/velero" ) @@ -85,6 +86,11 @@ func (a *PodAction) Execute(input *velero.RestoreItemActionExecuteInput) (*veler if err != nil { return nil, errors.WithStack(err) } - - return velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}), nil + restoreExecuteOutput := velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}) + if pod.Spec.PriorityClassName > "" { + a.logger.Infof("Adding priorityclass %s to AdditionalItems", pod.Spec.PriorityClassName) + restoreExecuteOutput.AdditionalItems = []velero.ResourceIdentifier{ + {GroupResource: kuberesource.PriorityClasses, Name: pod.Spec.PriorityClassName}} + } + return restoreExecuteOutput, nil } From d2ef5cbe0a08afbb6a94faa1d2f593b545f25717 Mon Sep 17 00:00:00 2001 From: "Hoang, Phuong" Date: Tue, 15 Mar 2022 19:00:49 -0400 Subject: [PATCH 4/7] Add changelog Signed-off-by: Hoang, Phuong --- changelogs/unreleased/4740-phuongatemc | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/unreleased/4740-phuongatemc diff --git a/changelogs/unreleased/4740-phuongatemc b/changelogs/unreleased/4740-phuongatemc new file mode 100644 index 000000000..0227a9665 --- /dev/null +++ b/changelogs/unreleased/4740-phuongatemc @@ -0,0 +1,2 @@ +Add PriorityClass to the AdditionalItems of Backup's PodAction and Restore's PodAction plugin to +backup and restore PriorityClass if it is used by a Pod. From e9d5f7121cae9338a0adc1fd33b488be0dd0a9c6 Mon Sep 17 00:00:00 2001 From: "Hoang, Phuong" Date: Tue, 15 Mar 2022 19:51:53 -0400 Subject: [PATCH 5/7] Add unit tests, change copyright years and revert unrelated changes. Signed-off-by: Hoang, Phuong --- changelogs/unreleased/4725-jxun | 1 - pkg/backup/pod_action.go | 2 +- pkg/backup/pod_action_test.go | 21 +++++++++++++++- pkg/kuberesource/kuberesource.go | 2 +- pkg/restore/pod_action.go | 2 +- pkg/restore/pod_action_test.go | 43 ++++++++++++++++++++++++++++---- site/content/docs/v1.8/_index.md | 2 +- test/e2e/Makefile | 3 +-- 8 files changed, 63 insertions(+), 13 deletions(-) delete mode 100644 changelogs/unreleased/4725-jxun diff --git a/changelogs/unreleased/4725-jxun b/changelogs/unreleased/4725-jxun deleted file mode 100644 index f9e0e4d94..000000000 --- a/changelogs/unreleased/4725-jxun +++ /dev/null @@ -1 +0,0 @@ -Support multiple skip option for E2E test \ No newline at end of file diff --git a/pkg/backup/pod_action.go b/pkg/backup/pod_action.go index 0fd479a71..bd1005500 100644 --- a/pkg/backup/pod_action.go +++ b/pkg/backup/pod_action.go @@ -1,5 +1,5 @@ /* -Copyright 2017 the Velero contributors. +Copyright 2017, 2022 the Velero contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/backup/pod_action_test.go b/pkg/backup/pod_action_test.go index c1a7f0e0a..80c9127d6 100644 --- a/pkg/backup/pod_action_test.go +++ b/pkg/backup/pod_action_test.go @@ -1,5 +1,5 @@ /* -Copyright 2018 the Velero contributors. +Copyright 2018, 2022 the Velero contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -115,6 +115,25 @@ func TestPodActionExecute(t *testing.T) { {GroupResource: kuberesource.PersistentVolumeClaims, Namespace: "foo", Name: "claim2"}, }, }, + { + name: "test priority class", + pod: velerotest.UnstructuredOrDie(` + { + "apiVersion": "v1", + "kind": "Pod", + "metadata": { + "namespace": "foo", + "name": "bar" + }, + "spec": { + "priorityClassName": "testPriorityClass" + } + } + `), + expected: []velero.ResourceIdentifier{ + {GroupResource: kuberesource.PriorityClasses, Name: "testPriorityClass"}, + }, + }, } for _, test := range tests { diff --git a/pkg/kuberesource/kuberesource.go b/pkg/kuberesource/kuberesource.go index c6dd36a05..a3a087244 100644 --- a/pkg/kuberesource/kuberesource.go +++ b/pkg/kuberesource/kuberesource.go @@ -1,5 +1,5 @@ /* -Copyright 2018 the Velero contributors. +Copyright 2018, 2022 the Velero contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/restore/pod_action.go b/pkg/restore/pod_action.go index 4db9da722..adfc83c0d 100644 --- a/pkg/restore/pod_action.go +++ b/pkg/restore/pod_action.go @@ -1,5 +1,5 @@ /* -Copyright 2017 the Velero contributors. +Copyright 2017, 2022 the Velero contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/restore/pod_action_test.go b/pkg/restore/pod_action_test.go index 1d0165541..c638b7229 100644 --- a/pkg/restore/pod_action_test.go +++ b/pkg/restore/pod_action_test.go @@ -1,5 +1,5 @@ /* -Copyright 2017, 2019 the Velero contributors. +Copyright 2017, 2019, 2022 the Velero contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -17,6 +17,8 @@ limitations under the License. package restore import ( + "github.com/vmware-tanzu/velero/pkg/kuberesource" + //"github.com/vmware-tanzu/velero/pkg/kuberesource" "testing" "github.com/stretchr/testify/assert" @@ -34,10 +36,11 @@ func TestPodActionExecute(t *testing.T) { var priority int32 = 1 tests := []struct { - name string - obj corev1api.Pod - expectedErr bool - expectedRes corev1api.Pod + name string + obj corev1api.Pod + expectedErr bool + expectedRes corev1api.Pod + additionalItems []velero.ResourceIdentifier }{ { name: "nodeName (only) should be deleted from spec", @@ -189,6 +192,35 @@ func TestPodActionExecute(t *testing.T) { }, }, }, + { + name: "test priority class", + obj: corev1api.Pod{ + ObjectMeta: metav1.ObjectMeta{Name: "pod-1"}, + Spec: corev1api.PodSpec{ + ServiceAccountName: "foo", + PriorityClassName: "testPriorityClass", + Volumes: []corev1api.Volume{ + {Name: "foo"}, + {Name: "foo-token-foo"}, + }, + }, + }, + expectedRes: corev1api.Pod{ + ObjectMeta: metav1.ObjectMeta{Name: "pod-1"}, + Spec: corev1api.PodSpec{ + ServiceAccountName: "foo", + PriorityClassName: "testPriorityClass", + Volumes: []corev1api.Volume{ + {Name: "foo"}, + }, + }, + }, + additionalItems: []velero.ResourceIdentifier{ + {GroupResource: kuberesource.PriorityClasses, + Name: "testPriorityClass", + }, + }, + }, } for _, test := range tests { @@ -214,6 +246,7 @@ func TestPodActionExecute(t *testing.T) { require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(res.UpdatedItem.UnstructuredContent(), &pod)) assert.Equal(t, test.expectedRes, pod) + assert.Equal(t, test.additionalItems, res.AdditionalItems) }) } } diff --git a/site/content/docs/v1.8/_index.md b/site/content/docs/v1.8/_index.md index d4a88da6a..74eece82f 100644 --- a/site/content/docs/v1.8/_index.md +++ b/site/content/docs/v1.8/_index.md @@ -33,7 +33,7 @@ If you encounter issues, review the [troubleshooting docs][30], [file an issue][ ## Contributing -If you are ready to jump in and test, add code, or help with documentation, follow the instructions on our [Start contributing](https://velero.io/docs/v1.8/start-contributing/) documentation for guidance on how to setup Velero for development. +If you are ready to jump in and test, add code, or help with documentation, follow the instructions on our [Start contributing](https://velero.io/docs/v1.8.0/start-contributing/) documentation for guidance on how to setup Velero for development. ## Changelog diff --git a/test/e2e/Makefile b/test/e2e/Makefile index 01099282d..b49829ab6 100644 --- a/test/e2e/Makefile +++ b/test/e2e/Makefile @@ -47,7 +47,6 @@ KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize OUTPUT_DIR := _output/$(GOOS)/$(GOARCH)/bin GINKGO_FOCUS ?= GINKGO_SKIP ?= -SKIP_STR := $(foreach var, $(subst ., ,$(GINKGO_SKIP)),-skip "$(var)") VELERO_CLI ?=$$(pwd)/../../_output/bin/$(GOOS)/$(GOARCH)/velero VELERO_IMAGE ?= velero/velero:main VELERO_VERSION ?= $(VERSION) @@ -87,7 +86,7 @@ run: ginkgo (echo "Bucket to store the backups from E2E tests is required, please re-run with BSL_BUCKET="; exit 1 ) @[ "${CLOUD_PROVIDER}" ] && echo "Using cloud provider ${CLOUD_PROVIDER}" || \ (echo "Cloud provider for target cloud/plug-in provider is required, please rerun with CLOUD_PROVIDER="; exit 1) - @$(GINKGO) -v -focus="$(GINKGO_FOCUS)" $(SKIP_STR) . -- -velerocli=$(VELERO_CLI) \ + @$(GINKGO) -v -focus="$(GINKGO_FOCUS)" -skip="$(GINKGO_SKIP)" . -- -velerocli=$(VELERO_CLI) \ -velero-image=$(VELERO_IMAGE) \ -plugins=$(PLUGINS) \ -velero-version=$(VELERO_VERSION) \ From b8b5427388b0877055a4238073c69c84e270b0c5 Mon Sep 17 00:00:00 2001 From: "Hoang, Phuong" Date: Tue, 15 Mar 2022 19:54:24 -0400 Subject: [PATCH 6/7] Fix format. Signed-off-by: Hoang, Phuong --- pkg/restore/pod_action_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/restore/pod_action_test.go b/pkg/restore/pod_action_test.go index c638b7229..0d6226fe2 100644 --- a/pkg/restore/pod_action_test.go +++ b/pkg/restore/pod_action_test.go @@ -17,8 +17,6 @@ limitations under the License. package restore import ( - "github.com/vmware-tanzu/velero/pkg/kuberesource" - //"github.com/vmware-tanzu/velero/pkg/kuberesource" "testing" "github.com/stretchr/testify/assert" @@ -28,6 +26,7 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" + "github.com/vmware-tanzu/velero/pkg/kuberesource" "github.com/vmware-tanzu/velero/pkg/plugin/velero" velerotest "github.com/vmware-tanzu/velero/pkg/test" ) From 0171a91366dd45950a2c5df2d35bf6e0977dbdda Mon Sep 17 00:00:00 2001 From: "Hoang, Phuong" Date: Mon, 21 Mar 2022 12:01:26 -0400 Subject: [PATCH 7/7] Correct copyright comment and string compare Signed-off-by: Hoang, Phuong --- pkg/backup/pod_action.go | 4 ++-- pkg/backup/pod_action_test.go | 2 +- pkg/kuberesource/kuberesource.go | 2 +- pkg/restore/pod_action.go | 4 ++-- pkg/restore/pod_action_test.go | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/backup/pod_action.go b/pkg/backup/pod_action.go index bd1005500..d0e834fbb 100644 --- a/pkg/backup/pod_action.go +++ b/pkg/backup/pod_action.go @@ -1,5 +1,5 @@ /* -Copyright 2017, 2022 the Velero contributors. +Copyright the Velero contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -57,7 +57,7 @@ func (a *PodAction) Execute(item runtime.Unstructured, backup *v1.Backup) (runti } var additionalItems []velero.ResourceIdentifier - if pod.Spec.PriorityClassName > "" { + if pod.Spec.PriorityClassName != "" { a.log.Infof("Adding priorityclass %s to additionalItems", pod.Spec.PriorityClassName) additionalItems = append(additionalItems, velero.ResourceIdentifier{ GroupResource: kuberesource.PriorityClasses, diff --git a/pkg/backup/pod_action_test.go b/pkg/backup/pod_action_test.go index 80c9127d6..1618b3089 100644 --- a/pkg/backup/pod_action_test.go +++ b/pkg/backup/pod_action_test.go @@ -1,5 +1,5 @@ /* -Copyright 2018, 2022 the Velero contributors. +Copyright the Velero contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/kuberesource/kuberesource.go b/pkg/kuberesource/kuberesource.go index a3a087244..c2c2d84ee 100644 --- a/pkg/kuberesource/kuberesource.go +++ b/pkg/kuberesource/kuberesource.go @@ -1,5 +1,5 @@ /* -Copyright 2018, 2022 the Velero contributors. +Copyright the Velero contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/pkg/restore/pod_action.go b/pkg/restore/pod_action.go index adfc83c0d..d4bdc1384 100644 --- a/pkg/restore/pod_action.go +++ b/pkg/restore/pod_action.go @@ -1,5 +1,5 @@ /* -Copyright 2017, 2022 the Velero contributors. +Copyright the Velero contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -87,7 +87,7 @@ func (a *PodAction) Execute(input *velero.RestoreItemActionExecuteInput) (*veler return nil, errors.WithStack(err) } restoreExecuteOutput := velero.NewRestoreItemActionExecuteOutput(&unstructured.Unstructured{Object: res}) - if pod.Spec.PriorityClassName > "" { + if pod.Spec.PriorityClassName != "" { a.logger.Infof("Adding priorityclass %s to AdditionalItems", pod.Spec.PriorityClassName) restoreExecuteOutput.AdditionalItems = []velero.ResourceIdentifier{ {GroupResource: kuberesource.PriorityClasses, Name: pod.Spec.PriorityClassName}} diff --git a/pkg/restore/pod_action_test.go b/pkg/restore/pod_action_test.go index 0d6226fe2..f1aa83c1a 100644 --- a/pkg/restore/pod_action_test.go +++ b/pkg/restore/pod_action_test.go @@ -1,5 +1,5 @@ /* -Copyright 2017, 2019, 2022 the Velero contributors. +Copyright the Velero contributors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.