-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Create CRD validation specs in CRD manifests and as Go code #869
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
Merged
Merged
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
c8cccc8
commands/.../generate/*: build and call openapi-gen, and re-scaffold …
0e5fb86
fix comment
7db89b6
only use controller-tools CRD generator if in a Go project
82c09e2
change dir in unit test so Go project is detected
cdb791c
add names and only overwrite dstCrd when a file at path was generated
2aeb74b
use generated crd if one isn't present locally
e78a483
add test case for non-Go crd generation
03f39de
internal/util/*util/*: remove pkg/scaffold imports, which cause cycles
ac572ae
test/e2e/memcached_test.go: symlink pkg and internal
39dd0f9
pkg/scaffold/*: use a testData dir for scaffold tests instead of test…
590d95e
rename test dir to avoid import cycles during e2e test
05c7318
pkg/scaffold/crd.go: add IsOperatorGo field for controller-tools crd …
397a9fe
use test/test-framework code as test project
ccce673
revert removing scaffold constants from internal/util
b06c742
revert SrcDir change and check IsOperatorGo first
70db2ca
Merge branch 'master' into crd-validation
3db3e2f
change function name
94021e5
pkg/scaffold/crd.go: simplify unmarshalling crd
df3df61
use Golang initialism/acronym conventions for naming CR(D) types/vari…
003dc22
Merge branch 'master' into crd-validation
63f5730
Merge branch 'master' into crd-validation
d15010c
Gopkg.lock: revendor
394b756
commands/.../openapi.go: return error from CLI func instead of log.Fatal
8275efa
Merge branch 'master' into crd-validation
fbec75b
fix kube-openapi revision
5113e09
Merge branch 'master' into crd-validation
b5e915d
pkg/scaffold/gopkgtoml*.go: force sigs.k8s.io/controller-tools/pkg/cr…
0796cb3
Merge branch 'master' into crd-validation
53d1b59
Merge branch 'master' into crd-validation
2367e09
Merge branch 'master' into crd-validation
3c307d6
Merge branch 'master' into crd-validation
64688b0
remove extra kube-openapi override
e38a2f4
pkg/scaffold/types*.go: add note on adding custom validation
92b416f
commands/.../api.go: comment on what is generated in add api command …
3c379d0
commands/.../openapi.go: remove go header file from openapi-gen
334156e
new() -> &...{}
d0cbe0c
correct verbosity settings for deepcopy and openapi generators
5390096
Merge branch 'master' into crd-validation
2d4b621
commands/operator-sdk/cmd/add/crd.go: only skip overwriting CRD's/CR'…
2c76037
Merge branch 'skip-crd' into crd-validation
9b04d84
Merge branch 'master' into crd-validation
1da3de9
Merge branch 'master' into crd-validation
cc36958
verbose code generation in e2e test
93229be
add --header-file for Go boilerplate file path
b46c19a
update openapi command comment
d8108ef
Merge branch 'master' into crd-validation
35ff825
override go-openapi/spec to avoid new project dep solve errors
4c50988
Merge branch 'master' into crd-validation
446d2f1
revendor
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,106 @@ | ||
| // Copyright 2018 The Operator-SDK Authors | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package genutil | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "io/ioutil" | ||
| "os" | ||
| "os/exec" | ||
| "path/filepath" | ||
| "strings" | ||
|
|
||
| "github.com/operator-framework/operator-sdk/internal/util/projutil" | ||
| "github.com/operator-framework/operator-sdk/pkg/scaffold" | ||
| ) | ||
|
|
||
| func BuildCodegenBinaries(genDirs []string, binDir, codegenSrcDir string) error { | ||
| for _, gd := range genDirs { | ||
| err := runGoBuildCodegen(binDir, codegenSrcDir, gd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func runGoBuildCodegen(binDir, repoDir, genDir string) error { | ||
| binPath := filepath.Join(binDir, filepath.Base(genDir)) | ||
| cmd := exec.Command("go", "build", "-o", binPath, genDir) | ||
| cmd.Dir = repoDir | ||
| if gf, ok := os.LookupEnv(projutil.GoFlagsEnv); ok && len(gf) != 0 { | ||
| cmd.Env = append(os.Environ(), projutil.GoFlagsEnv+"="+gf) | ||
| } | ||
|
|
||
| if projutil.IsGoVerbose() { | ||
| return projutil.ExecCmd(cmd) | ||
| } | ||
| cmd.Stdout = ioutil.Discard | ||
| cmd.Stderr = ioutil.Discard | ||
| return cmd.Run() | ||
| } | ||
|
|
||
| // ParseGroupVersions parses the layout of pkg/apis to return a map of | ||
| // API groups to versions. | ||
| func ParseGroupVersions() (map[string][]string, error) { | ||
| gvs := make(map[string][]string) | ||
| groups, err := ioutil.ReadDir(scaffold.ApisDir) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("could not read pkg/apis directory to find api Versions: %v", err) | ||
| } | ||
|
|
||
| for _, g := range groups { | ||
| if g.IsDir() { | ||
| groupDir := filepath.Join(scaffold.ApisDir, g.Name()) | ||
| versions, err := ioutil.ReadDir(groupDir) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("could not read %s directory to find api Versions: %v", groupDir, err) | ||
| } | ||
|
|
||
| gvs[g.Name()] = make([]string, 0) | ||
| for _, v := range versions { | ||
| if v.IsDir() && scaffold.ResourceVersionRegexp.MatchString(v.Name()) { | ||
| gvs[g.Name()] = append(gvs[g.Name()], v.Name()) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if len(gvs) == 0 { | ||
| return nil, fmt.Errorf("no groups or versions found in %s", scaffold.ApisDir) | ||
| } | ||
| return gvs, nil | ||
| } | ||
|
|
||
| // CreateFQApis return a string of all fully qualified pkg + groups + versions | ||
| // of pkg and gvs in the format: | ||
| // "pkg/groupA/v1,pkg/groupA/v2,pkg/groupB/v1" | ||
| func CreateFQApis(pkg string, gvs map[string][]string) string { | ||
| gn := 0 | ||
| fqb := &strings.Builder{} | ||
| for g, vs := range gvs { | ||
| for vn, v := range vs { | ||
| fqb.WriteString(filepath.Join(pkg, g, v)) | ||
| if vn < len(vs)-1 { | ||
| fqb.WriteString(",") | ||
| } | ||
| } | ||
| if gn < len(gvs)-1 { | ||
| fqb.WriteString(",") | ||
| } | ||
| gn++ | ||
| } | ||
| return fqb.String() | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.