diff --git a/pkg/kotsadm/types/constants.go b/pkg/kotsadm/types/constants.go index 4f65b299df..45618c6896 100644 --- a/pkg/kotsadm/types/constants.go +++ b/pkg/kotsadm/types/constants.go @@ -1,5 +1,7 @@ package types +import "github.com/replicatedhq/kots/pkg/util" + const KotsadmKey = "kots.io/kotsadm" const KotsadmLabelValue = "true" @@ -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" @@ -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) } diff --git a/pkg/kotsadm/types/constants_test.go b/pkg/kotsadm/types/constants_test.go index 296d998a9f..5cdac0e479 100644 --- a/pkg/kotsadm/types/constants_test.go +++ b/pkg/kotsadm/types/constants_test.go @@ -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 }{ { @@ -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) })