fix: empty terms

We crush if terms is empty.

Signed-off-by: Serge Logvinov <serge.logvinov@sinextra.dev>
This commit is contained in:
Serge Logvinov
2024-05-13 13:50:22 +03:00
parent 749a01d538
commit 9dde8aa331
3 changed files with 9 additions and 5 deletions

View File

@@ -35,7 +35,7 @@ jobs:
go-version-file: 'go.mod'
- name: Lint
uses: golangci/golangci-lint-action@v5
uses: golangci/golangci-lint-action@v6
with:
version: v1.58.0
args: --timeout=5m --config=.golangci.yml

View File

@@ -44,15 +44,15 @@ var prohibitedPlatformMetadataKeys = []string{"hostname", "platform"}
//
//nolint:gocyclo,cyclop
func TransformNode(terms []NodeTerm, platformMetadata *runtime.PlatformMetadataSpec) (*NodeSpec, error) {
if len(terms) == 0 {
return nil, nil
}
node := &NodeSpec{
Annotations: make(map[string]string),
Labels: make(map[string]string),
}
if len(terms) == 0 {
return node, nil
}
metadata := metadataFromStruct(platformMetadata)
for _, term := range terms {

View File

@@ -26,6 +26,10 @@ func TestMatch(t *testing.T) {
Platform: "test-platform",
Hostname: "test-hostname",
},
expected: &transformer.NodeSpec{
Annotations: map[string]string{},
Labels: map[string]string{},
},
},
{
name: "Transform labels",