Skip to content

Commit

Permalink
Update dependencies (#126)
Browse files Browse the repository at this point in the history
Signed-off-by: 1gtm <1gtm@appscode.com>
  • Loading branch information
1gtm committed Sep 11, 2021
1 parent f6511e7 commit c47f4d3
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -15,7 +15,7 @@ require (
gomodules.xyz/semvers v0.0.0-20210603205601-45dfbb5326a4
k8s.io/api v0.21.1
k8s.io/apimachinery v0.21.1
kmodules.xyz/client-go v0.0.0-20210827153326-54ead9c6225f
kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063
kmodules.xyz/schema-checker v0.1.2
sigs.k8s.io/yaml v1.2.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -681,8 +681,8 @@ k8s.io/klog/v2 v2.8.0/go.mod h1:hy9LJ/NvuK+iVyP4Ehqva4HxZG/oXyIS3n3Jmire4Ec=
k8s.io/kube-aggregator v0.21.1/go.mod h1:cAZ0n02IiSl57sQSHz4vvrz3upQRMbytOiZnpPJaQzQ=
k8s.io/kube-openapi v0.0.0-20210305001622-591a79e4bda7/go.mod h1:wXW5VT87nVfh/iLV8FpR2uDvrFyomxbtb1KivDbvPTE=
k8s.io/utils v0.0.0-20201110183641-67b214c5f920/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
kmodules.xyz/client-go v0.0.0-20210827153326-54ead9c6225f h1:yesFlt5yHpnklVxbVZWOQD2lWB5ETu85e1FGHdAorwg=
kmodules.xyz/client-go v0.0.0-20210827153326-54ead9c6225f/go.mod h1:0gkPeALtYjB27OHt4rd6+ZmMgoVTHVLtEJQeU23/gtA=
kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063 h1:u+/fmk4N1LsxeCU7q7vnNgaADK73UeyNWKzNtjFe3Bs=
kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063/go.mod h1:0gkPeALtYjB27OHt4rd6+ZmMgoVTHVLtEJQeU23/gtA=
kmodules.xyz/schema-checker v0.1.2 h1:HiG8pg/ROi+6D3HROUpHBCjEWF2aYXPxmycH/c5wAR4=
kmodules.xyz/schema-checker v0.1.2/go.mod h1:JyT3tjizU/gQY9bK56xzAvkjJoAaUPRam7HELx4Nb/o=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
Expand Down
73 changes: 73 additions & 0 deletions vendor/kmodules.xyz/client-go/tools/parser/parser.go
Expand Up @@ -19,6 +19,7 @@ package parser
import (
"bytes"
"io"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
Expand All @@ -43,6 +44,8 @@ func ProcessResources(data []byte, fn ResourceFn) error {
break
} else if IsYAMLSyntaxError(err) {
continue
} else if runtime.IsMissingKind(err) {
continue
} else if err != nil {
return err
}
Expand Down Expand Up @@ -83,6 +86,28 @@ func ProcessDir(dir string, fn ResourceFn) error {
})
}

func ProcessFS(fsys fs.FS, fn ResourceFn) error {
return fs.WalkDir(fsys, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
ext := filepath.Ext(d.Name())
if ext != ".yaml" && ext != ".yml" && ext != ".json" {
return nil
}

data, err := fs.ReadFile(fsys, path)
if err != nil {
return err
}

return ProcessResources(data, fn)
})
}

func ListResources(data []byte) ([]*unstructured.Unstructured, error) {
var resources []*unstructured.Unstructured

Expand All @@ -107,6 +132,54 @@ func ListResources(data []byte) ([]*unstructured.Unstructured, error) {
return resources, nil
}

func ListDirResources(dir string) ([]*unstructured.Unstructured, error) {
var resources []*unstructured.Unstructured

err := ProcessDir(dir, func(obj *unstructured.Unstructured) error {
if obj.GetNamespace() == "" {
obj.SetNamespace(core.NamespaceDefault)
}
resources = append(resources, obj)
return nil
})
if err != nil {
return nil, err
}

sort.Slice(resources, func(i, j int) bool {
if resources[i].GetAPIVersion() == resources[j].GetAPIVersion() {
return resources[i].GetKind() < resources[j].GetKind()
}
return resources[i].GetAPIVersion() < resources[j].GetAPIVersion()
})

return resources, nil
}

func ListFSResources(fsys fs.FS) ([]*unstructured.Unstructured, error) {
var resources []*unstructured.Unstructured

err := ProcessFS(fsys, func(obj *unstructured.Unstructured) error {
if obj.GetNamespace() == "" {
obj.SetNamespace(core.NamespaceDefault)
}
resources = append(resources, obj)
return nil
})
if err != nil {
return nil, err
}

sort.Slice(resources, func(i, j int) bool {
if resources[i].GetAPIVersion() == resources[j].GetAPIVersion() {
return resources[i].GetKind() < resources[j].GetKind()
}
return resources[i].GetAPIVersion() < resources[j].GetAPIVersion()
})

return resources, nil
}

var empty = struct{}{}

func ExtractComponents(data []byte) (map[metav1.GroupKind]struct{}, map[string]string, error) {
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Expand Up @@ -163,7 +163,7 @@ k8s.io/apimachinery/pkg/watch
k8s.io/apimachinery/third_party/forked/golang/reflect
# k8s.io/klog/v2 v2.8.0
k8s.io/klog/v2
# kmodules.xyz/client-go v0.0.0-20210827153326-54ead9c6225f
# kmodules.xyz/client-go v0.0.0-20210909114628-15cac6c74063
## explicit
kmodules.xyz/client-go/tools/parser
# kmodules.xyz/schema-checker v0.1.2
Expand Down

0 comments on commit c47f4d3

Please sign in to comment.