Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependence on kustomize/setters2 #604

Merged
merged 1 commit into from
Nov 20, 2023
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
32 changes: 29 additions & 3 deletions pkg/update/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ limitations under the License.
package update

import (
"encoding/json"

"github.com/go-logr/logr"
"k8s.io/kube-openapi/pkg/validation/spec"
"sigs.k8s.io/kustomize/kyaml/fieldmeta"
"sigs.k8s.io/kustomize/kyaml/openapi"
"sigs.k8s.io/kustomize/kyaml/setters2"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

Expand Down Expand Up @@ -112,8 +113,17 @@ func accept(v visitor, object *yaml.RNode, p string, settersSchema *spec.Schema)
return nil
}

type setter struct {
Name string `json:"name"`
Value string `json:"value"`
}

type extension struct {
Setter *setter `json:"setter,omitempty"`
}

// set applies the value from ext to field
func (s *SetAllCallback) set(field *yaml.RNode, ext *setters2.CliExtension, sch *spec.Schema) (bool, error) {
func (s *SetAllCallback) set(field *yaml.RNode, ext *extension, sch *spec.Schema) (bool, error) {
// check full setter
if ext.Setter == nil {
return false, nil
Expand All @@ -139,7 +149,7 @@ func (s *SetAllCallback) visitScalar(object *yaml.RNode, p string, fieldSchema *
return nil
}
// get the openAPI for this field describing how to apply the setter
ext, err := setters2.GetExtFromSchema(fieldSchema.Schema)
ext, err := getExtFromSchema(fieldSchema.Schema)
if err != nil {
return err
}
Expand All @@ -152,3 +162,19 @@ func (s *SetAllCallback) visitScalar(object *yaml.RNode, p string, fieldSchema *
_, err = s.set(object, ext, fieldSchema.Schema)
return err
}

func getExtFromSchema(schema *spec.Schema) (*extension, error) {
cep := schema.VendorExtensible.Extensions[K8sCliExtensionKey]
if cep == nil {
return nil, nil
}
b, err := json.Marshal(cep)
if err != nil {
return nil, err
}
val := &extension{}
if err := json.Unmarshal(b, val); err != nil {
return nil, err
}
return val, nil
}
6 changes: 4 additions & 2 deletions pkg/update/setters.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ import (
"sigs.k8s.io/kustomize/kyaml/kio/kioutil"
"sigs.k8s.io/kustomize/kyaml/openapi"
"sigs.k8s.io/kustomize/kyaml/sets"
"sigs.k8s.io/kustomize/kyaml/setters2"
"sigs.k8s.io/kustomize/kyaml/yaml"

imagev1_reflect "github.com/fluxcd/image-reflector-controller/api/v1beta2"
)

const (
// This is preserved from setters2
K8sCliExtensionKey = "x-k8s-cli"

// SetterShortHand is a shorthand that can be used to mark
// setters; instead of
// # { "$ref": "#/definitions/
Expand Down Expand Up @@ -256,7 +258,7 @@ func setAll(schema *spec.Schema, tracelog logr.Logger, callback func(file, sette
func setterSchema(name, value string) spec.Schema {
schema := spec.StringProperty()
schema.Extensions = map[string]interface{}{}
schema.Extensions.Add(setters2.K8sCliExtensionKey, map[string]interface{}{
schema.Extensions.Add(K8sCliExtensionKey, map[string]interface{}{
"setter": map[string]string{
"name": name,
"value": value,
Expand Down
Loading