Add ConsoleYAMLSample CRD type#465
Conversation
| Title string `json:"title"` | ||
| // description of the YAML sample. | ||
| Description string `json:"description"` | ||
| // yam is the used YAML sample. |
There was a problem hiding this comment.
"yaml is the YAML sample to display."
| Spec ConsoleYAMLSampleSpec `json:"spec"` | ||
| } | ||
|
|
||
| // ConsoleYAMLSampleSpec is the desired YAML sample configuration. |
There was a problem hiding this comment.
How does this know what resource to reference in the console? I'm assuming its a customyamlsample for deployments, or another resource.
There was a problem hiding this comment.
Here is the proposal for target resource in the console PR: https://github.com/openshift/console/pull/2889/files#r331471061
There was a problem hiding this comment.
so is that going to be added to this ConsoleYAMLSample api?
There was a problem hiding this comment.
so is that going to be added to this ConsoleYAMLSample api?
Yes, we'll need that to know the kind of resource. The alternative is to try to parse the YAML sample content for all types to filter based on group/version/kind, but I'm not sure that's practical.
There was a problem hiding this comment.
well, the other option, if you foresee a need to reuse yaml samples for different resources, would be to have two different CRDs:
- yaml sample
- yaml sample reference/link to resource type to use it for
So you can create a single (1) and then multiple (2)s.
but i don't know if that is a valid use case or not. Or even if it's valid, if it would be common enough to be worth the effort over just creating duplicate ConsoleYamlSample objects.
There was a problem hiding this comment.
Not really sure what would be the use-case for reusing the CR for different resources.
If the would be one of the solutions would be as @spadgett suggested in comment to have TargetResource that would be an array
type ConsoleYAMLSampleSpec struct {
TargetResource []metav1.TypeMeta `json:",targetResource"`
...Thinking that if it wouldn't make more sense to have a multiple YAMLs for a single TargetResource ? Since we have multiple examples for some resources, eg. buildConfigs
There was a problem hiding this comment.
I'm not sure what the use case is for having more than one target resource since the API group / version / kind is also in the YAML. These should almost always match.
We do have one edge case in the UI where we show Roles and Cluster Roles in the same sidebar, but I think this pretty rare. There's always the workaround of creating more than one sample.
| // description of the YAML sample. | ||
| Description string `json:"description"` | ||
| // yam is the used YAML sample. | ||
| Yaml string `json:"yaml"` |
There was a problem hiding this comment.
maybe
| Yaml string `json:"yaml"` | |
| YAML string `json:"yaml"` |
| type ConsoleYAMLSampleSpec struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| // title of the YAML sample. | ||
| Title string `json:"title"` |
There was a problem hiding this comment.
We'll want regex patterns for each of these strings to make sure they aren't empty strings
There was a problem hiding this comment.
wont it be enough to have these fields as required in the CRD ?
There was a problem hiding this comment.
No, the empty string is allowed even for required fields
| type ConsoleYAMLSample struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| // Standard object's metadata. | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` |
| Spec ConsoleYAMLSampleSpec `json:"spec"` | ||
| } | ||
|
|
||
| // ConsoleYAMLSampleSpec is the desired YAML sample configuration. |
There was a problem hiding this comment.
| // ConsoleYAMLSampleSpec is the desired YAML sample configuration. | |
| // ConsoleYAMLSampleSpec is the desired YAML sample configuration. | |
| // Samples will appear with their descriptions in a samples sidebar when creating a resources in the web console. |
| } | ||
|
|
||
| // ConsoleYAMLSampleSpec is the desired YAML sample configuration. | ||
| type ConsoleYAMLSampleSpec struct { |
There was a problem hiding this comment.
Looks like we're missing a way to specify the target resource apiVersion and kind
There was a problem hiding this comment.
metav1.TypeMeta contains apiVersion and kind that should target specific resource
There was a problem hiding this comment.
i think that field needs a more obvious name (rather than just inlining it) if that's how you're using it, to make it clear it's defining the resourcetype this sample applies to.
There was a problem hiding this comment.
Definitely, already added a comment in #465 (comment)
|
Also added a validation regexp that will check if the |
|
/approve |
|
@jhadvig lgtm, but will need |
|
/retest Please review the full test history for this PR and help us cut down flakes. |
|
/retest |
| // YAML sample is representating. | ||
| TargetResource metav1.TypeMeta `json:",targetResource"` | ||
| // title of the YAML sample. | ||
| // +kubebuilder:validation:Pattern=^(.|\s)*\S(.|\s)*$ |
There was a problem hiding this comment.
So unfortunately for this to work to generate the appropriate validation, the kubebuilder tag needs to be on a type. See https://github.com/openshift/api/pull/468/files#diff-b2e8eb141280483ab2ddd2a10a65ec30R54.
Not really difficult, but a little tedious:
// +kubebuilder:validation:Pattern=^(.|\s)*\S(.|\s)*$
type ConsoleYAMLSampleDescription stringetc.
| Description string `json:"description"` | ||
| // yaml is the YAML sample to display. | ||
| // +kubebuilder:validation:Pattern=^(.|\s)*\S(.|\s)*$ | ||
| YAML string `json:"yaml"` |
There was a problem hiding this comment.
Same, will need kubebuilder:validation pattern on a separate type.
|
/retest Please review the full test history for this PR and help us cut down flakes. |
|
I think you may need to do the following yet: func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(GroupVersion,
&ConsoleLink{},
&ConsoleLinkList{},
// other types....
&ConsoleYAMLExample
}in |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bparees, jhadvig, spadgett The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Part of https://jira.coreos.com/browse/CONSOLE-1825 story.
FYI @rhamilto
/assign @spadgett