-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Deprecate 'generate openapi', add 'generate crds' #2276
Merged
joelanford
merged 4 commits into
operator-framework:master
from
joelanford:remove-zz-generated-openapi
Dec 5, 2019
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
857e434
*: remove zz_generated.openapi.go generation, rename 'generate openap…
joelanford 7c75f90
cmd: keep openapi with deprecation and instructions for migrating
joelanford 8d8e787
hack/generate/gen-cli-doc.go: un-revert cli generator
joelanford 4c0feb8
CHANGELOG.md: remove outdated change line for #2276
joelanford 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
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
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2019 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 generate | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/operator-framework/operator-sdk/cmd/operator-sdk/internal/genutil" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newGenerateCRDsCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "crds", | ||
Short: "Generates CRDs for API's", | ||
Long: `generate crds generates CRDs or updates them if they exist, | ||
under deploy/crds/<full group>_<resource>_crd.yaml; OpenAPI | ||
V3 validation YAML is generated as a 'validation' object. | ||
|
||
Example: | ||
|
||
$ operator-sdk generate crds | ||
$ tree deploy/crds | ||
├── deploy/crds/app.example.com_v1alpha1_appservice_cr.yaml | ||
├── deploy/crds/app.example.com_appservices_crd.yaml | ||
`, | ||
RunE: crdsFunc, | ||
} | ||
} | ||
|
||
func crdsFunc(cmd *cobra.Command, args []string) error { | ||
if len(args) != 0 { | ||
return fmt.Errorf("command %s doesn't accept any arguments", cmd.CommandPath()) | ||
} | ||
|
||
return genutil.CRDGen() | ||
} |
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// 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" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/operator-framework/operator-sdk/internal/scaffold" | ||
"github.com/operator-framework/operator-sdk/internal/scaffold/input" | ||
"github.com/operator-framework/operator-sdk/internal/util/k8sutil" | ||
"github.com/operator-framework/operator-sdk/internal/util/projutil" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// CRDGen generates CRDs for all APIs in pkg/apis. | ||
func CRDGen() error { | ||
projutil.MustInProjectRoot() | ||
|
||
absProjectPath := projutil.MustGetwd() | ||
repoPkg := projutil.GetGoPkg() | ||
|
||
gvMap, err := k8sutil.ParseGroupSubpackages(scaffold.ApisDir) | ||
if err != nil { | ||
return fmt.Errorf("failed to parse group versions: (%v)", err) | ||
} | ||
gvb := &strings.Builder{} | ||
for g, vs := range gvMap { | ||
gvb.WriteString(fmt.Sprintf("%s:%v, ", g, vs)) | ||
} | ||
|
||
log.Infof("Running CRD generation for Custom Resource group versions: [%v]\n", gvb.String()) | ||
|
||
s := &scaffold.Scaffold{} | ||
cfg := &input.Config{ | ||
Repo: repoPkg, | ||
AbsProjectPath: absProjectPath, | ||
ProjectName: filepath.Base(absProjectPath), | ||
} | ||
crds, err := k8sutil.GetCRDs(scaffold.CRDsDir) | ||
if err != nil { | ||
return err | ||
} | ||
for _, crd := range crds { | ||
g, v, k := crd.Spec.Group, crd.Spec.Version, crd.Spec.Names.Kind | ||
if v == "" { | ||
if len(crd.Spec.Versions) != 0 { | ||
v = crd.Spec.Versions[0].Name | ||
} else { | ||
return fmt.Errorf("crd of group %s kind %s has no version", g, k) | ||
} | ||
} | ||
r, err := scaffold.NewResource(g+"/"+v, k) | ||
if err != nil { | ||
return err | ||
} | ||
err = s.Execute(cfg, | ||
&scaffold.CRD{Resource: r, IsOperatorGo: projutil.IsOperatorGo()}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
log.Info("CRD generation complete.") | ||
return nil | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
## operator-sdk generate crds | ||
|
||
Generates CRDs for API's | ||
|
||
### Synopsis | ||
|
||
generate crds generates CRDs or updates them if they exist, | ||
under deploy/crds/<full group>_<resource>_crd.yaml; OpenAPI | ||
V3 validation YAML is generated as a 'validation' object. | ||
|
||
Example: | ||
|
||
$ operator-sdk generate crds | ||
$ tree deploy/crds | ||
├── deploy/crds/app.example.com_v1alpha1_appservice_cr.yaml | ||
├── deploy/crds/app.example.com_appservices_crd.yaml | ||
|
||
|
||
``` | ||
operator-sdk generate crds [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for crds | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [operator-sdk generate](operator-sdk_generate.md) - Invokes specific generator | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a flag for passing in the location of the CRD's?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once this merges, I'll make an issue to discuss this idea for a follow-up.