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

chore: Update argocd, k8s & kustomize deps #46

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
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
286 changes: 137 additions & 149 deletions go.mod

Large diffs are not rendered by default.

1,446 changes: 480 additions & 966 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"net/http"

argoV1aplha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
argoV1aplha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down
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"
Copy link
Member Author

@svghadi svghadi Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigs.k8s.io/kustomize/pkg/fs package is deprecated in favour of sigs.k8s.io/kustomize/kyaml/filesys

Ref: https://github.com/kubernetes-sigs/kustomize/blob/afe77936761f8f7ee735a67f167a8382c8406f74/api/filesys/filesys.go#L8-L9

)

// 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
2 changes: 1 addition & 1 deletion pkg/httpapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"net/url"
"strings"

argoV1aplha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
argoV1aplha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
"github.com/julienschmidt/httprouter"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down
32 changes: 17 additions & 15 deletions pkg/httpapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"testing"
"time"

argoV1aplha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
argoV1aplha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
gogit "github.com/go-git/go-git/v5"
"github.com/google/go-cmp/cmp"
"github.com/redhat-developer/gitops-backend/pkg/git"
Expand All @@ -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
7 changes: 4 additions & 3 deletions pkg/httpapi/conversion.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package httpapi

import (
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sort"
"strings"

argoV1aplha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

argoV1aplha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
)

// TODO: this should really import the config from the upstream and use it to
Expand Down
3 changes: 2 additions & 1 deletion pkg/httpapi/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package httpapi

import (
"fmt"
argoV1aplha1 "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
"testing"
"time"

argoV1aplha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"

"github.com/google/go-cmp/cmp"
)

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()
Comment on lines -27 to -42
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// 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,
}
}
Loading