Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagated Workspaces to Beta #6030

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/pipelineruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ Consult the documentation of the custom task that you are using to determine whe

#### Propagated Workspaces

**([alpha only](https://github.com/tektoncd/pipeline/blob/main/docs/install.md#alpha-features))**
**[beta](https://github.com/tektoncd/pipeline/blob/main/docs/install.md#beta-features))**

When using an embedded spec, workspaces from the parent `PipelineRun` will be
propagated to any inlined specs without needing to be explicitly defined. This
Expand Down
2 changes: 1 addition & 1 deletion docs/taskruns.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ For more information, see the following topics:

#### Propagated Workspaces

**([alpha only](https://github.com/tektoncd/pipeline/blob/main/docs/install.md#alpha-features))**
**[beta](https://github.com/tektoncd/pipeline/blob/main/docs/install.md#beta-features))**

When using an embedded spec, workspaces from the parent `TaskRun` will be
propagated to any inlined specs without needing to be explicitly defined. This
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ func getTaskrunWorkspaces(ctx context.Context, pr *v1beta1.PipelineRun, rpt *res
pipelineRunWorkspaces[binding.Name] = binding
}

if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == config.AlphaAPIFields {
if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields != config.StableAPIFields {
jerop marked this conversation as resolved.
Show resolved Hide resolved
// Propagate required workspaces from pipelineRun to the pipelineTasks
if rpt.PipelineTask.TaskSpec != nil {
var err error
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8358,7 +8358,7 @@ spec:
},
},
}
ctx := config.EnableAlphaAPIFields(context.Background())
ctx := config.EnableBetaAPIFields(context.Background())
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, _, err := getTaskrunWorkspaces(ctx, tt.pr, tt.rprt)
Expand Down
6 changes: 3 additions & 3 deletions pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ func (c *Reconciler) prepare(ctx context.Context, tr *v1beta1.TaskRun) (*v1beta1
// Propagating workspaces allows users to skip declarations
// In order to validate the workspace bindings we create declarations based on
// the workspaces provided in the task run spec. This logic is hidden behind the
// alpha feature gate since propagating workspaces is behind that feature gate.
// alpha/beta feature gate since propagating workspaces is behind the beta feature gate.
// In addition, we only allow this feature for embedded taskSpec.
if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == config.AlphaAPIFields && tr.Spec.TaskSpec != nil {
if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields != config.StableAPIFields && tr.Spec.TaskSpec != nil {
chitrangpatel marked this conversation as resolved.
Show resolved Hide resolved
for _, ws := range tr.Spec.Workspaces {
wspaceDeclaration := v1beta1.WorkspaceDeclaration{Name: ws.Name}
workspaceDeclarations = append(workspaceDeclarations, wspaceDeclaration)
Expand Down Expand Up @@ -832,7 +832,7 @@ func applyParamsContextsResultsAndWorkspaces(ctx context.Context, tr *v1beta1.Ta
ts = resources.ApplyStepExitCodePath(ts)

// Apply workspace resource substitution
if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == config.AlphaAPIFields {
if config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields != config.StableAPIFields {
// propagate workspaces from taskrun to task.
twn := []string{}
for _, tw := range ts.Workspaces {
Expand Down
46 changes: 24 additions & 22 deletions pkg/reconciler/taskrun/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2780,29 +2780,31 @@ spec:
- emptyDir: {}
name: tr-workspace
`)
d := test.Data{
TaskRuns: []*v1beta1.TaskRun{taskRun},
}
d.ConfigMaps = []*corev1.ConfigMap{{
ObjectMeta: metav1.ObjectMeta{Namespace: system.Namespace(), Name: config.GetFeatureFlagsConfigName()},
Data: map[string]string{
"enable-api-fields": config.AlphaAPIFields,
},
}}
testAssets, cancel := getTaskRunController(t, d)
defer cancel()
createServiceAccount(t, testAssets, "default", taskRun.Namespace)
c := testAssets.Controller
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(taskRun)); err == nil {
t.Fatalf("Could not reconcile the taskrun: %v", err)
}
getTaskRun, _ := testAssets.Clients.Pipeline.TektonV1beta1().TaskRuns(taskRun.Namespace).Get(testAssets.Ctx, taskRun.Name, metav1.GetOptions{})
for _, apiField := range []string{config.BetaAPIFields, config.AlphaAPIFields} {
d := test.Data{
TaskRuns: []*v1beta1.TaskRun{taskRun},
}
d.ConfigMaps = []*corev1.ConfigMap{{
ObjectMeta: metav1.ObjectMeta{Namespace: system.Namespace(), Name: config.GetFeatureFlagsConfigName()},
Data: map[string]string{
"enable-api-fields": apiField,
},
}}
testAssets, cancel := getTaskRunController(t, d)
defer cancel()
createServiceAccount(t, testAssets, "default", taskRun.Namespace)
c := testAssets.Controller
if err := c.Reconciler.Reconcile(testAssets.Ctx, getRunName(taskRun)); err == nil {
t.Fatalf("Could not reconcile the taskrun: %v", err)
}
getTaskRun, _ := testAssets.Clients.Pipeline.TektonV1beta1().TaskRuns(taskRun.Namespace).Get(testAssets.Ctx, taskRun.Name, metav1.GetOptions{})

want := []v1beta1.WorkspaceDeclaration{{
Name: "tr-workspace",
}}
if c := cmp.Diff(want, getTaskRun.Status.TaskSpec.Workspaces); c != "" {
t.Errorf("TestPropagatedWorkspaces errored with: %s", diff.PrintWantGot(c))
want := []v1beta1.WorkspaceDeclaration{{
Name: "tr-workspace",
}}
if c := cmp.Diff(want, getTaskRun.Status.TaskSpec.Workspaces); c != "" {
t.Errorf("TestPropagatedWorkspaces errored with: %s", diff.PrintWantGot(c))
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/workspace/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ func Apply(ctx context.Context, ts v1beta1.TaskSpec, wb []v1beta1.WorkspaceBindi

isolatedWorkspaces := sets.NewString()

alphaAPIEnabled := config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields == config.AlphaAPIFields
alphaOrBetaEnabled := config.FromContextOrDefaults(ctx).FeatureFlags.EnableAPIFields != config.StableAPIFields

if alphaAPIEnabled {
if alphaOrBetaEnabled {
for _, step := range ts.Steps {
for _, workspaceUsage := range step.Workspaces {
isolatedWorkspaces.Insert(workspaceUsage.Name)
Expand All @@ -126,7 +126,7 @@ func Apply(ctx context.Context, ts v1beta1.TaskSpec, wb []v1beta1.WorkspaceBindi
}

for i := range wb {
if alphaAPIEnabled {
if alphaOrBetaEnabled {
// Propagate missing Workspaces
addWorkspace := true
for _, ws := range ts.Workspaces {
Expand All @@ -153,7 +153,7 @@ func Apply(ctx context.Context, ts v1beta1.TaskSpec, wb []v1beta1.WorkspaceBindi
ReadOnly: w.ReadOnly,
}

if alphaAPIEnabled {
if alphaOrBetaEnabled {
if isolatedWorkspaces.Has(w.Name) {
mountAsIsolatedWorkspace(ts, w.Name, volumeMount)
} else {
Expand Down
42 changes: 40 additions & 2 deletions pkg/workspace/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,9 @@ func TestApply_PropagatedWorkspacesFromWorkspaceBindingToDeclarations(t *testing
ts v1beta1.TaskSpec
workspaces []v1beta1.WorkspaceBinding
expectedTaskSpec v1beta1.TaskSpec
apiField string
}{{
name: "propagate workspaces",
name: "propagate workspaces alpha enabled",
ts: v1beta1.TaskSpec{
Workspaces: []v1beta1.WorkspaceDeclaration{{
Name: "workspace1",
Expand Down Expand Up @@ -739,11 +740,48 @@ func TestApply_PropagatedWorkspacesFromWorkspaceBindingToDeclarations(t *testing
VolumeMounts: []v1.VolumeMount{{Name: "ws-9l9zj", MountPath: "/workspace/workspace2"}},
},
},
apiField: config.AlphaAPIFields,
}, {
name: "propagate workspaces beta enabled",
ts: v1beta1.TaskSpec{
Workspaces: []v1beta1.WorkspaceDeclaration{{
Name: "workspace1",
}},
},
workspaces: []v1beta1.WorkspaceBinding{{
Name: "workspace2",
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "mypvc",
},
}},
expectedTaskSpec: v1beta1.TaskSpec{
Volumes: []corev1.Volume{{
Name: "ws-mz4c7",
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "mypvc",
},
},
}},
Workspaces: []v1beta1.WorkspaceDeclaration{{
Name: "workspace1",
MountPath: "",
ReadOnly: false,
}, {
Name: "workspace2",
MountPath: "",
ReadOnly: false,
}},
StepTemplate: &v1beta1.StepTemplate{
VolumeMounts: []v1.VolumeMount{{Name: "ws-mz4c7", MountPath: "/workspace/workspace2"}},
},
},
apiField: config.BetaAPIFields,
}} {
t.Run(tc.name, func(t *testing.T) {
ctx := config.ToContext(context.Background(), &config.Config{
FeatureFlags: &config.FeatureFlags{
EnableAPIFields: "alpha",
EnableAPIFields: tc.apiField,
},
})
vols := workspace.CreateVolumes(tc.workspaces)
Expand Down