Bug 1779681 - Try It button for ConsoleYAMLSample resources silently fails on invalid YAML
Summary: Try It button for ConsoleYAMLSample resources silently fails on invalid YAML
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: OpenShift Container Platform
Classification: Red Hat
Component: Management Console
Version: 4.3.0
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: ---
: 4.3.0
Assignee: Samuel Padgett
QA Contact: Yadan Pei
URL:
Whiteboard:
: 1778863 (view as bug list)
Depends On: 1776479
Blocks: 1778863
TreeView+ depends on / blocked
 
Reported: 2019-12-04 13:55 UTC by Robb Hamilton
Modified: 2020-01-23 11:18 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of: 1776479
Environment:
Last Closed: 2020-01-23 11:17:47 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github openshift console pull 3664 0 'None' closed [release-4.3] Bug 1779681: Show error modal for invalid YAML samples 2020-04-17 17:16:15 UTC
Red Hat Product Errata RHBA-2020:0062 0 None None None 2020-01-23 11:18:04 UTC

Description Robb Hamilton 2019-12-04 13:55:18 UTC
+++ This bug was initially created as a clone of Bug #1776479 +++

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.

--- Additional comment from Robb Hamilton on 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"]
```

--- Additional comment from Robb Hamilton on 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...

--- Additional comment from Samuel Padgett on 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.

--- Additional comment from Samuel Padgett on 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?

--- Additional comment from Robb Hamilton on 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 1 Samuel Padgett 2019-12-04 14:19:13 UTC
*** Bug 1778863 has been marked as a duplicate of this bug. ***

Comment 3 shahan 2019-12-05 07:43:37 UTC
$ oc create -f console.yaml
The ConsoleYAMLSample "foo-pod-example" is invalid: 
* spec.description: Required value
* spec.title: Required value
* spec.yaml: Required value
 Veirfy this bug
4.3.0-0.nightly-2019-12-04-214544

Comment 4 Samuel Padgett 2019-12-05 14:13:41 UTC
The original YAML example in the description isn't the right YAML to check. You need to use the following example. The fix is to show a modal error message in the console when a user tries to apply it (since the `yaml` property is not valid YAML). Moving back to ON_QA.


```
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 5 shahan 2019-12-06 02:54:51 UTC
Got bellow error when apply wrong yaml template:
Failed to Parse YAML Sample
incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 1, column 20:
apiVersion: v1 kind: Pod metadata:
^
4.3.0-0.nightly-2019-12-05-213858

Comment 8 errata-xmlrpc 2020-01-23 11:17:47 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:0062


Note You need to log in before you can comment on or make changes to this bug.