Skip to content

Commit da56630

Browse files
weshayutinkaovilai
andauthored
OADP-6500: allow nonadmin.enabled.false (#1897)
* OADP-6500: allow nonadmin.enabled.false Signed-off-by: Wesley Hayutin <[email protected]> * Update internal/controller/validator_test.go Co-authored-by: Tiger Kaovilai <[email protected]> --------- Signed-off-by: Wesley Hayutin <[email protected]> Co-authored-by: Tiger Kaovilai <[email protected]>
1 parent 517d614 commit da56630

File tree

2 files changed

+66
-27
lines changed

2 files changed

+66
-27
lines changed

internal/controller/validator.go

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -136,36 +136,32 @@ func (r *DataProtectionApplicationReconciler) ValidateDataProtectionCR(log logr.
136136
}
137137

138138
// validate non-admin enable
139-
if r.dpa.Spec.NonAdmin != nil {
140-
if r.dpa.Spec.NonAdmin.Enable != nil {
141-
142-
dpaList := &oadpv1alpha1.DataProtectionApplicationList{}
143-
err = r.ClusterWideClient.List(r.Context, dpaList)
144-
if err != nil {
145-
return false, err
146-
}
147-
for _, dpa := range dpaList.Items {
148-
if dpa.Namespace != r.NamespacedName.Namespace && (&DataProtectionApplicationReconciler{dpa: &dpa}).checkNonAdminEnabled() {
149-
nonAdminDeployment := &appsv1.Deployment{
150-
ObjectMeta: metav1.ObjectMeta{
151-
Name: nonAdminObjectName,
152-
Namespace: dpa.Namespace,
153-
},
154-
}
155-
if err := r.ClusterWideClient.Get(
156-
r.Context,
157-
types.NamespacedName{
158-
Name: nonAdminDeployment.Name,
159-
Namespace: nonAdminDeployment.Namespace,
160-
},
161-
nonAdminDeployment,
162-
); err == nil {
163-
return false, fmt.Errorf("only a single instance of Non-Admin Controller can be installed across the entire cluster. Non-Admin controller is already configured and installed in %s namespace", dpa.Namespace)
164-
}
139+
if r.checkNonAdminEnabled() {
140+
dpaList := &oadpv1alpha1.DataProtectionApplicationList{}
141+
err = r.ClusterWideClient.List(r.Context, dpaList)
142+
if err != nil {
143+
return false, err
144+
}
145+
for _, dpa := range dpaList.Items {
146+
if dpa.Namespace != r.NamespacedName.Namespace && (&DataProtectionApplicationReconciler{dpa: &dpa}).checkNonAdminEnabled() {
147+
nonAdminDeployment := &appsv1.Deployment{
148+
ObjectMeta: metav1.ObjectMeta{
149+
Name: nonAdminObjectName,
150+
Namespace: dpa.Namespace,
151+
},
152+
}
153+
if err := r.ClusterWideClient.Get(
154+
r.Context,
155+
types.NamespacedName{
156+
Name: nonAdminDeployment.Name,
157+
Namespace: nonAdminDeployment.Namespace,
158+
},
159+
nonAdminDeployment,
160+
); err == nil {
161+
return false, fmt.Errorf("only a single instance of Non-Admin Controller can be installed across the entire cluster. Non-Admin controller is already configured and installed in %s namespace", dpa.Namespace)
165162
}
166163
}
167164
}
168-
169165
garbageCollectionPeriod := r.dpa.Spec.NonAdmin.GarbageCollectionPeriod
170166
appliedGarbageCollectionPeriod := oadpv1alpha1.DefaultGarbageCollectionPeriod
171167
if garbageCollectionPeriod != nil {

internal/controller/validator_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,49 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
15071507
wantErr: true,
15081508
messageErr: "only a single instance of Non-Admin Controller can be installed across the entire cluster. Non-Admin controller is already configured and installed in test-another-ns namespace",
15091509
},
1510+
{
1511+
name: "[valid] DPA CR: NonAdmin.Enable is true with another DPA having NonAdmin.Enable false",
1512+
dpa: &oadpv1alpha1.DataProtectionApplication{
1513+
ObjectMeta: metav1.ObjectMeta{
1514+
Name: "test-DPA-CR",
1515+
Namespace: "test-ns",
1516+
},
1517+
Spec: oadpv1alpha1.DataProtectionApplicationSpec{
1518+
NonAdmin: &oadpv1alpha1.NonAdmin{
1519+
Enable: pointer.Bool(true),
1520+
},
1521+
Configuration: &oadpv1alpha1.ApplicationConfig{
1522+
Velero: &oadpv1alpha1.VeleroConfig{
1523+
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{
1524+
oadpv1alpha1.DefaultPluginAWS,
1525+
},
1526+
NoDefaultBackupLocation: true,
1527+
},
1528+
},
1529+
BackupImages: pointer.Bool(false),
1530+
},
1531+
},
1532+
objects: []client.Object{
1533+
&oadpv1alpha1.DataProtectionApplication{
1534+
ObjectMeta: metav1.ObjectMeta{
1535+
Name: "another-DPA-CR",
1536+
Namespace: "test-another-ns",
1537+
},
1538+
Spec: oadpv1alpha1.DataProtectionApplicationSpec{
1539+
NonAdmin: &oadpv1alpha1.NonAdmin{
1540+
Enable: pointer.Bool(false),
1541+
},
1542+
},
1543+
},
1544+
&appsv1.Deployment{
1545+
ObjectMeta: metav1.ObjectMeta{
1546+
Name: "non-admin-controller",
1547+
Namespace: "test-another-ns",
1548+
},
1549+
},
1550+
},
1551+
wantErr: false,
1552+
},
15101553
{
15111554
name: "given invalid DPA CR aws and legacy-aws plugins both specified",
15121555
dpa: &oadpv1alpha1.DataProtectionApplication{

0 commit comments

Comments
 (0)