Skip to content

Commit

Permalink
Add DRPolicy query helper functions to util package
Browse files Browse the repository at this point in the history
  • Loading branch information
Veera Deenadhayalan authored and ShyamsundarR committed Aug 11, 2021
1 parent be9ad83 commit 97b01e1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 38 deletions.
36 changes: 0 additions & 36 deletions api/v1alpha1/drpolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,3 @@ type DRPolicyList struct {
func init() {
SchemeBuilder.Register(&DRPolicy{}, &DRPolicyList{})
}

// Return a list of unique S3 profiles to upload the relevant cluster state of
// the given home cluster
func (d *DRPolicy) S3UploadProfileList(homeCluster string) (s3ProfileList []string) {
for _, drCluster := range d.Spec.DRClusterSet {
if drCluster.Name != homeCluster {
// This drCluster is not the home cluster and is hence, a candidate to
// upload cluster state to if this S3 profile is not already on the list.
found := false

for _, s3ProfileName := range s3ProfileList {
if s3ProfileName == drCluster.S3ProfileName {
found = true
}
}

if !found {
s3ProfileList = append(s3ProfileList, drCluster.S3ProfileName)
}
}
}

return
}

// Return the S3 profile to download the relevant cluster state to the given
// home cluster
func (d *DRPolicy) S3DownloadProfile(homeCluster string) (s3Profile string) {
for _, drCluster := range d.Spec.DRClusterSet {
if drCluster.Name == homeCluster {
s3Profile = drCluster.S3ProfileName
}
}

return
}
2 changes: 1 addition & 1 deletion controllers/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ func (d *DRPCInstance) listPVsFromS3Store(homeCluster string) ([]corev1.Persiste
s3Bucket := constructBucketName(d.instance.Namespace, d.instance.Name)

return d.reconciler.PVDownloader.DownloadPVs(
d.ctx, d.reconciler.Client, d.reconciler.ObjStoreGetter, d.drPolicy.S3DownloadProfile(homeCluster),
d.ctx, d.reconciler.Client, d.reconciler.ObjStoreGetter, rmnutil.S3DownloadProfile(*d.drPolicy, homeCluster),
d.instance.Name, s3Bucket)
}

Expand Down
57 changes: 57 additions & 0 deletions controllers/util/drpolicy_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2021 The RamenDR authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package util

import (
rmn "github.com/ramendr/ramen/api/v1alpha1"
)

// Return a list of unique S3 profiles to upload the relevant cluster state of
// the given home cluster
func s3UploadProfileList(drPolicy rmn.DRPolicy, homeCluster string) (s3ProfileList []string) {
for _, drCluster := range drPolicy.Spec.DRClusterSet {
if drCluster.Name != homeCluster {
// This drCluster is not the home cluster and is hence, a candidate to
// upload cluster state to if this S3 profile is not already on the list.
found := false

for _, s3ProfileName := range s3ProfileList {
if s3ProfileName == drCluster.S3ProfileName {
found = true
}
}

if !found {
s3ProfileList = append(s3ProfileList, drCluster.S3ProfileName)
}
}
}

return
}

// Return the S3 profile to download the relevant cluster state to the given
// home cluster
func S3DownloadProfile(drPolicy rmn.DRPolicy, homeCluster string) (s3Profile string) {
for _, drCluster := range drPolicy.Spec.DRClusterSet {
if drCluster.Name == homeCluster {
s3Profile = drCluster.S3ProfileName
}
}

return
}
2 changes: 1 addition & 1 deletion controllers/util/mw_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func IsManifestInAppliedState(mw *ocmworkv1.ManifestWork) bool {
func (mwu *MWUtil) CreateOrUpdateVRGManifestWork(
name, namespace, homeCluster string,
drPolicy *rmn.DRPolicy, pvcSelector metav1.LabelSelector) error {
s3ProfileList := drPolicy.S3UploadProfileList(homeCluster)
s3ProfileList := s3UploadProfileList(*drPolicy, homeCluster)
schedulingInterval := drPolicy.Spec.SchedulingInterval
replClassSelector := drPolicy.Spec.ReplicationClassSelector

Expand Down

0 comments on commit 97b01e1

Please sign in to comment.