Skip to content

Commit f361a33

Browse files
authored
Change set-labels to be importable (#929)
1 parent 2f61c91 commit f361a33

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

functions/go/set-labels/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ package main
1919
import (
2020
"context"
2121

22+
"github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/set-labels/setlabels"
2223
"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn"
2324
)
2425

2526
func NewTransformer() fn.ResourceListProcessor {
26-
return fn.WithContext(fn.Context{Context: context.Background()}, &SetLabels{})
27+
return fn.WithContext(fn.Context{Context: context.Background()}, &setlabels.SetLabels{})
2728
}
2829

2930
func run() error {

functions/go/set-labels/run_js.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"syscall/js"
2222

23+
"github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/set-labels/setlabels"
2324
"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn"
2425
)
2526

@@ -33,7 +34,7 @@ func run() error {
3334
}
3435

3536
func transformLabels(input []byte) ([]byte, error) {
36-
runner := fn.WithContext(fn.Context{Context: nil}, &SetLabels{})
37+
runner := fn.WithContext(fn.Context{Context: nil}, &setlabels.SetLabels{})
3738
return fn.Run(runner, []byte(input))
3839
}
3940

functions/go/set-labels/transformer.go renamed to functions/go/set-labels/setlabels/transformer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package setlabels
22

33
import (
44
"sort"
@@ -9,9 +9,10 @@ import (
99
type FieldPath []string
1010

1111
var (
12-
selectorPath = FieldPath{"selector", "matchLabels"}
1312
metaLabelsPath = FieldPath{"metadata", "labels"}
13+
selectorPath = FieldPath{"selector", "matchLabels"}
1414
podSelectorPath = FieldPath{"podSelector", "matchLabels"}
15+
labelSelector = FieldPath{"labelSelector", "matchLabels"}
1516
)
1617

1718
var _ fn.Runner = &SetLabels{}
@@ -257,8 +258,6 @@ func (p *SetLabels) setLabelsInVolume(volume *fn.SubObject) error {
257258

258259
// setLabelsInPodSpec set label path in PodSpec, that include path under topologySpreadConstraints and affinity
259260
func (p *SetLabels) setLabelsInPodSpec(podSpec *fn.SubObject) error {
260-
labelSelector := FieldPath{"labelSelector", "matchLabels"}
261-
262261
_, exist, _ := podSpec.NestedSlice("topologySpreadConstraints")
263262
if exist {
264263
for _, obj := range podSpec.GetSlice("topologySpreadConstraints") {
@@ -306,6 +305,7 @@ func (p *SetLabels) updateLabels(o *fn.SubObject, labelPath FieldPath, labels ma
306305
keys = append(keys, k)
307306
}
308307
sort.Strings(keys)
308+
309309
for i := 0; i < len(keys); i++ {
310310
key := keys[i]
311311
val := labels[key]

tests/set-labels/ill-formatted-fn-config/.expected/results.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ items:
88
stderr: 'failed to evaluate function: error: function failure'
99
exitCode: 1
1010
results:
11-
- message: 'unable to convert object to *main.SetLabels with error: json: cannot unmarshal array into Go struct field SetLabels.labels of type map[string]string'
12-
severity: error
11+
- message: 'unable to convert object to *setlabels.SetLabels with error: json: cannot unmarshal array into Go struct field SetLabels.labels of type map[string]string'
12+
severity: error

tests/set-labels/wrong-config-data-type/.expected/results.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ items:
88
stderr: 'failed to evaluate function: error: function failure'
99
exitCode: 1
1010
results:
11-
- message: 'unable to convert object to *main.SetLabels with error: json: cannot unmarshal array into Go struct field SetLabels.labels of type map[string]string'
12-
severity: error
11+
- message: 'unable to convert object to *setlabels.SetLabels with error: json: cannot unmarshal array into Go struct field SetLabels.labels of type map[string]string'
12+
severity: error

0 commit comments

Comments
 (0)