diff --git a/changelogs/unreleased/2886-alaypatel07 b/changelogs/unreleased/2886-alaypatel07 new file mode 100644 index 000000000..8eb9705f8 --- /dev/null +++ b/changelogs/unreleased/2886-alaypatel07 @@ -0,0 +1 @@ +cli: allow creating multiple instances of Velero across two different namespaces \ No newline at end of file diff --git a/pkg/install/resources.go b/pkg/install/resources.go index cbf78c5a4..9ea7ccbaf 100644 --- a/pkg/install/resources.go +++ b/pkg/install/resources.go @@ -51,6 +51,7 @@ var ( DefaultResticPodMemRequest = "512Mi" DefaultResticPodCPULimit = "1000m" DefaultResticPodMemLimit = "1Gi" + DefaultVeleroNamespace = "velero" ) func labels() map[string]string { @@ -105,8 +106,12 @@ func ServiceAccount(namespace string, annotations map[string]string) *corev1.Ser } func ClusterRoleBinding(namespace string) *rbacv1beta1.ClusterRoleBinding { + crbName := "velero" + if namespace != DefaultVeleroNamespace { + crbName = "velero-" + namespace + } crb := &rbacv1beta1.ClusterRoleBinding{ - ObjectMeta: objectMeta("", "velero"), + ObjectMeta: objectMeta("", crbName), TypeMeta: metav1.TypeMeta{ Kind: "ClusterRoleBinding", APIVersion: rbacv1beta1.SchemeGroupVersion.String(), diff --git a/pkg/install/resources_test.go b/pkg/install/resources_test.go index e2c296493..748d70def 100644 --- a/pkg/install/resources_test.go +++ b/pkg/install/resources_test.go @@ -23,7 +23,7 @@ import ( ) func TestResources(t *testing.T) { - bsl := BackupStorageLocation("velero", "test", "test", "", make(map[string]string), []byte("test")) + bsl := BackupStorageLocation(DefaultVeleroNamespace, "test", "test", "", make(map[string]string), []byte("test")) assert.Equal(t, "velero", bsl.ObjectMeta.Namespace) assert.Equal(t, "test", bsl.Spec.Provider) @@ -31,7 +31,7 @@ func TestResources(t *testing.T) { assert.Equal(t, make(map[string]string), bsl.Spec.Config) assert.Equal(t, []byte("test"), bsl.Spec.ObjectStorage.CACert) - vsl := VolumeSnapshotLocation("velero", "test", make(map[string]string)) + vsl := VolumeSnapshotLocation(DefaultVeleroNamespace, "test", make(map[string]string)) assert.Equal(t, "velero", vsl.ObjectMeta.Namespace) assert.Equal(t, "test", vsl.Spec.Provider) @@ -41,12 +41,19 @@ func TestResources(t *testing.T) { assert.Equal(t, "velero", ns.Name) - crb := ClusterRoleBinding("velero") + crb := ClusterRoleBinding(DefaultVeleroNamespace) // The CRB is a cluster-scoped resource assert.Equal(t, "", crb.ObjectMeta.Namespace) + assert.Equal(t, "velero", crb.ObjectMeta.Name) assert.Equal(t, "velero", crb.Subjects[0].Namespace) - sa := ServiceAccount("velero", map[string]string{"abcd": "cbd"}) + customNamespaceCRB := ClusterRoleBinding("foo") + // The CRB is a cluster-scoped resource + assert.Equal(t, "", customNamespaceCRB.ObjectMeta.Namespace) + assert.Equal(t, "velero-foo", customNamespaceCRB.ObjectMeta.Name) + assert.Equal(t, "foo", customNamespaceCRB.Subjects[0].Namespace) + + sa := ServiceAccount(DefaultVeleroNamespace, map[string]string{"abcd": "cbd"}) assert.Equal(t, "velero", sa.ObjectMeta.Namespace) assert.Equal(t, "cbd", sa.ObjectMeta.Annotations["abcd"]) }