Skip to content

Commit

Permalink
Add SecurityContext to Pipeline/TaskRunSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
dicarlo2 committed May 22, 2019
1 parent ea5cc07 commit 99a02b8
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 5 deletions.
3 changes: 3 additions & 0 deletions docs/pipelineruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ following fields:
- [`affinity`] - The pod's scheduling constraints. More info:

<https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#node-affinity-beta-feature>
- [`securityContext`] - holds pod-level security attributes and common
container settings. Defaults to empty. See type description for default
values of each field.

[kubernetes-overview]:
https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields
Expand Down
3 changes: 3 additions & 0 deletions docs/taskruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ following fields:
<https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/>
- [`affinity`] - the pod's scheduling constraints. More info:
<https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#node-affinity-beta-feature>
- [`securityContext`] - holds pod-level security attributes and common
container settings. Defaults to empty. See type description for default
values of each field.

[kubernetes-overview]:
https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/#required-fields
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1alpha1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ type PipelineRunSpec struct {
// If specified, the pod's scheduling constraints
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
// SecurityContext holds pod-level security attributes and common container settings.
// Optional: Defaults to empty. See type description for default values of each field.
// +optional
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
}

// PipelineRunSpecStatus defines the pipelinerun spec status the user can provide
Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/pipeline/v1alpha1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ type TaskRunSpec struct {
// If specified, the pod's scheduling constraints
// +optional
Affinity *corev1.Affinity `json:"affinity,omitempty"`
// SecurityContext holds pod-level security attributes and common container settings.
// Optional: Defaults to empty. See type description for default values of each field.
// +optional
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"`
}

// TaskRunSpecStatus defines the taskrun spec status the user can provide
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/pipeline/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions pkg/reconciler/v1alpha1/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,12 @@ func (c *Reconciler) createTaskRun(logger *zap.SugaredLogger, rprt *resources.Re
Inputs: v1alpha1.TaskRunInputs{
Params: rprt.PipelineTask.Params,
},
ServiceAccount: pr.Spec.ServiceAccount,
Timeout: taskRunTimeout,
NodeSelector: pr.Spec.NodeSelector,
Tolerations: pr.Spec.Tolerations,
Affinity: pr.Spec.Affinity,
ServiceAccount: pr.Spec.ServiceAccount,
Timeout: taskRunTimeout,
NodeSelector: pr.Spec.NodeSelector,
Tolerations: pr.Spec.Tolerations,
Affinity: pr.Spec.Affinity,
SecurityContext: pr.Spec.SecurityContext,
}}

resources.WrapSteps(&tr.Spec, rprt.PipelineTask, rprt.ResolvedTaskResources.Inputs, rprt.ResolvedTaskResources.Outputs, storageBasePath)
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/v1alpha1/taskrun/resources/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ func MakePod(taskRun *v1alpha1.TaskRun, taskSpec v1alpha1.TaskSpec, kubeclient k
NodeSelector: taskRun.Spec.NodeSelector,
Tolerations: taskRun.Spec.Tolerations,
Affinity: taskRun.Spec.Affinity,
SecurityContext: taskRun.Spec.SecurityContext,
},
}, nil
}
Expand Down
7 changes: 7 additions & 0 deletions test/builder/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ func PipelineRunAffinity(affinity *corev1.Affinity) PipelineRunSpecOp {
}
}

// PipelineRunSecurityContext sets the securityContext to the PipelineSpec.
func PipelineRunSecurityContext(securityContext *corev1.PodSecurityContext) PipelineRunSpecOp {
return func(prs *v1alpha1.PipelineRunSpec) {
prs.SecurityContext = securityContext
}
}

// PipelineRunStatus sets the PipelineRunStatus to the PipelineRun.
// Any number of PipelineRunStatus modifier can be passed to transform it.
func PipelineRunStatus(ops ...PipelineRunStatusOp) PipelineRunOp {
Expand Down
7 changes: 7 additions & 0 deletions test/builder/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ func TaskRunAffinity(affinity *corev1.Affinity) TaskRunSpecOp {
}
}

// TaskRunSecurityContext sets the SecurityContext to the PipelineSpec.
func TaskRunSecurityContext(securityContext *corev1.PodSecurityContext) TaskRunSpecOp {
return func(spec *v1alpha1.TaskRunSpec) {
spec.SecurityContext = securityContext
}
}

// StateTerminated set Terminated to the StepState.
func StateTerminated(exitcode int) StepStateOp {
return func(s *v1alpha1.StepState) {
Expand Down

0 comments on commit 99a02b8

Please sign in to comment.