-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
internal/scaffold/olm-catalog: populate CSV customresourcedefinitions from Go type annotations #1162
Merged
estroz
merged 68 commits into
operator-framework:master
from
estroz:csv-customresourcedefinitions
Dec 4, 2019
Merged
internal/scaffold/olm-catalog: populate CSV customresourcedefinitions from Go type annotations #1162
Changes from 61 commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
65236bd
pkg/scaffold/olm-catalog/*: generate CSV manifest {spec,status}Descri…
estroz 869e49a
add comments and reorg code a bit
estroz 1aea2a2
Merge branch 'master' into csv-customresourcedefinitions
estroz 2560266
make CSV CRD updates if fields are not set
estroz 84f85c9
pkg/scaffold/olm-catalog/*: suggest path and x-descriptors if not pre…
estroz 4ca3ce1
Merge branch 'master' into csv-customresourcedefinitions
estroz 267c6de
internal/pkg/scaffold/olm-catalog: use +operator-sdk:gen-csv parse an…
estroz 2d3dc95
sort descriptors by display name; make parser more robust
estroz e1e5351
add TODO's
estroz db75858
internal/annotations: implement annotations splitting and joining
estroz e07364d
rework annotations and parser
estroz 808a6b3
ignore non-existent API dirs
estroz ea9f7c0
fix vet issue
estroz 7884094
revendor
estroz c3b3580
add tag parsing for resources and displayName
estroz 2be5216
parse path directly from tags, no annotation override
estroz c4625d8
remove print statements, refactor initial type parsing, fix test CSV
estroz 6326cc5
append x-descriptors found by path elements to annotation-specified x…
estroz 5f50937
remove actionDescriptor parsing
estroz 141a384
persist actionDescriptors and required CRD's in CSV's
estroz 4119f15
cleanup and renaming
estroz c5e16db
get full hierarchal path instead of immediate parent+child
estroz c93b958
Merge branch 'master' into csv-customresourcedefinitions
estroz 291855c
Merge branch 'master' into csv-customresourcedefinitions
estroz 8cee281
bump maxLevel to 10; use 'spec'/'status' path segments if already see…
estroz e1bf6fe
add comments; refactor getSpecStatusPkgTypesForAPI to only do search …
estroz 753829d
Merge branch 'master' into csv-customresourcedefinitions
estroz 4de0e64
fix errors after merge
estroz 9b8addd
add required CRD's back to CSV testdata; some CRD Apply() updates
estroz 65c97b9
Merge branch 'master' into csv-customresourcedefinitions
estroz e854b16
Merge branch 'master' into csv-customresourcedefinitions
estroz f5a1809
some refactoring
estroz d9c7775
internal/pkg/scaffold/olm-catalog: error message updates and defer wr…
estroz a5bba17
some refactoring
estroz 8750e06
move descriptor.go to internal/pkg/descriptor, split functions into t…
estroz 1f37cfe
fix link
estroz 55a64c0
Merge branch 'master' into csv-customresourcedefinitions
estroz 4ae9847
Merge branch 'master' into csv-customresourcedefinitions
estroz 93560be
move search functions into search.go
estroz 3fc54a6
internal/pkg/scaffold/olm-catalog: sort both owned and required CRDDe…
estroz 86fccfa
refactor functions
estroz 70acfae
add parse and descriptor unit tests
estroz bfa2912
Merge branch 'master' into csv-customresourcedefinitions
estroz d4f0021
refactor descriptor retrieval from types
estroz 8725662
doc/user/olm-catalog/csv-annotations.md: document csv-gen annotations
estroz 0141a5f
add more unit tests and test data, fix errors caught by tests
estroz 23f48fc
use embedded SpecDescriptor in descriptor
estroz 9d806f3
Merge branch 'master' into csv-customresourcedefinitions
estroz 20f4390
fix unit test
estroz d222743
change resource name for dummy types
estroz 3cf1a3b
prevent generators from running on dummy types
estroz 22fb0cc
Merge branch 'master' into csv-customresourcedefinitions
estroz c5578ab
Apply suggestions from code review
1fb896d
updates based on PR comments
estroz 5214d50
respect inlined and omitted tags
estroz 8f07a49
Merge branch 'master' into csv-customresourcedefinitions
estroz fb93d43
check if prefix is local dir; chdir in tests
estroz 6e911ce
remove print statement
estroz db24904
Merge branch 'master' into csv-customresourcedefinitions
estroz 8735c3f
Merge remote-tracking branch 'origin/csv-customresourcedefinitions' i…
estroz c2a1843
use structtag.Parse to correctly parse tags; unit tests
estroz a67dc94
Merge branch 'master' into csv-customresourcedefinitions
estroz e0977a6
update test/test-framework go.sum
estroz 5b2693e
consider embedded structs and add test cases
estroz f11b35f
Merge branch 'master' into csv-customresourcedefinitions
estroz 4fe5f95
fix tests and return jsonTag.Name if name is -
estroz 7e3e9a6
Merge branch 'master' into csv-customresourcedefinitions
estroz 241f71a
fix linter error
estroz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
# Code Annotations for Cluster Service Versions | ||
|
||
## Overview | ||
|
||
This document describes the semantics of Cluster Service Version (CSV) [code annotations][code-annotations-design] and lists all possible annotations. | ||
|
||
## Usage | ||
|
||
All annotations have a `+operator-sdk:gen-csv` prefix, denoting that they're parsed while executing [`operator-sdk olm-catalog gen-csv`][sdk-cli-ref]. | ||
|
||
### Paths | ||
|
||
Paths are dot-separated string hierarchies with the above prefix that map to CSV [`spec`][csv-spec] field names. | ||
|
||
Example: `+operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Pod Count"` | ||
|
||
#### customresourcedefinitions | ||
|
||
- `customresourcedefinitions`: child path token | ||
- `displayName`: quoted string or string literal | ||
- `resources`: quoted string or string literal, in the format `"kind,version,\"name\""` or `` `kind,version,"name"` ``, where `kind`, `version`, and `name` are fields in each CSV `resources` entry | ||
- `specDescriptors`, `statusDescriptors`: bool, or child path token | ||
- `displayName`: quoted string or string literal | ||
- `x-descriptors`: quoted string or string literal comma-separated list of [`x-descriptor`][csv-x-desc] UI hints. | ||
|
||
**NOTES** | ||
- `specDescriptors` and `statusDescriptors` with a value of `true` is required for each field to be included in their respective `customresourcedefinitions` CSV fields. See the examples below. | ||
- `customresourcedefinitions` top-level `kind`, `name`, and `version` fields are parsed from API code. | ||
- All `description` fields are parsed from type declaration and `struct` type field comments. | ||
- `path` is parsed out of a field's JSON tag and merged with parent field path's in dot-hierarchy notation. | ||
|
||
### Examples | ||
|
||
These examples assume `Memcached`, `MemcachedSpec`, and `MemcachedStatus` are the example projects' kind, spec, and status. | ||
|
||
1. Set a display name for a `customresourcedefinitions` kind entry: | ||
|
||
```go | ||
// +operator-sdk:gen-csv:customresourcedefinitions.displayName="Memcached App" | ||
type Memcached struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec MemcachedSpec `json:"spec,omitempty"` | ||
Status MemcachedStatus `json:"status,omitempty"` | ||
} | ||
``` | ||
|
||
2. Set `displayName`, `path`, `x-descriptors`, and `description` on a field for a `customresourcedefinitions.specDescriptors` entry: | ||
|
||
```go | ||
type MemcachedSpec struct { | ||
// Size is the size of the memcached deployment. <-- This will become Size's specDescriptors.description. | ||
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true | ||
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.displayName="Pod Count" | ||
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors.x-descriptors="urn:alm:descriptor:com.tectonic.ui:podCount,urn:alm:descriptor:io.kubernetes:custom" | ||
Size int32 `json:"size"` // <-- Size's specDescriptors.path is inferred from this JSON tag. | ||
} | ||
``` | ||
|
||
3. Let the SDK infer all un-annotated paths on a field for a `customresourcedefinitions.specDescriptors` entry: | ||
|
||
```go | ||
type MemcachedSpec struct { | ||
// Size is the size of the memcached deployment. | ||
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true | ||
Size int32 `json:"size"` | ||
} | ||
``` | ||
|
||
The SDK uses the `Size` fields' `json` tag name as `path`, `Size` as `displayName`, and field comments as `description`. | ||
|
||
The SDK also checks `path` elements against a list of well-known path to x-descriptor string mappings and either uses a match as `x-descriptors`, or does not set `x-descriptors`. Supported mappings: | ||
|
||
#### Spec x-descriptors | ||
|
||
| PATH | X-DESCRIPTOR | | ||
| --- | --- | | ||
| `size` | `urn:alm:descriptor:com.tectonic.ui:podCount` | | ||
| `podCount` | `urn:alm:descriptor:com.tectonic.ui:podCount` | | ||
| `endpoints` | `urn:alm:descriptor:com.tectonic.ui:endpointList` | | ||
| `endpointList` | `urn:alm:descriptor:com.tectonic.ui:endpointList` | | ||
| `label` | `urn:alm:descriptor:com.tectonic.ui:label` | | ||
| `resources` | `urn:alm:descriptor:com.tectonic.ui:resourceRequirements` | | ||
| `resourceRequirements` | `urn:alm:descriptor:com.tectonic.ui:resourceRequirements` | | ||
| `selector` | `urn:alm:descriptor:com.tectonic.ui:selector:` | | ||
| `namespaceSelector` | `urn:alm:descriptor:com.tectonic.ui:namespaceSelector` | | ||
| none | `urn:alm:descriptor:io.kubernetes:` | | ||
| `booleanSwitch` | `urn:alm:descriptor:com.tectonic.ui:booleanSwitch` | | ||
| `password` | `urn:alm:descriptor:com.tectonic.ui:password` | | ||
| `checkbox` | `urn:alm:descriptor:com.tectonic.ui:checkbox` | | ||
| `imagePullPolicy` | `urn:alm:descriptor:com.tectonic.ui:imagePullPolicy` | | ||
| `updateStrategy` | `urn:alm:descriptor:com.tectonic.ui:updateStrategy` | | ||
| `text` | `urn:alm:descriptor:com.tectonic.ui:text` | | ||
| `number` | `urn:alm:descriptor:com.tectonic.ui:number` | | ||
| `nodeAffinity` | `urn:alm:descriptor:com.tectonic.ui:nodeAffinity` | | ||
| `podAffinity` | `urn:alm:descriptor:com.tectonic.ui:podAffinity` | | ||
| `podAntiAffinity` | `urn:alm:descriptor:com.tectonic.ui:podAntiAffinity` | | ||
| none | `urn:alm:descriptor:com.tectonic.ui:fieldGroup:` | | ||
| none | `urn:alm:descriptor:com.tectonic.ui:arrayFieldGroup:` | | ||
| none | `urn:alm:descriptor:com.tectonic.ui:select:` | | ||
| `advanced` | `urn:alm:descriptor:com.tectonic.ui:advanced` | | ||
|
||
#### Status x-descriptors | ||
|
||
| PATH | X-DESCRIPTOR | | ||
| --- | --- | | ||
| `podStatuses` | `urn:alm:descriptor:com.tectonic.ui:podStatuses` | | ||
| `size` | `urn:alm:descriptor:com.tectonic.ui:podCount` | | ||
| `podCount` | `urn:alm:descriptor:com.tectonic.ui:podCount` | | ||
| `link` | `urn:alm:descriptor:org.w3:link` | | ||
| `w3link` | `urn:alm:descriptor:org.w3:link` | | ||
| `conditions` | `urn:alm:descriptor:io.kubernetes.conditions` | | ||
| `text` | `urn:alm:descriptor:text` | | ||
| `prometheusEndpoint` | `urn:alm:descriptor:prometheusEndpoint` | | ||
| `phase` | `urn:alm:descriptor:io.kubernetes.phase` | | ||
| `k8sPhase` | `urn:alm:descriptor:io.kubernetes.phase` | | ||
| `reason` | `urn:alm:descriptor:io.kubernetes.phase:reason` | | ||
| `k8sReason` | `urn:alm:descriptor:io.kubernetes.phase:reason` | | ||
| none | `urn:alm:descriptor:io.kubernetes:` | | ||
|
||
**NOTE:** any x-descriptor that ends in `:` will not be inferred by `path` element, ex. `urn:alm:descriptor:io.kubernetes:`. Use the `x-descriptors` annotation if you want to enable one for your type. | ||
|
||
4. A comprehensive example: | ||
- Infer `path`, `description`, `displayName`, and `x-descriptors` for `specDescriptors` and `statusDescriptors` entries. | ||
- Create three `resources` entries each with `kind`, `version`, and `name` values. | ||
|
||
```go | ||
// Represents a cluster of Memcached apps | ||
// +operator-sdk:gen-csv:customresourcedefinitions.displayName="Memcached App" | ||
// +operator-sdk:gen-csv:customresourcedefinitions.resources="Deployment,v1,\"memcached-operator\"" | ||
// +operator-sdk:gen-csv:customresourcedefinitions.resources=`Service,v1,"memcached-operator"` | ||
type Memcached struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec MemcachedSpec `json:"spec,omitempty"` | ||
Status MemcachedStatus `json:"status,omitempty"` | ||
} | ||
|
||
type MemcachedSpec struct { | ||
Pods MemcachedPods `json:"pods"` | ||
} | ||
|
||
type MemcachedStatus struct { | ||
Pods MemcachedPods `json:"podStatuses"` | ||
} | ||
|
||
type MemcachedPods struct { | ||
// Size is the size of the memcached deployment. | ||
// +operator-sdk:gen-csv:customresourcedefinitions.specDescriptors=true | ||
// +operator-sdk:gen-csv:customresourcedefinitions.statusDescriptors=true | ||
Size int32 `json:"size"` | ||
} | ||
``` | ||
|
||
The generated `customresourcedefinitions` will look like: | ||
|
||
```yaml | ||
customresourcedefinitions: | ||
owned: | ||
- description: Represents a cluster of Memcached apps | ||
displayName: Memcached App | ||
kind: Memcached | ||
name: memcacheds.cache.example.com | ||
version: v1alpha1 | ||
resources: | ||
- kind: Deployment | ||
name: A Kubernetes Deployment | ||
version: v1 | ||
- kind: ReplicaSet | ||
name: A Kubernetes ReplicaSet | ||
version: v1beta2 | ||
- kind: Pod | ||
name: A Kubernetes Pod | ||
version: v1 | ||
specDescriptors: | ||
- description: The desired number of member Pods for the deployment. | ||
displayName: Size | ||
path: pods.size | ||
x-descriptors: | ||
- 'urn:alm:descriptor:com.tectonic.ui:podCount' | ||
statusDescriptors: | ||
- description: The desired number of member Pods for the deployment. | ||
displayName: Size | ||
path: podStatuses.size | ||
x-descriptors: | ||
- 'urn:alm:descriptor:com.tectonic.ui:podStatuses' | ||
- 'urn:alm:descriptor:com.tectonic.ui:podCount' | ||
``` | ||
|
||
[code-annotations-design]:../../proposals/sdk-code-annotations.md | ||
[sdk-cli-ref]:../../sdk-cli-reference.md#gen-csv | ||
[csv-x-desc]:https://github.com/openshift/console/blob/feabd61/frontend/packages/operator-lifecycle-manager/src/components/descriptors/types.ts#L3-L39 | ||
[csv-spec]:https://github.com/operator-framework/operator-lifecycle-manager/blob/e0eea22/doc/design/building-your-csv.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @estroz,
We forget to add the changelog entry over this one.