Skip to content

Commit

Permalink
Add OCM backup label to hub config map
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Gershkovich <elenage@il.ibm.com>
  • Loading branch information
ELENAGER authored and ShyamsundarR committed Jul 17, 2023
1 parent 015ae96 commit 372456d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions config/hub/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ resources:

generatorOptions:
disableNameSuffixHash: true
labels:
cluster.open-cluster-management.io/backup: resource

configMapGenerator:
- files:
Expand Down
10 changes: 10 additions & 0 deletions controllers/drpolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,16 @@ func (r *DRPolicyReconciler) configMapMapFunc(configMap client.Object) []reconci
return []reconcile.Request{}
}

labelAdded := util.AddLabel(configMap, util.OCMBackupLabelKey, util.OCMBackupLabelValue)

if labelAdded {
if err := r.Update(context.TODO(), configMap); err != nil {
r.Log.Error(err, "Failed to add OCM backup label to ramen-hub-operator-config map")

return []reconcile.Request{}
}
}

drpolicies := &ramen.DRPolicyList{}
if err := r.Client.List(context.TODO(), drpolicies); err != nil {
return []reconcile.Request{}
Expand Down
22 changes: 19 additions & 3 deletions controllers/ramenconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,32 @@ import (
. "github.com/onsi/gomega"
ramen "github.com/ramendr/ramen/api/v1alpha1"
"github.com/ramendr/ramen/controllers"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/yaml"
)

func configMapUpdate() {
ramenConfigYaml, err := yaml.Marshal(ramenConfig)
Expect(err).To(Succeed())
Expect(err).NotTo(HaveOccurred())

configMap.Data[controllers.ConfigMapRamenConfigKeyName] = string(ramenConfigYaml)
retryErr := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
key := types.NamespacedName{
Namespace: ramenNamespace,
Name: controllers.HubOperatorConfigMapName,
}

Expect(k8sClient.Update(context.TODO(), configMap)).To(Succeed())
err := k8sClient.Get(context.TODO(), key, configMap)
if err != nil {
return err
}

configMap.Data[controllers.ConfigMapRamenConfigKeyName] = string(ramenConfigYaml)

return k8sClient.Update(context.TODO(), configMap)
})

Expect(retryErr).NotTo(HaveOccurred())
}

func s3ProfilesStore(s3Profiles []ramen.S3StoreProfile) {
Expand Down
2 changes: 2 additions & 0 deletions ramenctl/ramenctl/resources/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
labels:
cluster.open-cluster-management.io/backup: resource
name: ramen-hub-operator-config
namespace: ramen-system
data:
Expand Down

0 comments on commit 372456d

Please sign in to comment.