-
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 34 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 …
estroz 0e5fb86
fix comment
estroz 7db89b6
only use controller-tools CRD generator if in a Go project
estroz 82c09e2
change dir in unit test so Go project is detected
estroz cdb791c
add names and only overwrite dstCrd when a file at path was generated
estroz 2aeb74b
use generated crd if one isn't present locally
estroz e78a483
add test case for non-Go crd generation
estroz 03f39de
internal/util/*util/*: remove pkg/scaffold imports, which cause cycles
estroz ac572ae
test/e2e/memcached_test.go: symlink pkg and internal
estroz 39dd0f9
pkg/scaffold/*: use a testData dir for scaffold tests instead of test…
estroz 590d95e
rename test dir to avoid import cycles during e2e test
estroz 05c7318
pkg/scaffold/crd.go: add IsOperatorGo field for controller-tools crd …
estroz 397a9fe
use test/test-framework code as test project
estroz ccce673
revert removing scaffold constants from internal/util
estroz b06c742
revert SrcDir change and check IsOperatorGo first
estroz 70db2ca
Merge branch 'master' into crd-validation
estroz 3db3e2f
change function name
estroz 94021e5
pkg/scaffold/crd.go: simplify unmarshalling crd
estroz df3df61
use Golang initialism/acronym conventions for naming CR(D) types/vari…
estroz 003dc22
Merge branch 'master' into crd-validation
estroz 63f5730
Merge branch 'master' into crd-validation
estroz d15010c
Gopkg.lock: revendor
estroz 394b756
commands/.../openapi.go: return error from CLI func instead of log.Fatal
estroz 8275efa
Merge branch 'master' into crd-validation
estroz fbec75b
fix kube-openapi revision
estroz 5113e09
Merge branch 'master' into crd-validation
estroz b5e915d
pkg/scaffold/gopkgtoml*.go: force sigs.k8s.io/controller-tools/pkg/cr…
estroz 0796cb3
Merge branch 'master' into crd-validation
estroz 53d1b59
Merge branch 'master' into crd-validation
estroz 2367e09
Merge branch 'master' into crd-validation
estroz 3c307d6
Merge branch 'master' into crd-validation
estroz 64688b0
remove extra kube-openapi override
estroz e38a2f4
pkg/scaffold/types*.go: add note on adding custom validation
estroz 92b416f
commands/.../api.go: comment on what is generated in add api command …
estroz 3c379d0
commands/.../openapi.go: remove go header file from openapi-gen
estroz 334156e
new() -> &...{}
estroz d0cbe0c
correct verbosity settings for deepcopy and openapi generators
estroz 5390096
Merge branch 'master' into crd-validation
estroz 2d4b621
commands/operator-sdk/cmd/add/crd.go: only skip overwriting CRD's/CR'…
estroz 2c76037
Merge branch 'skip-crd' into crd-validation
estroz 9b04d84
Merge branch 'master' into crd-validation
estroz 1da3de9
Merge branch 'master' into crd-validation
estroz cc36958
verbose code generation in e2e test
estroz 93229be
add --header-file for Go boilerplate file path
estroz b46c19a
update openapi command comment
estroz d8108ef
Merge branch 'master' into crd-validation
estroz 35ff825
override go-openapi/spec to avoid new project dep solve errors
estroz 4c50988
Merge branch 'master' into crd-validation
estroz 446d2f1
revendor
estroz 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,110 @@ | ||
// 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/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)) | ||
installCmd := exec.Command("go", "build", "-o", binPath, genDir) | ||
installCmd.Dir = repoDir | ||
isVerbose := false | ||
if gf, ok := os.LookupEnv("GOFLAGS"); ok && len(gf) != 0 { | ||
installCmd.Env = append(os.Environ(), "GOFLAGS="+gf) | ||
if strings.Contains(gf, "-v") { | ||
isVerbose = true | ||
} | ||
} | ||
if isVerbose { | ||
installCmd.Stdout = os.Stdout | ||
installCmd.Stderr = os.Stderr | ||
} else { | ||
installCmd.Stdout = ioutil.Discard | ||
installCmd.Stderr = ioutil.Discard | ||
} | ||
return installCmd.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.