Skip to content

generate: parse CSV annotations with controller-tools/pkg/markers#2792

Merged
estroz merged 4 commits intooperator-framework:masterfrom
estroz:refactor/csv-markers
Jul 22, 2020
Merged

generate: parse CSV annotations with controller-tools/pkg/markers#2792
estroz merged 4 commits intooperator-framework:masterfrom
estroz:refactor/csv-markers

Conversation

@estroz
Copy link
Copy Markdown
Member

@estroz estroz commented Apr 7, 2020

Description of the change: use sigs.k8s.io/controller-tools/pkg/markers to re-write the CSV annotations (now known as markers) machinery.

Motivation for the change: speedup of ~20x based on unit test runtime:

# Uses new markers.
$ go test ./internal/generate/clusterserviceversion/...
ok  	github.com/operator-framework/operator-sdk/internal/generate/clusterserviceversion	1.683s
ok  	github.com/operator-framework/operator-sdk/internal/generate/clusterserviceversion/bases	(cached)
ok  	github.com/operator-framework/operator-sdk/internal/generate/clusterserviceversion/bases/definitions	0.898s

# Uses old annotations.
$ go test ./internal/generate/olm-catalog/...
ok  	github.com/operator-framework/operator-sdk/internal/generate/olm-catalog	86.300s
ok  	github.com/operator-framework/operator-sdk/internal/generate/olm-catalog/descriptor	64.433s

TODO:

  • make sure we're ok with breaking changes to marker formats (there's no good way to maintain the old format with these changes)
  • clean up a few things left over from testing.

@estroz estroz added the olm-integration Issue relates to the OLM integration label Apr 7, 2020
@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 Apr 7, 2020
@estroz estroz requested review from hasbro17 and joelanford April 7, 2020 07:42
Comment thread internal/generate/olm-catalog/csv_updaters.go Outdated
Comment thread internal/generate/olm-catalog/descriptor/crd.go Outdated
Comment thread internal/generate/olm-catalog/descriptor/parse_test.go
Comment thread internal/generate/testdata/go/pkg/apis/cache/v1alpha1/dummy_types.go Outdated
@estroz estroz force-pushed the refactor/csv-markers branch 2 times, most recently from 88cd734 to a53c74a Compare April 7, 2020 22:53
@estroz estroz marked this pull request as ready for review April 14, 2020 01:04
@estroz estroz removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 14, 2020
@joelanford
Copy link
Copy Markdown
Member

What is the possibility of introducing the new format while simultaneously keeping the old format, so that we can deprecate without immediately breaking and give folks time to transition?

@estroz
Copy link
Copy Markdown
Member Author

estroz commented Apr 15, 2020

@joelanford that may prove difficult but let me see how easy it is first.

Edit: the dot-in-path (ex. customresourcedefinitions.displayName) is not allowed by the markers system. As far as I can tell we have two choices:

  1. Make a breaking change now.
  2. Support the new format using gengo parsing (the current method), and break later.

While method 2 does provide a true deprecation path, it will require some extra work to parse the new marker format.

@estroz estroz force-pushed the refactor/csv-markers branch from a53c74a to c5d0103 Compare April 15, 2020 00:50
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 17, 2020
@estroz estroz force-pushed the refactor/csv-markers branch from c5d0103 to 9446856 Compare April 17, 2020 21:42
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 17, 2020
@estroz
Copy link
Copy Markdown
Member Author

estroz commented Apr 17, 2020

Two more options:

  1. Write a migration script (effectively sed -i 's/old format/new format/g') which would be fairly easy.
  2. Keep all the old gengo code/format for legacy projects, and advertise the new format for kubebuilder projects.

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

@estroz

Two more options:

  1. Write a migration script (effectively sed -i 's/old format/new format/g') which would be fairly easy.
  2. Keep all the old gengo code/format for legacy projects, and advertise the new format for kubebuilder projects.

Can we do both of these and also deprecate the old gengo code/format for legacy projects?

So the result would be:

  • Kubebuilder projects are only compatible with the new format
  • Legacy projects are compatible with both formats for v0.18.0 and v0.19.0
  • Starting with v0.20.0, legacy project are only compatible with the new format

This way we have a path to fully removing the old gengo-based parsing.

@estroz estroz force-pushed the refactor/csv-markers branch from 9446856 to 7cd3e7a Compare April 24, 2020 17:32
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 24, 2020
@estroz estroz force-pushed the refactor/csv-markers branch 3 times, most recently from a7ed23d to 064aeda Compare April 28, 2020 17:43
@estroz
Copy link
Copy Markdown
Member Author

estroz commented Apr 28, 2020

@joelanford done adding back old behavior, take a look. Will write a migration script and docs.

Comment thread internal/generate/olm-catalog/csv.go Outdated
@estroz estroz force-pushed the refactor/csv-markers branch 3 times, most recently from c50ef88 to d0f4666 Compare May 11, 2020 19:33
@estroz estroz force-pushed the refactor/csv-markers branch 2 times, most recently from 1480b36 to 6095653 Compare June 23, 2020 21:07
@estroz
Copy link
Copy Markdown
Member Author

estroz commented Jun 23, 2020

@estroz estroz force-pushed the refactor/csv-markers branch from 6095653 to 84b26eb Compare June 23, 2020 21:54
@estroz estroz added this to the v1.0.0 milestone Jul 2, 2020
@joelanford joelanford mentioned this pull request Jul 2, 2020
92 tasks
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.

@estroz,

I tested it with a personal project and could not find any issue. So, all shows fine when has not the PROJECT file.

After, just add the project file I started to face :

$ operator-sdk generate csv --csv-version 0.0.2 --update-crds FATA[0000] version format must match ^(v)?([1-9][0-9]*)(-alpha|-beta)?$

Also, could you please clarify better in the first comment what are the breaking changes? Are we changing the markers?
I am not sure about what changes with this PR, would be nice have this info in the first comment for we know what exactly we need test and verify. Also, the motivation here just makes it runs faster?

@estroz estroz force-pushed the refactor/csv-markers branch from 84b26eb to d4b5758 Compare July 13, 2020 21:33
@estroz
Copy link
Copy Markdown
Member Author

estroz commented Jul 13, 2020

Closes #2983

Copy link
Copy Markdown
Contributor

@tlwu2013 tlwu2013 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 , this looks great! Spot a few errors from the example in the doc, can you help take a look? thanks!

- description: The desired number of member Pods for the deployment.
displayName: Size
path: podStatuses.size
- displayName: Size
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 description is a required property of both specDescriptors and statusDescriptors. We may need to add the default data for description field instead of omitting it.

Copy link
Copy Markdown
Contributor

@tlwu2013 tlwu2013 Jul 21, 2020

Choose a reason for hiding this comment

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

Just checked the struct again and notice in fact only the path is the required property. So no concerns on the examples as well.

Copy link
Copy Markdown
Contributor

@tlwu2013 tlwu2013 Jul 21, 2020

Choose a reason for hiding this comment

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

I almost regret immediately after posting my previous comments. :(

Although "technically" only path is the required property, an empty description leads to an empty tooltip on the UI:

Tooltip - with description:
1_tooltip___with_description

Empty tooltip - without description:
2_empty_tooltip___without_description

Can we at least include some simple text for the description field in the example (UI will be adding better handling for the empty description case)? Thanks!

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.

This is something I'd like to leave up to the OperatorHubValidator, since it is perfectly valid to have a CSV without these descriptions.

Comment thread website/content/en/docs/golang/references/markers.md
Copy link
Copy Markdown
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

LGTM. Just a few nits/questions.

Comment on lines +91 to +95
if kbutil.HasProjectFile() || areAnnotationsMigrated(b.APIsDir) {
err = updateDefinitions(base, b.APIsDir, b.GVKs)
} else {
err = updateDescriptionsForGVKs(base, b.APIsDir, b.GVKs)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We require that projects have a PROJECT file now, right? So no need for the updateDescriptionsForGVKs() call?

Also, as @fabianvf was suggesting for generate crds here, would it make sense to remove the requirement for projutil.OperatorTypeGo and only require that there are some parseable .go files?

Copy link
Copy Markdown
Member Author

@estroz estroz Jul 22, 2020

Choose a reason for hiding this comment

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

Shouldn't that requirement check be centralized in IsOperatorGo()?

Comment thread internal/generate/clusterserviceversion/bases/clusterserviceversion.go Outdated
Comment thread internal/generate/clusterserviceversion/bases/definitions/ast.go Outdated
Comment thread internal/generate/clusterserviceversion/bases/definitions/parse.go Outdated
Comment thread internal/generate/clusterserviceversion/bases/markers.go Outdated
Comment thread internal/generate/clusterserviceversion/bases/definitions/definitions.go Outdated
Comment thread internal/generate/clusterserviceversion/bases/definitions/definitions.go Outdated
Eric Stroczynski added 2 commits July 22, 2020 10:39
hack/generate/migrate-markers.sh: annotation -> marker migration script

internal/generate/olm-catalog: use legacy descriptor parsing if neither PROJECT nor the new markers format exists
@estroz estroz force-pushed the refactor/csv-markers branch from d4b5758 to bb31df0 Compare July 22, 2020 18:35
@estroz estroz force-pushed the refactor/csv-markers branch from bb31df0 to 598997b Compare July 22, 2020 18:58
Copy link
Copy Markdown
Member

@jmrodri jmrodri left a comment

Choose a reason for hiding this comment

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

/lgtm
I didn't see any red flags. Good job.

Comment on lines +21 to +25
local old_marker_pattern_1="${OLD_MARKER_BASE}"'\.resources="([^\,]+)\,([^\,]+)\,\\"([^\\]+)\\""'
local old_marker_pattern_2="${OLD_MARKER_BASE}"'\.resources="([^\,]+)\,([^\,]+)\,"'
local new_marker_pattern_1="${NEW_MARKER_BASE}"':resources={\1,\2,"\3"}'
local new_marker_pattern_2="${NEW_MARKER_BASE}"':resources={\1,\2,}'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Impressive! regex always impresses me :)

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 22, 2020
@openshift-ci-robot
Copy link
Copy Markdown

New changes are detected. LGTM label has been removed.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 22, 2020
@estroz estroz changed the title generate csv: parse CSV annotations with controller-tools/pkg/markers generate: parse CSV annotations with controller-tools/pkg/markers Jul 22, 2020
@estroz estroz merged commit 5256f82 into operator-framework:master Jul 22, 2020
@estroz estroz deleted the refactor/csv-markers branch July 22, 2020 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

olm-integration Issue relates to the OLM integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants