Skip to content

Conversation

@vojtechszocs
Copy link
Contributor

@vojtechszocs vojtechszocs commented May 24, 2019

This PR makes yamlTemplates in public/models/yaml-templates.ts extensible.

const plugin: Plugin<YAMLTemplate> = [
  {
    type: 'YAMLTemplate',
    properties: {
      model: FooBarModel,
      template: `
apiVersion: ${FooBarModel.apiVersion}
kind: ${FooBarModel.kind}
metadata:
  name: example
  namespace: default
`,
    },
  },
];

Note: due to how multi-line template literals work, leading whitespace within the template string should be removed.

It's also possible to pass a templateName (falls back to default if not specified):

const plugin: Plugin<YAMLTemplate> = [
  {
    type: 'YAMLTemplate',
    properties: {
      model: FooBarModel,
      template: '...',
      templateName: 'fb-compute',
    },
  },
];

Attempts to redefine existing templates (based on tuple key [modelRef, templateName]) will be logged and the conflicting templates will be discarded.

const plugin: Plugin<YAMLTemplate> = [
  {
    type: 'YAMLTemplate',
    properties: {
      model: PodModel,
      template: '...',
    },
  },
];
attempt to redefine YAML template default for model core~v1~Pod

@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 24, 2019
@vojtechszocs
Copy link
Contributor Author

vojtechszocs commented May 24, 2019

FYI @mareklibra @jtomasek

@vojtechszocs
Copy link
Contributor Author

/cc @spadgett

@spadgett spadgett added this to the v4.2 milestone May 24, 2019
Copy link
Contributor

Choose a reason for hiding this comment

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

What about throwing and Error? IMO, this conflict should be avoided.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code gets referenced & evaluated very early during Console startup.

Consequently, throwing an Error here will effectively break the whole application - just a blank page with error stack trace shown in the browser console. This is not the behavior we want.

In good browsers, console.warn and console.error provide you with a link to source code (based on source maps) if you want to investigate the issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be caught at build time.
@vojtechszocs and I talked about fixing this situation by creating unit tests to avoid duplicates and therefore can avoid this type of runtime validation.

@vojtechszocs vojtechszocs force-pushed the extend-yaml-templates branch from 278006c to e7f9901 Compare May 27, 2019 17:03
@vojtechszocs
Copy link
Contributor Author

Fresh rebase on top of #1586

@vojtechszocs vojtechszocs force-pushed the extend-yaml-templates branch from e7f9901 to 4875b25 Compare May 29, 2019 20:04
@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels May 29, 2019
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just realized this should be YAMLTemplate to match current naming conventions, will update.

@vojtechszocs vojtechszocs force-pushed the extend-yaml-templates branch from 4875b25 to a9e4cac Compare May 30, 2019 12:51
@vojtechszocs
Copy link
Contributor Author

PR updated & added packages/console-demo-plugin/src/yaml-templates.ts to encourage plugin developers to keep their YAML templates in a dedicated module.

@vojtechszocs
Copy link
Contributor Author

/retest

@christianvogt
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label May 30, 2019
@spadgett
Copy link
Member

/approve

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: christianvogt, spadgett, vojtechszocs

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-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 30, 2019
@openshift-merge-robot openshift-merge-robot merged commit 076473c into openshift:master May 30, 2019
@logonoff logonoff deleted the extend-yaml-templates branch September 25, 2025 14:38
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.

6 participants