From 22beab6cb4d456e7a0accc2d43006d397e9523b9 Mon Sep 17 00:00:00 2001 From: mbwhite Date: Mon, 8 Jan 2024 13:40:21 +0000 Subject: [PATCH] fix: pr 68 merge and added interfaces Signed-off-by: mbwhite --- interfaces/event-listener/index.ts | 13 ----- interfaces/pipeline/condition.ts | 10 ---- interfaces/pipeline/index.ts | 17 ------ interfaces/pipeline/resources.ts | 20 ------- interfaces/pipeline/task.ts | 28 --------- interfaces/task/index.ts | 10 ---- interfaces/task/resources.ts | 13 ----- interfaces/task/sidecar.ts | 8 --- interfaces/task/step.ts | 26 --------- interfaces/task/task-spec.ts | 21 ------- interfaces/task/workspace.ts | 7 --- interfaces/trigger-binding/index.ts | 10 ---- interfaces/trigger-template/index.ts | 13 ----- .../trigger-template/resource-template.ts | 57 ------------------- interfaces/trigger-template/workspace.ts | 9 --- no-duplicate-env.yaml | 20 +++++++ .../general/no-duplicate-env.yaml.expect.json | 2 +- src/interfaces/common.ts | 16 +++--- src/interfaces/event-listener/index.ts | 13 +++++ .../interfaces}/event-listener/trigger.ts | 16 +++--- src/interfaces/pipeline/condition.ts | 10 ++++ src/interfaces/pipeline/index.ts | 17 ++++++ src/interfaces/pipeline/resources.ts | 17 ++++++ src/interfaces/pipeline/task.ts | 28 +++++++++ .../interfaces}/pipeline/workspace.ts | 4 +- src/interfaces/task/index.ts | 10 ++++ src/interfaces/task/resources.ts | 13 +++++ src/interfaces/task/sidecar.ts | 8 +++ .../interfaces}/task/step-template.ts | 34 +++++------ src/interfaces/task/step.ts | 26 +++++++++ src/interfaces/task/task-spec.ts | 21 +++++++ {interfaces => src/interfaces}/task/volume.ts | 30 +++++----- src/interfaces/task/workspace.ts | 7 +++ src/interfaces/trigger-binding/index.ts | 10 ++++ src/interfaces/trigger-template/index.ts | 13 +++++ .../trigger-template/resource-template.ts | 57 +++++++++++++++++++ .../interfaces}/trigger-template/resource.ts | 6 +- src/interfaces/trigger-template/workspace.ts | 9 +++ src/rules/no-duplicate-env.ts | 20 ++++++- 39 files changed, 350 insertions(+), 319 deletions(-) delete mode 100644 interfaces/event-listener/index.ts delete mode 100644 interfaces/pipeline/condition.ts delete mode 100644 interfaces/pipeline/index.ts delete mode 100644 interfaces/pipeline/resources.ts delete mode 100644 interfaces/pipeline/task.ts delete mode 100644 interfaces/task/index.ts delete mode 100644 interfaces/task/resources.ts delete mode 100644 interfaces/task/sidecar.ts delete mode 100644 interfaces/task/step.ts delete mode 100644 interfaces/task/task-spec.ts delete mode 100644 interfaces/task/workspace.ts delete mode 100644 interfaces/trigger-binding/index.ts delete mode 100644 interfaces/trigger-template/index.ts delete mode 100644 interfaces/trigger-template/resource-template.ts delete mode 100644 interfaces/trigger-template/workspace.ts create mode 100644 no-duplicate-env.yaml create mode 100644 src/interfaces/event-listener/index.ts rename {interfaces => src/interfaces}/event-listener/trigger.ts (58%) create mode 100644 src/interfaces/pipeline/condition.ts create mode 100644 src/interfaces/pipeline/index.ts create mode 100644 src/interfaces/pipeline/resources.ts create mode 100644 src/interfaces/pipeline/task.ts rename {interfaces => src/interfaces}/pipeline/workspace.ts (54%) create mode 100644 src/interfaces/task/index.ts create mode 100644 src/interfaces/task/resources.ts create mode 100644 src/interfaces/task/sidecar.ts rename {interfaces => src/interfaces}/task/step-template.ts (50%) create mode 100644 src/interfaces/task/step.ts create mode 100644 src/interfaces/task/task-spec.ts rename {interfaces => src/interfaces}/task/volume.ts (51%) create mode 100644 src/interfaces/task/workspace.ts create mode 100644 src/interfaces/trigger-binding/index.ts create mode 100644 src/interfaces/trigger-template/index.ts create mode 100644 src/interfaces/trigger-template/resource-template.ts rename {interfaces => src/interfaces}/trigger-template/resource.ts (58%) create mode 100644 src/interfaces/trigger-template/workspace.ts diff --git a/interfaces/event-listener/index.ts b/interfaces/event-listener/index.ts deleted file mode 100644 index 0c9b134..0000000 --- a/interfaces/event-listener/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import Trigger from './trigger'; - -import { Base } from '../common'; - -interface EventListener extends Base { - kind: 'EventListener'; - spec: { - triggers: Trigger[]; - }; - serviceType?: string; -} - -export default EventListener; diff --git a/interfaces/pipeline/condition.ts b/interfaces/pipeline/condition.ts deleted file mode 100644 index 8c089b8..0000000 --- a/interfaces/pipeline/condition.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { TaskResource } from './resources'; -import { Base, ValueParam } from '../common'; - -interface Condition extends Base { - conditionRef: string; - params?: ValueParam[]; - resources?: TaskResource[]; -} - -export default Condition; diff --git a/interfaces/pipeline/index.ts b/interfaces/pipeline/index.ts deleted file mode 100644 index 839e8d1..0000000 --- a/interfaces/pipeline/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -import Task from './task'; -import Workspace from './workspace'; - -import { Base, Param } from '../common'; -import { PipelineResource } from './resources'; - -interface Pipeline extends Base { - kind: 'Pipeline'; - spec: { - params?: Param[]; - resources?: PipelineResource[]; - workspaces?: Workspace[]; - tasks: Task[]; - }; -} - -export default Pipeline; diff --git a/interfaces/pipeline/resources.ts b/interfaces/pipeline/resources.ts deleted file mode 100644 index 5553f4b..0000000 --- a/interfaces/pipeline/resources.ts +++ /dev/null @@ -1,20 +0,0 @@ -interface Resource { - name: string; - resource: string; - from?: string[]; -} - -interface PipelineResource { - name: string; - type: string; -} - -interface TaskResource { - inputs: Resource[]; - outputs: Resource[]; -} - -export { - TaskResource, - PipelineResource, -}; diff --git a/interfaces/pipeline/task.ts b/interfaces/pipeline/task.ts deleted file mode 100644 index 4dfbe48..0000000 --- a/interfaces/pipeline/task.ts +++ /dev/null @@ -1,28 +0,0 @@ -import Condition from './condition'; -import TaskSpecs from '../task/task-spec'; -import Workspace from './workspace'; - -import { BaseName, ValueParam } from '../common'; -import { TaskResource } from './resources'; - -interface BaseTask { - name: string; - params?: ValueParam[]; - resources?: TaskResource; - workspaces?: Workspace[]; - conditions?: Condition[]; - runAfter?: string[]; - retries?: number; -} - -interface TaskRef extends BaseTask { - taskRef: BaseName; -} - -interface TaskSpec extends BaseTask { - taskSpec: TaskSpecs; -} - -type Task = TaskRef | TaskSpec; - -export default Task; diff --git a/interfaces/task/index.ts b/interfaces/task/index.ts deleted file mode 100644 index c492455..0000000 --- a/interfaces/task/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import TaskSpec from './task-spec'; - -import { Base } from '../common'; - -interface Task extends Base { - kind: 'Task'; - spec: TaskSpec; -} - -export default Task; diff --git a/interfaces/task/resources.ts b/interfaces/task/resources.ts deleted file mode 100644 index 4d5166c..0000000 --- a/interfaces/task/resources.ts +++ /dev/null @@ -1,13 +0,0 @@ -interface Resource { - name: string; - resource: string; - from?: string[]; - optional?: boolean; -} - -interface Resources { - inputs: Resource[]; - outputs: Resource[]; -} - -export default Resources; diff --git a/interfaces/task/sidecar.ts b/interfaces/task/sidecar.ts deleted file mode 100644 index 41ddf11..0000000 --- a/interfaces/task/sidecar.ts +++ /dev/null @@ -1,8 +0,0 @@ -import StepTemplate from './step-template'; - -interface Sidecar extends StepTemplate { - name: string; - image: string; -} - -export default Sidecar; diff --git a/interfaces/task/step.ts b/interfaces/task/step.ts deleted file mode 100644 index 94334aa..0000000 --- a/interfaces/task/step.ts +++ /dev/null @@ -1,26 +0,0 @@ -import StepTemplate from './step-template'; - -interface BaseStep extends StepTemplate { - name?: string; - image: string; - workingDir?: string; - imagePullPolicy?: 'Always' | 'IfNotPresent' | 'Never'; - volumeMounts?: { - name: string; - mountPath: string; - readOnly: boolean; - }[]; -} - -interface CommandStep extends BaseStep { - command: string[]; - args: string[]; -} - -interface ScriptStep extends BaseStep { - script: string; -} - -type Step = ScriptStep | CommandStep; - -export default Step; diff --git a/interfaces/task/task-spec.ts b/interfaces/task/task-spec.ts deleted file mode 100644 index 9176567..0000000 --- a/interfaces/task/task-spec.ts +++ /dev/null @@ -1,21 +0,0 @@ -import Resources from './resources'; -import Sidecar from './sidecar'; -import Step from './step'; -import StepTemplate from './step-template'; -import Volume from './volume'; -import Workspace from './workspace'; - -import { Param, BaseName } from '../common'; - -interface TaskSpec { - steps: Step[]; - params?: Param[]; - resources?: Resources; - workspaces?: Workspace[]; - stepTemplate?: StepTemplate; - results?: BaseName[]; - volumes?: Volume[]; - sidecars?: Sidecar[]; -} - -export default TaskSpec; diff --git a/interfaces/task/workspace.ts b/interfaces/task/workspace.ts deleted file mode 100644 index c44c54e..0000000 --- a/interfaces/task/workspace.ts +++ /dev/null @@ -1,7 +0,0 @@ -interface Workspace { - name: string; - mountPath?: string; - readonly?: boolean; -} - -export default Workspace; diff --git a/interfaces/trigger-binding/index.ts b/interfaces/trigger-binding/index.ts deleted file mode 100644 index f652b7a..0000000 --- a/interfaces/trigger-binding/index.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Base, ValueParam } from '../common'; - -interface TriggerBinding extends Base { - kind: 'TriggerBinding'; - spec: { - params: ValueParam[]; - }; -} - -export default TriggerBinding; diff --git a/interfaces/trigger-template/index.ts b/interfaces/trigger-template/index.ts deleted file mode 100644 index 4bf6b3a..0000000 --- a/interfaces/trigger-template/index.ts +++ /dev/null @@ -1,13 +0,0 @@ -import ResourceTemplate from './resource-template'; - -import { Base, Param } from '../common'; - -interface TriggerTemplate extends Base { - kind: 'TriggerTemplate'; - spec: { - params: Param[]; - resourcetemplates: ResourceTemplate[]; - }; -} - -export default TriggerTemplate; diff --git a/interfaces/trigger-template/resource-template.ts b/interfaces/trigger-template/resource-template.ts deleted file mode 100644 index cf1833a..0000000 --- a/interfaces/trigger-template/resource-template.ts +++ /dev/null @@ -1,57 +0,0 @@ -import Resource from './resource'; -import Workspace from './workspace'; - -import { Base, BaseName, ValueParam } from '../common'; - -interface PipelineRun extends Base { - kind: 'PipelineRun'; - spec: { - pipelineRef: BaseName; - params?: ValueParam[]; - workspaces?: Workspace[]; - resources?: Resource[]; - serviceAccountName?: string; - timeout?: string; - }; -} - -interface PipelineResource extends Base { - kind: 'PipelineResource'; - spec: { - type: string; - params?: ValueParam; - }; -} - -interface PersistentVolumeClaim extends Base { - kind: 'PersistentVolumeClaim'; - spec: { - resources: { - requests: { - storage: string; - }; - }; - volumeMode: string; - accessModes: string[]; - }; -} - -interface Secret extends Base { - kind: 'Secret'; - type: string; - data?: { - [key: string]: string; - }; - stringData?: { - [key: string]: string; - }; -} - -interface ServiceAccount extends Base { - kind: 'ServiceAccount'; - imagePullSecrets?: BaseName[]; -} - -type ResourceTemplate = PipelineRun | PipelineResource | PersistentVolumeClaim | Secret | ServiceAccount; - -export default ResourceTemplate; diff --git a/interfaces/trigger-template/workspace.ts b/interfaces/trigger-template/workspace.ts deleted file mode 100644 index 8db9781..0000000 --- a/interfaces/trigger-template/workspace.ts +++ /dev/null @@ -1,9 +0,0 @@ -interface Workspace { - name: string; - persistentVolumeClaim?: { - claimName: string; - }; - subPath?: string; -} - -export default Workspace; diff --git a/no-duplicate-env.yaml b/no-duplicate-env.yaml new file mode 100644 index 0000000..c1a475d --- /dev/null +++ b/no-duplicate-env.yaml @@ -0,0 +1,20 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: no-duplicate-env-3 +spec: + stepTemplate: + env: + - name: FOO + value: foo + steps: + - name: step-1 + image: alpine + env: + - name: FOO + value: foo + script: | + #!/bin/sh + + echo ${FOO} diff --git a/regression-tests/general/no-duplicate-env.yaml.expect.json b/regression-tests/general/no-duplicate-env.yaml.expect.json index 186eb5a..b425be5 100644 --- a/regression-tests/general/no-duplicate-env.yaml.expect.json +++ b/regression-tests/general/no-duplicate-env.yaml.expect.json @@ -1 +1 @@ -[{"message":"Step 'step-2' has env variable 'FOO' duplicated in task 'no-duplicate-env-1'.","rule":"no-duplicate-env","level":"error","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[393,396,397],"startLine":25,"startColumn":17,"endLine":25,"endColumn":20}},{"message":"StepTemplate has env variable 'FOO' duplicated in task 'no-duplicate-env-2'.","rule":"no-duplicate-env","level":"error","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[733,736,737],"startLine":48,"startColumn":15,"endLine":48,"endColumn":18}},{"message":"Invalid image: 'alpine'. Specify the image tag instead of using ':latest'","rule":"no-latest-image","level":"warning","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[130,136,137],"startLine":9,"startColumn":14,"endLine":9,"endColumn":20}},{"message":"Invalid image: 'alpine'. Specify the image tag instead of using ':latest'","rule":"no-latest-image","level":"warning","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[318,324,325],"startLine":21,"startColumn":14,"endLine":21,"endColumn":20}},{"message":"Invalid image: 'alpine'. Specify the image tag instead of using ':latest'","rule":"no-latest-image","level":"warning","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[506,512,513],"startLine":33,"startColumn":14,"endLine":33,"endColumn":20}},{"message":"Invalid image: 'alpine'. Specify the image tag instead of using ':latest'","rule":"no-latest-image","level":"warning","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[797,803,804],"startLine":52,"startColumn":14,"endLine":52,"endColumn":20}},{"message":"Invalid image: 'alpine'. Specify the image tag instead of using ':latest'","rule":"no-latest-image","level":"warning","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[1051,1057,1058],"startLine":69,"startColumn":14,"endLine":69,"endColumn":20}}] \ No newline at end of file +[{"message":"Step 'step-2' has env variable 'FOO' duplicated in task 'no-duplicate-env-1'.","rule":"no-duplicate-env","level":"error","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[393,396,397],"startLine":25,"startColumn":17,"endLine":25,"endColumn":20}},{"message":"StepTemplate has env variable 'FOO' duplicated in task 'no-duplicate-env-2'.","rule":"no-duplicate-env","level":"error","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[733,736,737],"startLine":48,"startColumn":15,"endLine":48,"endColumn":18}},{"message":"StepTemplate in task 'no-duplicate-env-3' and Step 'step-1' define the same env variable.","rule":"no-duplicate-env","level":"error","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[1085,1088,1089],"startLine":71,"startColumn":17,"endLine":71,"endColumn":20}},{"message":"Invalid image: 'alpine'. Specify the image tag instead of using ':latest'","rule":"no-latest-image","level":"warning","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[130,136,137],"startLine":9,"startColumn":14,"endLine":9,"endColumn":20}},{"message":"Invalid image: 'alpine'. Specify the image tag instead of using ':latest'","rule":"no-latest-image","level":"warning","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[318,324,325],"startLine":21,"startColumn":14,"endLine":21,"endColumn":20}},{"message":"Invalid image: 'alpine'. Specify the image tag instead of using ':latest'","rule":"no-latest-image","level":"warning","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[506,512,513],"startLine":33,"startColumn":14,"endLine":33,"endColumn":20}},{"message":"Invalid image: 'alpine'. Specify the image tag instead of using ':latest'","rule":"no-latest-image","level":"warning","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[797,803,804],"startLine":52,"startColumn":14,"endLine":52,"endColumn":20}},{"message":"Invalid image: 'alpine'. Specify the image tag instead of using ':latest'","rule":"no-latest-image","level":"warning","path":"./regression-tests/general/no-duplicate-env.yaml","loc":{"range":[1051,1057,1058],"startLine":69,"startColumn":14,"endLine":69,"endColumn":20}}] \ No newline at end of file diff --git a/src/interfaces/common.ts b/src/interfaces/common.ts index 8c0d466..01e90f0 100644 --- a/src/interfaces/common.ts +++ b/src/interfaces/common.ts @@ -24,7 +24,7 @@ interface ValueParam { value: string; } -type listResources = { +type ListResources = { [key: string]: Base; }; @@ -35,12 +35,12 @@ interface ExternalResource { } interface Tekton { - tasks?: listResources; - pipelines?: listResources; - listeners?: listResources; - triggerTemplates?: listResources; - triggerBindings?: listResources; - conditions?: listResources; + tasks?: { [key: string]: Base }; + pipelines?: ListResources; + listeners?: ListResources; + triggerTemplates?: ListResources; + triggerBindings?: ListResources; + conditions?: ListResources; externaltasks?: ExternalResource[]; } @@ -83,4 +83,4 @@ export type Problem = { loc: Location; }; -export { Tekton, Base, Param, BaseName, ValueParam, ExternalResource }; +export { Tekton, Base, Param, BaseName, ValueParam, ExternalResource, ListResources }; diff --git a/src/interfaces/event-listener/index.ts b/src/interfaces/event-listener/index.ts new file mode 100644 index 0000000..ea85aa1 --- /dev/null +++ b/src/interfaces/event-listener/index.ts @@ -0,0 +1,13 @@ +import Trigger from './trigger.js'; + +import { Base } from '../common.js'; + +interface EventListener extends Base { + kind: 'EventListener'; + spec: { + triggers: Trigger[]; + }; + serviceType?: string; +} + +export default EventListener; diff --git a/interfaces/event-listener/trigger.ts b/src/interfaces/event-listener/trigger.ts similarity index 58% rename from interfaces/event-listener/trigger.ts rename to src/interfaces/event-listener/trigger.ts index 2a2dfa1..dcd725c 100644 --- a/interfaces/event-listener/trigger.ts +++ b/src/interfaces/event-listener/trigger.ts @@ -1,19 +1,19 @@ -import { BaseName } from '../common'; +import { BaseName } from '../common.js'; interface BaseTrigger { - name? : string; - template: BaseName; + name?: string; + template: BaseName; } interface BindingTrigger extends BaseTrigger { - binding: BaseName; + binding: BaseName; } interface BindingsTrigger extends BaseTrigger { - bindings: { - name?: string; - ref?: string; - }[]; + bindings: { + name?: string; + ref?: string; + }[]; } type Trigger = BindingTrigger | BindingsTrigger; diff --git a/src/interfaces/pipeline/condition.ts b/src/interfaces/pipeline/condition.ts new file mode 100644 index 0000000..358434f --- /dev/null +++ b/src/interfaces/pipeline/condition.ts @@ -0,0 +1,10 @@ +import { TaskResource } from './resources.js'; +import { Base, ValueParam } from '../common.js'; + +interface Condition extends Base { + conditionRef: string; + params?: ValueParam[]; + resources?: TaskResource[]; +} + +export default Condition; diff --git a/src/interfaces/pipeline/index.ts b/src/interfaces/pipeline/index.ts new file mode 100644 index 0000000..016ccb9 --- /dev/null +++ b/src/interfaces/pipeline/index.ts @@ -0,0 +1,17 @@ +import Task from './task.js'; +import Workspace from './workspace.js'; + +import { Base, Param } from '../common.js'; +import { PipelineResource } from './resources.js'; + +interface Pipeline extends Base { + kind: 'Pipeline'; + spec: { + params?: Param[]; + resources?: PipelineResource[]; + workspaces?: Workspace[]; + tasks: Task[]; + }; +} + +export default Pipeline; diff --git a/src/interfaces/pipeline/resources.ts b/src/interfaces/pipeline/resources.ts new file mode 100644 index 0000000..993e803 --- /dev/null +++ b/src/interfaces/pipeline/resources.ts @@ -0,0 +1,17 @@ +interface Resource { + name: string; + resource: string; + from?: string[]; +} + +interface PipelineResource { + name: string; + type: string; +} + +interface TaskResource { + inputs: Resource[]; + outputs: Resource[]; +} + +export { TaskResource, PipelineResource }; diff --git a/src/interfaces/pipeline/task.ts b/src/interfaces/pipeline/task.ts new file mode 100644 index 0000000..0079675 --- /dev/null +++ b/src/interfaces/pipeline/task.ts @@ -0,0 +1,28 @@ +import Condition from './condition.js'; +import TaskSpecs from '../task/task-spec.js'; +import Workspace from './workspace.js'; + +import { BaseName, ValueParam } from '../common.js'; +import { TaskResource } from './resources.js'; + +interface BaseTask { + name: string; + params?: ValueParam[]; + resources?: TaskResource; + workspaces?: Workspace[]; + conditions?: Condition[]; + runAfter?: string[]; + retries?: number; +} + +interface TaskRef extends BaseTask { + taskRef: BaseName; +} + +interface TaskSpec extends BaseTask { + taskSpec: TaskSpecs; +} + +type Task = TaskRef | TaskSpec; + +export default Task; diff --git a/interfaces/pipeline/workspace.ts b/src/interfaces/pipeline/workspace.ts similarity index 54% rename from interfaces/pipeline/workspace.ts rename to src/interfaces/pipeline/workspace.ts index e3cd787..310126a 100644 --- a/interfaces/pipeline/workspace.ts +++ b/src/interfaces/pipeline/workspace.ts @@ -1,6 +1,6 @@ interface Workspace { - name: string; - workspace?: string; + name: string; + workspace?: string; } export default Workspace; diff --git a/src/interfaces/task/index.ts b/src/interfaces/task/index.ts new file mode 100644 index 0000000..5653c30 --- /dev/null +++ b/src/interfaces/task/index.ts @@ -0,0 +1,10 @@ +import TaskSpec from './task-spec.js'; + +import { Base } from '../common.js'; + +interface Task extends Base { + kind: 'Task'; + spec: TaskSpec; +} + +export default Task; diff --git a/src/interfaces/task/resources.ts b/src/interfaces/task/resources.ts new file mode 100644 index 0000000..0b2aab2 --- /dev/null +++ b/src/interfaces/task/resources.ts @@ -0,0 +1,13 @@ +interface Resource { + name: string; + resource: string; + from?: string[]; + optional?: boolean; +} + +interface Resources { + inputs: Resource[]; + outputs: Resource[]; +} + +export default Resources; diff --git a/src/interfaces/task/sidecar.ts b/src/interfaces/task/sidecar.ts new file mode 100644 index 0000000..d781210 --- /dev/null +++ b/src/interfaces/task/sidecar.ts @@ -0,0 +1,8 @@ +import StepTemplate from './step-template.js'; + +interface Sidecar extends StepTemplate { + name: string; + image: string; +} + +export default Sidecar; diff --git a/interfaces/task/step-template.ts b/src/interfaces/task/step-template.ts similarity index 50% rename from interfaces/task/step-template.ts rename to src/interfaces/task/step-template.ts index e301e53..8f30053 100644 --- a/interfaces/task/step-template.ts +++ b/src/interfaces/task/step-template.ts @@ -1,39 +1,39 @@ -import { BaseName } from '../common'; +import { BaseName } from '../common.js'; interface ValueVariable extends BaseName { - value: string; + value: string; } interface AnnotationVariable extends BaseName { - valueFrom: { - fieldRef: { - fieldPath: string; + valueFrom: { + fieldRef: { + fieldPath: string; + }; }; - }; } interface SecretKeyVariable extends BaseName { - valueFrom: { - secretKeyRef: { - name: string; - key: string; + valueFrom: { + secretKeyRef: { + name: string; + key: string; + }; }; - }; } interface ConfigMapKeyVariable extends BaseName { - valueFrom: { - configMapKeyRef: { - name: string; - key: string; + valueFrom: { + configMapKeyRef: { + name: string; + key: string; + }; }; - }; } type Variable = ValueVariable | AnnotationVariable | SecretKeyVariable | ConfigMapKeyVariable; interface StepTemplate { - env?: Variable[]; + env?: Variable[]; } export default StepTemplate; diff --git a/src/interfaces/task/step.ts b/src/interfaces/task/step.ts new file mode 100644 index 0000000..b39dd44 --- /dev/null +++ b/src/interfaces/task/step.ts @@ -0,0 +1,26 @@ +import StepTemplate from './step-template.js'; + +interface BaseStep extends StepTemplate { + name?: string; + image: string; + workingDir?: string; + imagePullPolicy?: 'Always' | 'IfNotPresent' | 'Never'; + volumeMounts?: { + name: string; + mountPath: string; + readOnly: boolean; + }[]; +} + +interface CommandStep extends BaseStep { + command: string[]; + args: string[]; +} + +interface ScriptStep extends BaseStep { + script: string; +} + +type Step = ScriptStep | CommandStep; + +export default Step; diff --git a/src/interfaces/task/task-spec.ts b/src/interfaces/task/task-spec.ts new file mode 100644 index 0000000..1971401 --- /dev/null +++ b/src/interfaces/task/task-spec.ts @@ -0,0 +1,21 @@ +import Resources from './resources.js'; +import Sidecar from './sidecar.js'; +import Step from './step.js'; +import StepTemplate from './step-template.js'; +import Volume from './volume.js'; +import Workspace from './workspace.js'; + +import { Param, BaseName } from '../common.js'; + +interface TaskSpec { + steps: Step[]; + params?: Param[]; + resources?: Resources; + workspaces?: Workspace[]; + stepTemplate?: StepTemplate; + results?: BaseName[]; + volumes?: Volume[]; + sidecars?: Sidecar[]; +} + +export default TaskSpec; diff --git a/interfaces/task/volume.ts b/src/interfaces/task/volume.ts similarity index 51% rename from interfaces/task/volume.ts rename to src/interfaces/task/volume.ts index 1620141..3851d7d 100644 --- a/interfaces/task/volume.ts +++ b/src/interfaces/task/volume.ts @@ -1,29 +1,29 @@ -import { BaseName } from '../common'; +import { BaseName } from '../common.js'; interface EmptyDirVolume extends BaseName { - emtyDir: {}; + emtyDir: {}; } interface ConfigMapVolume extends BaseName { - configMap: { - name: string; - items?: { - key: string; - path: string; - }[]; - }; + configMap: { + name: string; + items?: { + key: string; + path: string; + }[]; + }; } interface PersistentVolumeClaimVolume extends BaseName { - persistentVolumeClaim: { - claimName: string; - }; + persistentVolumeClaim: { + claimName: string; + }; } interface SecretVolume extends BaseName { - secret: { - secretName: string; - }; + secret: { + secretName: string; + }; } type Volume = EmptyDirVolume | ConfigMapVolume | PersistentVolumeClaimVolume | SecretVolume; diff --git a/src/interfaces/task/workspace.ts b/src/interfaces/task/workspace.ts new file mode 100644 index 0000000..bb98771 --- /dev/null +++ b/src/interfaces/task/workspace.ts @@ -0,0 +1,7 @@ +interface Workspace { + name: string; + mountPath?: string; + readonly?: boolean; +} + +export default Workspace; diff --git a/src/interfaces/trigger-binding/index.ts b/src/interfaces/trigger-binding/index.ts new file mode 100644 index 0000000..9cb31a1 --- /dev/null +++ b/src/interfaces/trigger-binding/index.ts @@ -0,0 +1,10 @@ +import { Base, ValueParam } from '../common.js'; + +interface TriggerBinding extends Base { + kind: 'TriggerBinding'; + spec: { + params: ValueParam[]; + }; +} + +export default TriggerBinding; diff --git a/src/interfaces/trigger-template/index.ts b/src/interfaces/trigger-template/index.ts new file mode 100644 index 0000000..0430ce0 --- /dev/null +++ b/src/interfaces/trigger-template/index.ts @@ -0,0 +1,13 @@ +import ResourceTemplate from './resource-template.js'; + +import { Base, Param } from '../common.js'; + +interface TriggerTemplate extends Base { + kind: 'TriggerTemplate'; + spec: { + params: Param[]; + resourcetemplates: ResourceTemplate[]; + }; +} + +export default TriggerTemplate; diff --git a/src/interfaces/trigger-template/resource-template.ts b/src/interfaces/trigger-template/resource-template.ts new file mode 100644 index 0000000..3448c07 --- /dev/null +++ b/src/interfaces/trigger-template/resource-template.ts @@ -0,0 +1,57 @@ +import Resource from './resource.js'; +import Workspace from './workspace.js'; + +import { Base, BaseName, ValueParam } from '../common.js'; + +interface PipelineRun extends Base { + kind: 'PipelineRun'; + spec: { + pipelineRef: BaseName; + params?: ValueParam[]; + workspaces?: Workspace[]; + resources?: Resource[]; + serviceAccountName?: string; + timeout?: string; + }; +} + +interface PipelineResource extends Base { + kind: 'PipelineResource'; + spec: { + type: string; + params?: ValueParam; + }; +} + +interface PersistentVolumeClaim extends Base { + kind: 'PersistentVolumeClaim'; + spec: { + resources: { + requests: { + storage: string; + }; + }; + volumeMode: string; + accessModes: string[]; + }; +} + +interface Secret extends Base { + kind: 'Secret'; + type: string; + data?: { + [key: string]: string; + }; + stringData?: { + [key: string]: string; + }; +} + +interface ServiceAccount extends Base { + kind: 'ServiceAccount'; + imagePullSecrets?: BaseName[]; +} + +type ResourceTemplate = PipelineRun | PipelineResource | PersistentVolumeClaim | Secret | ServiceAccount; + +export default ResourceTemplate; diff --git a/interfaces/trigger-template/resource.ts b/src/interfaces/trigger-template/resource.ts similarity index 58% rename from interfaces/trigger-template/resource.ts rename to src/interfaces/trigger-template/resource.ts index 205d114..62b522d 100644 --- a/interfaces/trigger-template/resource.ts +++ b/src/interfaces/trigger-template/resource.ts @@ -1,8 +1,8 @@ interface Resource { - name: string; - resourceRef: { name: string; - }; + resourceRef: { + name: string; + }; } export default Resource; diff --git a/src/interfaces/trigger-template/workspace.ts b/src/interfaces/trigger-template/workspace.ts new file mode 100644 index 0000000..7b6533d --- /dev/null +++ b/src/interfaces/trigger-template/workspace.ts @@ -0,0 +1,9 @@ +interface Workspace { + name: string; + persistentVolumeClaim?: { + claimName: string; + }; + subPath?: string; +} + +export default Workspace; diff --git a/src/rules/no-duplicate-env.ts b/src/rules/no-duplicate-env.ts index 20724c2..5e7aa0a 100644 --- a/src/rules/no-duplicate-env.ts +++ b/src/rules/no-duplicate-env.ts @@ -1,9 +1,16 @@ -export default (docs, tekton, report) => { - for (const task of Object.values(tekton.tasks)) { +import { Tekton } from '../interfaces/common.js'; + +export default (docs, tekton: Tekton, report) => { + if (!tekton.tasks) { + return; + } + + for (const task of Object.values(tekton.tasks!)) { if (!task.spec) continue; + const templateEnvVars = new Set(); + if (task.spec.stepTemplate && task.spec.stepTemplate.env) { - const templateEnvVars = new Set(); for (const env of task.spec.stepTemplate.env) { if (!templateEnvVars.has(env.name)) { templateEnvVars.add(env.name); @@ -30,6 +37,13 @@ export default (docs, tekton, report) => { 'name', ); } + if (templateEnvVars.has(env.name)) { + report( + `StepTemplate in task '${task.metadata.name}' and Step '${step.name}' define the same env variable.`, + env, + 'name', + ); + } } } }