-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add ConfigMap volume source support to workspaces #1800
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,13 @@ spec: | |
accessModes: | ||
- ReadWriteOnce | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: my-configmap | ||
data: | ||
message: hello world | ||
--- | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
apiVersion: tekton.dev/v1alpha1 | ||
kind: TaskRun | ||
metadata: | ||
|
@@ -26,43 +33,39 @@ spec: | |
- name: custom3 | ||
emptyDir: {} | ||
subPath: testing | ||
- name: custom4 | ||
configMap: | ||
name: my-configmap | ||
items: | ||
- key: message | ||
path: my-message.txt | ||
taskSpec: | ||
steps: | ||
- name: write | ||
image: ubuntu | ||
script: | | ||
#!/usr/bin/env bash | ||
set -xe | ||
echo $(workspaces.custom.volume) > $(workspaces.custom.path)/foo | ||
script: echo $(workspaces.custom.volume) > $(workspaces.custom.path)/foo | ||
- name: read | ||
image: ubuntu | ||
script: | | ||
#!/usr/bin/env bash | ||
set -xe | ||
cat $(workspaces.custom.path)/foo | grep $(workspaces.custom.volume) | ||
script: cat $(workspaces.custom.path)/foo | grep $(workspaces.custom.volume) | ||
- name: write2 | ||
image: ubuntu | ||
script: | | ||
#!/usr/bin/env bash | ||
set -xe | ||
echo $(workspaces.custom2.path) > $(workspaces.custom2.path)/foo | ||
script: echo $(workspaces.custom2.path) > $(workspaces.custom2.path)/foo | ||
- name: read2 | ||
image: ubuntu | ||
script: | | ||
#!/usr/bin/env bash | ||
cat $(workspaces.custom2.path)/foo | grep $(workspaces.custom2.path) | ||
script: cat $(workspaces.custom2.path)/foo | grep $(workspaces.custom2.path) | ||
- name: write3 | ||
image: ubuntu | ||
script: | | ||
#!/usr/bin/env bash | ||
echo $(workspaces.custom3.path) > $(workspaces.custom3.path)/foo | ||
script: echo $(workspaces.custom3.path) > $(workspaces.custom3.path)/foo | ||
- name: read3 | ||
image: ubuntu | ||
script: | | ||
#!/usr/bin/env bash | ||
cat $(workspaces.custom3.path)/foo | grep $(workspaces.custom3.path) | ||
script: cat $(workspaces.custom3.path)/foo | grep $(workspaces.custom3.path) | ||
- name: readconfigmap | ||
image: ubuntu | ||
script: cat $(workspaces.custom4.path)/my-message.txt | grep "hello world" | ||
workspaces: | ||
- name: custom | ||
- name: custom2 | ||
mountPath: /foo/bar/baz | ||
- name: custom3 | ||
- name: custom3 | ||
- name: custom4 | ||
mountPath: /baz/bar/quux |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,5 @@ import ( | |
type WorkspaceDeclaration = v1alpha2.WorkspaceDeclaration | ||
|
||
// WorkspaceBinding maps a Task's declared workspace to a Volume. | ||
// Currently we only support PersistentVolumeClaims and EmptyDir. | ||
// Currently we only support PersistentVolumeClaims, EmptyDir and ConfigMap. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we'd be better off removing this comment so we don't have it fall out of date later 🤔 |
||
type WorkspaceBinding = v1alpha2.WorkspaceBinding |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,14 @@ import ( | |
"knative.dev/pkg/apis" | ||
) | ||
|
||
// allVolumeSourceFields is a list of all the volume source field paths that a | ||
// WorkspaceBinding may include. | ||
var allVolumeSourceFields []string = []string{ | ||
"workspace.persistentvolumeclaim", | ||
"workspace.emptydir", | ||
"workspace.configmap", | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎉 |
||
|
||
// Validate looks at the Volume provided in wb and makes sure that it is valid. | ||
// This means that only one VolumeSource can be specified, and also that the | ||
// supported VolumeSource is itself valid. | ||
|
@@ -31,19 +39,41 @@ func (b *WorkspaceBinding) Validate(ctx context.Context) *apis.FieldError { | |
return apis.ErrMissingField(apis.CurrentField) | ||
} | ||
|
||
// Users should only provide one supported VolumeSource. | ||
if b.PersistentVolumeClaim != nil && b.EmptyDir != nil { | ||
return apis.ErrMultipleOneOf("workspace.persistentvolumeclaim", "workspace.emptydir") | ||
numSources := b.numSources() | ||
|
||
if numSources > 1 { | ||
return apis.ErrMultipleOneOf(allVolumeSourceFields...) | ||
} | ||
|
||
// Users must provide at least one supported VolumeSource. | ||
if b.PersistentVolumeClaim == nil && b.EmptyDir == nil { | ||
return apis.ErrMissingOneOf("workspace.persistentvolumeclaim", "workspace.emptydir") | ||
if numSources == 0 { | ||
return apis.ErrMissingOneOf(allVolumeSourceFields...) | ||
} | ||
|
||
// For a PersistentVolumeClaim to work, you must at least provide the name of the PVC to use. | ||
if b.PersistentVolumeClaim != nil && b.PersistentVolumeClaim.ClaimName == "" { | ||
return apis.ErrMissingField("workspace.persistentvolumeclaim.claimname") | ||
} | ||
|
||
// For a ConfigMap to work, you must provide the name of the ConfigMap to use. | ||
if b.ConfigMap != nil && b.ConfigMap.LocalObjectReference.Name == "" { | ||
return apis.ErrMissingField("workspace.configmap.name") | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we have a unit test that tries to set a configmap + something else? that's quickly starting to balloon out of control unit test permutation wise - i wonder if we can isolate the logic for determining this somehow such that the tests wont need to be updated with every permutation 🤔 |
||
|
||
return nil | ||
} | ||
|
||
// numSources returns the total number of volume sources that this WorkspaceBinding | ||
// has been configured with. | ||
func (b *WorkspaceBinding) numSources() int { | ||
n := 0 | ||
if b.PersistentVolumeClaim != nil { | ||
n++ | ||
} | ||
if b.EmptyDir != nil { | ||
n++ | ||
} | ||
if b.ConfigMap != nil { | ||
n++ | ||
} | ||
return n | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉