Skip to content

internal/generator/olm-catalog: implement CSV generator #2407

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

Closed
wants to merge 11 commits into from

Conversation

estroz
Copy link
Member

@estroz estroz commented Jan 14, 2020

Description of the change:

  • cmd/operator-sdk/olmcatalog: remove config flag, add include flag, use CSV and package manifest generators

  • internal/generate/olm-catalog: implement CSV generator, moving most of the code from internal/scaffold/olm-catalog verbatim. Also removed CSV config

  • doc: remove CSVConfig documentation, update CLI docs

Motivation for the change: prepare CSV generator for plugin refactor. CSV config was removed in favor of the more flexible --include flag.

estroz added 3 commits January 9, 2020 12:57
use CSV and package manifest generators

internal/generate/olm-catalog: implement CSV and package manifest
generators, moving most of the code from internal/scaffold/olm-catalog
verbatim. Also removed CSV config

doc: remove CSVConfig documentation, update CLI docs
@estroz estroz added olm-integration Issue relates to the OLM integration kubebuilder-integration Relates to rewriting the SDK in Kubebuilder plugin form labels Jan 14, 2020
@openshift-ci-robot openshift-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jan 14, 2020
@estroz
Copy link
Member Author

estroz commented Jan 22, 2020

@aliok you can test #2279 using this branch. Note --inputs -> --include.

@aliok
Copy link
Contributor

aliok commented Jan 23, 2020

hi @estroz
Thanks a lot for the work. I think we're getting closer to an ideal functionality.

I found these problems:

1. Need build/Dockerfile.

The operator I am trying to run the CLI against is not using Operator SDK and no Dockerfile exists. We use ko to build the images.
This wasn't happening in my trials with previous versions of the tool.

2. Execution of command won't copy the CRD file.

My execution:

GO111MODULE="on" operator-sdk generate csv            \
  --include       "config/operator.yaml,config/role.yaml,config/300-eventing-v1alpha1-knativeeventing-crd.yaml,config/role_binding.yaml,config/service_account.yaml" \
  --from-version  "0.11.0"       \
  --csv-version   "0.12.0"       \
  --operator-name knative-eventing-operator \
  --csv-channel   alpha                     \
  --default-channel                         \
  --output-dir    "deploy/olm-catalog/knative-eventing-operator/0.12.0"      \
  --verbose

Tree before:

[aliok@localhost eventing-operator]$ tree deploy/
deploy/
└── olm-catalog
    └── knative-eventing-operator
        ├── 0.11.0
        │   ├── eventing_v1alpha1_knativeeventing_crd.yaml
        │   └── knative-eventing-operator.v0.11.0.clusterserviceversion.yaml
        └── knative-eventing-operator.package.yaml

Tree after execution:

[aliok@localhost eventing-operator]$ tree deploy/
deploy/
└── olm-catalog
    └── knative-eventing-operator
        ├── 0.11.0
        │   ├── eventing_v1alpha1_knativeeventing_crd.yaml
        │   └── knative-eventing-operator.v0.11.0.clusterserviceversion.yaml
        ├── 0.12.0
        │   ├── knative-eventing-operator.package.yaml
        │   └── knative-eventing-operator.v0.12.0.clusterserviceversion.yaml
        └── knative-eventing-operator.package.yaml

The CRD file is included in the --include, but wont' be outputted to directory for 0.12.0 (the new CSV version).
If I add --update-crds, I receive this message:

FATA[0000] open deploy/olm-catalog/knative-eventing-operator/0.12.0/knative-eventing-operator/0.12.0/config/300-eventing-v1alpha1-knativeeventing-crd.yaml: no such file or directory 

I guess the message above is normal, as --update-crds tries to update and overwrite CRD file in olm-catalog. We need some mechanism to also copy the crd into new directory for new CSV version.

3. Package and CSV is put into the same directory.

You can see that in the trees above.
If I use --output-dir "deploy/olm-catalog/knative-eventing-operator/", this time the package will be placed correctly but no nested directory will be created for the new CSV version.

Sorry for complaining a lot :( I am simply trying to make operator-sdk more useful in non-Operator-SDK scenarios in hope for more adoption in all operator communities.

4. Need GO111MODULE="on"

Need GO111MODULE="on" when running operator-sdk CLI. The operator I am trying to run the CLI against is not using Go modules. Adding GO111MODULE="on" won't make any harm when running the gen csv command, but it is annoying and maybe a sign of something wrong.
I am not sure if this is related to your changes in this PR. I guess probably not.
This is not a major issue.

@estroz
Copy link
Member Author

estroz commented Jan 23, 2020

@aliok thanks a bunch for testing this.

Turns out that exposing output-dir adds unnecessary complexity and results in potentially incorrect assumptions (resulting in 2 and 3 above) in the CSV generator, so I've removed it. It wasn't useful either, since CSV's should be read from a standard location for --from-version to work.

1 was introduced in #2322 to uphold assumptions the generator makes about where it is run. Perhaps we can relax this requirement to just having a deploy directory present.

I was not able to reproduce 4. Can you post your project's path? Does this affect our latest release (v0.15.0)?

@aliok
Copy link
Contributor

aliok commented Jan 24, 2020

@estroz

I see (2) and (3) are now fixed. That's really awesome!

1 was introduced in #2322 to uphold assumptions the generator makes about where it is run. Perhaps we can relax this requirement to just having a deploy directory present.

That would be great I think.

I was not able to reproduce 4. Can you post your project's path? Does this affect our latest release (v0.15.0)?

It happens with 0.15.0 as well. I think that's probably a problem on my side.

The project is at standard GOPATH (/home/aliok/go/src/knative.dev/eventing-operator) and is not a GoModules project (uses dep).
My GO111MODULE is off in my env vars.
I guess we should probably ignore this problem.

Thanks a lot again. Once we relax the rule for (1), we will be able to use the operator-sdk CLI with no problems at the Knative upstream operators.

err = writeCRDsToDir(csvCfg.CRDCRPaths, filepath.Dir(input.Path))
if err != nil {
return err
bundleDir := filepath.Join(gencatalog.OLMCatalogDir, strings.ToLower(c.operatorName), c.csvVersion)
Copy link
Contributor

Choose a reason for hiding this comment

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

@estroz I might have missed this from previous PRs but if the CSV generator inputs are meant to be configurable i.e change g.inputs[DeployDirKey] to point to another location deploy/production/ or in my case config for Kubebuilder's layout, then updating the CRD manifest to that new location would fail.
While the CSV and package manifests are written out to the new location, OLMCatalogDir is currently fixed to always be rooted at the deploy/ directory so it will try to update the CRDs there.

Is there any way we can stop using that constant, and instead use the generator's input for DeployDirKey?

Not sure if any other cmds that need to have a configurable "deploy" directory are using this constant as well. That could be another thing to watch out for.

Copy link
Member Author

Choose a reason for hiding this comment

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

Going to reconsider how inputs/filters are set up.

if typeMeta, err := GetTypeMetaFromBytes(b); err == nil {
if typeMeta.Kind == "CustomResourceDefinition" {
crdPaths = append(crdPaths, path)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Great 👍

Copy link
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.

Hi @estroz,

It shows great. Just missing a rebase.

@@ -18,6 +19,8 @@

### Removed

- **Breaking Change:** Removed CSV configuration file support in favor of including files as input to the generator using [`generate csv --include`](doc/cli/operator-sdk_generate_csv.md#options), defaulting to the `deploy/` directory. ([#2249](https://github.com/operator-framework/operator-sdk/pull/2249))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- **Breaking Change:** Removed CSV configuration file support in favor of including files as input to the generator using [`generate csv --include`](doc/cli/operator-sdk_generate_csv.md#options), defaulting to the `deploy/` directory. ([#2249](https://github.com/operator-framework/operator-sdk/pull/2249))
- **Breaking Change:** Removed CSV configuration file support (Defaults to deploy/olm-catalog/csv-config.yaml) in favor of including files as input to the generator using [`generate csv --include`](doc/cli/operator-sdk_generate_csv.md#options), defaulting to the `deploy/` directory. ([#2249](https://github.com/operator-framework/operator-sdk/pull/2249))

@hasbro17
Copy link
Contributor

hasbro17 commented Feb 4, 2020

@camilamacedo86 We discussed some necessary changes to the flags and generator config to better facilitate inputs/output for non-standard projects layout.
I'll be taking over this PR to add those in, along with the rebase.

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 4, 2020
@openshift-ci-robot
Copy link

@estroz: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@hasbro17
Copy link
Contributor

hasbro17 commented Feb 4, 2020

/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 4, 2020
@aliok
Copy link
Contributor

aliok commented Feb 5, 2020

@hasbro17 let me know if you need somebody to give things a try

@hasbro17
Copy link
Contributor

hasbro17 commented Feb 7, 2020

Closing this in favor of #2511 although that's still a WIP so not quite ready for reviews yet.

@hasbro17 hasbro17 closed this Feb 7, 2020
@estroz estroz deleted the feature/gen-csv-poc branch April 1, 2020 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kubebuilder-integration Relates to rewriting the SDK in Kubebuilder plugin form needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. olm-integration Issue relates to the OLM integration size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants