Bug 1776479

Summary: Try It button for ConsoleYAMLSample resources silently fails on invalid YAML
Product: OpenShift Container Platform Reporter: bpeterse
Component: Management ConsoleAssignee: Samuel Padgett <spadgett>
Status: CLOSED ERRATA QA Contact: Yadan Pei <yapei>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 4.3.0CC: aos-bugs, bparees, jokerman, spadgett, yapei
Target Milestone: ---   
Target Release: 4.4.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of:
: 1778863 1779681 (view as bug list) Environment:
Last Closed: 2020-05-04 11:17:08 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1778863, 1779681    
Attachments:
Description Flags
ModalShowingError none

Description bpeterse 2019-11-25 18:49:12 UTC
Given a slightly incorrect block of YAML, within the ConsoleEXAMPLEYaml resource:

```````
apiVersion: console.openshift.io/v1
kind: ConsoleYAMLSample
metadata:
  name: foo-pod-example
spec:
  targetResource:
    apiVersion: v1
    kind: Pod
    title: foo pod example
    description: our company's preferred foo pod
    yaml: >-
      apiVersion: v1
      kind: Pod
      metadata:
        name: foo-pod-example
        labels:
          app: web
          foo: bar
          bar: baz
      spec:
        containers:
          - name: foo-pod-example
            image: foopod/example
            command: ["foo"]
            args: ["--example", "1"]
```````

Both the web console ConsoleYAMLSample create page && oc create -f - will accept the above as valid. However, when you attempt to use the example within the page (for example, go to create a Pod after creating the above sample), nothing happens.  

- Try It button does nothing.  Page is not unresponsive, and there is no console error.
- Download button does nothing. Again, no console error.

It appears that the console is broken, when in fact, the YAML Sample is incorrect, but there is no indication that something needs to be fixed.


How reproducible:

Always

Steps to Reproduce:
1.  echo "the-above-text" | oc create -f -
2.  alternatively, paste the above text into the custom resource create form
3.  navigate to the pods page
4.  click "create pod"
5.  click "try it" in the sample sidebar

Actual results:

Console appears to do nothing


Expected results:

Console should either use my sample, or notify me that something is preventing the use of the sample.  Note that I don't think we can truly validate the yaml prior to use.  It is valid YAML (generically), but is invalid for the Pod use case.  I imagine the console should just always use, but when the user submits the YAML we should show the validation error.

Comment 1 Robb Hamilton 2019-11-25 21:12:04 UTC
The example(In reply to bpeterse from comment #0)

> ```````
> apiVersion: console.openshift.io/v1
> kind: ConsoleYAMLSample
> metadata:
>   name: foo-pod-example
> spec:
>   targetResource:
>     apiVersion: v1
>     kind: Pod
>     title: foo pod example
>     description: our company's preferred foo pod
>     yaml: >-
>       apiVersion: v1
>       kind: Pod
>       metadata:
>         name: foo-pod-example
>         labels:
>           app: web
>           foo: bar
>           bar: baz
>       spec:
>         containers:
>           - name: foo-pod-example
>             image: foopod/example
>             command: ["foo"]
>             args: ["--example", "1"]
> ```````

This should be:
```
apiVersion: console.openshift.io/v1
kind: ConsoleYAMLSample
metadata:
  name: foo-pod-example
spec:
  targetResource:
    apiVersion: v1
    kind: Pod
  title: foo pod example
  description: our company's preferred foo pod
  yaml: >-
    apiVersion: v1
    kind: Pod
    metadata:
      name: foo-pod-example
      labels:
        app: web
        foo: bar
        bar: baz
    spec:
      containers:
        - name: foo-pod-example
          image: foopod/example
          command: ["foo"]
          args: ["--example", "1"]
```

Comment 2 Robb Hamilton 2019-11-25 21:22:25 UTC
I believe this bug is occurring because Ben's example uses the yaml folded style block style indicator (`>`) instead of the literal block style indicator (`|`) in the yaml value, so the new lines get stripped.  Not sure how we go about enforcing the use of the literal block style indicator...

Comment 3 Samuel Padgett 2019-12-02 14:12:14 UTC
It looks like the indentation is wrong is the provided YAML. The `yaml` property should not be under `targetResource`, but one level up. It should be a required property, though. I'd expect that to fail validation.

Comment 4 Samuel Padgett 2019-12-02 14:14:42 UTC
I get an error when I try to create that resource.

> Error "Required value" for field "spec.description".

Is there a copy/paste error in the YAML in the description?

Comment 5 Robb Hamilton 2019-12-02 14:16:45 UTC
(In reply to Samuel Padgett from comment #3)
> It looks like the indentation is wrong is the provided YAML. The `yaml`
> property should not be under `targetResource`, but one level up. It should
> be a required property, though. I'd expect that to fail validation.

Ben's example is incorrect and does fail validation.  I provided a corrected example in https://bugzilla.redhat.com/show_bug.cgi?id=1776479#c1.  However, this corrected example fails due to the use of the folded style block indicator (see https://bugzilla.redhat.com/show_bug.cgi?id=1776479#c2).

Comment 7 Yadan Pei 2019-12-16 03:36:04 UTC
1. Create ConsoleYAMLSample instance with yaml in comment #1
2. Goes to Workloads -> Pods -> Create Pods -> click Try It button in Samples 
An error modal will prompt and show Failed to Parse YAML Sample


Verified on 4.4.0-0.nightly-2019-12-15-184910

Comment 8 Yadan Pei 2019-12-16 03:36:35 UTC
Created attachment 1645420 [details]
ModalShowingError

Comment 11 errata-xmlrpc 2020-05-04 11:17:08 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:0581