From b8beaaa4753314797ac7f8e2c74f08b562fc7e16 Mon Sep 17 00:00:00 2001 From: Alan Greene Date: Thu, 15 Feb 2024 17:47:37 +0000 Subject: [PATCH] Add support for updated resourceTemplates field in future Triggers release Triggers v0.26.0 attempted to rename `resourcetemplates` to `resourceTemplates` but it was done in a backwards incompatible way and reverted in v0.26.1. This change will be reintroduced in a backwards compatible way in a future release. Update the Dashboard code to handle both variants, including ensuring we have test coverage for both. --- .../src/components/Trigger/Trigger.test.jsx | 34 +++++++++++++++++-- .../TriggerTemplate/TriggerTemplate.jsx | 17 ++++++---- .../TriggerTemplate/TriggerTemplate.test.jsx | 4 +-- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/packages/components/src/components/Trigger/Trigger.test.jsx b/packages/components/src/components/Trigger/Trigger.test.jsx index 170b65b40..eff489ef2 100644 --- a/packages/components/src/components/Trigger/Trigger.test.jsx +++ b/packages/components/src/components/Trigger/Trigger.test.jsx @@ -1,5 +1,5 @@ /* -Copyright 2019-2023 The Tekton Authors +Copyright 2019-2024 The Tekton Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -284,7 +284,7 @@ describe('Trigger', () => { expect(queryByText(/TriggerBindings/i)).toBeFalsy(); }); - it('handles embedded template spec', () => { + it('handles embedded template spec - resourcetemplates', () => { const props = { namespace: 'tekton-pipelines', trigger: { @@ -314,6 +314,36 @@ describe('Trigger', () => { expect(getByText(/hello there/)).toBeTruthy(); }); + it('handles embedded template spec - resourceTemplates', () => { + const props = { + namespace: 'tekton-pipelines', + trigger: { + ...fakeTrigger, + template: { + spec: { + params: [{ name: 'foo' }], + resourceTemplates: [ + { + apiVersion: 'tekton.dev/v1beta1', + kind: 'TaskRun', + metadata: { + generateName: 'pr-run-' + }, + spec: { + taskSpec: { + steps: [{ image: 'ubuntu', script: 'echo "hello there"' }] + } + } + } + ] + } + } + } + }; + const { getByText } = renderWithRouter(); + expect(getByText(/hello there/)).toBeTruthy(); + }); + it('handles ClusterInterceptor', () => { const clusterInterceptorName = 'fake_clusterInterceptorName'; const props = { diff --git a/src/containers/TriggerTemplate/TriggerTemplate.jsx b/src/containers/TriggerTemplate/TriggerTemplate.jsx index fff9df9da..212857bf3 100644 --- a/src/containers/TriggerTemplate/TriggerTemplate.jsx +++ b/src/containers/TriggerTemplate/TriggerTemplate.jsx @@ -1,5 +1,5 @@ /* -Copyright 2019-2023 The Tekton Authors +Copyright 2019-2024 The Tekton Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -73,7 +73,12 @@ export /* istanbul ignore next */ function TriggerTemplateContainer() { return null; } - const { params, resourcetemplates } = triggerTemplate.spec; + const { + params, + resourceTemplates: newResourceTemplates, + resourcetemplates: oldResourceTemplates + } = triggerTemplate.spec; + const resourceTemplates = oldResourceTemplates || newResourceTemplates; const headersForParameters = [ { @@ -130,12 +135,12 @@ export /* istanbul ignore next */ function TriggerTemplateContainer() { emptyTextAllNamespaces={emptyTextMessage} emptyTextSelectedNamespace={emptyTextMessage} /> - {resourcetemplates && ( + {resourceTemplates && ( // This is a very customised expandable table so intentionally not the one used elsewhere // although it should look the same
({ + rows={resourceTemplates.map((item, index) => ({ id: `${index}|${ item.metadata.name || item.metadata.generateName }`, @@ -191,9 +196,7 @@ export /* istanbul ignore next */ function TriggerTemplateContainer() { {row.isExpanded && ( diff --git a/src/containers/TriggerTemplate/TriggerTemplate.test.jsx b/src/containers/TriggerTemplate/TriggerTemplate.test.jsx index ead14502c..3c46551c0 100644 --- a/src/containers/TriggerTemplate/TriggerTemplate.test.jsx +++ b/src/containers/TriggerTemplate/TriggerTemplate.test.jsx @@ -1,5 +1,5 @@ /* -Copyright 2019-2023 The Tekton Authors +Copyright 2019-2024 The Tekton Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -115,7 +115,7 @@ const fakeTriggerTemplateWithLabels = { }, { description: 'The Content-Type of the event', name: 'contenttype' } ], - resourcetemplates: [ + resourceTemplates: [ resourceTemplate1Details, { apiVersion: 'tekton.dev/v1alpha1',