*: operator-sdk new command generates project skeleton#21
*: operator-sdk new command generates project skeleton#21hongchaodeng merged 5 commits intooperator-framework:masterfrom fanminshi:gen_dirs
Conversation
|
Please do not generate |
|
let's finalize the skd command's interface and its behavior before continuing this pr; coding is simple but thinking is hard :) |
| codegenDir = tmpDir + "/codegen" | ||
| pkgDir = "pkg" | ||
| apisDir = pkgDir + "/apis" | ||
| clientDir = pkgDir + "/client" |
There was a problem hiding this comment.
No need for client as discussed.
| err = os.MkdirAll(filepath.Join(projDir, "pkg/apis", groupName, apiVersion), defaultFileMode) | ||
| if err != nil { | ||
| func (g *Generator) renderDeploy() error { | ||
| if err := os.MkdirAll(filepath.Join(deployDir, g.projectName), defaultFileMode); err != nil { |
There was a problem hiding this comment.
Only deploy/.
There will be a file <project-name>.yaml, e.g. memcached-operator.yaml.
|
@fanminshi |
|
@hongchaodeng yeah, i'll do that. |
|
test: func TestGenDirs(t *testing.T) {
gen := NewGenerator("app.example.com/v1alpha1", "AppService", "app-operator")
if err := gen.Render(); err != nil {
t.Error(err)
}
}output: |
| } | ||
|
|
||
| // Render generates the default project structure. | ||
| func (g *Generator) Render() error { |
There was a problem hiding this comment.
Add the ascii graph here?
This would be useful since we would keep it in sync when changing the layout.
Ideally we should also have test.
There was a problem hiding this comment.
kk, let me think of something.
|
all fixed. PTAL cc/ @hongchaodeng @hasbro17 |
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/coreos/operator-sdk/pkg/generator" |
There was a problem hiding this comment.
Leave space between non operator-sdk imports.
|
LGTM |
| // it uses the first word separated with "." of the groupName as the api directory name. | ||
| // for example, | ||
| // apiDirName("app.example.com/v1alpha1") => "app". | ||
| func apiDirName(apiGroup string) string { |
There was a problem hiding this comment.
We should do some error checking here on the format of the string, like if the user enters app/v1alpha.
Same for groupName() and apiVersion() functions.
There was a problem hiding this comment.
@hasbro17 I have a todo in https://github.com/coreos/operator-sdk/blob/master/commands/operator-sdk/cmd/new.go#L65 for that.
I think it is better to check input on top lvl so that the lower lvl code doesn't have to worry about it.
There was a problem hiding this comment.
@fanminshi Can you follow this comment in a new PR?
There was a problem hiding this comment.
@hongchaodeng it is a TODO inside cmd/new.go.
There was a problem hiding this comment.
I added this as part of the Action Items.
| } | ||
|
|
||
| // apiVersion extracts api version from the given apiGroup. | ||
| func apiVersion(apiGroup string) string { |
There was a problem hiding this comment.
So the APIVersion string is made up of group/version, e.g the APIVersion string app.example.com/v1alpha1 has group app.example.com and version v1alpha1.
So probably modify this func signature to
// version extracts version from the given apiVersion
func version(apiVersion string) string {
Similarly use the name apiVersion instead of apiGroup as the argument for the functions below as well.
The term apiGroup is not correct in this context since we're actually passing in the apiVersion string of the format "group/version".
There was a problem hiding this comment.
Also just FYI this format is only for CRDs and apis under the rest path /apis.
The core API group doesn't use this format. e.g for pods apiVersion=v1
https://kubernetes.io/docs/reference/api-overview/#api-groups
There was a problem hiding this comment.
The "v1" is actually legacy now. All new APIs will follow the group/version format including CRD and UAS.
There was a problem hiding this comment.
I took a look of the api-group definition at here https://kubernetes.io/docs/reference/api-overview/#api-groups.
The API group is specified in a REST path and in the apiVersion field of a serialized object.
It seems like api-group is equivalent apiVersion. In our case, the operator-sdk has a flag called --api-group. do we want to use that or --api-version instead?
the distinction between apiVersion and apiGroup is not very clear.
There was a problem hiding this comment.
I agree with what @hasbro17 said. Let's change based on his suggestion.
…-tini-path Bug 1747376 - Fix tini path in downstream image
operator-sdk new command now generates the project skeleton based on the new input.
operator-sdk new play-operatorcreates the follow defaults dirs: