-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate 'generate openapi', add 'generate crds' (#2276)
* Deprecate 'generate openapi', add 'generate crds'
- Loading branch information
1 parent
d147bb3
commit 7cc38cc
Showing
23 changed files
with
266 additions
and
154 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
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.