mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-20 15:04:17 +00:00
chore: define common aliases for k8s packages (#8672)
Run the E2E test on kind / build (push) Failing after 6m48s
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / Build (push) Failing after 35s
Close stale issues and PRs / stale (push) Successful in 8s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 1m11s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-aws, main) (push) Failing after 47s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-gcp, main) (push) Failing after 49s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-microsoft-azure, main) (push) Failing after 43s
Run the E2E test on kind / build (push) Failing after 6m48s
Run the E2E test on kind / setup-test-matrix (push) Successful in 3s
Run the E2E test on kind / run-e2e-test (push) Has been skipped
Main CI / Build (push) Failing after 35s
Close stale issues and PRs / stale (push) Successful in 8s
Trivy Nightly Scan / Trivy nightly scan (velero, main) (push) Failing after 1m11s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-aws, main) (push) Failing after 47s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-gcp, main) (push) Failing after 49s
Trivy Nightly Scan / Trivy nightly scan (velero-plugin-for-microsoft-azure, main) (push) Failing after 43s
* lchore: define common alias for k8s packages Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Update .golangci.yaml Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Update .golangci.yaml Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * Update .golangci.yaml Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> --------- Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
@@ -21,7 +21,6 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
@@ -60,57 +59,57 @@ func TestBackupPVAction(t *testing.T) {
|
||||
assert.Empty(t, additional)
|
||||
|
||||
// Action should clean the spec.Selector when the StorageClassName is not set.
|
||||
input := builder.ForPersistentVolumeClaim("abc", "abc").VolumeName("pv").Selector(&metav1.LabelSelector{MatchLabels: map[string]string{"abc": "abc"}}).Phase(corev1.ClaimBound).Result()
|
||||
input := builder.ForPersistentVolumeClaim("abc", "abc").VolumeName("pv").Selector(&metav1.LabelSelector{MatchLabels: map[string]string{"abc": "abc"}}).Phase(corev1api.ClaimBound).Result()
|
||||
inputUnstructured, err := runtime.DefaultUnstructuredConverter.ToUnstructured(input)
|
||||
require.NoError(t, err)
|
||||
item, additional, err := a.Execute(&unstructured.Unstructured{Object: inputUnstructured}, backup)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, additional, 1)
|
||||
modifiedPVC := new(corev1.PersistentVolumeClaim)
|
||||
modifiedPVC := new(corev1api.PersistentVolumeClaim)
|
||||
require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(item.UnstructuredContent(), modifiedPVC))
|
||||
require.Nil(t, modifiedPVC.Spec.Selector)
|
||||
|
||||
// Action should clean the spec.Selector when the StorageClassName is set to specific StorageClass
|
||||
input2 := builder.ForPersistentVolumeClaim("abc", "abc").VolumeName("pv").StorageClass("sc1").Selector(&metav1.LabelSelector{MatchLabels: map[string]string{"abc": "abc"}}).Phase(corev1.ClaimBound).Result()
|
||||
input2 := builder.ForPersistentVolumeClaim("abc", "abc").VolumeName("pv").StorageClass("sc1").Selector(&metav1.LabelSelector{MatchLabels: map[string]string{"abc": "abc"}}).Phase(corev1api.ClaimBound).Result()
|
||||
inputUnstructured2, err2 := runtime.DefaultUnstructuredConverter.ToUnstructured(input2)
|
||||
require.NoError(t, err2)
|
||||
item2, additional2, err2 := a.Execute(&unstructured.Unstructured{Object: inputUnstructured2}, backup)
|
||||
require.NoError(t, err2)
|
||||
require.Len(t, additional2, 1)
|
||||
modifiedPVC2 := new(corev1.PersistentVolumeClaim)
|
||||
modifiedPVC2 := new(corev1api.PersistentVolumeClaim)
|
||||
require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(item2.UnstructuredContent(), modifiedPVC2))
|
||||
require.Nil(t, modifiedPVC2.Spec.Selector)
|
||||
|
||||
// Action should keep the spec.Selector when the StorageClassName is set to ""
|
||||
input3 := builder.ForPersistentVolumeClaim("abc", "abc").StorageClass("").Selector(&metav1.LabelSelector{MatchLabels: map[string]string{"abc": "abc"}}).VolumeName("pv").Phase(corev1.ClaimBound).Result()
|
||||
input3 := builder.ForPersistentVolumeClaim("abc", "abc").StorageClass("").Selector(&metav1.LabelSelector{MatchLabels: map[string]string{"abc": "abc"}}).VolumeName("pv").Phase(corev1api.ClaimBound).Result()
|
||||
inputUnstructured3, err3 := runtime.DefaultUnstructuredConverter.ToUnstructured(input3)
|
||||
require.NoError(t, err3)
|
||||
item3, additional3, err3 := a.Execute(&unstructured.Unstructured{Object: inputUnstructured3}, backup)
|
||||
require.NoError(t, err3)
|
||||
require.Len(t, additional3, 1)
|
||||
modifiedPVC3 := new(corev1.PersistentVolumeClaim)
|
||||
modifiedPVC3 := new(corev1api.PersistentVolumeClaim)
|
||||
require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(item3.UnstructuredContent(), modifiedPVC3))
|
||||
require.Equal(t, input3.Spec.Selector, modifiedPVC3.Spec.Selector)
|
||||
|
||||
// Action should delete label started with"velero.io/" from the spec.Selector when the StorageClassName is set to ""
|
||||
input4 := builder.ForPersistentVolumeClaim("abc", "abc").StorageClass("").Selector(&metav1.LabelSelector{MatchLabels: map[string]string{"velero.io/abc": "abc", "abc": "abc"}}).VolumeName("pv").Phase(corev1.ClaimBound).Result()
|
||||
input4 := builder.ForPersistentVolumeClaim("abc", "abc").StorageClass("").Selector(&metav1.LabelSelector{MatchLabels: map[string]string{"velero.io/abc": "abc", "abc": "abc"}}).VolumeName("pv").Phase(corev1api.ClaimBound).Result()
|
||||
inputUnstructured4, err4 := runtime.DefaultUnstructuredConverter.ToUnstructured(input4)
|
||||
require.NoError(t, err4)
|
||||
item4, additional4, err4 := a.Execute(&unstructured.Unstructured{Object: inputUnstructured4}, backup)
|
||||
require.NoError(t, err4)
|
||||
require.Len(t, additional4, 1)
|
||||
modifiedPVC4 := new(corev1.PersistentVolumeClaim)
|
||||
modifiedPVC4 := new(corev1api.PersistentVolumeClaim)
|
||||
require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(item4.UnstructuredContent(), modifiedPVC4))
|
||||
require.Equal(t, &metav1.LabelSelector{MatchLabels: map[string]string{"abc": "abc"}}, modifiedPVC4.Spec.Selector)
|
||||
|
||||
// Action should clean the spec.Selector when the StorageClassName has value
|
||||
input5 := builder.ForPersistentVolumeClaim("abc", "abc").StorageClass("sc1").Selector(&metav1.LabelSelector{MatchLabels: map[string]string{"velero.io/abc": "abc", "abc": "abc"}}).VolumeName("pv").Phase(corev1.ClaimBound).Result()
|
||||
input5 := builder.ForPersistentVolumeClaim("abc", "abc").StorageClass("sc1").Selector(&metav1.LabelSelector{MatchLabels: map[string]string{"velero.io/abc": "abc", "abc": "abc"}}).VolumeName("pv").Phase(corev1api.ClaimBound).Result()
|
||||
inputUnstructured5, err5 := runtime.DefaultUnstructuredConverter.ToUnstructured(input5)
|
||||
require.NoError(t, err5)
|
||||
item5, additional5, err5 := a.Execute(&unstructured.Unstructured{Object: inputUnstructured5}, backup)
|
||||
require.NoError(t, err5)
|
||||
require.Len(t, additional5, 1)
|
||||
modifiedPVC5 := new(corev1.PersistentVolumeClaim)
|
||||
modifiedPVC5 := new(corev1api.PersistentVolumeClaim)
|
||||
require.NoError(t, runtime.DefaultUnstructuredConverter.FromUnstructured(item5.UnstructuredContent(), modifiedPVC5))
|
||||
require.Nil(t, modifiedPVC5.Spec.Selector)
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ import (
|
||||
v1 "github.com/kubernetes-csi/external-snapshotter/client/v7/apis/volumesnapshot/v1"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/require"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
storagev1 "k8s.io/api/storage/v1"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
storagev1api "k8s.io/api/storage/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
@@ -52,16 +52,16 @@ func TestExecute(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
backup *velerov1api.Backup
|
||||
pvc *corev1.PersistentVolumeClaim
|
||||
pv *corev1.PersistentVolume
|
||||
sc *storagev1.StorageClass
|
||||
pvc *corev1api.PersistentVolumeClaim
|
||||
pv *corev1api.PersistentVolume
|
||||
sc *storagev1api.StorageClass
|
||||
vsClass *snapshotv1api.VolumeSnapshotClass
|
||||
operationID string
|
||||
expectedErr error
|
||||
expectedBackup *velerov1api.Backup
|
||||
expectedDataUpload *velerov2alpha1.DataUpload
|
||||
expectedPVC *corev1.PersistentVolumeClaim
|
||||
resourcePolicy *corev1.ConfigMap
|
||||
expectedPVC *corev1api.PersistentVolumeClaim
|
||||
resourcePolicy *corev1api.ConfigMap
|
||||
}{
|
||||
{
|
||||
name: "Skip PVC BIA when backup is in finalizing phase",
|
||||
@@ -71,7 +71,7 @@ func TestExecute(t *testing.T) {
|
||||
{
|
||||
name: "Test SnapshotMoveData",
|
||||
backup: builder.ForBackup("velero", "test").SnapshotMoveData(true).CSISnapshotTimeout(1 * time.Minute).Result(),
|
||||
pvc: builder.ForPersistentVolumeClaim("velero", "testPVC").VolumeName("testPV").StorageClass("testSC").Phase(corev1.ClaimBound).Result(),
|
||||
pvc: builder.ForPersistentVolumeClaim("velero", "testPVC").VolumeName("testPV").StorageClass("testSC").Phase(corev1api.ClaimBound).Result(),
|
||||
pv: builder.ForPersistentVolume("testPV").CSI("hostpath", "testVolume").Result(),
|
||||
sc: builder.ForStorageClass("testSC").Provisioner("hostpath").Result(),
|
||||
vsClass: builder.ForVolumeSnapshotClass("testVSClass").Driver("hostpath").ObjectMeta(builder.WithLabels(velerov1api.VolumeSnapshotClassSelectorLabel, "")).Result(),
|
||||
@@ -117,7 +117,7 @@ func TestExecute(t *testing.T) {
|
||||
{
|
||||
name: "Verify PVC is modified as expected",
|
||||
backup: builder.ForBackup("velero", "test").SnapshotMoveData(true).CSISnapshotTimeout(1 * time.Minute).Result(),
|
||||
pvc: builder.ForPersistentVolumeClaim("velero", "testPVC").VolumeName("testPV").StorageClass("testSC").Phase(corev1.ClaimBound).Result(),
|
||||
pvc: builder.ForPersistentVolumeClaim("velero", "testPVC").VolumeName("testPV").StorageClass("testSC").Phase(corev1api.ClaimBound).Result(),
|
||||
pv: builder.ForPersistentVolume("testPV").CSI("hostpath", "testVolume").Result(),
|
||||
sc: builder.ForStorageClass("testSC").Provisioner("hostpath").Result(),
|
||||
vsClass: builder.ForVolumeSnapshotClass("tescVSClass").Driver("hostpath").ObjectMeta(builder.WithLabels(velerov1api.VolumeSnapshotClassSelectorLabel, "")).Result(),
|
||||
@@ -126,13 +126,13 @@ func TestExecute(t *testing.T) {
|
||||
expectedPVC: builder.ForPersistentVolumeClaim("velero", "testPVC").
|
||||
ObjectMeta(builder.WithAnnotations(velerov1api.MustIncludeAdditionalItemAnnotation, "true", velerov1api.DataUploadNameAnnotation, "velero/"),
|
||||
builder.WithLabels(velerov1api.BackupNameLabel, "test")).
|
||||
VolumeName("testPV").StorageClass("testSC").Phase(corev1.ClaimBound).Result(),
|
||||
VolumeName("testPV").StorageClass("testSC").Phase(corev1api.ClaimBound).Result(),
|
||||
},
|
||||
{
|
||||
name: "Test ResourcePolicy",
|
||||
backup: builder.ForBackup("velero", "test").ResourcePolicies("resourcePolicy").SnapshotVolumes(false).Result(),
|
||||
resourcePolicy: builder.ForConfigMap("velero", "resourcePolicy").Data("policy", "{\"version\":\"v1\", \"volumePolicies\":[{\"conditions\":{\"csi\": {}},\"action\":{\"type\":\"snapshot\"}}]}").Result(),
|
||||
pvc: builder.ForPersistentVolumeClaim("velero", "testPVC").VolumeName("testPV").StorageClass("testSC").Phase(corev1.ClaimBound).Result(),
|
||||
pvc: builder.ForPersistentVolumeClaim("velero", "testPVC").VolumeName("testPV").StorageClass("testSC").Phase(corev1api.ClaimBound).Result(),
|
||||
pv: builder.ForPersistentVolume("testPV").CSI("hostpath", "testVolume").Result(),
|
||||
sc: builder.ForStorageClass("testSC").Provisioner("hostpath").Result(),
|
||||
vsClass: builder.ForVolumeSnapshotClass("tescVSClass").Driver("hostpath").ObjectMeta(builder.WithLabels(velerov1api.VolumeSnapshotClassSelectorLabel, "")).Result(),
|
||||
@@ -217,10 +217,10 @@ func TestExecute(t *testing.T) {
|
||||
}
|
||||
|
||||
if tc.expectedPVC != nil {
|
||||
resultPVC := new(corev1.PersistentVolumeClaim)
|
||||
resultPVC := new(corev1api.PersistentVolumeClaim)
|
||||
runtime.DefaultUnstructuredConverter.FromUnstructured(resultUnstructed.UnstructuredContent(), resultPVC)
|
||||
|
||||
require.True(t, cmp.Equal(tc.expectedPVC, resultPVC, cmpopts.IgnoreFields(corev1.PersistentVolumeClaim{}, "ResourceVersion", "Annotations", "Labels")))
|
||||
require.True(t, cmp.Equal(tc.expectedPVC, resultPVC, cmpopts.IgnoreFields(corev1api.PersistentVolumeClaim{}, "ResourceVersion", "Annotations", "Labels")))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
rbac "k8s.io/api/rbac/v1"
|
||||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
rbacbeta "k8s.io/api/rbac/v1beta1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
"github.com/vmware-tanzu/velero/pkg/util/actionhelpers"
|
||||
)
|
||||
|
||||
func newV1ClusterRoleBindingList(rbacCRBList []rbac.ClusterRoleBinding) []actionhelpers.ClusterRoleBinding {
|
||||
func newV1ClusterRoleBindingList(rbacCRBList []rbacv1.ClusterRoleBinding) []actionhelpers.ClusterRoleBinding {
|
||||
var crbs []actionhelpers.ClusterRoleBinding
|
||||
for _, c := range rbacCRBList {
|
||||
crbs = append(crbs, actionhelpers.V1ClusterRoleBinding{Crb: c})
|
||||
@@ -53,7 +53,7 @@ func newV1beta1ClusterRoleBindingList(rbacCRBList []rbacbeta.ClusterRoleBinding)
|
||||
}
|
||||
|
||||
type FakeV1ClusterRoleBindingLister struct {
|
||||
v1crbs []rbac.ClusterRoleBinding
|
||||
v1crbs []rbacv1.ClusterRoleBinding
|
||||
}
|
||||
|
||||
func (f FakeV1ClusterRoleBindingLister) List() ([]actionhelpers.ClusterRoleBinding, error) {
|
||||
@@ -98,17 +98,17 @@ func TestNewServiceAccountAction(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "rbac v1 API instantiates an saAction",
|
||||
version: rbac.SchemeGroupVersion.Version,
|
||||
version: rbacv1.SchemeGroupVersion.Version,
|
||||
expectedCRBs: []actionhelpers.ClusterRoleBinding{
|
||||
actionhelpers.V1ClusterRoleBinding{
|
||||
Crb: rbac.ClusterRoleBinding{
|
||||
Crb: rbacv1.ClusterRoleBinding{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "v1crb-1",
|
||||
},
|
||||
},
|
||||
},
|
||||
actionhelpers.V1ClusterRoleBinding{
|
||||
Crb: rbac.ClusterRoleBinding{
|
||||
Crb: rbacv1.ClusterRoleBinding{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "v1crb-2",
|
||||
},
|
||||
@@ -146,7 +146,7 @@ func TestNewServiceAccountAction(t *testing.T) {
|
||||
discoveryHelper := velerotest.FakeDiscoveryHelper{}
|
||||
logger := velerotest.NewLogger()
|
||||
|
||||
v1crbs := []rbac.ClusterRoleBinding{
|
||||
v1crbs := []rbacv1.ClusterRoleBinding{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "v1crb-1",
|
||||
@@ -173,7 +173,7 @@ func TestNewServiceAccountAction(t *testing.T) {
|
||||
}
|
||||
|
||||
clusterRoleBindingListers := map[string]actionhelpers.ClusterRoleBindingLister{
|
||||
rbac.SchemeGroupVersion.Version: FakeV1ClusterRoleBindingLister{v1crbs: v1crbs},
|
||||
rbacv1.SchemeGroupVersion.Version: FakeV1ClusterRoleBindingLister{v1crbs: v1crbs},
|
||||
rbacbeta.SchemeGroupVersion.Version: FakeV1beta1ClusterRoleBindingLister{v1beta1crbs: v1beta1crbs},
|
||||
"": actionhelpers.NoopClusterRoleBindingLister{},
|
||||
}
|
||||
@@ -183,7 +183,7 @@ func TestNewServiceAccountAction(t *testing.T) {
|
||||
// We only care about the preferred version, nothing else in the list
|
||||
discoveryHelper.APIGroupsList = []metav1.APIGroup{
|
||||
{
|
||||
Name: rbac.GroupName,
|
||||
Name: rbacv1.GroupName,
|
||||
PreferredVersion: metav1.GroupVersionForDiscovery{
|
||||
Version: test.version,
|
||||
},
|
||||
@@ -200,7 +200,7 @@ func TestServiceAccountActionExecute(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
serviceAccount runtime.Unstructured
|
||||
crbs []rbac.ClusterRoleBinding
|
||||
crbs []rbacv1.ClusterRoleBinding
|
||||
expectedAdditionalItems []velero.ResourceIdentifier
|
||||
}{
|
||||
{
|
||||
@@ -230,9 +230,9 @@ func TestServiceAccountActionExecute(t *testing.T) {
|
||||
}
|
||||
}
|
||||
`),
|
||||
crbs: []rbac.ClusterRoleBinding{
|
||||
crbs: []rbacv1.ClusterRoleBinding{
|
||||
{
|
||||
Subjects: []rbac.Subject{
|
||||
Subjects: []rbacv1.Subject{
|
||||
{
|
||||
Kind: "non-matching-kind",
|
||||
Namespace: "non-matching-ns",
|
||||
@@ -244,17 +244,17 @@ func TestServiceAccountActionExecute(t *testing.T) {
|
||||
Name: "velero",
|
||||
},
|
||||
{
|
||||
Kind: rbac.ServiceAccountKind,
|
||||
Kind: rbacv1.ServiceAccountKind,
|
||||
Namespace: "non-matching-ns",
|
||||
Name: "velero",
|
||||
},
|
||||
{
|
||||
Kind: rbac.ServiceAccountKind,
|
||||
Kind: rbacv1.ServiceAccountKind,
|
||||
Namespace: "velero",
|
||||
Name: "non-matching-name",
|
||||
},
|
||||
},
|
||||
RoleRef: rbac.RoleRef{
|
||||
RoleRef: rbacv1.RoleRef{
|
||||
Name: "role",
|
||||
},
|
||||
},
|
||||
@@ -273,19 +273,19 @@ func TestServiceAccountActionExecute(t *testing.T) {
|
||||
}
|
||||
}
|
||||
`),
|
||||
crbs: []rbac.ClusterRoleBinding{
|
||||
crbs: []rbacv1.ClusterRoleBinding{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "crb-1",
|
||||
},
|
||||
Subjects: []rbac.Subject{
|
||||
Subjects: []rbacv1.Subject{
|
||||
{
|
||||
Kind: "non-matching-kind",
|
||||
Namespace: "non-matching-ns",
|
||||
Name: "non-matching-name",
|
||||
},
|
||||
},
|
||||
RoleRef: rbac.RoleRef{
|
||||
RoleRef: rbacv1.RoleRef{
|
||||
Name: "role-1",
|
||||
},
|
||||
},
|
||||
@@ -293,19 +293,19 @@ func TestServiceAccountActionExecute(t *testing.T) {
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "crb-2",
|
||||
},
|
||||
Subjects: []rbac.Subject{
|
||||
Subjects: []rbacv1.Subject{
|
||||
{
|
||||
Kind: "non-matching-kind",
|
||||
Namespace: "non-matching-ns",
|
||||
Name: "non-matching-name",
|
||||
},
|
||||
{
|
||||
Kind: rbac.ServiceAccountKind,
|
||||
Kind: rbacv1.ServiceAccountKind,
|
||||
Namespace: "velero",
|
||||
Name: "velero",
|
||||
},
|
||||
},
|
||||
RoleRef: rbac.RoleRef{
|
||||
RoleRef: rbacv1.RoleRef{
|
||||
Name: "role-2",
|
||||
},
|
||||
},
|
||||
@@ -313,14 +313,14 @@ func TestServiceAccountActionExecute(t *testing.T) {
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "crb-3",
|
||||
},
|
||||
Subjects: []rbac.Subject{
|
||||
Subjects: []rbacv1.Subject{
|
||||
{
|
||||
Kind: rbac.ServiceAccountKind,
|
||||
Kind: rbacv1.ServiceAccountKind,
|
||||
Namespace: "velero",
|
||||
Name: "velero",
|
||||
},
|
||||
},
|
||||
RoleRef: rbac.RoleRef{
|
||||
RoleRef: rbacv1.RoleRef{
|
||||
Name: "role-3",
|
||||
},
|
||||
},
|
||||
@@ -328,9 +328,9 @@ func TestServiceAccountActionExecute(t *testing.T) {
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "crb-4",
|
||||
},
|
||||
Subjects: []rbac.Subject{
|
||||
Subjects: []rbacv1.Subject{
|
||||
{
|
||||
Kind: rbac.ServiceAccountKind,
|
||||
Kind: rbacv1.ServiceAccountKind,
|
||||
Namespace: "velero",
|
||||
Name: "velero",
|
||||
},
|
||||
@@ -340,7 +340,7 @@ func TestServiceAccountActionExecute(t *testing.T) {
|
||||
Name: "non-matching-name",
|
||||
},
|
||||
},
|
||||
RoleRef: rbac.RoleRef{
|
||||
RoleRef: rbacv1.RoleRef{
|
||||
Name: "role-4",
|
||||
},
|
||||
},
|
||||
|
||||
+10
-10
@@ -35,7 +35,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
@@ -1399,12 +1399,12 @@ func TestBackupItemActionsForSkippedPV(t *testing.T) {
|
||||
builder.ForPersistentVolume("pv-1").StorageClass("gp2").Result(),
|
||||
),
|
||||
test.PVCs(
|
||||
builder.ForPersistentVolumeClaim("ns-1", "pvc-1").VolumeName("pv-1").StorageClass("gp2").Phase(corev1.ClaimBound).Result(),
|
||||
builder.ForPersistentVolumeClaim("ns-1", "pvc-1").VolumeName("pv-1").StorageClass("gp2").Phase(corev1api.ClaimBound).Result(),
|
||||
),
|
||||
},
|
||||
runtimeResources: []runtime.Object{
|
||||
builder.ForPersistentVolume("pv-1").StorageClass("gp2").Result(),
|
||||
builder.ForPersistentVolumeClaim("ns-1", "pvc-1").VolumeName("pv-1").StorageClass("gp2").Phase(corev1.ClaimBound).Result(),
|
||||
builder.ForPersistentVolumeClaim("ns-1", "pvc-1").VolumeName("pv-1").StorageClass("gp2").Phase(corev1api.ClaimBound).Result(),
|
||||
},
|
||||
actions: []*recordResourcesAction{
|
||||
new(recordResourcesAction).WithName(csiBIAPluginName).ForNamespace("ns-1").ForResource("persistentvolumeclaims").WithSkippedCSISnapshotFlag(true),
|
||||
@@ -1433,11 +1433,11 @@ func TestBackupItemActionsForSkippedPV(t *testing.T) {
|
||||
},
|
||||
apiResources: []*test.APIResource{
|
||||
test.PVCs(
|
||||
builder.ForPersistentVolumeClaim("ns-1", "pvc-1").VolumeName("pv-1").Phase(corev1.ClaimBound).Result(),
|
||||
builder.ForPersistentVolumeClaim("ns-1", "pvc-1").VolumeName("pv-1").Phase(corev1api.ClaimBound).Result(),
|
||||
),
|
||||
},
|
||||
runtimeResources: []runtime.Object{
|
||||
builder.ForPersistentVolumeClaim("ns-1", "pvc-1").VolumeName("pv-1").Phase(corev1.ClaimBound).Result(),
|
||||
builder.ForPersistentVolumeClaim("ns-1", "pvc-1").VolumeName("pv-1").Phase(corev1api.ClaimBound).Result(),
|
||||
builder.ForPersistentVolume("pv-1").StorageClass("gp2").Result(),
|
||||
},
|
||||
actions: []*recordResourcesAction{
|
||||
@@ -4014,7 +4014,7 @@ type fakePodVolumeBackupper struct {
|
||||
|
||||
// BackupPodVolumes returns one pod volume backup per entry in volumes, with namespace "velero"
|
||||
// and name "pvb-<pod-namespace>-<pod-name>-<volume-name>".
|
||||
func (b *fakePodVolumeBackupper) BackupPodVolumes(backup *velerov1.Backup, pod *corev1.Pod, volumes []string, _ *resourcepolicies.Policies, _ logrus.FieldLogger) ([]*velerov1.PodVolumeBackup, *podvolume.PVCBackupSummary, []error) {
|
||||
func (b *fakePodVolumeBackupper) BackupPodVolumes(backup *velerov1.Backup, pod *corev1api.Pod, volumes []string, _ *resourcepolicies.Policies, _ logrus.FieldLogger) ([]*velerov1.PodVolumeBackup, *podvolume.PVCBackupSummary, []error) {
|
||||
var res []*velerov1.PodVolumeBackup
|
||||
pvcSummary := podvolume.NewPVCBackupSummary()
|
||||
|
||||
@@ -4064,7 +4064,7 @@ func TestBackupWithPodVolume(t *testing.T) {
|
||||
name string
|
||||
backup *velerov1.Backup
|
||||
apiResources []*test.APIResource
|
||||
pod *corev1.Pod
|
||||
pod *corev1api.Pod
|
||||
vsl *velerov1.VolumeSnapshotLocation
|
||||
snapshotterGetter volumeSnapshotterGetter
|
||||
want []*velerov1.PodVolumeBackup
|
||||
@@ -4076,10 +4076,10 @@ func TestBackupWithPodVolume(t *testing.T) {
|
||||
test.Pods(
|
||||
builder.ForPod("ns-1", "pod-1").
|
||||
ObjectMeta(builder.WithAnnotations("backup.velero.io/backup-volumes", "foo")).
|
||||
Volumes(&corev1.Volume{
|
||||
Volumes(&corev1api.Volume{
|
||||
Name: "foo",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
|
||||
VolumeSource: corev1api.VolumeSource{
|
||||
PersistentVolumeClaim: &corev1api.PersistentVolumeClaimVolumeSource{
|
||||
ClaimName: "foo",
|
||||
},
|
||||
},
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
corev1api "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@@ -155,7 +155,7 @@ func TestItemCollectorBackupNamespaces(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
ie *collections.IncludesExcludes
|
||||
namespaces []*corev1.Namespace
|
||||
namespaces []*corev1api.Namespace
|
||||
backup *velerov1api.Backup
|
||||
expectedTrackedNS []string
|
||||
}{
|
||||
@@ -163,7 +163,7 @@ func TestItemCollectorBackupNamespaces(t *testing.T) {
|
||||
name: "ns filter by namespace IE filter",
|
||||
backup: builder.ForBackup("velero", "backup").Result(),
|
||||
ie: collections.NewIncludesExcludes().Includes("ns1"),
|
||||
namespaces: []*corev1.Namespace{
|
||||
namespaces: []*corev1api.Namespace{
|
||||
builder.ForNamespace("ns1").Result(),
|
||||
builder.ForNamespace("ns2").Result(),
|
||||
},
|
||||
@@ -175,7 +175,7 @@ func TestItemCollectorBackupNamespaces(t *testing.T) {
|
||||
MatchLabels: map[string]string{"name": "ns1"},
|
||||
}).Result(),
|
||||
ie: collections.NewIncludesExcludes().Includes("*"),
|
||||
namespaces: []*corev1.Namespace{
|
||||
namespaces: []*corev1api.Namespace{
|
||||
builder.ForNamespace("ns1").ObjectMeta(builder.WithLabels("name", "ns1")).Result(),
|
||||
builder.ForNamespace("ns2").Result(),
|
||||
},
|
||||
@@ -187,7 +187,7 @@ func TestItemCollectorBackupNamespaces(t *testing.T) {
|
||||
{MatchLabels: map[string]string{"name": "ns1"}},
|
||||
}).Result(),
|
||||
ie: collections.NewIncludesExcludes().Includes("*"),
|
||||
namespaces: []*corev1.Namespace{
|
||||
namespaces: []*corev1api.Namespace{
|
||||
builder.ForNamespace("ns1").ObjectMeta(builder.WithLabels("name", "ns1")).Result(),
|
||||
builder.ForNamespace("ns2").Result(),
|
||||
},
|
||||
@@ -199,7 +199,7 @@ func TestItemCollectorBackupNamespaces(t *testing.T) {
|
||||
MatchLabels: map[string]string{"name": "ns1"},
|
||||
}).Result(),
|
||||
ie: collections.NewIncludesExcludes().Excludes("ns1"),
|
||||
namespaces: []*corev1.Namespace{
|
||||
namespaces: []*corev1api.Namespace{
|
||||
builder.ForNamespace("ns1").ObjectMeta(builder.WithLabels("name", "ns1")).Result(),
|
||||
builder.ForNamespace("ns2").Result(),
|
||||
},
|
||||
@@ -211,7 +211,7 @@ func TestItemCollectorBackupNamespaces(t *testing.T) {
|
||||
{MatchLabels: map[string]string{"name": "ns1"}},
|
||||
}).Result(),
|
||||
ie: collections.NewIncludesExcludes().Excludes("ns1", "ns2"),
|
||||
namespaces: []*corev1.Namespace{
|
||||
namespaces: []*corev1api.Namespace{
|
||||
builder.ForNamespace("ns1").ObjectMeta(builder.WithLabels("name", "ns1")).Result(),
|
||||
builder.ForNamespace("ns2").Result(),
|
||||
builder.ForNamespace("ns3").Result(),
|
||||
@@ -222,7 +222,7 @@ func TestItemCollectorBackupNamespaces(t *testing.T) {
|
||||
name: "No ns filters",
|
||||
backup: builder.ForBackup("velero", "backup").Result(),
|
||||
ie: collections.NewIncludesExcludes().Includes("*"),
|
||||
namespaces: []*corev1.Namespace{
|
||||
namespaces: []*corev1api.Namespace{
|
||||
builder.ForNamespace("ns1").ObjectMeta(builder.WithLabels("name", "ns1")).Result(),
|
||||
builder.ForNamespace("ns2").Result(),
|
||||
},
|
||||
@@ -232,7 +232,7 @@ func TestItemCollectorBackupNamespaces(t *testing.T) {
|
||||
name: "ns specified by the IncludeNamespaces cannot be found",
|
||||
backup: builder.ForBackup("velero", "backup").IncludedNamespaces("ns1", "invalid", "*").Result(),
|
||||
ie: collections.NewIncludesExcludes().Includes("ns1", "invalid", "*"),
|
||||
namespaces: []*corev1.Namespace{
|
||||
namespaces: []*corev1api.Namespace{
|
||||
builder.ForNamespace("ns1").ObjectMeta(builder.WithLabels("name", "ns1")).Result(),
|
||||
builder.ForNamespace("ns2").Result(),
|
||||
builder.ForNamespace("ns3").Result(),
|
||||
|
||||
Reference in New Issue
Block a user