Skip to content

Commit

Permalink
Upgrade kustomize dep
Browse files Browse the repository at this point in the history
Signed-off-by: Siddhesh Ghadi <[email protected]>
  • Loading branch information
svghadi committed Nov 8, 2024
1 parent 0869d72 commit ba4651d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 206 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
default: test

.PHONY: build
build:
go build -v ./...

.PHONY: test
test:
go test `go list ./... | grep -v test`
Expand Down
17 changes: 6 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ require (
go.uber.org/zap v1.26.0
k8s.io/api v0.31.2
k8s.io/apimachinery v0.31.2
k8s.io/client-go v11.0.0+incompatible
sigs.k8s.io/controller-runtime v0.17.2
sigs.k8s.io/kustomize v2.0.3+incompatible
k8s.io/client-go v0.31.2
sigs.k8s.io/controller-runtime v0.19.1
sigs.k8s.io/kustomize/api v0.17.2
sigs.k8s.io/kustomize/kyaml v0.17.1
sigs.k8s.io/yaml v1.4.0
)

Expand Down Expand Up @@ -53,20 +54,18 @@ require (
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
github.com/exponent-io/jsonpath v0.0.0-20151013193312-d6023ce2651d // indirect
github.com/fatih/camelcase v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-fed/httpsig v1.1.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-redis/cache/v9 v9.0.0 // indirect
github.com/gobwas/glob v0.2.3 // indirect
Expand Down Expand Up @@ -126,7 +125,7 @@ require (
github.com/shurcooL/githubv4 v0.0.0-20190718010115-4ba037080260 // indirect
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/afero v1.1.2 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down Expand Up @@ -172,9 +171,5 @@ require (
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
oras.land/oras-go/v2 v2.3.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.17.2 // indirect
sigs.k8s.io/kustomize/kyaml v0.17.1 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)

replace k8s.io/client-go => k8s.io/client-go v0.31.0
178 changes: 24 additions & 154 deletions go.sum

Large diffs are not rendered by default.

13 changes: 12 additions & 1 deletion pkg/gitfs/gitfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package gitfs
import (
"fmt"
"path"
"path/filepath"
"strings"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/plumbing/storer"
"github.com/go-git/go-git/v5/storage/memory"
"sigs.k8s.io/kustomize/pkg/fs"
fs "sigs.k8s.io/kustomize/kyaml/filesys"
)

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

// Walk implementation for fs.FileSystem
func (g gitFS) Walk(path string, walkFn filepath.WalkFunc) error {
return errNotSupported("Walk")
}

// ReadDir implementation for fs.FileSystem
func (g gitFS) ReadDir(path string) ([]string, error) {
return []string{}, errNotSupported("ReadDir")
}

func errNotSupported(s string) error {
return notSupported(s)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gitfs/gitfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"

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

"github.com/redhat-developer/gitops-backend/test"
)
Expand Down
30 changes: 16 additions & 14 deletions pkg/httpapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ const (
testRef = "7638417db6d59f3c431d3e1f261cc637155684cd"
)

func makeTestClient() ctrlclient.Client {
_ = argoV1aplha1.AddToScheme(scheme.Scheme)
builder := fake.NewClientBuilder().WithIndex(
&argoV1aplha1.Application{},
"metadata.name",
func(o ctrlclient.Object) []string {
return []string{o.GetName()}
},
)
return builder.Build()
}

func TestGetPipelines(t *testing.T) {
ts, c := makeServer(t)
c.addContents("example/gitops", "pipelines.yaml", "HEAD", "testdata/pipelines.yaml")
Expand Down Expand Up @@ -403,13 +415,8 @@ func TestListApplications_badURL(t *testing.T) {
}

func TestGetApplicationDetails(t *testing.T) {
err := argoV1aplha1.AddToScheme(scheme.Scheme)
if err != nil {
t.Fatal(err)
}

builder := fake.NewClientBuilder()
kc := builder.Build()
var err error
kc := makeTestClient()

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

func TestGetApplicationHistory(t *testing.T) {
err := argoV1aplha1.AddToScheme(scheme.Scheme)
if err != nil {
t.Fatal(err)
}

builder := fake.NewClientBuilder()
kc := builder.Build()
var err error
kc := makeTestClient()

ts, _ := makeServer(t, func(router *APIRouter) {
router.k8sClient = kc
Expand Down
40 changes: 15 additions & 25 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"github.com/go-git/go-git/v5"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"sigs.k8s.io/kustomize/k8sdeps"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/target"
"sigs.k8s.io/kustomize/api/krusty"
"sigs.k8s.io/kustomize/api/resource"
fs "sigs.k8s.io/kustomize/kyaml/filesys"

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

func parseConfig(path string, files fs.FileSystem) ([]*Resource, error) {
k8sfactory := k8sdeps.NewFactory()
ldr, err := loader.NewLoader(path, files)
if err != nil {
return nil, err
}
defer func() {
err = ldr.Cleanup()
if err != nil {
panic(err)
}
}()
kt, err := target.NewKustTarget(ldr, k8sfactory.ResmapF, k8sfactory.TransformerF)
if err != nil {
return nil, err
}
r, err := kt.MakeCustomizedResMap()

// Run performs a kustomization.
// It reads given path from the given file system, interprets it as
// a kustomization.yaml file, perform the kustomization it represents,
// and return the resulting resources.
kt := krusty.MakeKustomizer(krusty.MakeDefaultOptions())
r, err := kt.Run(files, path)
if err != nil {
return nil, err
}
if len(r) == 0 {
if len(r.Resources()) == 0 {
return nil, nil
}

Expand All @@ -52,7 +41,7 @@ func parseConfig(path string, files fs.FileSystem) ([]*Resource, error) {
return nil, err
}
resources := []*Resource{}
for _, v := range r {
for _, v := range r.Resources() {
resources = append(resources, extractResource(conv, v))
}
return resources, nil
Expand Down Expand Up @@ -82,9 +71,10 @@ func extractResource(conv *unstructuredConverter, res *resource.Resource) *Resou
}

// convert converts a Kustomize resource into a generic Unstructured resource
// which which the unstructured converter uses to create resources from.
// which the unstructured converter uses to create resources from.
func convert(r *resource.Resource) *unstructured.Unstructured {
res, _ := r.Map()
return &unstructured.Unstructured{
Object: r.Map(),
Object: res,
}
}

0 comments on commit ba4651d

Please sign in to comment.