Skip to content

Commit

Permalink
OADP-524 mtc operator type (#701)
Browse files Browse the repository at this point in the history
* OADP-524 mtc operator type

Enables alternative behavior when OADP is consumed by MTC

* error case test name typo
  • Loading branch information
kaovilai authored May 18, 2022
1 parent 185151e commit b64e96e
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 5 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/oadp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ const CSIPluginImageKey UnsupportedImageKey = "csiPluginImageFqin"
const ResticRestoreImageKey UnsupportedImageKey = "resticRestoreImageFqin"
const RegistryImageKey UnsupportedImageKey = "registryImageFqin"
const KubeVirtPluginImageKey UnsupportedImageKey = "kubevirtPluginImageFqin"
const OperatorTypeKey UnsupportedImageKey = "operator-type"

const OperatorTypeMTC = "mtc"

type VeleroConfig struct {
// FeatureFlags defines the list of features to enable for Velero instance
Expand Down
4 changes: 4 additions & 0 deletions controllers/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (r *DPAReconciler) ValidateDataProtectionCR(log logr.Logger) (bool, error)
}
}

if val, found := dpa.Spec.UnsupportedOverrides[oadpv1alpha1.OperatorTypeKey]; found && val != oadpv1alpha1.OperatorTypeMTC {
return false, errors.New("only mtc operator type override is supported")
}

if _, err := r.ValidateVeleroPlugins(r.Log); err != nil {
return false, err
}
Expand Down
52 changes: 52 additions & 0 deletions controllers/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,58 @@ func TestDPAReconciler_ValidateDataProtectionCR(t *testing.T) {
wantErr: false,
want: true,
},
{
name: "given valid DPA CR, no default backup location, no backup images, MTC type override, no error case",
dpa: &oadpv1alpha1.DataProtectionApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "test-DPA-CR",
Namespace: "test-ns",
},
Spec: oadpv1alpha1.DataProtectionApplicationSpec{
Configuration: &oadpv1alpha1.ApplicationConfig{
Velero: &oadpv1alpha1.VeleroConfig{
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{
oadpv1alpha1.DefaultPluginAWS,
},
NoDefaultBackupLocation: true,
},
},
BackupImages: pointer.Bool(false),
UnsupportedOverrides: map[oadpv1alpha1.UnsupportedImageKey]string{
oadpv1alpha1.OperatorTypeKey: oadpv1alpha1.OperatorTypeMTC,
},
},
},
objects: []client.Object{},
wantErr: false,
want: true,
},
{
name: "given valid DPA CR, no default backup location, no backup images, notMTC type override, error case",
dpa: &oadpv1alpha1.DataProtectionApplication{
ObjectMeta: metav1.ObjectMeta{
Name: "test-DPA-CR",
Namespace: "test-ns",
},
Spec: oadpv1alpha1.DataProtectionApplicationSpec{
Configuration: &oadpv1alpha1.ApplicationConfig{
Velero: &oadpv1alpha1.VeleroConfig{
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{
oadpv1alpha1.DefaultPluginAWS,
},
NoDefaultBackupLocation: true,
},
},
BackupImages: pointer.Bool(false),
UnsupportedOverrides: map[oadpv1alpha1.UnsupportedImageKey]string{
oadpv1alpha1.OperatorTypeKey: "not" + oadpv1alpha1.OperatorTypeMTC,
},
},
},
objects: []client.Object{},
wantErr: true,
want: false,
},
{
name: "given valid DPA CR, no default backup location, backup images cannot be nil, error case",
dpa: &oadpv1alpha1.DataProtectionApplication{
Expand Down
8 changes: 7 additions & 1 deletion controllers/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,16 @@ func (r DPAReconciler) noDefaultCredentials(dpa oadpv1alpha1.DataProtectionAppli
providerNeedsDefaultCreds := map[string]bool{}
hasCloudStorage := false
if dpa.Spec.Configuration.Velero.NoDefaultBackupLocation {
needDefaultCred := false

if dpa.Spec.UnsupportedOverrides[oadpv1alpha1.OperatorTypeKey] == oadpv1alpha1.OperatorTypeMTC {
// MTC requires default credentials
needDefaultCred = true
}
// go through cloudprovider plugins and mark providerNeedsDefaultCreds to false
for _, provider := range dpa.Spec.Configuration.Velero.DefaultPlugins {
if psf, ok := credentials.PluginSpecificFields[provider]; ok && psf.IsCloudProvider {
providerNeedsDefaultCreds[psf.PluginName] = false
providerNeedsDefaultCreds[psf.PluginName] = needDefaultCred
}
}
} else {
Expand Down
Loading

0 comments on commit b64e96e

Please sign in to comment.