From dfe3f2d514ca1ab1edecf50d9546c676c4a678b9 Mon Sep 17 00:00:00 2001 From: snehajais22 Date: Tue, 6 Aug 2024 17:30:04 -0400 Subject: [PATCH 1/4] Basic TaskRunBuilder class Signed-off-by: snehajais22 --- src/builders.ts | 117 ++++++++++++++++++++++++++++++++++++++++++++++++ src/tasks.ts | 112 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 229 insertions(+) diff --git a/src/builders.ts b/src/builders.ts index 770f81a..0374c19 100644 --- a/src/builders.ts +++ b/src/builders.ts @@ -30,6 +30,9 @@ import { ResolverParam, RemoteTaskRef, TaskRef, + TaskRunWorkspace, + TaskRun, + TaskRunParam, } from './tasks'; const DefaultPipelineServiceAccountName = 'default:pipeline'; @@ -970,6 +973,120 @@ export class TaskBuilder { } } +/** + * Builds a `TaskRun` using the supplied configuration. + * + * @see https://tekton.dev/docs/pipelines/taskruns/ + */ +export class TaskRunBuilder { + private readonly _scope: Construct; + private readonly _id: string; + private readonly _task: TaskBuilder; + private readonly _runParams: TaskRunParam[]; + private readonly _runWorkspaces: TaskRunWorkspace[]; + // private _sa: string; + // private _crbProps: ApiObjectProps; + + /** + * Creates a new instance of the `TaskRunBuilder` for the specified + * `Task` that is built by the `TaskBuilder` supplied here. + * + * A pipeline run is configured only for a specific task, so it did not + * make any sense here to allow the run to be created without the task + * specified. + * + * @param scope The `Construct` in which to create the `TaskRun`. + * @param id The logical ID of the `TaskRun` construct. + * @param pipeline The `Task` for which to create this run, using the `TaskBuilder`. + */ + public constructor(scope: Construct, id: string, task: TaskBuilder) { + this._scope = scope; + this._id = id; + this._task = task; + // this._sa = DefaultPipelineServiceAccountName; + // this._crbProps = DefaultClusterRoleBindingProps; + this._runParams = new Array(); + this._runWorkspaces = new Array(); + } + + /** + * Adds a run parameter to the `TaskRun`. It will throw an error if you try + * to add a parameter that does not exist on the task. + * + * @param name The name of the parameter added to the task run. + * @param value The value of the parameter added to the task run. + */ + public withRunParam(name: string, value: string): TaskRunBuilder { + const params = this._task.parameters!; + const p = params.find((obj) => obj.name === name); + if (p) { + this._runParams.push({ + name: name, + value: value, + }); + } else { + throw new Error(`TaskRun parameter '${name}' does not exist in task '${this._task.logicalID}'`); + } + return this; + } + + /** + * Allows you to specify the name of a `PersistentVolumeClaim` but does not + * do any compile-time validation on the volume claim's name or existence. + * + * @see https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolumeclaim + * + * @param name The name of the workspace in the `TaskRun` that will be used by the `Task`. + * @param claimName The name of the `PersistentVolumeClaim` to use for the `workspace`. + * @param subPath The sub path on the `persistentVolumeClaim` to use for the `workspace`. + */ + public withWorkspace(name: string, claimName: string, subPath: string): TaskRunBuilder { + this._runWorkspaces.push({ + name: name, + persistentVolumeClaim: { + claimName: claimName, + }, + subPath: subPath, + }); + return this; + } + + /** + * Builds the `TaskRun` for the configured `Task` used in the constructor. + * @param opts + */ + public buildTaskRun(opts: BuilderOptions = DefaultBuilderOptions): void { + const params = this._task.parameters!; + params.forEach((p) => { + const prp = this._runParams.find((obj) => obj.name == p.name); + if (!prp) { + throw new Error(`Task parameter '${p.name}' is not defined in TaskRun '${this._id}'`); + } + }); + + const workspaces: TaskWorkspace[] = this._task.workspaces!; + workspaces.forEach((ws) => { + const pws = this._runWorkspaces.find((obj) => obj.name == ws.name); + if (!pws) { + throw new Error(`Task workspace '${ws.name}' is not defined in TaskRun '${this._id}'`); + } + }); + + new TaskRun(this._scope, this._id, { + metadata: { + name: this._id, + }, + spec: { + taskRef: { + name: this._task.logicalID, + }, + params: this._runParams, + workspaces: this._runWorkspaces, + }, + }); + } +} + /** * */ diff --git a/src/tasks.ts b/src/tasks.ts index f19d209..7e279dc 100644 --- a/src/tasks.ts +++ b/src/tasks.ts @@ -20,6 +20,7 @@ import { ApiObject, ApiObjectMetadata, GroupVersionKind } from 'cdk8s'; import { Construct } from 'constructs'; import { NamedResource, NameKeyPair, TektonV1ApiVersion } from './common'; +import { PersistentVolumeClaimRef } from './pipelines'; /** @@ -302,3 +303,114 @@ export class Task extends ApiObject { }), {}); } } + +/** + * The parameters for a particular `TaskRun`. + */ +export interface TaskRunParam extends NamedResource { + /** + * The value of the parameter in this `TaskRun`. + */ + readonly value: string; +} + +/** + * The `Workspace` configuration for a `TaskRun`. + * + * @see https://tekton.dev/docs/pipelines/taskruns/#specifying-workspaces + */ +export interface TaskRunWorkspace extends NamedResource { + readonly persistentVolumeClaim: PersistentVolumeClaimRef; + readonly subPath: string; +} + +/** + * The details for the `TaskRun`. + * @see https://tekton.dev/docs/pipelines/taskruns/#configuring-a-taskrun + */ +export interface TaskRunSpec { + /** + * Required `Task` reference. + */ + readonly taskRef: TaskRef; + readonly params?: TaskRunParam[]; + readonly workspaces?: TaskRunWorkspace[]; +} + +export interface TaskRunProps { + readonly metadata?: ApiObjectMetadata; + /** + * Specifies the configuration information for this `TaskRun` object. + */ + readonly spec?: TaskRunSpec; + /** + * Specifies a `ServiceAccount` object that supplies specific execution + * credentials for the `Task`. + */ + readonly serviceAccountName?: string; //NOTE should be 'default' if unspecified +} + +/** + * The TaskRun allows you to specify how you want to execute a `Task`. + * + * @see https://tekton.dev/docs/pipelines/taskruns/ + * @schema TaskRun + */ +export class TaskRun extends ApiObject { + + /** + * Returns the apiVersion and kind for "TaskRun" + */ + public static readonly GVK: GroupVersionKind = { + apiVersion: TektonV1ApiVersion, + kind: 'TaskRun', + }; + + /** + * Renders a Kubernetes manifest for `TaskRun`. + * + * This can be used to inline resource manifests inside other objects (e.g. as templates). + * + * @param props initialization props + */ + public static manifest(props: TaskProps = {}): any { + return { + ...TaskRun.GVK, + ...props, + }; + } + + private readonly _metadata?: ApiObjectMetadata; + private readonly _spec?: TaskRunSpec; + + /** + * Defines a `TaskRun` API object + * @param scope the scope in which to define this object + * @param id a scope-local name for the object + * @param props initialization props + */ + public constructor(scope: Construct, id: string, props: TaskRunProps = {}) { + super(scope, id, { + ...TaskRun.GVK, + }); + this._metadata = props.metadata; + this._spec = props.spec; + } + + /** + * Renders the object to Kubernetes JSON. + */ + public toJson(): any { + const result = { + ...TaskRun.GVK, + ...{ + metadata: this._metadata, + spec: this._spec, + }, + }; + return Object.entries(result).reduce((r, i) => (i[1] === undefined) ? r : ({ + ...r, + [i[0]]: i[1], + }), {}); + } +} From 3bdd36620a1c1d02cf37a7f822fd41de2bc9407c Mon Sep 17 00:00:00 2001 From: snehajais22 Date: Wed, 7 Aug 2024 10:56:40 -0400 Subject: [PATCH 2/4] Remote Resolvers in TaskRuns Signed-off-by: snehajais22 --- src/builders.ts | 124 ++++++++++++++++++++++++++++++++++-------------- src/tasks.ts | 14 +++--- 2 files changed, 95 insertions(+), 43 deletions(-) diff --git a/src/builders.ts b/src/builders.ts index bed1929..7508c75 100644 --- a/src/builders.ts +++ b/src/builders.ts @@ -986,11 +986,11 @@ export class TaskBuilder { export class TaskRunBuilder { private readonly _scope: Construct; private readonly _id: string; - private readonly _task: TaskBuilder; + private readonly _task: TaskBuilder | IRemoteResolver; private readonly _runParams: TaskRunParam[]; private readonly _runWorkspaces: TaskRunWorkspace[]; - // private _sa: string; - // private _crbProps: ApiObjectProps; + private _sa: string; + private _crbProps: ApiObjectProps; /** * Creates a new instance of the `TaskRunBuilder` for the specified @@ -1002,14 +1002,15 @@ export class TaskRunBuilder { * * @param scope The `Construct` in which to create the `TaskRun`. * @param id The logical ID of the `TaskRun` construct. - * @param pipeline The `Task` for which to create this run, using the `TaskBuilder`. + * @param pipeline The `Task` for which to create this run, using the `TaskBuilder` or + * `IRemoteResolver` for a remote `Task`. */ - public constructor(scope: Construct, id: string, task: TaskBuilder) { + public constructor(scope: Construct, id: string, task: TaskBuilder | IRemoteResolver) { this._scope = scope; this._id = id; this._task = task; - // this._sa = DefaultPipelineServiceAccountName; - // this._crbProps = DefaultClusterRoleBindingProps; + this._sa = DefaultPipelineServiceAccountName; + this._crbProps = DefaultClusterRoleBindingProps; this._runParams = new Array(); this._runWorkspaces = new Array(); } @@ -1017,20 +1018,28 @@ export class TaskRunBuilder { /** * Adds a run parameter to the `TaskRun`. It will throw an error if you try * to add a parameter that does not exist on the task. + * If the `TaskRun` references a remote task, consistency checks are omitted. * * @param name The name of the parameter added to the task run. * @param value The value of the parameter added to the task run. */ public withRunParam(name: string, value: string): TaskRunBuilder { - const params = this._task.parameters!; - const p = params.find((obj) => obj.name === name); - if (p) { + if (this._task instanceof TaskBuilder) { + const params = this._task.parameters!; + const p = params.find((obj) => obj.name === name); + if (p) { + this._runParams.push({ + name: name, + value: value, + }); + } else { + throw new Error(`TaskRun parameter '${name}' does not exist in task '${this._task.logicalID}'`); + } + } else { this._runParams.push({ name: name, value: value, }); - } else { - throw new Error(`TaskRun parameter '${name}' does not exist in task '${this._task.logicalID}'`); } return this; } @@ -1056,39 +1065,82 @@ export class TaskRunBuilder { return this; } + public withClusterRoleBindingProps(props: ApiObjectProps): TaskRunBuilder { + this._crbProps = props; + return this; + } + + /** + * Uses the provided role name for the `serviceAccountName` on the + * `TaskRun`. If this method is not called prior to `buildTaskRun()`, + * then the default service account will be used, which is _default:pipeline_. + * + * @param sa The name of the service account (`serviceAccountName`) to use. + */ + public withServiceAccount(sa: string): TaskRunBuilder { + this._sa = sa; + return this; + } + /** * Builds the `TaskRun` for the configured `Task` used in the constructor. + * If the `TaskRun` references a remote task, consistency checks for parameters + * and workspaces expected by the pipeline are omitted. * @param opts */ public buildTaskRun(opts: BuilderOptions = DefaultBuilderOptions): void { - const params = this._task.parameters!; - params.forEach((p) => { - const prp = this._runParams.find((obj) => obj.name == p.name); - if (!prp) { - throw new Error(`Task parameter '${p.name}' is not defined in TaskRun '${this._id}'`); - } - }); + if (opts && opts.includeDependencies) { + // Generate the ClusterRoleBinding document, if configured to do so. + new ApiObject(this._scope, this._crbProps.metadata?.name!, this._crbProps); + } - const workspaces: TaskWorkspace[] = this._task.workspaces!; - workspaces.forEach((ws) => { - const pws = this._runWorkspaces.find((obj) => obj.name == ws.name); - if (!pws) { - throw new Error(`Task workspace '${ws.name}' is not defined in TaskRun '${this._id}'`); + if (this._task instanceof TaskBuilder) { + const params = this._task.parameters!; + params.forEach((p) => { + const prp = this._runParams.find((obj) => obj.name == p.name); + if (!prp) { + throw new Error(`Task parameter '${p.name}' is not defined in TaskRun '${this._id}'`); + } + }); + + const workspaces: TaskWorkspace[] = this._task.workspaces!; + workspaces.forEach((ws) => { + const pws = this._runWorkspaces.find((obj) => obj.name == ws.name); + if (!pws) { + throw new Error(`Task workspace '${ws.name}' is not defined in TaskRun '${this._id}'`); + } + }); + + new TaskRun(this._scope, this._id, { + metadata: { + name: this._id, + }, + spec: { + serviceAccountName: this._sa, + taskRef: { + name: this._task.logicalID, + }, + params: this._runParams, + workspaces: this._runWorkspaces, + }, + }); + } else { + if (this._task.kind != 'task') { + throw new Error(`Remote resource must be of kind 'task' in taskRef of TaskRun '${this._id}'.`); } - }); - new TaskRun(this._scope, this._id, { - metadata: { - name: this._id, - }, - spec: { - taskRef: { - name: this._task.logicalID, + new TaskRun(this._scope, this._id, { + metadata: { + name: this._id, }, - params: this._runParams, - workspaces: this._runWorkspaces, - }, - }); + spec: { + serviceAccountName: this._sa, + taskRef: this._task.remoteRef, + params: this._runParams, + workspaces: this._runWorkspaces, + }, + }); + } } } diff --git a/src/tasks.ts b/src/tasks.ts index 7d7298e..6cbb220 100644 --- a/src/tasks.ts +++ b/src/tasks.ts @@ -19,7 +19,7 @@ */ import { ApiObject, ApiObjectMetadata, GroupVersionKind } from 'cdk8s'; import { Construct } from 'constructs'; -import { NamedResource, NameKeyPair, TektonV1ApiVersion } from './common'; +import { NamedResource, NameKeyPair, TektonV1ApiVersion, RemoteRef } from './common'; import { PersistentVolumeClaimRef } from './pipelines'; @@ -309,9 +309,14 @@ export interface TaskRunSpec { /** * Required `Task` reference. */ - readonly taskRef: TaskRef; + readonly taskRef: TaskRef | RemoteRef; readonly params?: TaskRunParam[]; readonly workspaces?: TaskRunWorkspace[]; + /** + * Specifies a `ServiceAccount` object that supplies specific execution + * credentials for the `Task`. + */ + readonly serviceAccountName?: string; } export interface TaskRunProps { @@ -320,11 +325,6 @@ export interface TaskRunProps { * Specifies the configuration information for this `TaskRun` object. */ readonly spec?: TaskRunSpec; - /** - * Specifies a `ServiceAccount` object that supplies specific execution - * credentials for the `Task`. - */ - readonly serviceAccountName?: string; //NOTE should be 'default' if unspecified } /** From 6c59e6321cf33b66aa294509326bc823d86aea3a Mon Sep 17 00:00:00 2001 From: snehajais22 Date: Wed, 7 Aug 2024 10:57:35 -0400 Subject: [PATCH 3/4] TaskRun unit tests & documentation Signed-off-by: snehajais22 --- API.md | 884 ++++++++++++++++++-- test/__snapshots__/taskbuilder.test.ts.snap | 199 +++++ test/taskbuilder.test.ts | 177 +++- 3 files changed, 1169 insertions(+), 91 deletions(-) diff --git a/API.md b/API.md index 4f6b515..c9a8a91 100644 --- a/API.md +++ b/API.md @@ -1237,6 +1237,334 @@ Returns the apiVersion and kind for "Task". --- +### TaskRun + +The TaskRun allows you to specify how you want to execute a `Task`. + +> [https://tekton.dev/docs/pipelines/taskruns/](https://tekton.dev/docs/pipelines/taskruns/) + +#### Initializers + +```typescript +import { TaskRun } from 'cdk8s-pipelines' + +new TaskRun(scope: Construct, id: string, props?: TaskRunProps) +``` + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| scope | constructs.Construct | the scope in which to define this object. | +| id | string | a scope-local name for the object. | +| props | TaskRunProps | initialization props. | + +--- + +##### `scope`Required + +- *Type:* constructs.Construct + +the scope in which to define this object. + +--- + +##### `id`Required + +- *Type:* string + +a scope-local name for the object. + +--- + +##### `props`Optional + +- *Type:* TaskRunProps + +initialization props. + +--- + +#### Methods + +| **Name** | **Description** | +| --- | --- | +| toString | Returns a string representation of this construct. | +| addDependency | Create a dependency between this ApiObject and other constructs. | +| addJsonPatch | Applies a set of RFC-6902 JSON-Patch operations to the manifest synthesized for this API object. | +| toJson | Renders the object to Kubernetes JSON. | + +--- + +##### `toString` + +```typescript +public toString(): string +``` + +Returns a string representation of this construct. + +##### `addDependency` + +```typescript +public addDependency(dependencies: IConstruct): void +``` + +Create a dependency between this ApiObject and other constructs. + +These can be other ApiObjects, Charts, or custom. + +###### `dependencies`Required + +- *Type:* constructs.IConstruct + +the dependencies to add. + +--- + +##### `addJsonPatch` + +```typescript +public addJsonPatch(ops: JsonPatch): void +``` + +Applies a set of RFC-6902 JSON-Patch operations to the manifest synthesized for this API object. + +*Example* + +```typescript + kubePod.addJsonPatch(JsonPatch.replace('/spec/enableServiceLinks', true)); +``` + + +###### `ops`Required + +- *Type:* cdk8s.JsonPatch + +The JSON-Patch operations to apply. + +--- + +##### `toJson` + +```typescript +public toJson(): any +``` + +Renders the object to Kubernetes JSON. + +#### Static Functions + +| **Name** | **Description** | +| --- | --- | +| isConstruct | Checks if `x` is a construct. | +| isApiObject | Return whether the given object is an `ApiObject`. | +| of | Returns the `ApiObject` named `Resource` which is a child of the given construct. | +| manifest | Renders a Kubernetes manifest for `TaskRun`. | + +--- + +##### ~~`isConstruct`~~ + +```typescript +import { TaskRun } from 'cdk8s-pipelines' + +TaskRun.isConstruct(x: any) +``` + +Checks if `x` is a construct. + +###### `x`Required + +- *Type:* any + +Any object. + +--- + +##### `isApiObject` + +```typescript +import { TaskRun } from 'cdk8s-pipelines' + +TaskRun.isApiObject(o: any) +``` + +Return whether the given object is an `ApiObject`. + +We do attribute detection since we can't reliably use 'instanceof'. + +###### `o`Required + +- *Type:* any + +The object to check. + +--- + +##### `of` + +```typescript +import { TaskRun } from 'cdk8s-pipelines' + +TaskRun.of(c: IConstruct) +``` + +Returns the `ApiObject` named `Resource` which is a child of the given construct. + +If `c` is an `ApiObject`, it is returned directly. Throws an +exception if the construct does not have a child named `Default` _or_ if +this child is not an `ApiObject`. + +###### `c`Required + +- *Type:* constructs.IConstruct + +The higher-level construct. + +--- + +##### `manifest` + +```typescript +import { TaskRun } from 'cdk8s-pipelines' + +TaskRun.manifest(props?: TaskProps) +``` + +Renders a Kubernetes manifest for `TaskRun`. + +This can be used to inline resource manifests inside other objects (e.g. as templates). + +###### `props`Optional + +- *Type:* TaskProps + +initialization props. + +--- + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| node | constructs.Node | The tree node. | +| apiGroup | string | The group portion of the API version (e.g. `authorization.k8s.io`). | +| apiVersion | string | The object's API version (e.g. `authorization.k8s.io/v1`). | +| chart | cdk8s.Chart | The chart in which this object is defined. | +| kind | string | The object kind. | +| metadata | cdk8s.ApiObjectMetadataDefinition | Metadata associated with this API object. | +| name | string | The name of the API object. | + +--- + +##### `node`Required + +```typescript +public readonly node: Node; +``` + +- *Type:* constructs.Node + +The tree node. + +--- + +##### `apiGroup`Required + +```typescript +public readonly apiGroup: string; +``` + +- *Type:* string + +The group portion of the API version (e.g. `authorization.k8s.io`). + +--- + +##### `apiVersion`Required + +```typescript +public readonly apiVersion: string; +``` + +- *Type:* string + +The object's API version (e.g. `authorization.k8s.io/v1`). + +--- + +##### `chart`Required + +```typescript +public readonly chart: Chart; +``` + +- *Type:* cdk8s.Chart + +The chart in which this object is defined. + +--- + +##### `kind`Required + +```typescript +public readonly kind: string; +``` + +- *Type:* string + +The object kind. + +--- + +##### `metadata`Required + +```typescript +public readonly metadata: ApiObjectMetadataDefinition; +``` + +- *Type:* cdk8s.ApiObjectMetadataDefinition + +Metadata associated with this API object. + +--- + +##### `name`Required + +```typescript +public readonly name: string; +``` + +- *Type:* string + +The name of the API object. + +If a name is specified in `metadata.name` this will be the name returned. +Otherwise, a name will be generated by calling +`Chart.of(this).generatedObjectName(this)`, which by default uses the +construct path to generate a DNS-compatible name for the resource. + +--- + +#### Constants + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| GVK | cdk8s.GroupVersionKind | Returns the apiVersion and kind for "TaskRun". | + +--- + +##### `GVK`Required + +```typescript +public readonly GVK: GroupVersionKind; +``` + +- *Type:* cdk8s.GroupVersionKind + +Returns the apiVersion and kind for "TaskRun". + +--- + ## Structs ### BuilderOptions @@ -1947,80 +2275,284 @@ public readonly refParams: PipelineParam[]; --- -##### `refWorkspaces`Optional +##### `refWorkspaces`Optional + +```typescript +public readonly refWorkspaces: PipelineTaskWorkspace[]; +``` + +- *Type:* PipelineTaskWorkspace[] + +--- + +### PipelineTaskWorkspace + +#### Initializer + +```typescript +import { PipelineTaskWorkspace } from 'cdk8s-pipelines' + +const pipelineTaskWorkspace: PipelineTaskWorkspace = { ... } +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| name | string | *No description.* | +| workspace | string | *No description.* | + +--- + +##### `name`Optional + +```typescript +public readonly name: string; +``` + +- *Type:* string + +--- + +##### `workspace`Optional + +```typescript +public readonly workspace: string; +``` + +- *Type:* string + +--- + +### PipelineWorkspace + +A workspace for a pipeline. + +See https://tekton.dev/docs/pipelines/pipelines/#specifying-workspaces +and https://tekton.dev/docs/pipelines/workspaces/#using-workspaces-in-pipelines. + +#### Initializer + +```typescript +import { PipelineWorkspace } from 'cdk8s-pipelines' + +const pipelineWorkspace: PipelineWorkspace = { ... } +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| name | string | *No description.* | +| description | string | The description of the workspace. | + +--- + +##### `name`Optional + +```typescript +public readonly name: string; +``` + +- *Type:* string + +--- + +##### `description`Optional + +```typescript +public readonly description: string; +``` + +- *Type:* string + +The description of the workspace. + +--- + +### ResolverParam + +A Resolver parameter value. + +#### Initializer + +```typescript +import { ResolverParam } from 'cdk8s-pipelines' + +const resolverParam: ResolverParam = { ... } +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| name | string | *No description.* | +| value | string | The value of the resolver parameter. | + +--- + +##### `name`Optional + +```typescript +public readonly name: string; +``` + +- *Type:* string + +--- + +##### `value`Optional + +```typescript +public readonly value: string; +``` + +- *Type:* string + +The value of the resolver parameter. + +--- + +### TaskEnvValueSource + +The source for a `env` `valueFrom`. + +#### Initializer + +```typescript +import { TaskEnvValueSource } from 'cdk8s-pipelines' + +const taskEnvValueSource: TaskEnvValueSource = { ... } +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| secretKeyRef | NameKeyPair | *No description.* | + +--- + +##### `secretKeyRef`Required + +```typescript +public readonly secretKeyRef: NameKeyPair; +``` + +- *Type:* NameKeyPair + +--- + +### TaskParam + +A Task parameter value. + +#### Initializer + +```typescript +import { TaskParam } from 'cdk8s-pipelines' + +const taskParam: TaskParam = { ... } +``` + +#### Properties + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| name | string | *No description.* | +| value | string | The value of the task parameter. | + +--- + +##### `name`Optional + +```typescript +public readonly name: string; +``` + +- *Type:* string + +--- + +##### `value`Optional ```typescript -public readonly refWorkspaces: PipelineTaskWorkspace[]; +public readonly value: string; ``` -- *Type:* PipelineTaskWorkspace[] +- *Type:* string + +The value of the task parameter. --- -### PipelineTaskWorkspace +### TaskProps -#### Initializer +Properties used to create the Task. + +#### Initializer ```typescript -import { PipelineTaskWorkspace } from 'cdk8s-pipelines' +import { TaskProps } from 'cdk8s-pipelines' -const pipelineTaskWorkspace: PipelineTaskWorkspace = { ... } +const taskProps: TaskProps = { ... } ``` #### Properties | **Name** | **Type** | **Description** | | --- | --- | --- | -| name | string | *No description.* | -| workspace | string | *No description.* | +| metadata | cdk8s.ApiObjectMetadata | The object [metadata](https://kubernetes.io/docs/concepts/overview/working-with-objects/#required-fields) that conforms to standard Kubernetes metadata. | +| spec | TaskSpec | The `spec` is the configuration of the `Task` object. | --- -##### `name`Optional +##### `metadata`Optional ```typescript -public readonly name: string; +public readonly metadata: ApiObjectMetadata; ``` -- *Type:* string +- *Type:* cdk8s.ApiObjectMetadata + +The object [metadata](https://kubernetes.io/docs/concepts/overview/working-with-objects/#required-fields) that conforms to standard Kubernetes metadata. --- -##### `workspace`Optional +##### `spec`Optional ```typescript -public readonly workspace: string; +public readonly spec: TaskSpec; ``` -- *Type:* string +- *Type:* TaskSpec ---- +The `spec` is the configuration of the `Task` object. -### PipelineWorkspace +--- -A workspace for a pipeline. +### TaskRunParam -See https://tekton.dev/docs/pipelines/pipelines/#specifying-workspaces -and https://tekton.dev/docs/pipelines/workspaces/#using-workspaces-in-pipelines. +The parameters for a particular `TaskRun`. -#### Initializer +#### Initializer ```typescript -import { PipelineWorkspace } from 'cdk8s-pipelines' +import { TaskRunParam } from 'cdk8s-pipelines' -const pipelineWorkspace: PipelineWorkspace = { ... } +const taskRunParam: TaskRunParam = { ... } ``` #### Properties | **Name** | **Type** | **Description** | | --- | --- | --- | -| name | string | *No description.* | -| description | string | The description of the workspace. | +| name | string | *No description.* | +| value | string | The value of the parameter in this `TaskRun`. | --- -##### `name`Optional +##### `name`Optional ```typescript public readonly name: string; @@ -2030,176 +2562,179 @@ public readonly name: string; --- -##### `description`Optional +##### `value`Required ```typescript -public readonly description: string; +public readonly value: string; ``` - *Type:* string -The description of the workspace. +The value of the parameter in this `TaskRun`. --- -### ResolverParam - -A Resolver parameter value. +### TaskRunProps -#### Initializer +#### Initializer ```typescript -import { ResolverParam } from 'cdk8s-pipelines' +import { TaskRunProps } from 'cdk8s-pipelines' -const resolverParam: ResolverParam = { ... } +const taskRunProps: TaskRunProps = { ... } ``` #### Properties | **Name** | **Type** | **Description** | | --- | --- | --- | -| name | string | *No description.* | -| value | string | The value of the resolver parameter. | +| metadata | cdk8s.ApiObjectMetadata | *No description.* | +| spec | TaskRunSpec | Specifies the configuration information for this `TaskRun` object. | --- -##### `name`Optional +##### `metadata`Optional ```typescript -public readonly name: string; +public readonly metadata: ApiObjectMetadata; ``` -- *Type:* string +- *Type:* cdk8s.ApiObjectMetadata --- -##### `value`Optional +##### `spec`Optional ```typescript -public readonly value: string; +public readonly spec: TaskRunSpec; ``` -- *Type:* string +- *Type:* TaskRunSpec -The value of the resolver parameter. +Specifies the configuration information for this `TaskRun` object. --- -### TaskEnvValueSource +### TaskRunSpec -The source for a `env` `valueFrom`. +The details for the `TaskRun`. -#### Initializer +> [https://tekton.dev/docs/pipelines/taskruns/#configuring-a-taskrun](https://tekton.dev/docs/pipelines/taskruns/#configuring-a-taskrun) + +#### Initializer ```typescript -import { TaskEnvValueSource } from 'cdk8s-pipelines' +import { TaskRunSpec } from 'cdk8s-pipelines' -const taskEnvValueSource: TaskEnvValueSource = { ... } +const taskRunSpec: TaskRunSpec = { ... } ``` #### Properties | **Name** | **Type** | **Description** | | --- | --- | --- | -| secretKeyRef | NameKeyPair | *No description.* | +| taskRef | RemoteRef \| TaskRef | Required `Task` reference. | +| params | TaskRunParam[] | *No description.* | +| serviceAccountName | string | Specifies a `ServiceAccount` object that supplies specific execution credentials for the `Task`. | +| workspaces | TaskRunWorkspace[] | *No description.* | --- -##### `secretKeyRef`Required +##### `taskRef`Required ```typescript -public readonly secretKeyRef: NameKeyPair; +public readonly taskRef: RemoteRef | TaskRef; ``` -- *Type:* NameKeyPair - ---- +- *Type:* RemoteRef | TaskRef -### TaskParam +Required `Task` reference. -A Task parameter value. +--- -#### Initializer +##### `params`Optional ```typescript -import { TaskParam } from 'cdk8s-pipelines' - -const taskParam: TaskParam = { ... } +public readonly params: TaskRunParam[]; ``` -#### Properties - -| **Name** | **Type** | **Description** | -| --- | --- | --- | -| name | string | *No description.* | -| value | string | The value of the task parameter. | +- *Type:* TaskRunParam[] --- -##### `name`Optional +##### `serviceAccountName`Optional ```typescript -public readonly name: string; +public readonly serviceAccountName: string; ``` - *Type:* string +Specifies a `ServiceAccount` object that supplies specific execution credentials for the `Task`. + --- -##### `value`Optional +##### `workspaces`Optional ```typescript -public readonly value: string; +public readonly workspaces: TaskRunWorkspace[]; ``` -- *Type:* string - -The value of the task parameter. +- *Type:* TaskRunWorkspace[] --- -### TaskProps +### TaskRunWorkspace -Properties used to create the Task. +The `Workspace` configuration for a `TaskRun`. -#### Initializer +> [https://tekton.dev/docs/pipelines/taskruns/#specifying-workspaces](https://tekton.dev/docs/pipelines/taskruns/#specifying-workspaces) + +#### Initializer ```typescript -import { TaskProps } from 'cdk8s-pipelines' +import { TaskRunWorkspace } from 'cdk8s-pipelines' -const taskProps: TaskProps = { ... } +const taskRunWorkspace: TaskRunWorkspace = { ... } ``` #### Properties | **Name** | **Type** | **Description** | | --- | --- | --- | -| metadata | cdk8s.ApiObjectMetadata | The object [metadata](https://kubernetes.io/docs/concepts/overview/working-with-objects/#required-fields) that conforms to standard Kubernetes metadata. | -| spec | TaskSpec | The `spec` is the configuration of the `Task` object. | +| name | string | *No description.* | +| persistentVolumeClaim | PersistentVolumeClaimRef | *No description.* | +| subPath | string | *No description.* | --- -##### `metadata`Optional +##### `name`Optional ```typescript -public readonly metadata: ApiObjectMetadata; +public readonly name: string; ``` -- *Type:* cdk8s.ApiObjectMetadata - -The object [metadata](https://kubernetes.io/docs/concepts/overview/working-with-objects/#required-fields) that conforms to standard Kubernetes metadata. +- *Type:* string --- -##### `spec`Optional +##### `persistentVolumeClaim`Required ```typescript -public readonly spec: TaskSpec; +public readonly persistentVolumeClaim: PersistentVolumeClaimRef; ``` -- *Type:* TaskSpec +- *Type:* PersistentVolumeClaimRef -The `spec` is the configuration of the `Task` object. +--- + +##### `subPath`Required + +```typescript +public readonly subPath: string; +``` + +- *Type:* string --- @@ -3884,6 +4419,175 @@ public readonly name: string; --- +### TaskRunBuilder + +Builds a `TaskRun` using the supplied configuration. + +> [https://tekton.dev/docs/pipelines/taskruns/](https://tekton.dev/docs/pipelines/taskruns/) + +#### Initializers + +```typescript +import { TaskRunBuilder } from 'cdk8s-pipelines' + +new TaskRunBuilder(scope: Construct, id: string, task: IRemoteResolver | TaskBuilder) +``` + +| **Name** | **Type** | **Description** | +| --- | --- | --- | +| scope | constructs.Construct | The `Construct` in which to create the `TaskRun`. | +| id | string | The logical ID of the `TaskRun` construct. | +| task | IRemoteResolver \| TaskBuilder | *No description.* | + +--- + +##### `scope`Required + +- *Type:* constructs.Construct + +The `Construct` in which to create the `TaskRun`. + +--- + +##### `id`Required + +- *Type:* string + +The logical ID of the `TaskRun` construct. + +--- + +##### `task`Required + +- *Type:* IRemoteResolver | TaskBuilder + +--- + +#### Methods + +| **Name** | **Description** | +| --- | --- | +| buildTaskRun | Builds the `TaskRun` for the configured `Task` used in the constructor. | +| withClusterRoleBindingProps | *No description.* | +| withRunParam | Adds a run parameter to the `TaskRun`. | +| withServiceAccount | Uses the provided role name for the `serviceAccountName` on the `TaskRun`. | +| withWorkspace | Allows you to specify the name of a `PersistentVolumeClaim` but does not do any compile-time validation on the volume claim's name or existence. | + +--- + +##### `buildTaskRun` + +```typescript +public buildTaskRun(opts?: BuilderOptions): void +``` + +Builds the `TaskRun` for the configured `Task` used in the constructor. + +If the `TaskRun` references a remote task, consistency checks for parameters +and workspaces expected by the pipeline are omitted. + +###### `opts`Optional + +- *Type:* BuilderOptions + +--- + +##### `withClusterRoleBindingProps` + +```typescript +public withClusterRoleBindingProps(props: ApiObjectProps): TaskRunBuilder +``` + +###### `props`Required + +- *Type:* cdk8s.ApiObjectProps + +--- + +##### `withRunParam` + +```typescript +public withRunParam(name: string, value: string): TaskRunBuilder +``` + +Adds a run parameter to the `TaskRun`. + +It will throw an error if you try +to add a parameter that does not exist on the task. +If the `TaskRun` references a remote task, consistency checks are omitted. + +###### `name`Required + +- *Type:* string + +The name of the parameter added to the task run. + +--- + +###### `value`Required + +- *Type:* string + +The value of the parameter added to the task run. + +--- + +##### `withServiceAccount` + +```typescript +public withServiceAccount(sa: string): TaskRunBuilder +``` + +Uses the provided role name for the `serviceAccountName` on the `TaskRun`. + +If this method is not called prior to `buildTaskRun()`, +then the default service account will be used, which is _default:pipeline_. + +###### `sa`Required + +- *Type:* string + +The name of the service account (`serviceAccountName`) to use. + +--- + +##### `withWorkspace` + +```typescript +public withWorkspace(name: string, claimName: string, subPath: string): TaskRunBuilder +``` + +Allows you to specify the name of a `PersistentVolumeClaim` but does not do any compile-time validation on the volume claim's name or existence. + +> [https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolumeclaim](https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolumeclaim) + +###### `name`Required + +- *Type:* string + +The name of the workspace in the `TaskRun` that will be used by the `Task`. + +--- + +###### `claimName`Required + +- *Type:* string + +The name of the `PersistentVolumeClaim` to use for the `workspace`. + +--- + +###### `subPath`Required + +- *Type:* string + +The sub path on the `persistentVolumeClaim` to use for the `workspace`. + +--- + + + + ### TaskStepBuilder Creates a `Step` in a `Task`. diff --git a/test/__snapshots__/taskbuilder.test.ts.snap b/test/__snapshots__/taskbuilder.test.ts.snap index 663a4a1..e3c5140 100644 --- a/test/__snapshots__/taskbuilder.test.ts.snap +++ b/test/__snapshots__/taskbuilder.test.ts.snap @@ -1,5 +1,93 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`TaskBuilderTest CustomTaskRunBuilder 1`] = ` +[ + { + "apiVersion": "tekton.dev/v1", + "kind": "Task", + "metadata": { + "annotations": undefined, + "labels": undefined, + "name": "echo-input", + }, + "spec": { + "description": undefined, + "params": [ + { + "default": "", + "description": "", + "name": "input", + }, + ], + "results": [], + "steps": [ + { + "env": undefined, + "image": "ubuntu", + "name": "step", + "script": "#!/usr/bin/env bash +echo $(params.input)", + "workingDir": undefined, + }, + ], + "workspaces": [ + { + "description": "The files cloned by the task", + "name": "output", + }, + ], + }, + }, + { + "apiVersion": "rbac.authorization.k8s.io/v1", + "kind": "ClusterRoleBinding", + "metadata": { + "name": "task-admin-default-crb", + "namespace": "default", + }, + "roleRef": { + "kind": "ClusterRole", + "name": "cluster-admin", + }, + "subjects": [ + { + "kind": "ServiceAccount", + "name": "default", + "namespace": "default", + }, + ], + }, + { + "apiVersion": "tekton.dev/v1", + "kind": "TaskRun", + "metadata": { + "name": "echo-input-run", + }, + "spec": { + "params": [ + { + "name": "input", + "value": "Hello World!", + }, + ], + "serviceAccountName": "default:default", + "taskRef": { + "name": "echo-input", + }, + "workspaces": [ + { + "name": "output", + "persistentVolumeClaim": { + "claimName": "myPVC", + }, + "subPath": "", + }, + ], + }, + }, +] +`; + exports[`TaskBuilderTest ObjectTaskBuilder 1`] = ` [ { @@ -240,6 +328,117 @@ exports[`TaskBuilderTest TaskBuilderBasic 1`] = ` ] `; +exports[`TaskBuilderTest TaskRunBuilder 1`] = ` +[ + { + "apiVersion": "tekton.dev/v1", + "kind": "Task", + "metadata": { + "annotations": undefined, + "labels": undefined, + "name": "echo-input", + }, + "spec": { + "description": undefined, + "params": [ + { + "default": "", + "description": "", + "name": "input", + }, + ], + "results": [], + "steps": [ + { + "env": undefined, + "image": "ubuntu", + "name": "step", + "script": "#!/usr/bin/env bash +echo $(params.input)", + "workingDir": undefined, + }, + ], + "workspaces": [ + { + "description": "The files cloned by the task", + "name": "output", + }, + ], + }, + }, + { + "apiVersion": "tekton.dev/v1", + "kind": "TaskRun", + "metadata": { + "name": "echo-input-run", + }, + "spec": { + "params": [ + { + "name": "input", + "value": "Hello World!", + }, + ], + "serviceAccountName": "default:pipeline", + "taskRef": { + "name": "echo-input", + }, + "workspaces": [ + { + "name": "output", + "persistentVolumeClaim": { + "claimName": "myPVC", + }, + "subPath": "", + }, + ], + }, + }, +] +`; + +exports[`TaskBuilderTest TaskRunResolver 1`] = ` +[ + { + "apiVersion": "tekton.dev/v1", + "kind": "TaskRun", + "metadata": { + "name": "git-clone-run", + }, + "spec": { + "params": [], + "serviceAccountName": "default:pipeline", + "taskRef": { + "params": [ + { + "name": "name", + "value": "git-clone", + }, + { + "name": "namespace", + "value": "default", + }, + { + "name": "kind", + "value": "task", + }, + ], + "resolver": "cluster", + }, + "workspaces": [ + { + "name": "output", + "persistentVolumeClaim": { + "claimName": "myPVC", + }, + "subPath": "", + }, + ], + }, + }, +] +`; + exports[`TaskBuilderTest TestIBMCloudSecretsManagerGet 1`] = ` [ { diff --git a/test/taskbuilder.test.ts b/test/taskbuilder.test.ts index 92fd580..03ca263 100644 --- a/test/taskbuilder.test.ts +++ b/test/taskbuilder.test.ts @@ -2,7 +2,7 @@ import * as path from 'path'; import { Chart, Testing } from 'cdk8s'; import { ChartProps } from 'cdk8s/lib/chart'; import { Construct } from 'constructs'; -import { usingBuildParameter, usingWorkspacePath, secretKeyRef, TaskBuilder, TaskStepBuilder, valueFrom, WorkspaceBuilder, ParameterBuilder, fromPipelineParam } from '../src'; +import { usingBuildParameter, usingWorkspacePath, secretKeyRef, TaskBuilder, TaskStepBuilder, valueFrom, WorkspaceBuilder, ParameterBuilder, fromPipelineParam, TaskRunBuilder, createRoleBindingProps, ClusterRemoteResolver } from '../src'; /** * Using "ansible-runner" as the reference task that I want this test builder to @@ -195,6 +195,135 @@ class TestPullRequestTaskBuild extends Chart { } +class TestTaskRunBuilder extends Chart { + constructor(scope: Construct, id: string, props?: ChartProps) { + super(scope, id, props); + + const myTask = new TaskBuilder(this, 'echo-input') + .withWorkspace(new WorkspaceBuilder('output') + .withDescription('The files cloned by the task')) + .withStringParam(new ParameterBuilder('input')) + .withStep(new TaskStepBuilder() + .withName('step') + .withImage('ubuntu') + .fromScriptData('#!/usr/bin/env bash\necho $(params.input)')); + myTask.buildTask(); + + new TaskRunBuilder(this, 'echo-input-run', myTask) + .withRunParam('input', 'Hello World!') + .withWorkspace('output', 'myPVC', '') + .buildTaskRun(); + } +} + +class TestCustomTaskRunBuilder extends Chart { + constructor(scope: Construct, id: string, props?: ChartProps) { + super(scope, id, props); + + const myTask = new TaskBuilder(this, 'echo-input') + .withWorkspace(new WorkspaceBuilder('output') + .withDescription('The files cloned by the task')) + .withStringParam(new ParameterBuilder('input')) + .withStep(new TaskStepBuilder() + .withName('step') + .withImage('ubuntu') + .fromScriptData('#!/usr/bin/env bash\necho $(params.input)')); + myTask.buildTask(); + + const CRB = createRoleBindingProps( + 'task-admin-default-crb', + 'default', + 'cluster-admin', + 'default', + 'default'); + + const serviceAccount = 'default:default'; + + new TaskRunBuilder(this, 'echo-input-run', myTask) + .withRunParam('input', 'Hello World!') + .withWorkspace('output', 'myPVC', '') + .withClusterRoleBindingProps(CRB) + .withServiceAccount(serviceAccount) + .buildTaskRun({ includeDependencies: true }); + } +} + +class TestTaskRunBuilderParamError extends Chart { + constructor(scope: Construct, id: string, props?: ChartProps) { + super(scope, id, props); + + const myTask = new TaskBuilder(this, 'echo-hello') + .withStep(new TaskStepBuilder() + .withName('step') + .withImage('ubuntu') + .fromScriptData('#!/usr/bin/env bash\necho Hello')); + myTask.buildTask(); + + new TaskRunBuilder(this, 'echo-input-run', myTask) + .withRunParam('input', 'Hello World!') + .buildTaskRun(); + } +} + +class TestTaskRunBuilderParamError2 extends Chart { + constructor(scope: Construct, id: string, props?: ChartProps) { + super(scope, id, props); + + const myTask = new TaskBuilder(this, 'echo-input') + .withStringParam(new ParameterBuilder('input')) + .withStep(new TaskStepBuilder() + .withName('step') + .withImage('ubuntu') + .fromScriptData('#!/usr/bin/env bash\necho $(params.input)')); + myTask.buildTask(); + + new TaskRunBuilder(this, 'echo-input-run', myTask) + .buildTaskRun(); + } +} + +class TestTaskRunBuilderWorkspaceError extends Chart { + constructor(scope: Construct, id: string, props?: ChartProps) { + super(scope, id, props); + + const myTask = new TaskBuilder(this, 'echo-input') + .withWorkspace(new WorkspaceBuilder('output') + .withDescription('The files cloned by the task')) + .withStep(new TaskStepBuilder() + .withName('step') + .withImage('ubuntu') + .fromScriptData('#!/usr/bin/env bash\necho $(params.input)')); + myTask.buildTask(); + + new TaskRunBuilder(this, 'echo-input-run', myTask) + .buildTaskRun(); + } +} + +class TestTaskRunBuilderResolver extends Chart { + constructor(scope: Construct, id: string, props?: ChartProps) { + super(scope, id, props); + + const resolver = new ClusterRemoteResolver('task', 'git-clone', 'default'); + + new TaskRunBuilder(this, 'git-clone-run', resolver) + .withWorkspace('output', 'myPVC', '') + .buildTaskRun(); + } +} + +class TestTaskRunBuilderResolverError extends Chart { + constructor(scope: Construct, id: string, props?: ChartProps) { + super(scope, id, props); + + const resolver = new ClusterRemoteResolver('pipeline', 'git-clone', 'default'); + + new TaskRunBuilder(this, 'git-clone-run', resolver) + .withWorkspace('output', 'myPVC', '') + .buildTaskRun(); + } +} + describe('TaskBuilderTest', () => { test('TaskBuilderBasic', () => { const app = Testing.app(); @@ -226,4 +355,50 @@ describe('TaskBuilderTest', () => { const results = Testing.synth(chart); expect(results).toMatchSnapshot(); }); + test('TaskRunBuilder', () => { + const app = Testing.app(); + const chart = new TestTaskRunBuilder(app, 'taskrun'); + const results = Testing.synth(chart); + expect(results).toMatchSnapshot(); + }); + test('CustomTaskRunBuilder', () => { + const app = Testing.app(); + const chart = new TestCustomTaskRunBuilder(app, 'custom-taskrun'); + const results = Testing.synth(chart); + expect(results).toMatchSnapshot(); + }); + test('TaskRunExtraParamError', () => { + const app = Testing.app(); + const f = () => { + new TestTaskRunBuilderParamError(app, 'extra-param'); + }; + expect(f).toThrowError('TaskRun parameter \'input\' does not exist in task \'echo-hello\''); + }); + test('TaskRunMissingParamError', () => { + const app = Testing.app(); + const f = () => { + new TestTaskRunBuilderParamError2(app, 'missing-param'); + }; + expect(f).toThrowError('Task parameter \'input\' is not defined in TaskRun \'echo-input-run\''); + }); + test('TaskRunMissingWorkspaceError', () => { + const app = Testing.app(); + const f = () => { + new TestTaskRunBuilderWorkspaceError(app, 'missing-workspace'); + }; + expect(f).toThrowError('Task workspace \'output\' is not defined in TaskRun \'echo-input-run\''); + }); + test('TaskRunResolver', () => { + const app = Testing.app(); + const chart = new TestTaskRunBuilderResolver(app, 'resolver'); + const results = Testing.synth(chart); + expect(results).toMatchSnapshot(); + }); + test('TaskRunResolverError', () => { + const app = Testing.app(); + const f = () => { + new TestTaskRunBuilderResolverError(app, 'resolver-error'); + }; + expect(f).toThrowError('Remote resource must be of kind \'task\' in taskRef of TaskRun \'git-clone-run\''); + }); }); From 1fc54a37f67e6b328a66f3947ea111625aad652e Mon Sep 17 00:00:00 2001 From: snehajais22 Date: Wed, 7 Aug 2024 12:07:17 -0400 Subject: [PATCH 4/4] Update default TaskRun serviceAccountName Signed-off-by: snehajais22 --- src/builders.ts | 3 ++- test/__snapshots__/taskbuilder.test.ts.snap | 6 +++--- test/taskbuilder.test.ts | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/builders.ts b/src/builders.ts index 7508c75..4d67de9 100644 --- a/src/builders.ts +++ b/src/builders.ts @@ -34,6 +34,7 @@ import { } from './tasks'; const DefaultPipelineServiceAccountName = 'default:pipeline'; +const DefaultTaskServiceAccountName = 'default'; /** * Creates the properties for a `ClusterRoleBinding` @@ -1009,7 +1010,7 @@ export class TaskRunBuilder { this._scope = scope; this._id = id; this._task = task; - this._sa = DefaultPipelineServiceAccountName; + this._sa = DefaultTaskServiceAccountName; this._crbProps = DefaultClusterRoleBindingProps; this._runParams = new Array(); this._runWorkspaces = new Array(); diff --git a/test/__snapshots__/taskbuilder.test.ts.snap b/test/__snapshots__/taskbuilder.test.ts.snap index e3c5140..60fb6b9 100644 --- a/test/__snapshots__/taskbuilder.test.ts.snap +++ b/test/__snapshots__/taskbuilder.test.ts.snap @@ -70,7 +70,7 @@ echo $(params.input)", "value": "Hello World!", }, ], - "serviceAccountName": "default:default", + "serviceAccountName": "default", "taskRef": { "name": "echo-input", }, @@ -379,7 +379,7 @@ echo $(params.input)", "value": "Hello World!", }, ], - "serviceAccountName": "default:pipeline", + "serviceAccountName": "default", "taskRef": { "name": "echo-input", }, @@ -407,7 +407,7 @@ exports[`TaskBuilderTest TaskRunResolver 1`] = ` }, "spec": { "params": [], - "serviceAccountName": "default:pipeline", + "serviceAccountName": "default", "taskRef": { "params": [ { diff --git a/test/taskbuilder.test.ts b/test/taskbuilder.test.ts index 03ca263..0e29fa8 100644 --- a/test/taskbuilder.test.ts +++ b/test/taskbuilder.test.ts @@ -237,7 +237,7 @@ class TestCustomTaskRunBuilder extends Chart { 'default', 'default'); - const serviceAccount = 'default:default'; + const serviceAccount = 'default'; new TaskRunBuilder(this, 'echo-input-run', myTask) .withRunParam('input', 'Hello World!')