Skip to content

Commit

Permalink
Fix Workspace validation (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
arybolovlev authored Nov 27, 2024
1 parent 5c0da46 commit bcf8308
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/unreleased/BUG FIXES-504-20241107-160657.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: BUG FIXES
body: '`Workspace`: Fix an issue where `spec.agentPool` can be set even when `spec.executionMode` is not set to `agent`.'
time: 2024-11-07T16:06:57.85398+01:00
custom:
PR: "504"
6 changes: 6 additions & 0 deletions api/v1alpha2/workspace_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func (w *Workspace) validateSpecAgentPool() field.ErrorList {
}

f := field.NewPath("spec").Child("agentPool")
if w.Spec.ExecutionMode != "agent" {
allErrs = append(allErrs, field.Required(
f,
"'spec.executionMode' must be set to 'agent' when 'spec.agentPool' is set"),
)
}

if spec.ID == "" && spec.Name == "" {
allErrs = append(allErrs, field.Invalid(
Expand Down
15 changes: 14 additions & 1 deletion api/v1alpha2/workspace_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ func TestValidateWorkspaceSpecAgentPool(t *testing.T) {
AgentPool: &WorkspaceAgentPool{
ID: "this",
},
ExecutionMode: "agent",
},
},
"HasOnlyName": {
Spec: WorkspaceSpec{
AgentPool: &WorkspaceAgentPool{
Name: "this",
},
ExecutionMode: "agent",
},
},
}
Expand All @@ -46,11 +48,22 @@ func TestValidateWorkspaceSpecAgentPool(t *testing.T) {
ID: "this",
Name: "this",
},
ExecutionMode: "agent",
},
},
"HasEmptyIDandName": {
Spec: WorkspaceSpec{
AgentPool: &WorkspaceAgentPool{},
AgentPool: &WorkspaceAgentPool{},
ExecutionMode: "agent",
},
},
"HasInvalidExecutionMode": {
Spec: WorkspaceSpec{
AgentPool: &WorkspaceAgentPool{
ID: "this",
Name: "this",
},
ExecutionMode: "remote",
},
},
}
Expand Down

0 comments on commit bcf8308

Please sign in to comment.