Break a bad dep.

This commit is contained in:
Jeffrey Regan
2019-05-21 17:21:32 -07:00
committed by jregan
parent d4e3cd31a4
commit b28aaae66b
10 changed files with 72 additions and 91 deletions

View File

@@ -1,40 +0,0 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
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 patch
import "sigs.k8s.io/kustomize/pkg/gvk"
// Json6902 represents a json patch for an object
// with format documented https://tools.ietf.org/html/rfc6902.
type Json6902 struct {
// Target refers to a Kubernetes object that the json patch will be
// applied to. It must refer to a Kubernetes resource under the
// purview of this kustomization. Target should use the
// raw name of the object (the name specified in its YAML,
// before addition of a namePrefix and a nameSuffix).
Target *Target `json:"target" yaml:"target"`
// relative file path for a json patch file inside a kustomization
Path string `json:"path,omitempty" yaml:"path,omitempty"`
}
// Target represents the kubernetes object that the patch is applied to
type Target struct {
gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
Name string `json:"name" yaml:"name"`
}

View File

@@ -16,23 +16,20 @@ limitations under the License.
package patch
// StrategicMerge represents a relative path to a
// stategic merge patch with the format
// https://github.com/kubernetes/community/blob/master/contributors/devel/strategic-merge-patch.md
type StrategicMerge string
import "sigs.k8s.io/kustomize/pkg/types"
// Append appends a slice of patch paths to a StrategicMerge slice
func Append(patches []StrategicMerge, paths ...string) []StrategicMerge {
// Append appends a slice of patch paths to a PatchStrategicMerge slice
func Append(patches []types.PatchStrategicMerge, paths ...string) []types.PatchStrategicMerge {
for _, p := range paths {
patches = append(patches, StrategicMerge(p))
patches = append(patches, types.PatchStrategicMerge(p))
}
return patches
}
// Exist determines if a patch path exists in a slice of StrategicMerge
func Exist(patches []StrategicMerge, path string) bool {
// Exist determines if a patch path exists in a slice of PatchStrategicMerge
func Exist(patches []types.PatchStrategicMerge, path string) bool {
for _, p := range patches {
if p == StrategicMerge(path) {
if p == types.PatchStrategicMerge(path) {
return true
}
}

View File

@@ -18,15 +18,15 @@ package transformer
import (
"fmt"
"sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/patch"
"sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/transformers"
"sigs.k8s.io/kustomize/pkg/types"
)
// PatchJson6902Factory makes Json6902 transformers
// PatchJson6902Factory makes PatchJson6902 transformers
type PatchJson6902Factory struct {
loader ifc.Loader
}
@@ -36,8 +36,8 @@ func NewPatchJson6902Factory(l ifc.Loader) PatchJson6902Factory {
return PatchJson6902Factory{loader: l}
}
// MakePatchJson6902Transformer returns a transformer for applying Json6902 patch
func (f PatchJson6902Factory) MakePatchJson6902Transformer(patches []patch.Json6902) (transformers.Transformer, error) {
// MakePatchJson6902Transformer returns a transformer for applying PatchJson6902 patch
func (f PatchJson6902Factory) MakePatchJson6902Transformer(patches []types.PatchJson6902) (transformers.Transformer, error) {
var ts []transformers.Transformer
for _, p := range patches {
t, err := f.makeOnePatchJson6902Transformer(p)
@@ -51,7 +51,7 @@ func (f PatchJson6902Factory) MakePatchJson6902Transformer(patches []patch.Json6
return transformers.NewMultiTransformerWithConflictCheck(ts), nil
}
func (f PatchJson6902Factory) makeOnePatchJson6902Transformer(p patch.Json6902) (transformers.Transformer, error) {
func (f PatchJson6902Factory) makeOnePatchJson6902Transformer(p types.PatchJson6902) (transformers.Transformer, error) {
if p.Target == nil {
return nil, fmt.Errorf("must specify the target field in patchesJson6902")
}

View File

@@ -25,17 +25,17 @@ import (
"sigs.k8s.io/kustomize/internal/loadertest"
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/patch"
"sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/types"
)
var rf = resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
func TestNewPatchJson6902FactoryNoTarget(t *testing.T) {
p := patch.Json6902{}
p := types.PatchJson6902{}
_, err := NewPatchJson6902Factory(nil).makeOnePatchJson6902Transformer(p)
if err == nil {
t.Fatal("expected error")
@@ -51,7 +51,7 @@ target:
name: some-name
kind: Deployment
`)
p := patch.Json6902{}
p := types.PatchJson6902{}
err := yaml.Unmarshal(jsonPatch, &p)
if err != nil {
t.Fatalf("expected error %v", err)
@@ -84,7 +84,7 @@ target:
name: some-name
path: patch.json
`)
p := patch.Json6902{}
p := types.PatchJson6902{}
err = yaml.Unmarshal(jsonPatch, &p)
if err != nil {
t.Fatal("expected error")
@@ -122,7 +122,7 @@ target:
kind: Deployment
path: patch.yaml
`)
p := patch.Json6902{}
p := types.PatchJson6902{}
err = yaml.Unmarshal(jsonPatch, &p)
if err != nil {
t.Fatalf("unexpected error : %v", err)
@@ -169,7 +169,7 @@ func TestNewPatchJson6902FactoryMulti(t *testing.T) {
name: some-name
path: patch.yaml
`)
var p []patch.Json6902
var p []types.PatchJson6902
err = yaml.Unmarshal(jsonPatches, &p)
if err != nil {
t.Fatalf("unexpected error : %v", err)
@@ -283,7 +283,7 @@ func TestNewPatchJson6902FactoryMultiConflict(t *testing.T) {
name: some-name
path: patch.yaml
`)
var p []patch.Json6902
var p []types.PatchJson6902
err = yaml.Unmarshal(jsonPatches, &p)
if err != nil {
t.Fatalf("unexpected error : %v", err)