From 5504d359ba33832bbae7e7e2b30616ab7e891e63 Mon Sep 17 00:00:00 2001 From: Andy Pliszka Date: Mon, 18 Sep 2023 17:06:05 -0400 Subject: [PATCH] feat: sets node type label --- internal/fullnode/labels.go | 2 ++ internal/fullnode/labels_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 internal/fullnode/labels_test.go diff --git a/internal/fullnode/labels.go b/internal/fullnode/labels.go index e742dc3f..ac48635e 100644 --- a/internal/fullnode/labels.go +++ b/internal/fullnode/labels.go @@ -10,6 +10,7 @@ import ( const ( networkLabel = "cosmos.strange.love/network" + typeLabel = "cosmos.strange.love/type" ) // kv is a list of extra kv pairs to add to the labels. Must be even. @@ -23,6 +24,7 @@ func defaultLabels(crd *cosmosv1.CosmosFullNode, kvPairs ...string) map[string]s kube.NameLabel: appName(crd), kube.VersionLabel: kube.ParseImageVersion(crd.Spec.PodTemplate.Image), networkLabel: crd.Spec.ChainSpec.Network, + typeLabel: string(crd.Spec.Type), } for i := 0; i < len(kvPairs); i += 2 { labels[kvPairs[i]] = kvPairs[i+1] diff --git a/internal/fullnode/labels_test.go b/internal/fullnode/labels_test.go new file mode 100644 index 00000000..d01af89a --- /dev/null +++ b/internal/fullnode/labels_test.go @@ -0,0 +1,30 @@ +package fullnode + +import ( + "github.com/stretchr/testify/require" + "testing" + + cosmosv1 "github.com/strangelove-ventures/cosmos-operator/api/v1" +) + +func TestDefaultLabels(t *testing.T) { + t.Parallel() + + t.Run("give full node", func(t *testing.T) { + var crd cosmosv1.CosmosFullNode + crd.Spec.Type = "FullNode" + + labels := defaultLabels(&crd) + + require.Equal(t, "FullNode", labels["cosmos.strange.love/type"]) + }) + + t.Run("give sentry node", func(t *testing.T) { + var crd cosmosv1.CosmosFullNode + crd.Spec.Type = "Sentry" + + labels := defaultLabels(&crd) + + require.Equal(t, "Sentry", labels["cosmos.strange.love/type"]) + }) +}