Skip to content

Commit 829a167

Browse files
committed
Add 'env' field to runner resource
1 parent c66916a commit 829a167

4 files changed

Lines changed: 127 additions & 15 deletions

File tree

api/v1alpha1/runner_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
corev1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

@@ -28,6 +29,9 @@ type RunnerSpec struct {
2829

2930
// +optional
3031
Image string `json:"image"`
32+
33+
// +optional
34+
Env []corev1.EnvVar `json:"env"`
3135
}
3236

3337
// RunnerStatus defines the observed state of Runner

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/actions.summerwind.dev_runners.yaml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,103 @@ spec:
4343
spec:
4444
description: RunnerSpec defines the desired state of Runner
4545
properties:
46+
env:
47+
items:
48+
description: EnvVar represents an environment variable present in
49+
a Container.
50+
properties:
51+
name:
52+
description: Name of the environment variable. Must be a C_IDENTIFIER.
53+
type: string
54+
value:
55+
description: 'Variable references $(VAR_NAME) are expanded using
56+
the previous defined environment variables in the container
57+
and any service environment variables. If a variable cannot
58+
be resolved, the reference in the input string will be unchanged.
59+
The $(VAR_NAME) syntax can be escaped with a double $$, ie:
60+
$$(VAR_NAME). Escaped references will never be expanded, regardless
61+
of whether the variable exists or not. Defaults to "".'
62+
type: string
63+
valueFrom:
64+
description: Source for the environment variable's value. Cannot
65+
be used if value is not empty.
66+
properties:
67+
configMapKeyRef:
68+
description: Selects a key of a ConfigMap.
69+
properties:
70+
key:
71+
description: The key to select.
72+
type: string
73+
name:
74+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
75+
TODO: Add other useful fields. apiVersion, kind, uid?'
76+
type: string
77+
optional:
78+
description: Specify whether the ConfigMap or its key
79+
must be defined
80+
type: boolean
81+
required:
82+
- key
83+
type: object
84+
fieldRef:
85+
description: 'Selects a field of the pod: supports metadata.name,
86+
metadata.namespace, metadata.labels, metadata.annotations,
87+
spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP.'
88+
properties:
89+
apiVersion:
90+
description: Version of the schema the FieldPath is written
91+
in terms of, defaults to "v1".
92+
type: string
93+
fieldPath:
94+
description: Path of the field to select in the specified
95+
API version.
96+
type: string
97+
required:
98+
- fieldPath
99+
type: object
100+
resourceFieldRef:
101+
description: 'Selects a resource of the container: only resources
102+
limits and requests (limits.cpu, limits.memory, limits.ephemeral-storage,
103+
requests.cpu, requests.memory and requests.ephemeral-storage)
104+
are currently supported.'
105+
properties:
106+
containerName:
107+
description: 'Container name: required for volumes, optional
108+
for env vars'
109+
type: string
110+
divisor:
111+
description: Specifies the output format of the exposed
112+
resources, defaults to "1"
113+
type: string
114+
resource:
115+
description: 'Required: resource to select'
116+
type: string
117+
required:
118+
- resource
119+
type: object
120+
secretKeyRef:
121+
description: Selects a key of a secret in the pod's namespace
122+
properties:
123+
key:
124+
description: The key of the secret to select from. Must
125+
be a valid secret key.
126+
type: string
127+
name:
128+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
129+
TODO: Add other useful fields. apiVersion, kind, uid?'
130+
type: string
131+
optional:
132+
description: Specify whether the Secret or its key must
133+
be defined
134+
type: boolean
135+
required:
136+
- key
137+
type: object
138+
type: object
139+
required:
140+
- name
141+
type: object
142+
type: array
46143
image:
47144
type: string
48145
repository:

controllers/runner_controller.go

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,22 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
334334
runnerImage = r.RunnerImage
335335
}
336336

337+
env := []corev1.EnvVar{
338+
{
339+
Name: "RUNNER_NAME",
340+
Value: runner.Name,
341+
},
342+
{
343+
Name: "RUNNER_REPO",
344+
Value: runner.Spec.Repository,
345+
},
346+
{
347+
Name: "RUNNER_TOKEN",
348+
Value: runner.Status.Registration.Token,
349+
},
350+
}
351+
env = append(env, runner.Spec.Env...)
352+
337353
pod := corev1.Pod{
338354
ObjectMeta: metav1.ObjectMeta{
339355
Name: runner.Name,
@@ -346,20 +362,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
346362
Name: containerName,
347363
Image: runnerImage,
348364
ImagePullPolicy: "Always",
349-
Env: []corev1.EnvVar{
350-
{
351-
Name: "RUNNER_NAME",
352-
Value: runner.Name,
353-
},
354-
{
355-
Name: "RUNNER_REPO",
356-
Value: runner.Spec.Repository,
357-
},
358-
{
359-
Name: "RUNNER_TOKEN",
360-
Value: runner.Status.Registration.Token,
361-
},
362-
},
365+
Env: env,
363366
VolumeMounts: []corev1.VolumeMount{
364367
{
365368
Name: "docker",

0 commit comments

Comments
 (0)