Skip to content

generate: add bundle subcommand for new project layouts#3065

Merged
estroz merged 2 commits intooperator-framework:masterfrom
estroz:feature/generate-bundle
May 22, 2020
Merged

generate: add bundle subcommand for new project layouts#3065
estroz merged 2 commits intooperator-framework:masterfrom
estroz:feature/generate-bundle

Conversation

@estroz
Copy link
Copy Markdown
Member

@estroz estroz commented May 18, 2020

Description of the change:

  • operator-sdk generate bundle with:
    • --kustomize: creates config/bundle/kustomization.yaml, and creates or updates config/bundle/bases with UI metadata. The base contains no manifests. This command will read API type data to generate customresourcedefinitions metadata using GVK's in PROJECT.
    • --manifests: reads either from stdin or on-disk files and applies them to a base to write CSV and CRD manifests to config/bases/manifests. This command emulates kustomize build.
    • --metadata: calls the same generator as the current bundle create --generate-only.

Motivation for the change: See #2860.

Depends on #3064.

@openshift-ci-robot openshift-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 18, 2020
@estroz estroz force-pushed the feature/generate-bundle branch from c94c126 to de0633e Compare May 19, 2020 00:21
@estroz estroz changed the title [WIP] generate bundle generate: add bundle subcommand for new project layouts May 19, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label May 19, 2020
@estroz estroz force-pushed the feature/generate-bundle branch from de0633e to e801396 Compare May 19, 2020 00:36
@estroz
Copy link
Copy Markdown
Member Author

estroz commented May 19, 2020

/cc @hasbro17

Copy link
Copy Markdown
Contributor

@hasbro17 hasbro17 left a comment

Choose a reason for hiding this comment

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

Still going through but had a question on the --manifest-root flag.

Comment thread internal/generate/clusterserviceversion/clusterserviceversion.go Outdated
Comment thread internal/generate/clusterserviceversion/clusterserviceversion.go Outdated
Comment thread cmd/operator-sdk/generate/bundle/cmd.go Outdated
"Only set if creating a new bundle or upgrading your operator")
fs.StringVar(&c.inputDir, "input-dir", "", "Directory to read an existing bundle format from")
fs.StringVar(&c.outputDir, "output-dir", "", "Directory to write the bundle format to")
fs.StringVar(&c.manifestRoot, "manifest-root", "", "Root directory for operator manifests, ex. Deployment and RBAC")
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.

@estroz So this is effectively --deploy-dir right?
I guess this is subjective but manifests immediately made me think of the bundle manifests directory.
I wonder if a better name wouldn't be operator-manifests-dir similar to crds-dir even if it's more verbose.
Also correct me if I'm wrong but this dir is used for Custom Resource manifests collection, and not the crd dir as mentioned below:

Suggested change
fs.StringVar(&c.manifestRoot, "manifest-root", "", "Root directory for operator manifests, ex. Deployment and RBAC")
fs.StringVar(&c.manifestRoot, "manifest-root", "", "Root directory for operator manifests: Deployment, RBAC and CustomResources.")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

operator-manifests-dir doesn't seem different enough to me. Perhaps a better solution is to be explicit about the difference between --input-dir and --manifest-root in flag help.

Comment thread cmd/operator-sdk/generate/bundle/cmd.go Outdated
Comment thread cmd/operator-sdk/generate/bundle/cmd.go Outdated
@estroz estroz force-pushed the feature/generate-bundle branch from 288b773 to 0da8689 Compare May 21, 2020 19:06
Copy link
Copy Markdown
Contributor

@hasbro17 hasbro17 left a comment

Choose a reason for hiding this comment

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

LGTM

The Gomega tests are a joy to read. A far cry from our current csv unit tests. Great work on making it so readable.

Just one nit on making the internal errors constants.

Also I still think having the flags --manifests for bundle generation and manifest-root for operator manifests makes it seems like they're related when they're not.
But not going to hold up this PR over that since the flags have enough descriptions to highlight the difference.


BeforeEach(func() {
tmp, err = ioutil.TempDir(".", "")
ExpectWithOffset(1, err).ToNot(HaveOccurred())
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.

Why are we using ExpectWithOffset()?
Does Expect(err).ToNot(HaveOccurred()) not work here?

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.

Unlike `Expect` and `Ω`, `ExpectWithOffset` takes an additional integer argument that is used to modify the call-stack offset when computing line numbers.

This is most useful in helper functions that make assertions. If you want Gomega's error message to refer to the calling line in the test (as opposed to the line in the helper function) set the first argument of `ExpectWithOffset` appropriately.

Seems like this is to bubble up error to the line number of the caller and not the helper itself.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Exactly, and I've named all test helper functions that use gomega Expect*() functions with the Helper suffix.

Comment thread internal/generate/clusterserviceversion/clusterserviceversion_test.go Outdated
@estroz estroz force-pushed the feature/generate-bundle branch from 0da8689 to 24ab500 Compare May 21, 2020 23:39
Comment thread cmd/operator-sdk/generate/bundle/cmd.go Outdated
},
}

cmd.Flags().BoolVar(&c.kustomize, "kustomize", false, "Generate kustomize bases")
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.

Suggested change
cmd.Flags().BoolVar(&c.kustomize, "kustomize", false, "Generate kustomize bases")
cmd.Flags().BoolVar(&c.kustomize, "kustomize", false, "If set, generate ONLY the kustomize config bases")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If you set --kustomize --manifests, both bases and manifests will be generated. I think giving this a simple help description is ok for now.

Copy link
Copy Markdown
Contributor

@camilamacedo86 camilamacedo86 May 22, 2020

Choose a reason for hiding this comment

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

My suggestion is made clear that if we set the option than means that only that will be exec which in POV not so intuitive as described here: https://github.com/operator-framework/operator-sdk/pull/2860/files#r427888547

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If you only set --kustomize, only kustomize bases are generated, as you'd expect. If you set another flag with --kustomize like --manifests, then both kustomize bases and manifests will be generated. I think that's what you're trying to say right?

}

cmd.Flags().BoolVar(&c.kustomize, "kustomize", false, "Generate kustomize bases")
cmd.Flags().BoolVar(&c.manifests, "manifests", false, "Generate bundle manifests")
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.

Suggested change
cmd.Flags().BoolVar(&c.manifests, "manifests", false, "Generate bundle manifests")
cmd.Flags().BoolVar(&c.manifests, "manifests", false, "If set, generate ONLY the bundle manifests")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ditto ^


cmd.Flags().BoolVar(&c.kustomize, "kustomize", false, "Generate kustomize bases")
cmd.Flags().BoolVar(&c.manifests, "manifests", false, "Generate bundle manifests")
cmd.Flags().BoolVar(&c.metadata, "metadata", false, "Generate bundle metadata and Dockerfile")
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.

Suggested change
cmd.Flags().BoolVar(&c.metadata, "metadata", false, "Generate bundle metadata and Dockerfile")
cmd.Flags().BoolVar(&c.metadata, "metadata", false, "If set, generate ONLY the bundle metadata and its Dockerfile")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ditto ^

Comment thread cmd/operator-sdk/generate/bundle/bundle.go Outdated
Comment thread cmd/operator-sdk/generate/bundle/bundle.go
@estroz estroz force-pushed the feature/generate-bundle branch 2 times, most recently from c08c8c0 to 10527e2 Compare May 21, 2020 23:58
Comment thread cmd/operator-sdk/generate/bundle/bundle.go Outdated
Comment thread cmd/operator-sdk/generate/bundle/bundle.go Outdated
Comment thread cmd/operator-sdk/generate/bundle/bundle.go
if err := fs.MarkHidden("manifest-root"); err != nil {
panic(err)
}

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.

Can we just improve the info to clarifies by giving examples over what from where is expected usually? Eg. Directory to read an existing bundle format from. Eg

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For --manifest-root? The help lists deploy and config as example values to pass. I expect we can improve this flag in #2860.

Comment thread cmd/operator-sdk/generate/cmd.go
Copy link
Copy Markdown
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

IMO it is just missing doc methods in order to allow others to understand where/when/why better as improving the flags info to make easier know what is expected in each case and their behaviour.

Otherwise, it is LGTM.

Eric Stroczynski added 2 commits May 21, 2020 17:15
for a "new" project layout.

cmd/operator-sdk/generate: bundle command; CustomResourceDefinition update
behvior lives here

internal/generate/clusterserviceversion: modular ClusterServiceVersion
generator
@estroz estroz force-pushed the feature/generate-bundle branch from 10527e2 to ace0487 Compare May 22, 2020 00:15
@estroz estroz merged commit 357491d into operator-framework:master May 22, 2020
@estroz estroz deleted the feature/generate-bundle branch May 22, 2020 01:49
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.

4 participants