Skip to content

Commit cea8221

Browse files
authored
OADP-524, OADP-460 mtc operator type, noDefaultBackupLocation secret handling [1.0 cp] #701 #607 (#702)
* OADP-524 mtc operator type Enables alternative behavior when OADP is consumed by MTC * Remove unused comment. * Don't getProviderSecret when noDefaultBackupLocation: true, backupImages: false (#607) * Don't getProviderSecret when noDefaultBackupLocation flag set Signed-off-by: Tiger Kaovilai <[email protected]> * add check that when NoDefaultBackupLocation is set, dpa.Spec.BackupImages is false Use BackupImages functions when checking conditions * fix test case * remove duplicate test entry * test case name typo
1 parent dc1b87c commit cea8221

File tree

7 files changed

+420
-9
lines changed

7 files changed

+420
-9
lines changed

api/v1alpha1/oadp_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ const CSIPluginImageKey UnsupportedImageKey = "csiPluginImageFqin"
5656
const ResticRestoreImageKey UnsupportedImageKey = "resticRestoreImageFqin"
5757
const RegistryImageKey UnsupportedImageKey = "registryImageFqin"
5858
const KubeVirtPluginImageKey UnsupportedImageKey = "kubevirtPluginImageFqin"
59+
const OperatorTypeKey UnsupportedImageKey = "operator-type"
60+
61+
const OperatorTypeMTC = "mtc"
5962

6063
type VeleroConfig struct {
6164
// FeatureFlags defines the list of features to enable for Velero instance

controllers/validator.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ func (r *DPAReconciler) ValidateDataProtectionCR(log logr.Logger) (bool, error)
2828
}
2929
}
3030

31+
if dpa.Spec.Configuration.Velero.NoDefaultBackupLocation && dpa.BackupImages() {
32+
return false, errors.New("backupImages needs to be set to false when noDefaultLocationBackupLocation is set")
33+
}
34+
3135
if len(dpa.Spec.BackupLocations) > 0 {
3236
for _, location := range dpa.Spec.BackupLocations {
3337
// check for velero BSL config or cloud storage config
@@ -45,6 +49,10 @@ func (r *DPAReconciler) ValidateDataProtectionCR(log logr.Logger) (bool, error)
4549
}
4650
}
4751

52+
if val, found := dpa.Spec.UnsupportedOverrides[oadpv1alpha1.OperatorTypeKey]; found && val != oadpv1alpha1.OperatorTypeMTC {
53+
return false, errors.New("only mtc operator type override is supported")
54+
}
55+
4856
if _, err := r.ValidateVeleroPlugins(r.Log); err != nil {
4957
return false, err
5058
}
@@ -76,7 +84,7 @@ func (r *DPAReconciler) ValidateVeleroPlugins(log logr.Logger) (bool, error) {
7684
pluginNeedsCheck = true
7785
}
7886

79-
if ok && pluginSpecificMap.IsCloudProvider && pluginNeedsCheck {
87+
if ok && pluginSpecificMap.IsCloudProvider && pluginNeedsCheck && !dpa.Spec.Configuration.Velero.NoDefaultBackupLocation {
8088
secretName := pluginSpecificMap.SecretName
8189
_, err := r.getProviderSecret(secretName)
8290
if err != nil {

controllers/validator_test.go

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1111
"k8s.io/apimachinery/pkg/types"
1212
"k8s.io/client-go/tools/record"
13+
"k8s.io/utils/pointer"
1314
"sigs.k8s.io/controller-runtime/pkg/client"
1415
)
1516

@@ -22,7 +23,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
2223
wantErr bool
2324
}{
2425
{
25-
name: "given valid DPA CR, no error case",
26+
name: "given valid DPA CR, no default backup location, no backup images, no error case",
2627
dpa: &oadpv1alpha1.DataProtectionApplication{
2728
ObjectMeta: metav1.ObjectMeta{
2829
Name: "test-DPA-CR",
@@ -37,6 +38,33 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
3738
NoDefaultBackupLocation: true,
3839
},
3940
},
41+
BackupImages: pointer.Bool(false),
42+
},
43+
},
44+
objects: []client.Object{},
45+
wantErr: false,
46+
want: true,
47+
},
48+
{
49+
name: "given valid DPA CR, no default backup location, no backup images, MTC type override, no error case",
50+
dpa: &oadpv1alpha1.DataProtectionApplication{
51+
ObjectMeta: metav1.ObjectMeta{
52+
Name: "test-DPA-CR",
53+
Namespace: "test-ns",
54+
},
55+
Spec: oadpv1alpha1.DataProtectionApplicationSpec{
56+
Configuration: &oadpv1alpha1.ApplicationConfig{
57+
Velero: &oadpv1alpha1.VeleroConfig{
58+
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{
59+
oadpv1alpha1.DefaultPluginAWS,
60+
},
61+
NoDefaultBackupLocation: true,
62+
},
63+
},
64+
BackupImages: pointer.Bool(false),
65+
UnsupportedOverrides: map[oadpv1alpha1.UnsupportedImageKey]string{
66+
oadpv1alpha1.OperatorTypeKey: oadpv1alpha1.OperatorTypeMTC,
67+
},
4068
},
4169
},
4270
objects: []client.Object{
@@ -51,7 +79,62 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
5179
want: true,
5280
},
5381
{
54-
name: "given valid DPA CR, error case",
82+
name: "given valid DPA CR, no default backup location, no backup images, notMTC type override, error case",
83+
dpa: &oadpv1alpha1.DataProtectionApplication{
84+
ObjectMeta: metav1.ObjectMeta{
85+
Name: "test-DPA-CR",
86+
Namespace: "test-ns",
87+
},
88+
Spec: oadpv1alpha1.DataProtectionApplicationSpec{
89+
Configuration: &oadpv1alpha1.ApplicationConfig{
90+
Velero: &oadpv1alpha1.VeleroConfig{
91+
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{
92+
oadpv1alpha1.DefaultPluginAWS,
93+
},
94+
NoDefaultBackupLocation: true,
95+
},
96+
},
97+
BackupImages: pointer.Bool(false),
98+
UnsupportedOverrides: map[oadpv1alpha1.UnsupportedImageKey]string{
99+
oadpv1alpha1.OperatorTypeKey: "not" + oadpv1alpha1.OperatorTypeMTC,
100+
},
101+
},
102+
},
103+
objects: []client.Object{
104+
&corev1.Secret{
105+
ObjectMeta: metav1.ObjectMeta{
106+
Name: "cloud-credentials",
107+
Namespace: "test-ns",
108+
},
109+
},
110+
},
111+
wantErr: true,
112+
want: false,
113+
},
114+
{
115+
name: "given valid DPA CR, no default backup location, backup images cannot be nil, error case",
116+
dpa: &oadpv1alpha1.DataProtectionApplication{
117+
ObjectMeta: metav1.ObjectMeta{
118+
Name: "test-DPA-CR",
119+
Namespace: "test-ns",
120+
},
121+
Spec: oadpv1alpha1.DataProtectionApplicationSpec{
122+
Configuration: &oadpv1alpha1.ApplicationConfig{
123+
Velero: &oadpv1alpha1.VeleroConfig{
124+
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{
125+
oadpv1alpha1.DefaultPluginAWS,
126+
},
127+
NoDefaultBackupLocation: true,
128+
},
129+
},
130+
},
131+
},
132+
objects: []client.Object{},
133+
wantErr: true,
134+
want: false,
135+
},
136+
{
137+
name: "given valid DPA CR, no default backup location, backup images cannot be true, error case",
55138
dpa: &oadpv1alpha1.DataProtectionApplication{
56139
ObjectMeta: metav1.ObjectMeta{
57140
Name: "test-DPA-CR",
@@ -66,6 +149,7 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
66149
NoDefaultBackupLocation: true,
67150
},
68151
},
152+
BackupImages: pointer.Bool(true),
69153
},
70154
},
71155
objects: []client.Object{},

controllers/velero.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,10 +713,16 @@ func (r DPAReconciler) noDefaultCredentials(dpa oadpv1alpha1.DataProtectionAppli
713713
providerNeedsDefaultCreds := map[string]bool{}
714714
hasCloudStorage := false
715715
if dpa.Spec.Configuration.Velero.NoDefaultBackupLocation {
716+
needDefaultCred := false
717+
718+
if dpa.Spec.UnsupportedOverrides[oadpv1alpha1.OperatorTypeKey] == oadpv1alpha1.OperatorTypeMTC {
719+
// MTC requires default credentials
720+
needDefaultCred = true
721+
}
716722
// go through cloudprovider plugins and mark providerNeedsDefaultCreds to false
717723
for _, provider := range dpa.Spec.Configuration.Velero.DefaultPlugins {
718724
if psf, ok := credentials.PluginSpecificFields[provider]; ok && psf.IsCloudProvider {
719-
providerNeedsDefaultCreds[psf.PluginName] = false
725+
providerNeedsDefaultCreds[psf.PluginName] = needDefaultCred
720726
}
721727
}
722728
} else {
@@ -761,4 +767,3 @@ func (r DPAReconciler) noDefaultCredentials(dpa oadpv1alpha1.DataProtectionAppli
761767
return providerNeedsDefaultCreds, hasCloudStorage, nil
762768

763769
}
764-

0 commit comments

Comments
 (0)