new command kustomize edit add buildmetadata (#4413)

* new command kustomize edit add buildmetadata

* new commands kustomize edit set buildmetadata and kustomize edit remove buildmetadata
This commit is contained in:
Natasha Sarkar
2022-01-26 15:34:50 -08:00
committed by GitHub
parent c65ef489ca
commit bcebad1664
16 changed files with 450 additions and 6 deletions

View File

@@ -67,6 +67,7 @@ func determineFieldOrder() []string {
"Inventory",
"Components",
"OpenAPI",
"BuildMetadata",
}
// Add deprecated fields here.

View File

@@ -49,6 +49,7 @@ func TestFieldOrder(t *testing.T) {
"Inventory",
"Components",
"OpenAPI",
"BuildMetadata",
}
actual := determineFieldOrder()
if len(expected) != len(actual) {

View File

@@ -1,3 +1,6 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package util
import (

View File

@@ -0,0 +1,31 @@
// Copyright 2022 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package util
import (
"errors"
"fmt"
"strings"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/kustomize/kustomize/v4/commands/internal/kustfile"
)
type BuildMetadataValidator struct{}
func (b *BuildMetadataValidator) Validate(args []string) ([]string, error) {
if len(args) == 0 {
return nil, errors.New("must specify a buildMetadata option")
}
if len(args) > 1 {
return nil, fmt.Errorf("too many arguments: %s; to provide multiple buildMetadata options, please separate options by comma", args)
}
opts := strings.Split(args[0], ",")
for _, opt := range opts {
if !kustfile.StringInSlice(opt, types.BuildMetadataOptions) {
return nil, fmt.Errorf("invalid buildMetadata option: %s", opt)
}
}
return opts, nil
}