Skip to content

*: operator-sdk new command generates project skeleton#21

Merged
hongchaodeng merged 5 commits intooperator-framework:masterfrom
fanminshi:gen_dirs
Feb 20, 2018
Merged

*: operator-sdk new command generates project skeleton#21
hongchaodeng merged 5 commits intooperator-framework:masterfrom
fanminshi:gen_dirs

Conversation

@fanminshi
Copy link
Copy Markdown
Contributor

@fanminshi fanminshi commented Feb 19, 2018

operator-sdk new command now generates the project skeleton based on the new input.

operator-sdk new play-operator creates the follow defaults dirs:

├── cmd
│   └── play-operator
├── config
├── deploy
│   └── play-operator
├── pkg
│   ├── apis
│   │   └── play
│   │       └── v1
│   └── stub
└── tmp
    ├── build
    └── codegen

@fanminshi
Copy link
Copy Markdown
Contributor Author

cc/ @hasbro17 @hongchaodeng

@fanminshi fanminshi mentioned this pull request Feb 19, 2018
21 tasks
@hongchaodeng
Copy link
Copy Markdown
Contributor

Please do not generate pkg/apis by default.
See #20 (comment).
The default PlayService isn't very reusable. We should not have it by default.

@fanminshi
Copy link
Copy Markdown
Contributor Author

let's finalize the skd command's interface and its behavior before continuing this pr; coding is simple but thinking is hard :)

Comment thread pkg/generator/generator.go Outdated
codegenDir = tmpDir + "/codegen"
pkgDir = "pkg"
apisDir = pkgDir + "/apis"
clientDir = pkgDir + "/client"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for client as discussed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

less is more :)

Comment thread pkg/generator/generator.go Outdated
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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only deploy/.
There will be a file <project-name>.yaml, e.g. memcached-operator.yaml.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine with me!

@hongchaodeng
Copy link
Copy Markdown
Contributor

@fanminshi
When you address the change, can you also paste the layout after changed? Thanks!

@fanminshi
Copy link
Copy Markdown
Contributor Author

@hongchaodeng yeah, i'll do that.

@fanminshi
Copy link
Copy Markdown
Contributor Author

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:

├── app-operator
│   ├── cmd
│   │   └── app-operator
│   ├── config
│   ├── deploy
│   ├── pkg
│   │   ├── apis
│   │   │   └── app
│   │   │       └── v1alpha1
│   │   └── stub
│   └── tmp
│       ├── build
│       └── codegen

cc/ @hongchaodeng @hasbro17

}

// Render generates the default project structure.
func (g *Generator) Render() error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kk, let me think of something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added!

@fanminshi
Copy link
Copy Markdown
Contributor Author

all fixed. PTAL cc/ @hongchaodeng @hasbro17

import (
"fmt"

"github.com/coreos/operator-sdk/pkg/generator"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave space between non operator-sdk imports.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

@hongchaodeng
Copy link
Copy Markdown
Contributor

LGTM

@hongchaodeng hongchaodeng merged commit d255e8e into operator-framework:master Feb 20, 2018
@hongchaodeng hongchaodeng deleted the gen_dirs branch February 20, 2018 22:53
// 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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fanminshi Can you follow this comment in a new PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hongchaodeng it is a TODO inside cmd/new.go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this as part of the Action Items.

}

// apiVersion extracts api version from the given apiGroup.
func apiVersion(apiGroup string) string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "v1" is actually legacy now. All new APIs will follow the group/version format including CRD and UAS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with what @hasbro17 said. Let's change based on his suggestion.

m1kola pushed a commit to m1kola/operator-sdk that referenced this pull request Jun 7, 2024
…-tini-path

Bug 1747376 - Fix tini path in downstream image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants