Skip to content

Commit

Permalink
Add support for updated resourceTemplates field in future Triggers re…
Browse files Browse the repository at this point in the history
…lease

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.
  • Loading branch information
AlanGreene authored and tekton-robot committed Feb 16, 2024
1 parent c5b53e4 commit e32e04e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
34 changes: 32 additions & 2 deletions packages/components/src/components/Trigger/Trigger.test.jsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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(<Trigger {...props} />);
expect(getByText(/hello there/)).toBeTruthy();
});

it('handles ClusterInterceptor', () => {
const clusterInterceptorName = 'fake_clusterInterceptorName';
const props = {
Expand Down
17 changes: 10 additions & 7 deletions src/containers/TriggerTemplate/TriggerTemplate.jsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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
<div className="tkn--table">
<DataTable
rows={resourcetemplates.map((item, index) => ({
rows={resourceTemplates.map((item, index) => ({
id: `${index}|${
item.metadata.name || item.metadata.generateName
}`,
Expand Down Expand Up @@ -191,9 +196,7 @@ export /* istanbul ignore next */ function TriggerTemplateContainer() {
{row.isExpanded && (
<TableExpandedRow colSpan={headers.length + 1}>
<ViewYAML
resource={
triggerTemplate.spec.resourcetemplates[index]
}
resource={resourceTemplates[index]}
dark
/>
</TableExpandedRow>
Expand Down
4 changes: 2 additions & 2 deletions src/containers/TriggerTemplate/TriggerTemplate.test.jsx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -115,7 +115,7 @@ const fakeTriggerTemplateWithLabels = {
},
{ description: 'The Content-Type of the event', name: 'contenttype' }
],
resourcetemplates: [
resourceTemplates: [
resourceTemplate1Details,
{
apiVersion: 'tekton.dev/v1alpha1',
Expand Down

0 comments on commit e32e04e

Please sign in to comment.