generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename localFilesClient to localSchemasClient and don't con…
…sider CRDs Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
- Loading branch information
1 parent
352a78c
commit c3e7d68
Showing
4 changed files
with
62 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,4 @@ func TestGitHubBuiltins(t *testing.T) { | |
t.Fatal(err) | ||
} | ||
fmt.Println(m) | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package openapiclient | ||
|
||
import ( | ||
"fmt" | ||
"io/fs" | ||
"path/filepath" | ||
"strings" | ||
|
||
"k8s.io/client-go/openapi" | ||
"sigs.k8s.io/kubectl-validate/pkg/openapiclient/groupversion" | ||
"sigs.k8s.io/kubectl-validate/pkg/utils" | ||
) | ||
|
||
// client which provides openapi read from files on disk | ||
type localSchemasClient struct { | ||
fs fs.FS | ||
dir string | ||
} | ||
|
||
// Dir should have openapi files following directory layout: | ||
// /<apis>/<group>/<version>.json | ||
// /api/<version>.json | ||
func NewLocalSchemas(fs fs.FS, dirPath string) openapi.Client { | ||
return &localSchemasClient{ | ||
fs: fs, | ||
dir: dirPath, | ||
} | ||
} | ||
|
||
func (k *localSchemasClient) Paths() (map[string]openapi.GroupVersion, error) { | ||
if len(k.dir) == 0 { | ||
return nil, nil | ||
} | ||
res := map[string]openapi.GroupVersion{} | ||
apiGroups, _ := utils.ReadDir(k.fs, filepath.Join(k.dir, "apis")) | ||
for _, f := range apiGroups { | ||
groupPath := filepath.Join(k.dir, "apis", f.Name()) | ||
versions, err := utils.ReadDir(k.fs, groupPath) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed reading local files dir %s: %w", groupPath, err) | ||
} | ||
for _, v := range versions { | ||
if !utils.IsJson(v.Name()) { | ||
continue | ||
} | ||
name := strings.TrimSuffix(v.Name(), filepath.Ext(v.Name())) | ||
path := filepath.Join("apis", f.Name(), name) | ||
res[path] = groupversion.NewForFile(k.fs, filepath.Join(groupPath, v.Name())) | ||
} | ||
} | ||
coregroup, _ := utils.ReadDir(k.fs, filepath.Join(k.dir, "api")) | ||
for _, v := range coregroup { | ||
if !utils.IsJson(v.Name()) { | ||
continue | ||
} | ||
name := strings.TrimSuffix(v.Name(), filepath.Ext(v.Name())) | ||
path := filepath.Join("api", name) | ||
res[path] = groupversion.NewForFile(k.fs, filepath.Join(k.dir, "api", v.Name())) | ||
} | ||
return res, nil | ||
} |