mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-07-31 12:32:44 +00:00
create CRB with velero-<namespace> (#2886)
* create CRB with velero-<namespace> This will allow creating multiple instances of velero, across two different namespaces Signed-off-by: Alay Patel <alay1431@gmail.com> * add changelog Signed-off-by: Alay Patel <alay1431@gmail.com> * add package var DefaultVeleroNamespace and use it wherever needed Signed-off-by: Alay Patel <alay1431@gmail.com>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
cli: allow creating multiple instances of Velero across two different namespaces
|
||||
@@ -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(),
|
||||
|
||||
@@ -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"])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user