Skip to content

Commit ba4651d

Browse files
committed
Upgrade kustomize dep
Signed-off-by: Siddhesh Ghadi <[email protected]>
1 parent 0869d72 commit ba4651d

File tree

7 files changed

+78
-206
lines changed

7 files changed

+78
-206
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
default: test
22

3+
.PHONY: build
4+
build:
5+
go build -v ./...
6+
37
.PHONY: test
48
test:
59
go test `go list ./... | grep -v test`

go.mod

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ require (
1818
go.uber.org/zap v1.26.0
1919
k8s.io/api v0.31.2
2020
k8s.io/apimachinery v0.31.2
21-
k8s.io/client-go v11.0.0+incompatible
22-
sigs.k8s.io/controller-runtime v0.17.2
23-
sigs.k8s.io/kustomize v2.0.3+incompatible
21+
k8s.io/client-go v0.31.2
22+
sigs.k8s.io/controller-runtime v0.19.1
23+
sigs.k8s.io/kustomize/api v0.17.2
24+
sigs.k8s.io/kustomize/kyaml v0.17.1
2425
sigs.k8s.io/yaml v1.4.0
2526
)
2627

@@ -53,20 +54,18 @@ require (
5354
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
5455
github.com/emirpasic/gods v1.18.1 // indirect
5556
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
56-
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
57+
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
5758
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
5859
github.com/fatih/camelcase v1.0.0 // indirect
5960
github.com/fsnotify/fsnotify v1.7.0 // indirect
6061
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
61-
github.com/ghodss/yaml v1.0.0 // indirect
6262
github.com/go-errors/errors v1.4.2 // indirect
6363
github.com/go-fed/httpsig v1.1.0 // indirect
6464
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
6565
github.com/go-git/go-billy/v5 v5.5.0 // indirect
6666
github.com/go-logr/logr v1.4.2 // indirect
6767
github.com/go-openapi/jsonpointer v0.19.6 // indirect
6868
github.com/go-openapi/jsonreference v0.20.2 // indirect
69-
github.com/go-openapi/spec v0.20.8 // indirect
7069
github.com/go-openapi/swag v0.22.4 // indirect
7170
github.com/go-redis/cache/v9 v9.0.0 // indirect
7271
github.com/gobwas/glob v0.2.3 // indirect
@@ -126,7 +125,7 @@ require (
126125
github.com/shurcooL/githubv4 v0.0.0-20190718010115-4ba037080260 // indirect
127126
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
128127
github.com/skeema/knownhosts v1.2.2 // indirect
129-
github.com/spf13/afero v1.1.2 // indirect
128+
github.com/spf13/afero v1.2.2 // indirect
130129
github.com/spf13/cast v1.6.0 // indirect
131130
github.com/spf13/jwalterweatherman v1.0.0 // indirect
132131
github.com/spf13/pflag v1.0.5 // indirect
@@ -172,9 +171,5 @@ require (
172171
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
173172
oras.land/oras-go/v2 v2.3.0 // indirect
174173
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
175-
sigs.k8s.io/kustomize/api v0.17.2 // indirect
176-
sigs.k8s.io/kustomize/kyaml v0.17.1 // indirect
177174
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
178175
)
179-
180-
replace k8s.io/client-go => k8s.io/client-go v0.31.0

go.sum

Lines changed: 24 additions & 154 deletions
Large diffs are not rendered by default.

pkg/gitfs/gitfs.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ package gitfs
33
import (
44
"fmt"
55
"path"
6+
"path/filepath"
67
"strings"
78

89
"github.com/go-git/go-git/v5"
910
"github.com/go-git/go-git/v5/plumbing/object"
1011
"github.com/go-git/go-git/v5/plumbing/storer"
1112
"github.com/go-git/go-git/v5/storage/memory"
12-
"sigs.k8s.io/kustomize/pkg/fs"
13+
fs "sigs.k8s.io/kustomize/kyaml/filesys"
1314
)
1415

1516
// gitFS is an internal implementation of the Kustomize
@@ -136,6 +137,16 @@ func (g gitFS) WriteFile(name string, data []byte) error {
136137
return errNotSupported("WriteFile")
137138
}
138139

140+
// Walk implementation for fs.FileSystem
141+
func (g gitFS) Walk(path string, walkFn filepath.WalkFunc) error {
142+
return errNotSupported("Walk")
143+
}
144+
145+
// ReadDir implementation for fs.FileSystem
146+
func (g gitFS) ReadDir(path string) ([]string, error) {
147+
return []string{}, errNotSupported("ReadDir")
148+
}
149+
139150
func errNotSupported(s string) error {
140151
return notSupported(s)
141152
}

pkg/gitfs/gitfs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66

77
"github.com/google/go-cmp/cmp"
8-
"sigs.k8s.io/kustomize/pkg/fs"
8+
fs "sigs.k8s.io/kustomize/kyaml/filesys"
99

1010
"github.com/redhat-developer/gitops-backend/test"
1111
)

pkg/httpapi/api_test.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ const (
3232
testRef = "7638417db6d59f3c431d3e1f261cc637155684cd"
3333
)
3434

35+
func makeTestClient() ctrlclient.Client {
36+
_ = argoV1aplha1.AddToScheme(scheme.Scheme)
37+
builder := fake.NewClientBuilder().WithIndex(
38+
&argoV1aplha1.Application{},
39+
"metadata.name",
40+
func(o ctrlclient.Object) []string {
41+
return []string{o.GetName()}
42+
},
43+
)
44+
return builder.Build()
45+
}
46+
3547
func TestGetPipelines(t *testing.T) {
3648
ts, c := makeServer(t)
3749
c.addContents("example/gitops", "pipelines.yaml", "HEAD", "testdata/pipelines.yaml")
@@ -403,13 +415,8 @@ func TestListApplications_badURL(t *testing.T) {
403415
}
404416

405417
func TestGetApplicationDetails(t *testing.T) {
406-
err := argoV1aplha1.AddToScheme(scheme.Scheme)
407-
if err != nil {
408-
t.Fatal(err)
409-
}
410-
411-
builder := fake.NewClientBuilder()
412-
kc := builder.Build()
418+
var err error
419+
kc := makeTestClient()
413420

414421
ts, _ := makeServer(t, func(router *APIRouter) {
415422
router.k8sClient = kc
@@ -510,13 +517,8 @@ func TestGetApplicationDetails(t *testing.T) {
510517
}
511518

512519
func TestGetApplicationHistory(t *testing.T) {
513-
err := argoV1aplha1.AddToScheme(scheme.Scheme)
514-
if err != nil {
515-
t.Fatal(err)
516-
}
517-
518-
builder := fake.NewClientBuilder()
519-
kc := builder.Build()
520+
var err error
521+
kc := makeTestClient()
520522

521523
ts, _ := makeServer(t, func(router *APIRouter) {
522524
router.k8sClient = kc

pkg/parser/parser.go

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import (
44
"github.com/go-git/go-git/v5"
55

66
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
7-
"sigs.k8s.io/kustomize/k8sdeps"
8-
"sigs.k8s.io/kustomize/pkg/fs"
9-
"sigs.k8s.io/kustomize/pkg/loader"
10-
"sigs.k8s.io/kustomize/pkg/resource"
11-
"sigs.k8s.io/kustomize/pkg/target"
7+
"sigs.k8s.io/kustomize/api/krusty"
8+
"sigs.k8s.io/kustomize/api/resource"
9+
fs "sigs.k8s.io/kustomize/kyaml/filesys"
1210

1311
"github.com/redhat-developer/gitops-backend/pkg/gitfs"
1412
)
@@ -24,26 +22,17 @@ func ParseFromGit(path string, opts *git.CloneOptions) ([]*Resource, error) {
2422
}
2523

2624
func parseConfig(path string, files fs.FileSystem) ([]*Resource, error) {
27-
k8sfactory := k8sdeps.NewFactory()
28-
ldr, err := loader.NewLoader(path, files)
29-
if err != nil {
30-
return nil, err
31-
}
32-
defer func() {
33-
err = ldr.Cleanup()
34-
if err != nil {
35-
panic(err)
36-
}
37-
}()
38-
kt, err := target.NewKustTarget(ldr, k8sfactory.ResmapF, k8sfactory.TransformerF)
39-
if err != nil {
40-
return nil, err
41-
}
42-
r, err := kt.MakeCustomizedResMap()
25+
26+
// Run performs a kustomization.
27+
// It reads given path from the given file system, interprets it as
28+
// a kustomization.yaml file, perform the kustomization it represents,
29+
// and return the resulting resources.
30+
kt := krusty.MakeKustomizer(krusty.MakeDefaultOptions())
31+
r, err := kt.Run(files, path)
4332
if err != nil {
4433
return nil, err
4534
}
46-
if len(r) == 0 {
35+
if len(r.Resources()) == 0 {
4736
return nil, nil
4837
}
4938

@@ -52,7 +41,7 @@ func parseConfig(path string, files fs.FileSystem) ([]*Resource, error) {
5241
return nil, err
5342
}
5443
resources := []*Resource{}
55-
for _, v := range r {
44+
for _, v := range r.Resources() {
5645
resources = append(resources, extractResource(conv, v))
5746
}
5847
return resources, nil
@@ -82,9 +71,10 @@ func extractResource(conv *unstructuredConverter, res *resource.Resource) *Resou
8271
}
8372

8473
// convert converts a Kustomize resource into a generic Unstructured resource
85-
// which which the unstructured converter uses to create resources from.
74+
// which the unstructured converter uses to create resources from.
8675
func convert(r *resource.Resource) *unstructured.Unstructured {
76+
res, _ := r.Map()
8777
return &unstructured.Unstructured{
88-
Object: r.Map(),
78+
Object: res,
8979
}
9080
}

0 commit comments

Comments
 (0)