Skip to content

Commit

Permalink
BUILD-273 Volumes override by Build and BuildRun
Browse files Browse the repository at this point in the history
Build and BuildRun objects can now override volumes defined by
BuildStrategy in case they are overridable.
Only overridable volumes are allowed to be overriden.
  • Loading branch information
Alice Rum committed Apr 5, 2022
1 parent af4407c commit 3b2de29
Show file tree
Hide file tree
Showing 7 changed files with 4,609 additions and 3 deletions.
3,072 changes: 3,072 additions & 0 deletions deploy/crds/shipwright.io_buildruns.yaml

Large diffs are not rendered by default.

1,502 changes: 1,502 additions & 0 deletions deploy/crds/shipwright.io_builds.yaml

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions pkg/apis/build/v1alpha1/build_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ type BuildSpec struct {
// Env contains additional environment variables that should be passed to the build container
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`

// Volumes contains volume Overrides of the BuildStrategy volumes in case those are allowed
// to be overriden. Must only contain volumes that exist in the corresponding BuildStrategy
// +optional
Volumes []BuildVolume `json:"volumes,omitempty"`
}

// StrategyName returns the name of the configured strategy, or 'undefined' in
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/build/v1alpha1/buildrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ type BuildRunSpec struct {
// Env contains additional environment variables that should be passed to the build container
// +optional
Env []corev1.EnvVar `json:"env,omitempty"`

// Volumes contains volume Overrides of the BuildStrategy volumes in case those are allowed
// to be overriden. Must only contain volumes that exist in the corresponding BuildStrategy
// +optional
Volumes []BuildVolume `json:"volumes,omitempty"`
}

// BuildRunRequestedState defines the buildrun state the user can provide to override whatever is the current state.
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/build/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/resources/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func GenerateTaskSpec(

// Add volumes from the strategy to generated task spec
// will have to add buildrun volumes here for merging later, too
volumes, err := volumes.TaskSpecVolumes(existingVolumeMounts, buildVolumes, nil)
volumes, err := volumes.TaskSpecVolumes(existingVolumeMounts, buildVolumes, build.Spec.Volumes, buildRun.Spec.Volumes)
if err != nil {
return nil, err
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/volumes/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ func NewStepVolumeMount(name string, readOnly bool) StepVolumeMount {
func TaskSpecVolumes(
existingVolumeMounts []StepVolumeMount,
strategyVolumes []buildv1alpha1.BuildVolume,
buildVolumes []buildv1alpha1.BuildVolume,
buildrunVolumes []buildv1alpha1.BuildVolume,
) ([]corev1.Volume, error) {
res := []corev1.Volume{}

volumes, err := MergeBuildVolumes(strategyVolumes, buildrunVolumes)
// first we merge build volumes into the strategy ones, next we merge
// build run volumes into result of the previous merge.
// eventual list of volumes will be added to the generated TaskSpec object
volumes, err := MergeBuildVolumes(strategyVolumes, buildVolumes)
if err != nil {
return nil, err
}
volumes, err = MergeBuildVolumes(volumes, buildrunVolumes)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -79,7 +87,7 @@ func TaskSpecVolumes(
// MergeBuildVolumes merges Build Volumes from one list into the other. It only allows to merge those that have property
// Overridable set to true. In case it is empty or false, it is not allowed to be overridden, so Volume cannot be merged
// Merging in this context means copying the VolumeSource from one object to the other.
func MergeBuildVolumes(new []buildv1alpha1.BuildVolume, into []buildv1alpha1.BuildVolume) ([]buildv1alpha1.BuildVolume, error) {
func MergeBuildVolumes(into []buildv1alpha1.BuildVolume, new []buildv1alpha1.BuildVolume) ([]buildv1alpha1.BuildVolume, error) {
if len(new) == 0 && len(into) == 0 {
return []buildv1alpha1.BuildVolume{}, nil
}
Expand Down

0 comments on commit 3b2de29

Please sign in to comment.