Skip to content

Commit c6a1a3e

Browse files
committed
Add field to DevWorkspace to allow overriding Pod spec (devfile#860)
Add field `podSpecOverride` to the DevWorkspace spec (but not Devfile or DevWorkspaceTemplate) that allows specifying arbitrary fields on any pods created for the DevWorkspace. Signed-off-by: Angel Misevski <[email protected]>
1 parent 351f05b commit c6a1a3e

File tree

2 files changed

+197
-0
lines changed

2 files changed

+197
-0
lines changed

pkg/apis/workspaces/v1alpha2/devworkspace_types.go

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ type DevWorkspaceSpec struct {
1010
Started bool `json:"started"`
1111
RoutingClass string `json:"routingClass,omitempty"`
1212
Template DevWorkspaceTemplateSpec `json:"template,omitempty"`
13+
// Pod fields to override within the DevWorkspace's Deployment. Fields defined
14+
// here are strategically merged on top of the Pod template in the deployment,
15+
// allowing for fine-grained customization of the Pods that are started for
16+
// this DevWorkspace.
17+
PodSpecOverrides *PodTemplateSpecOverrides `json:"podSpecOverride,omitempty"`
1318
}
1419

1520
// DevWorkspaceStatus defines the observed state of DevWorkspace
+192
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
package v1alpha2
2+
3+
import (
4+
corev1 "k8s.io/api/core/v1"
5+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
)
7+
8+
type PodTemplateSpecOverrides struct {
9+
// Standard object's metadata.
10+
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
11+
// +optional
12+
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
13+
14+
// Subset of Pod Spec fields that can be overridden in a DevWorkspace's deployment
15+
// +optional
16+
Spec PodSpecOverrides `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
17+
}
18+
19+
type PodSpecOverrides struct {
20+
// Optional duration in seconds the pod needs to terminate gracefully. May be decreased in delete request.
21+
// Value must be non-negative integer. The value zero indicates stop immediately via
22+
// the kill signal (no opportunity to shut down).
23+
// If this value is nil, the default grace period will be used instead.
24+
// The grace period is the duration in seconds after the processes running in the pod are sent
25+
// a termination signal and the time when the processes are forcibly halted with a kill signal.
26+
// Set this value longer than the expected cleanup time for your process.
27+
// Defaults to 30 seconds.
28+
// +optional
29+
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty" protobuf:"varint,4,opt,name=terminationGracePeriodSeconds"`
30+
// Optional duration in seconds the pod may be active on the node relative to
31+
// StartTime before the system will actively try to mark it failed and kill associated containers.
32+
// Value must be a positive integer.
33+
// +optional
34+
ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds,omitempty" protobuf:"varint,5,opt,name=activeDeadlineSeconds"`
35+
// Set DNS policy for the pod.
36+
// Defaults to "ClusterFirst".
37+
// Valid values are 'ClusterFirstWithHostNet', 'ClusterFirst', 'Default' or 'None'.
38+
// DNS parameters given in DNSConfig will be merged with the policy selected with DNSPolicy.
39+
// To have DNS options set along with hostNetwork, you have to specify DNS policy
40+
// explicitly to 'ClusterFirstWithHostNet'.
41+
// +optional
42+
DNSPolicy corev1.DNSPolicy `json:"dnsPolicy,omitempty" protobuf:"bytes,6,opt,name=dnsPolicy,casttype=DNSPolicy"`
43+
// NodeSelector is a selector which must be true for the pod to fit on a node.
44+
// Selector which must match a node's labels for the pod to be scheduled on that node.
45+
// More info: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/
46+
// +optional
47+
NodeSelector map[string]string `json:"nodeSelector,omitempty" protobuf:"bytes,7,rep,name=nodeSelector"`
48+
// ServiceAccountName is the name of the ServiceAccount to use to run this pod.
49+
// More info: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
50+
// +optional
51+
ServiceAccountName string `json:"serviceAccountName,omitempty" protobuf:"bytes,8,opt,name=serviceAccountName"`
52+
// AutomountServiceAccountToken indicates whether a service account token should be automatically mounted.
53+
// +optional
54+
AutomountServiceAccountToken *bool `json:"automountServiceAccountToken,omitempty" protobuf:"varint,21,opt,name=automountServiceAccountToken"`
55+
// NodeName is a request to schedule this pod onto a specific node. If it is non-empty,
56+
// the scheduler simply schedules this pod onto that node, assuming that it fits resource
57+
// requirements.
58+
// +optional
59+
NodeName string `json:"nodeName,omitempty" protobuf:"bytes,10,opt,name=nodeName"`
60+
// Host networking requested for this pod. Use the host's network namespace.
61+
// If this option is set, the ports that will be used must be specified.
62+
// Default to false.
63+
// +k8s:conversion-gen=false
64+
// +optional
65+
HostNetwork bool `json:"hostNetwork,omitempty" protobuf:"varint,11,opt,name=hostNetwork"`
66+
// Use the host's pid namespace.
67+
// Optional: Default to false.
68+
// +k8s:conversion-gen=false
69+
// +optional
70+
HostPID bool `json:"hostPID,omitempty" protobuf:"varint,12,opt,name=hostPID"`
71+
// Use the host's ipc namespace.
72+
// Optional: Default to false.
73+
// +k8s:conversion-gen=false
74+
// +optional
75+
HostIPC bool `json:"hostIPC,omitempty" protobuf:"varint,13,opt,name=hostIPC"`
76+
// Share a single process namespace between all of the containers in a pod.
77+
// When this is set containers will be able to view and signal processes from other containers
78+
// in the same pod, and the first process in each container will not be assigned PID 1.
79+
// HostPID and ShareProcessNamespace cannot both be set.
80+
// Optional: Default to false.
81+
// +k8s:conversion-gen=false
82+
// +optional
83+
ShareProcessNamespace *bool `json:"shareProcessNamespace,omitempty" protobuf:"varint,27,opt,name=shareProcessNamespace"`
84+
// SecurityContext holds pod-level security attributes and common container settings.
85+
// Optional: Defaults to empty. See type description for default values of each field.
86+
// +optional
87+
SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty" protobuf:"bytes,14,opt,name=securityContext"`
88+
// ImagePullSecrets is an optional list of references to secrets in the same namespace to use for pulling any of the images used by this PodSpec.
89+
// If specified, these secrets will be passed to individual puller implementations for them to use. For example,
90+
// in the case of docker, only DockerConfig type secrets are honored.
91+
// More info: https://kubernetes.io/docs/concepts/containers/images#specifying-imagepullsecrets-on-a-pod
92+
// +optional
93+
// +patchMergeKey=name
94+
// +patchStrategy=merge
95+
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,15,rep,name=imagePullSecrets"`
96+
// Specifies the hostname of the Pod
97+
// If not specified, the pod's hostname will be set to a system-defined value.
98+
// +optional
99+
Hostname string `json:"hostname,omitempty" protobuf:"bytes,16,opt,name=hostname"`
100+
// If specified, the fully qualified Pod hostname will be "<hostname>.<subdomain>.<pod namespace>.svc.<cluster domain>".
101+
// If not specified, the pod will not have a domainname at all.
102+
// +optional
103+
Subdomain string `json:"subdomain,omitempty" protobuf:"bytes,17,opt,name=subdomain"`
104+
// If specified, the pod's scheduling constraints
105+
// +optional
106+
Affinity *corev1.Affinity `json:"affinity,omitempty" protobuf:"bytes,18,opt,name=affinity"`
107+
// If specified, the pod will be dispatched by specified scheduler.
108+
// If not specified, the pod will be dispatched by default scheduler.
109+
// +optional
110+
SchedulerName string `json:"schedulerName,omitempty" protobuf:"bytes,19,opt,name=schedulerName"`
111+
// If specified, the pod's tolerations.
112+
// +optional
113+
Tolerations []corev1.Toleration `json:"tolerations,omitempty" protobuf:"bytes,22,opt,name=tolerations"`
114+
// HostAliases is an optional list of hosts and IPs that will be injected into the pod's hosts
115+
// file if specified. This is only valid for non-hostNetwork pods.
116+
// +optional
117+
// +patchMergeKey=ip
118+
// +patchStrategy=merge
119+
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty" patchStrategy:"merge" patchMergeKey:"ip" protobuf:"bytes,23,rep,name=hostAliases"`
120+
// If specified, indicates the pod's priority. "system-node-critical" and
121+
// "system-cluster-critical" are two special keywords which indicate the
122+
// highest priorities with the former being the highest priority. Any other
123+
// name must be defined by creating a PriorityClass object with that name.
124+
// If not specified, the pod priority will be default or zero if there is no
125+
// default.
126+
// +optional
127+
PriorityClassName string `json:"priorityClassName,omitempty" protobuf:"bytes,24,opt,name=priorityClassName"`
128+
// The priority value. Various system components use this field to find the
129+
// priority of the pod. When Priority Admission Controller is enabled, it
130+
// prevents users from setting this field. The admission controller populates
131+
// this field from PriorityClassName.
132+
// The higher the value, the higher the priority.
133+
// +optional
134+
Priority *int32 `json:"priority,omitempty" protobuf:"bytes,25,opt,name=priority"`
135+
// Specifies the DNS parameters of a pod.
136+
// Parameters specified here will be merged to the generated DNS
137+
// configuration based on DNSPolicy.
138+
// +optional
139+
DNSConfig *corev1.PodDNSConfig `json:"dnsConfig,omitempty" protobuf:"bytes,26,opt,name=dnsConfig"`
140+
// If specified, all readiness gates will be evaluated for pod readiness.
141+
// A pod is ready when all its containers are ready AND
142+
// all conditions specified in the readiness gates have status equal to "True"
143+
// More info: https://git.k8s.io/enhancements/keps/sig-network/0007-pod-ready%2B%2B.md
144+
// +optional
145+
ReadinessGates []corev1.PodReadinessGate `json:"readinessGates,omitempty" protobuf:"bytes,28,opt,name=readinessGates"`
146+
// RuntimeClassName refers to a RuntimeClass object in the node.k8s.io group, which should be used
147+
// to run this pod. If no RuntimeClass resource matches the named class, the pod will not be run.
148+
// If unset or empty, the "legacy" RuntimeClass will be used, which is an implicit class with an
149+
// empty definition that uses the default runtime handler.
150+
// More info: https://git.k8s.io/enhancements/keps/sig-node/runtime-class.md
151+
// This is a beta feature as of Kubernetes v1.14.
152+
// +optional
153+
RuntimeClassName *string `json:"runtimeClassName,omitempty" protobuf:"bytes,29,opt,name=runtimeClassName"`
154+
// EnableServiceLinks indicates whether information about services should be injected into pod's
155+
// environment variables, matching the syntax of Docker links.
156+
// Optional: Defaults to true.
157+
// +optional
158+
EnableServiceLinks *bool `json:"enableServiceLinks,omitempty" protobuf:"varint,30,opt,name=enableServiceLinks"`
159+
// PreemptionPolicy is the Policy for preempting pods with lower priority.
160+
// One of Never, PreemptLowerPriority.
161+
// Defaults to PreemptLowerPriority if unset.
162+
// This field is beta-level, gated by the NonPreemptingPriority feature-gate.
163+
// +optional
164+
PreemptionPolicy *corev1.PreemptionPolicy `json:"preemptionPolicy,omitempty" protobuf:"bytes,31,opt,name=preemptionPolicy"`
165+
// Overhead represents the resource overhead associated with running a pod for a given RuntimeClass.
166+
// This field will be autopopulated at admission time by the RuntimeClass admission controller. If
167+
// the RuntimeClass admission controller is enabled, overhead must not be set in Pod create requests.
168+
// The RuntimeClass admission controller will reject Pod create requests which have the overhead already
169+
// set. If RuntimeClass is configured and selected in the PodSpec, Overhead will be set to the value
170+
// defined in the corresponding RuntimeClass, otherwise it will remain unset and treated as zero.
171+
// More info: https://git.k8s.io/enhancements/keps/sig-node/20190226-pod-overhead.md
172+
// This field is alpha-level as of Kubernetes v1.16, and is only honored by servers that enable the PodOverhead feature.
173+
// +optional
174+
Overhead corev1.ResourceList `json:"overhead,omitempty" protobuf:"bytes,32,opt,name=overhead"`
175+
// TopologySpreadConstraints describes how a group of pods ought to spread across topology
176+
// domains. Scheduler will schedule pods in a way which abides by the constraints.
177+
// All topologySpreadConstraints are ANDed.
178+
// +optional
179+
// +patchMergeKey=topologyKey
180+
// +patchStrategy=merge
181+
// +listType=map
182+
// +listMapKey=topologyKey
183+
// +listMapKey=whenUnsatisfiable
184+
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty" patchStrategy:"merge" patchMergeKey:"topologyKey" protobuf:"bytes,33,opt,name=topologySpreadConstraints"`
185+
// If true the pod's hostname will be configured as the pod's FQDN, rather than the leaf name (the default).
186+
// In Linux containers, this means setting the FQDN in the hostname field of the kernel (the nodename field of struct utsname).
187+
// In Windows containers, this means setting the registry value of hostname for the registry key HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters to FQDN.
188+
// If a pod does not have FQDN, this has no effect.
189+
// Default to false.
190+
// +optional
191+
SetHostnameAsFQDN *bool `json:"setHostnameAsFQDN,omitempty" protobuf:"varint,35,opt,name=setHostnameAsFQDN"`
192+
}

0 commit comments

Comments
 (0)