Skip to content

Commit

Permalink
Adds hub recovery labels on blue secrets
Browse files Browse the repository at this point in the history
Adds label changes to managedcluster agent where they will
add hub recovery label by default onto any source secret

Signed-off-by: vbadrina <[email protected]>
  • Loading branch information
vbnrh committed Mar 6, 2024
1 parent aa8736b commit 76fb4c7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion addons/token-exchange/rook_secret_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/red-hat-storage/odf-multicluster-orchestrator/addons/setup"
"reflect"
"testing"
"time"

"github.com/red-hat-storage/odf-multicluster-orchestrator/addons/setup"

"github.com/red-hat-storage/odf-multicluster-orchestrator/controllers/utils"

"github.com/openshift/library-go/pkg/operator/events/eventstesting"
Expand Down Expand Up @@ -296,6 +297,7 @@ func getExpectedRookBlueSecret(t *testing.T) *corev1.Secret {
Namespace: TestManagedClusterName,
Labels: map[string]string{
utils.SecretLabelTypeKey: string(utils.SourceLabel),
HubRecoveryLabel: "",
},
},
Type: utils.SecretLabelTypeKey,
Expand All @@ -322,6 +324,7 @@ func getExpectedExternalClusterRookBlueSecret(t *testing.T) *corev1.Secret {
Namespace: TestManagedClusterName,
Labels: map[string]string{
utils.SecretLabelTypeKey: string(utils.InternalLabel),
HubRecoveryLabel: "",
},
},
Type: utils.SecretLabelTypeKey,
Expand Down
1 change: 1 addition & 0 deletions addons/token-exchange/s3_secret_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func getExpectedS3BlueSecret(t *testing.T) *corev1.Secret {
Namespace: TestManagedClusterName,
Labels: map[string]string{
utils.SecretLabelTypeKey: string(utils.InternalLabel),
HubRecoveryLabel: "",
},
},
Type: utils.SecretLabelTypeKey,
Expand Down
4 changes: 4 additions & 0 deletions addons/token-exchange/secret_exchange_handler_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
corev1lister "k8s.io/client-go/listers/core/v1"
)

const HubRecoveryLabel = "cluster.open-cluster-management.io/backup"

func getSecret(lister corev1lister.SecretLister, name, namespace string) (*corev1.Secret, error) {
se, err := lister.Secrets(namespace).Get(name)
switch {
Expand Down Expand Up @@ -64,6 +66,7 @@ func generateBlueSecret(secret *corev1.Secret, secretType utils.SecretLabelType,
Namespace: managedCluster,
Labels: map[string]string{
utils.SecretLabelTypeKey: string(secretType),
HubRecoveryLabel: "",
},
},
Type: utils.SecretLabelTypeKey,
Expand Down Expand Up @@ -97,6 +100,7 @@ func generateBlueSecretForExternal(rookCephMon *corev1.Secret, labelType utils.S
Namespace: managedClusterName,
Labels: map[string]string{
utils.SecretLabelTypeKey: string(labelType),
HubRecoveryLabel: "",
},
},
Type: utils.SecretLabelTypeKey,
Expand Down
7 changes: 4 additions & 3 deletions controllers/mirrorpeer_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package controllers

import (
"context"
"testing"

"github.com/red-hat-storage/odf-multicluster-orchestrator/addons/setup"
multiclusterv1alpha1 "github.com/red-hat-storage/odf-multicluster-orchestrator/api/v1alpha1"
"github.com/red-hat-storage/odf-multicluster-orchestrator/controllers/utils"
Expand All @@ -31,7 +33,6 @@ import (
clusterv1 "open-cluster-management.io/api/cluster/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"testing"
)

func TestMirrorPeerReconcilerReconcile(t *testing.T) {
Expand Down Expand Up @@ -80,8 +81,8 @@ func TestMirrorPeerReconcilerReconcile(t *testing.T) {
t.Errorf("Failed to get MirrorPeer. Error: %s", err)
}

if val, ok := mp.Labels[hubRecoveryLabel]; !ok || val != "resource" {
t.Errorf("MirrorPeer.Labels[%s] is not set correctly. Expected: %s, Actual: %s", hubRecoveryLabel, "resource", val)
if val, ok := mp.Labels[utils.HubRecoveryLabel]; !ok || val != "resource" {
t.Errorf("MirrorPeer.Labels[%s] is not set correctly. Expected: %s, Actual: %s", utils.HubRecoveryLabel, "resource", val)
}
}

Expand Down

0 comments on commit 76fb4c7

Please sign in to comment.