Skip to content

Commit

Permalink
add disaster recovery labels if embedded-cluster (#4593)
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig O'Donnell authored May 2, 2024
1 parent 27413c2 commit d1f5433
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/kotsadm/types/constants.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package types

import "github.com/replicatedhq/kots/pkg/util"

const KotsadmKey = "kots.io/kotsadm"
const KotsadmLabelValue = "true"

Expand All @@ -13,6 +15,9 @@ const ExcludeValue = "true"
const BackupLabel = "kots.io/backup"
const BackupLabelValue = "velero"

const DisasterRecoveryLabel = "replicated.com/disaster-recovery"
const DisasterRecoveryLabelValue = "infra"

const TroubleshootKey = "troubleshoot.sh/kind"
const TroubleshootValue = "support-bundle"

Expand All @@ -26,6 +31,10 @@ func GetKotsadmLabels(additionalLabels ...map[string]string) map[string]string {
BackupLabel: BackupLabelValue,
}

if util.IsEmbeddedCluster() {
labels[DisasterRecoveryLabel] = DisasterRecoveryLabelValue
}

for _, l := range additionalLabels {
labels = MergeLabels(labels, l)
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/kotsadm/types/constants_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func Test_getKotsadmLabels(t *testing.T) {
tests := []struct {
name string
labels []map[string]string
env map[string]string
expectLabels map[string]string
}{
{
Expand All @@ -19,16 +20,37 @@ func Test_getKotsadmLabels(t *testing.T) {
"foo": "foo",
},
},
env: map[string]string{},
expectLabels: map[string]string{
"kots.io/kotsadm": "true",
"kots.io/backup": "velero",
"foo": "foo",
},
},
{
name: "pass case with additional labels in embedded-cluster",
labels: []map[string]string{
{
"foo": "foo",
},
},
env: map[string]string{
"EMBEDDED_CLUSTER_ID": "foo",
},
expectLabels: map[string]string{
"kots.io/kotsadm": "true",
"kots.io/backup": "velero",
"replicated.com/disaster-recovery": "infra",
"foo": "foo",
},
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
for k, v := range test.env {
t.Setenv(k, v)
}
labels := GetKotsadmLabels(test.labels...)
assert.Equal(t, test.expectLabels, labels)
})
Expand Down

0 comments on commit d1f5433

Please sign in to comment.