Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[oadp-1.2] OADP-639: Pass custom CA configuration to volsync #958

25 changes: 19 additions & 6 deletions controllers/datamover.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
const (
ResticPassword = "RESTIC_PASSWORD"
ResticRepository = "RESTIC_REPOSITORY"
ResticCustomCAKey = "RESTIC_CUSTOM_CA"
ResticsecretName = "dm-credential"
ResticPruneInterval = "restic-prune-interval"

Expand Down Expand Up @@ -393,6 +394,7 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
pruneInterval = strings.ReplaceAll(pruneInterval, `"`, "")
pruneInterval = strings.ReplaceAll(pruneInterval, `'`, "")
}
resticCustomCA := bsl.Spec.ObjectStorage.CACert
rsecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-volsync-restic", bsl.Name),
Expand All @@ -412,7 +414,7 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
return err
}

return r.buildDataMoverResticSecretForAWS(rsecret, key, secret, bsl.Spec.Config[Region], pass, repo, pruneInterval)
return r.buildDataMoverResticSecretForAWS(rsecret, key, secret, bsl.Spec.Config[Region], pass, repo, pruneInterval, resticCustomCA)
})

if err != nil {
Expand Down Expand Up @@ -463,6 +465,7 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
if len(dpa.Spec.Features.DataMover.PruneInterval) > 0 {
pruneInterval = dpa.Spec.Features.DataMover.PruneInterval
}
resticCustomCA := bsl.Spec.ObjectStorage.CACert
// We are done with checks no lets create the azure dm secret
rsecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -483,7 +486,7 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
return err
}

return r.buildDataMoverResticSecretForAzure(rsecret, accountName, accountKey, pass, repo, pruneInterval)
return r.buildDataMoverResticSecretForAzure(rsecret, accountName, accountKey, pass, repo, pruneInterval, resticCustomCA)
})

if err != nil {
Expand Down Expand Up @@ -519,6 +522,7 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
if len(dpa.Spec.Features.DataMover.PruneInterval) > 0 {
pruneInterval = dpa.Spec.Features.DataMover.PruneInterval
}
resticCustomCA := bsl.Spec.ObjectStorage.CACert
// We are done with checks no lets create the gcp dm secret
rsecret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -539,7 +543,7 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
return err
}

return r.buildDataMoverResticSecretForGCP(rsecret, gcpcreds.googleApplicationCredentials, pass, repo, pruneInterval)
return r.buildDataMoverResticSecretForGCP(rsecret, gcpcreds.googleApplicationCredentials, pass, repo, pruneInterval, resticCustomCA)
})

if err != nil {
Expand All @@ -560,7 +564,7 @@ func (r *DPAReconciler) createResticSecretsPerBSL(dpa *oadpv1alpha1.DataProtecti
}

//build data mover restic secret for given aws bsl
func (r *DPAReconciler) buildDataMoverResticSecretForAWS(rsecret *corev1.Secret, key string, secret string, region string, pass []byte, repo string, pruneInterval string) error {
func (r *DPAReconciler) buildDataMoverResticSecretForAWS(rsecret *corev1.Secret, key string, secret string, region string, pass []byte, repo string, pruneInterval string, resticCustomCA []byte) error {

// TODO: add gcp, azure support
rData := &corev1.Secret{
Expand All @@ -573,12 +577,15 @@ func (r *DPAReconciler) buildDataMoverResticSecretForAWS(rsecret *corev1.Secret,
ResticPruneInterval: []byte(pruneInterval),
},
}
if len(resticCustomCA) > 0 {
rData.Data[ResticCustomCAKey] = resticCustomCA
}
rsecret.Data = rData.Data
return nil
}

//build data mover restic secret for given bsl
func (r *DPAReconciler) buildDataMoverResticSecretForAzure(rsecret *corev1.Secret, accountName string, accountKey string, pass []byte, repo string, pruneInterval string) error {
func (r *DPAReconciler) buildDataMoverResticSecretForAzure(rsecret *corev1.Secret, accountName string, accountKey string, pass []byte, repo string, pruneInterval string, resticCustomCA []byte) error {

rData := &corev1.Secret{
Data: map[string][]byte{
Expand All @@ -589,12 +596,15 @@ func (r *DPAReconciler) buildDataMoverResticSecretForAzure(rsecret *corev1.Secre
ResticPruneInterval: []byte(pruneInterval),
},
}
if len(resticCustomCA) > 0 {
rData.Data[ResticCustomCAKey] = resticCustomCA
}
rsecret.Data = rData.Data
return nil
}

//build data mover restic secret for given gcp bsl
func (r *DPAReconciler) buildDataMoverResticSecretForGCP(rsecret *corev1.Secret, googleApplicationCredentials string, pass []byte, repo string, pruneInterval string) error {
func (r *DPAReconciler) buildDataMoverResticSecretForGCP(rsecret *corev1.Secret, googleApplicationCredentials string, pass []byte, repo string, pruneInterval string, resticCustomCA []byte) error {

rData := &corev1.Secret{
Data: map[string][]byte{
Expand All @@ -604,6 +614,9 @@ func (r *DPAReconciler) buildDataMoverResticSecretForGCP(rsecret *corev1.Secret,
ResticPruneInterval: []byte(pruneInterval),
},
}
if len(resticCustomCA) > 0 {
rData.Data[ResticCustomCAKey] = resticCustomCA
}
rsecret.Data = rData.Data
return nil
}
Expand Down