Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ GOBIN := $(shell go env GOPATH)/bin
OUT_DIR := .out
MODULES = $(shell find . -name 'go.mod' -print)

.PHONY: api
api:
(which swagger || go install github.com/go-swagger/go-swagger/cmd/[email protected])
$(GOPATH)/bin/swagger generate spec -m -w api/kptfile/v1 -o ../openapi/kptfile.yaml

.PHONY: fix
fix: $(MODULES)
@for f in $(^D); do (cd $$f; echo "Fixing $$f"; go fix ./...) || exit 1; done
Expand All @@ -19,12 +14,18 @@ fix: $(MODULES)
fmt: $(MODULES)
@for f in $(^D); do (cd $$f; echo "Formatting $$f"; go fmt ./...); done

.PHONY: install-golangci-lint
install-golangci-lint:
go install github.com/golangci/golangci-lint/v2/cmd/[email protected]

.PHONY: lint
lint: $(MODULES)
lint: install-golangci-lint lint-modules

.PHONY: lint-modules
lint-modules: $(MODULES)
@for f in $(^D); do \
(cd $$f; echo "Checking golangci-lint $$f"; \
(which $(GOPATH)/bin/golangci-lint || go install github.com/golangci/golangci-lint/v2/cmd/[email protected]); \
$(GOPATH)/bin/golangci-lint run ./...); \
$(GOBIN)/golangci-lint run ./...); \
done

.PHONY: test
Expand Down
4 changes: 3 additions & 1 deletion go/fn/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package fn

const (
Expand Down Expand Up @@ -53,6 +54,7 @@ const (

// UnknownNamespace is the special char for cluster-scoped or unknown-scoped resources. This is only used in upstream-identifier
UnknownNamespace = "~C"

// DefaultNamespace is the actual namespace value if a namespace-scoped resource has its namespace field unspecified.
DefaultNamespace = "default"
)
Expand All @@ -67,5 +69,5 @@ const (
KptFunctionVersion = "v1alpha1"
// KptFunctionGroup is the ApiVersion for the KRM resource which defines the configuration of a function execution.
// See KRM function specification `ResourceList.FunctionConfig`
KptFunctionApiVersion = KptFunctionGroup + "/" + KptFunctionVersion
KptFunctionAPIVersion = KptFunctionGroup + "/" + KptFunctionVersion
)
1 change: 1 addition & 0 deletions go/fn/examples/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
go.yaml.in/yaml/v2 v2.4.2 // indirect
Expand Down
8 changes: 6 additions & 2 deletions go/fn/examples/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFd
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -55,8 +57,8 @@ github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
Expand Down Expand Up @@ -108,6 +110,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
k8s.io/api v0.34.1 h1:jC+153630BMdlFukegoEL8E/yT7aLyQkIVuwhmwDgJM=
k8s.io/api v0.34.1/go.mod h1:SB80FxFtXn5/gwzCoN6QCtPD7Vbu5w2n1S0J5gFfTYk=
k8s.io/apimachinery v0.34.1 h1:dTlxFls/eikpJxmAC7MVE8oOeP1zryV7iRyIjB0gky4=
Expand Down
7 changes: 5 additions & 2 deletions go/fn/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ require (
github.com/go-errors/errors v1.5.1
github.com/google/go-cmp v0.7.0
github.com/kptdev/kpt v1.0.0-beta.59
github.com/stretchr/testify v1.11.1
k8s.io/apimachinery v0.34.1
github.com/stretchr/testify v1.10.0
gotest.tools v2.2.0+incompatible
k8s.io/apimachinery v0.33.1
// We must not include any core k8s APIs (e.g. k8s.io/api) in
// the dependencies, depending on them will likely to cause version skew for
// consumers. The dependencies for tests and examples should be isolated.
k8s.io/klog/v2 v2.130.1
sigs.k8s.io/kustomize/kyaml v0.20.1
)

require github.com/pkg/errors v0.9.1

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand Down
12 changes: 8 additions & 4 deletions go/fn/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -40,8 +42,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ=
github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down Expand Up @@ -85,8 +87,10 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/apimachinery v0.34.1 h1:dTlxFls/eikpJxmAC7MVE8oOeP1zryV7iRyIjB0gky4=
k8s.io/apimachinery v0.34.1/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
k8s.io/apimachinery v0.33.1 h1:mzqXWV8tW9Rw4VeW9rEkqvnxj59k1ezDUl20tFK/oM4=
k8s.io/apimachinery v0.33.1/go.mod h1:BHW0YOu7n22fFv/JkYOEfkUYNRN0fj0BlvMFWA7b+SM=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 h1:Y3gxNAuB0OBLImH611+UDZcmKS3g6CthxToOb37KgwE=
Expand Down
40 changes: 35 additions & 5 deletions go/fn/internal/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,23 @@ type MapVariant struct {
node *yaml.Node
}

func (o *MapVariant) GetKind() variantKind {
return variantKindMap
func (o *MapVariant) GetKind() VariantKind {
return VariantKindMap
}

func (o *MapVariant) Node() *yaml.Node {
return o.node
}

func (o *MapVariant) IsEmpty() bool {
return o == nil || o.node == nil || len(o.node.Content) == 0
}

func (o *MapVariant) HasKey(key string) bool {
_, found := o.getVariant(key)
return found
}

func (o *MapVariant) Entries() (map[string]variant, error) {
entries := make(map[string]variant)

Expand Down Expand Up @@ -275,11 +284,32 @@ func (nodes yamlKeyValuePairs) Swap(i, j int) { nodes[i], nodes[j] = nodes[j], n
// otherwise it will insert a map at the specified field.
// Note that if the value exists but is not a map, it will be replaced with a map.
func (o *MapVariant) UpsertMap(field string) *MapVariant {
m := o.GetMap(field)
if m != nil {
return m
node, found := o.getVariant(field)

if found {
switch node := node.(type) {
case *MapVariant:
// field was found and it is a map
if !node.IsEmpty() {
return node
}
// if the map is empty, replace it with a new map
// this supposed to result in better formatting if the map value is specified as {}
_, err := o.remove(field)
if err != nil {
klog.Warningf("upsert: couldn't remove field %s: %v", field, err)
}

default:
// field was found and it is NOT a map
_, err := o.remove(field)
if err != nil {
log.Fatalf("KubeObject.UpsertMap(): couldn't remove mistyped field %s: %v", field, err)
}
}
}

// insert map at field
keyNode := &yaml.Node{
Kind: yaml.ScalarNode,
Value: field,
Expand Down
6 changes: 3 additions & 3 deletions go/fn/internal/maphelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,19 +180,19 @@ func (o *MapVariant) SetNestedFloat(f float64, fields ...string) error {
return o.SetNestedValue(newFloatScalarVariant(f), fields...)
}

func (o *MapVariant) GetNestedSlice(fields ...string) (*sliceVariant, bool, error) {
func (o *MapVariant) GetNestedSlice(fields ...string) (*SliceVariant, bool, error) {
node, found, err := o.GetNestedValue(fields...)
if err != nil || !found {
return nil, found, err
}
nodeS, ok := node.(*sliceVariant)
nodeS, ok := node.(*SliceVariant)
if !ok {
return nil, found, fmt.Errorf("incorrect type, was %T", node)
}
return nodeS, found, err
}

func (o *MapVariant) SetNestedSlice(s *sliceVariant, fields ...string) error {
func (o *MapVariant) SetNestedSlice(s *SliceVariant, fields ...string) error {
return o.SetNestedValue(s, fields...)
}

Expand Down
4 changes: 2 additions & 2 deletions go/fn/internal/scalar.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type scalarVariant struct {
node *yaml.Node
}

func (v *scalarVariant) GetKind() variantKind {
return variantKindScalar
func (v *scalarVariant) GetKind() VariantKind {
return VariantKindScalar
}

func newStringScalarVariant(s string) *scalarVariant {
Expand Down
18 changes: 9 additions & 9 deletions go/fn/internal/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ import (
"sigs.k8s.io/kustomize/kyaml/yaml"
)

type sliceVariant struct {
type SliceVariant struct {
node *yaml.Node
}

func NewSliceVariant(s ...variant) *sliceVariant {
func NewSliceVariant(s ...variant) *SliceVariant {
node := buildSequenceNode()
for _, v := range s {
node.Content = append(node.Content, v.Node())
}
return &sliceVariant{node: node}
return &SliceVariant{node: node}
}

func (v *sliceVariant) GetKind() variantKind {
return variantKindSlice
func (v *SliceVariant) GetKind() VariantKind {
return VariantKindSlice
}

func (v *sliceVariant) Node() *yaml.Node {
func (v *SliceVariant) Node() *yaml.Node {
return v.node
}

func (v *sliceVariant) Clear() {
func (v *SliceVariant) Clear() {
v.node.Content = nil
}

func (v *sliceVariant) Elements() ([]*MapVariant, error) {
func (v *SliceVariant) Elements() ([]*MapVariant, error) {
return ExtractObjects(v.node.Content...)
}

func (v *sliceVariant) Add(node variant) {
func (v *SliceVariant) Add(node variant) {
v.node.Content = append(v.node.Content, node.Node())
}
1 change: 1 addition & 0 deletions go/fn/internal/test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go/fn/internal/test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFd
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0=
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -108,6 +110,8 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
k8s.io/api v0.34.1 h1:jC+153630BMdlFukegoEL8E/yT7aLyQkIVuwhmwDgJM=
k8s.io/api v0.34.1/go.mod h1:SB80FxFtXn5/gwzCoN6QCtPD7Vbu5w2n1S0J5gFfTYk=
k8s.io/apimachinery v0.34.1 h1:dTlxFls/eikpJxmAC7MVE8oOeP1zryV7iRyIjB0gky4=
Expand Down
16 changes: 8 additions & 8 deletions go/fn/internal/variant.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import (
"sigs.k8s.io/kustomize/kyaml/yaml"
)

type variantKind string
type VariantKind string

const (
variantKindMap variantKind = "Map"
variantKindSlice variantKind = "Slice"
variantKindScalar variantKind = "Scalar"
VariantKindMap VariantKind = "Map"
VariantKindSlice VariantKind = "Slice"
VariantKindScalar VariantKind = "Scalar"
)

type variant interface {
GetKind() variantKind
GetKind() VariantKind
Node() *yaml.Node
}

Expand Down Expand Up @@ -90,7 +90,7 @@ func toVariant(n *yaml.Node) variant {
case yaml.MappingNode:
return &MapVariant{node: n}
case yaml.SequenceNode:
return &sliceVariant{node: n}
return &SliceVariant{node: n}

default:
panic("unhandled yaml node kind")
Expand Down Expand Up @@ -150,7 +150,7 @@ func TypedObjectToMapVariant(v interface{}) (*MapVariant, error) {
return mv, err
}

func TypedObjectToSliceVariant(v interface{}) (*sliceVariant, error) {
func TypedObjectToSliceVariant(v interface{}) (*SliceVariant, error) {
// The built-in types only have json tags. We can't simply do ynode.Encode(v),
// since it use the lowercased field name by default if no yaml tag is specified.
// This affects both k8s built-in types (e.g. appsv1.Deployment) and any types
Expand All @@ -177,7 +177,7 @@ func TypedObjectToSliceVariant(v interface{}) (*sliceVariant, error) {
return nil, fmt.Errorf("unable to convert strong typed object to yaml node: %w", err)
}

return &sliceVariant{node: node}, nil
return &SliceVariant{node: node}, nil
}

func MapVariantToTypedObject(mv *MapVariant, ptr interface{}) error {
Expand Down
Loading
Loading