Skip to content

Commit

Permalink
feat: sets node type label
Browse files Browse the repository at this point in the history
  • Loading branch information
AntiTyping committed Sep 18, 2023
1 parent 18f98d4 commit 5504d35
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/fullnode/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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]
Expand Down
30 changes: 30 additions & 0 deletions internal/fullnode/labels_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package fullnode

import (
"github.com/stretchr/testify/require"

Check failure on line 4 in internal/fullnode/labels_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed (goimports)
"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"])
})
}

0 comments on commit 5504d35

Please sign in to comment.