Skip to content

Commit 4c7b63a

Browse files
committed
remove dependency on apimachinery from gvk package
1 parent 1e04a0e commit 4c7b63a

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

internal/k8sdeps/patch/patch.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ import (
2222

2323
"github.com/evanphx/json-patch"
2424
"k8s.io/apimachinery/pkg/runtime"
25+
"k8s.io/apimachinery/pkg/runtime/schema"
2526
"k8s.io/apimachinery/pkg/util/strategicpatch"
2627
"k8s.io/client-go/kubernetes/scheme"
28+
"sigs.k8s.io/kustomize/pkg/gvk"
2729
"sigs.k8s.io/kustomize/pkg/resmap"
2830
"sigs.k8s.io/kustomize/pkg/resource"
2931
"sigs.k8s.io/kustomize/pkg/transformers"
@@ -81,7 +83,7 @@ func (pt *patchTransformer) Transform(baseResourceMap resmap.ResMap) error {
8183
id = matchedIds[0]
8284
base := baseResourceMap[id]
8385
merged := map[string]interface{}{}
84-
versionedObj, err := scheme.Scheme.New(id.Gvk().ToSchemaGvk())
86+
versionedObj, err := scheme.Scheme.New(toSchemaGvk(id.Gvk()))
8587
baseName := base.GetName()
8688
switch {
8789
case runtime.IsNotRegisteredError(err):
@@ -139,7 +141,7 @@ func (pt *patchTransformer) mergePatches() (resmap.ResMap, error) {
139141
continue
140142
}
141143

142-
versionedObj, err := scheme.Scheme.New(id.Gvk().ToSchemaGvk())
144+
versionedObj, err := scheme.Scheme.New(toSchemaGvk(id.Gvk()))
143145
if err != nil && !runtime.IsNotRegisteredError(err) {
144146
return nil, err
145147
}
@@ -174,3 +176,12 @@ func (pt *patchTransformer) mergePatches() (resmap.ResMap, error) {
174176
}
175177
return rc, nil
176178
}
179+
180+
// toSchemaGvk converts to a schema.GroupVersionKind.
181+
func toSchemaGvk(x gvk.Gvk) schema.GroupVersionKind {
182+
return schema.GroupVersionKind{
183+
Group: x.Group,
184+
Version: x.Version,
185+
Kind: x.Kind,
186+
}
187+
}

internal/k8sdeps/unstructadapter.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ func NewKunstructuredFromObject(obj runtime.Object) (ifc.Kunstructured, error) {
5454

5555
// GetGvk returns the Gvk name of the object.
5656
func (fs *UnstructAdapter) GetGvk() gvk.Gvk {
57-
return gvk.FromSchemaGvk(fs.GroupVersionKind())
57+
x := fs.GroupVersionKind()
58+
return gvk.Gvk{
59+
Group: x.Group,
60+
Version: x.Version,
61+
Kind: x.Kind,
62+
}
5863
}
5964

6065
// Copy provides a copy behind an interface.

pkg/gvk/gvk.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package gvk
1818

1919
import (
20-
"k8s.io/apimachinery/pkg/runtime/schema"
2120
"strings"
2221
)
2322

@@ -36,24 +35,6 @@ func FromKind(k string) Gvk {
3635
}
3736
}
3837

39-
// FromSchemaGvk converts from a schema.GroupVersionKind.
40-
func FromSchemaGvk(x schema.GroupVersionKind) Gvk {
41-
return Gvk{
42-
Group: x.Group,
43-
Version: x.Version,
44-
Kind: x.Kind,
45-
}
46-
}
47-
48-
// ToSchemaGvk converts to a schema.GroupVersionKind.
49-
func (x Gvk) ToSchemaGvk() schema.GroupVersionKind {
50-
return schema.GroupVersionKind{
51-
Group: x.Group,
52-
Version: x.Version,
53-
Kind: x.Kind,
54-
}
55-
}
56-
5738
const (
5839
noGroup = "noGroup"
5940
noVersion = "noVersion"

0 commit comments

Comments
 (0)