Skip to content

Add ConsoleYAMLSample CRD type#465

Merged
openshift-merge-robot merged 1 commit intoopenshift:masterfrom
jhadvig:yaml-sample
Oct 15, 2019
Merged

Add ConsoleYAMLSample CRD type#465
openshift-merge-robot merged 1 commit intoopenshift:masterfrom
jhadvig:yaml-sample

Conversation

@jhadvig
Copy link
Copy Markdown
Member

@jhadvig jhadvig commented Oct 11, 2019

@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 11, 2019
Comment thread console/v1/types_console_yaml_sample.go Outdated
Title string `json:"title"`
// description of the YAML sample.
Description string `json:"description"`
// yam is the used YAML sample.
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.

yam -> yaml.

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.

"yaml is the YAML sample to display."

Spec ConsoleYAMLSampleSpec `json:"spec"`
}

// ConsoleYAMLSampleSpec is the desired YAML sample configuration.
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.

How does this know what resource to reference in the console? I'm assuming its a customyamlsample for deployments, or another resource.

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.

Here is the proposal for target resource in the console PR: https://github.com/openshift/console/pull/2889/files#r331471061

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.

so is that going to be added to this ConsoleYAMLSample api?

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.

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.

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.

well, the other option, if you foresee a need to reuse yaml samples for different resources, would be to have two different CRDs:

  1. yaml sample
  2. 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.

Copy link
Copy Markdown
Member Author

@jhadvig jhadvig Oct 14, 2019

Choose a reason for hiding this comment

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

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

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.

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.

Copy link
Copy Markdown
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

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

Thanks @jhadvig. Will need make generate when ready

cc @bparees

Comment thread console/v1/types_console_yaml_sample.go Outdated
// description of the YAML sample.
Description string `json:"description"`
// yam is the used YAML sample.
Yaml string `json:"yaml"`
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.

maybe

Suggested change
Yaml string `json:"yaml"`
YAML string `json:"yaml"`

Comment thread console/v1/types_console_yaml_sample.go Outdated
type ConsoleYAMLSampleSpec struct {
metav1.TypeMeta `json:",inline"`
// title of the YAML sample.
Title string `json:"title"`
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'll want regex patterns for each of these strings to make sure they aren't empty strings

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.

wont it be enough to have these fields as required in the CRD ?

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.

No, the empty string is allowed even for required fields

Comment thread console/v1/types_console_yaml_sample.go Outdated
type ConsoleYAMLSample struct {
metav1.TypeMeta `json:",inline"`
// Standard object's metadata.
metav1.ObjectMeta `json:"metadata,omitempty"`
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.

remove omitempty?

Spec ConsoleYAMLSampleSpec `json:"spec"`
}

// ConsoleYAMLSampleSpec is the desired YAML sample configuration.
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.

Suggested change
// 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 {
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.

Looks like we're missing a way to specify the target resource apiVersion and kind

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.

metav1.TypeMeta contains apiVersion and kind that should target specific resource

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.

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.

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.

Definitely, already added a comment in #465 (comment)

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 14, 2019
@jhadvig
Copy link
Copy Markdown
Member Author

jhadvig commented Oct 14, 2019

@spadgett @bparees update PR with addressed comments and adding a few of my own...
PTAL

@jhadvig
Copy link
Copy Markdown
Member Author

jhadvig commented Oct 14, 2019

Also added a validation regexp that will check if the Title, Description and YAML are non-empty or just containing whitespace chars

@bparees
Copy link
Copy Markdown
Contributor

bparees commented Oct 14, 2019

/approve

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 14, 2019
@spadgett
Copy link
Copy Markdown
Member

@jhadvig lgtm, but will need make generate

Copy link
Copy Markdown
Member

@spadgett spadgett left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 15, 2019
@openshift-bot
Copy link
Copy Markdown

/retest

Please review the full test history for this PR and help us cut down flakes.

@jhadvig
Copy link
Copy Markdown
Member Author

jhadvig commented Oct 15, 2019

/retest

Comment thread console/v1/types_console_yaml_sample.go Outdated
// YAML sample is representating.
TargetResource metav1.TypeMeta `json:",targetResource"`
// title of the YAML sample.
// +kubebuilder:validation:Pattern=^(.|\s)*\S(.|\s)*$
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.

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 string

etc.

Comment thread console/v1/types_console_yaml_sample.go Outdated
Description string `json:"description"`
// yaml is the YAML sample to display.
// +kubebuilder:validation:Pattern=^(.|\s)*\S(.|\s)*$
YAML string `json:"yaml"`
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.

Same, will need kubebuilder:validation pattern on a separate type.

@openshift-bot
Copy link
Copy Markdown

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 15, 2019
@benjaminapetersen
Copy link
Copy Markdown
Contributor

benjaminapetersen commented Oct 15, 2019

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 console/v1/register.go

@spadgett
Copy link
Copy Markdown
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 15, 2019
@openshift-ci-robot
Copy link
Copy Markdown

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 538f3e8 into openshift:master Oct 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants