Skip to content

Commit 4ac900c

Browse files
Merge pull request #20 from mikebaum/add-env-property
Add env property to pipeline API
2 parents f4e4748 + e86812c commit 4ac900c

File tree

6 files changed

+162
-20
lines changed

6 files changed

+162
-20
lines changed

README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ kind: Pipeline
1919
metadata:
2020
name: pipeline-sample
2121
spec:
22-
replicas: 2
22+
replicas: 1
2323
config:
2424
input:
25-
broker:
26-
inputs:
27-
- file:
28-
paths: ["./config/meow.txt"]
29-
- generate:
30-
mapping: root = "woof"
31-
interval: 10s
32-
count: 0
25+
generate:
26+
mapping: |
27+
let favorite_animal = env("FAVORITE_ANIMAL")
28+
root = match $favorite_animal {
29+
"cat" => file("/config/cat.txt")
30+
"dog" => file("/config/dog.txt")
31+
_ => file("/config/dog.txt")
32+
}
33+
interval: 5s
34+
count: 0
3335

3436
pipeline:
3537
processors:
@@ -39,8 +41,14 @@ spec:
3941
stdout: {}
4042

4143
configFiles:
42-
meow.txt: |
44+
cat.txt: |
4345
meow
46+
dog.txt: |
47+
woof
48+
49+
env:
50+
- name: FAVORITE_ANIMAL
51+
value: cat
4452
```
4553
4654
Once the resource is deployed, you can monitor the state of the resource:

api/v1alpha1/pipeline_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v1alpha1
22

33
import (
4+
v1 "k8s.io/api/core/v1"
45
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
56
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
67
)
@@ -29,6 +30,9 @@ type PipelineSpec struct {
2930
// ConfigFiles Additional configuration, as Key/Value pairs, that will be mounted as files with the /config
3031
// directory on the pod. The key should be the file name and the value should be its content.
3132
ConfigFiles map[string]string `json:"configFiles,omitempty"`
33+
34+
// Env Environment Variables to set in the benthos pipeline pod.
35+
Env []v1.EnvVar `json:"env,omitempty"`
3236
}
3337

3438
// PipelineStatus defines the observed state of Pipeline

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/captain.benthos.dev_pipelines.yaml

Lines changed: 114 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,121 @@ spec:
6868
type: string
6969
description: |-
7070
ConfigFiles Additional configuration, as Key/Value pairs, that will be mounted as files with the /config
71-
directory on the pod. The key should be the file name and the value should be it's content.
71+
directory on the pod. The key should be the file name and the value should be its content.
7272
type: object
73+
env:
74+
description: Env Environment Variable to set in the benthos pipeline
75+
pod.
76+
items:
77+
description: EnvVar represents an environment variable present in
78+
a Container.
79+
properties:
80+
name:
81+
description: Name of the environment variable. Must be a C_IDENTIFIER.
82+
type: string
83+
value:
84+
description: |-
85+
Variable references $(VAR_NAME) are expanded
86+
using the previously defined environment variables in the container and
87+
any service environment variables. If a variable cannot be resolved,
88+
the reference in the input string will be unchanged. Double $$ are reduced
89+
to a single $, which allows for escaping the $(VAR_NAME) syntax: i.e.
90+
"$$(VAR_NAME)" will produce the string literal "$(VAR_NAME)".
91+
Escaped references will never be expanded, regardless of whether the variable
92+
exists or not.
93+
Defaults to "".
94+
type: string
95+
valueFrom:
96+
description: Source for the environment variable's value. Cannot
97+
be used if value is not empty.
98+
properties:
99+
configMapKeyRef:
100+
description: Selects a key of a ConfigMap.
101+
properties:
102+
key:
103+
description: The key to select.
104+
type: string
105+
name:
106+
description: |-
107+
Name of the referent.
108+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
109+
TODO: Add other useful fields. apiVersion, kind, uid?
110+
type: string
111+
optional:
112+
description: Specify whether the ConfigMap or its key
113+
must be defined
114+
type: boolean
115+
required:
116+
- key
117+
type: object
118+
x-kubernetes-map-type: atomic
119+
fieldRef:
120+
description: |-
121+
Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['<KEY>']`, `metadata.annotations['<KEY>']`,
122+
spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs.
123+
properties:
124+
apiVersion:
125+
description: Version of the schema the FieldPath is
126+
written in terms of, defaults to "v1".
127+
type: string
128+
fieldPath:
129+
description: Path of the field to select in the specified
130+
API version.
131+
type: string
132+
required:
133+
- fieldPath
134+
type: object
135+
x-kubernetes-map-type: atomic
136+
resourceFieldRef:
137+
description: |-
138+
Selects a resource of the container: only resources limits and requests
139+
(limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported.
140+
properties:
141+
containerName:
142+
description: 'Container name: required for volumes,
143+
optional for env vars'
144+
type: string
145+
divisor:
146+
anyOf:
147+
- type: integer
148+
- type: string
149+
description: Specifies the output format of the exposed
150+
resources, defaults to "1"
151+
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
152+
x-kubernetes-int-or-string: true
153+
resource:
154+
description: 'Required: resource to select'
155+
type: string
156+
required:
157+
- resource
158+
type: object
159+
x-kubernetes-map-type: atomic
160+
secretKeyRef:
161+
description: Selects a key of a secret in the pod's namespace
162+
properties:
163+
key:
164+
description: The key of the secret to select from. Must
165+
be a valid secret key.
166+
type: string
167+
name:
168+
description: |-
169+
Name of the referent.
170+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
171+
TODO: Add other useful fields. apiVersion, kind, uid?
172+
type: string
173+
optional:
174+
description: Specify whether the Secret or its key must
175+
be defined
176+
type: boolean
177+
required:
178+
- key
179+
type: object
180+
x-kubernetes-map-type: atomic
181+
type: object
182+
required:
183+
- name
184+
type: object
185+
type: array
73186
image:
74187
description: Image defines the image and tag to use for the Benthos
75188
deployment.

config/samples/captain_v1alpha1_pipeline.yaml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ spec:
1212
replicas: 1
1313
config:
1414
input:
15-
broker:
16-
inputs:
17-
- file:
18-
paths: ["./config/meow.txt"]
19-
- generate:
20-
mapping: root = "woof"
21-
interval: 10s
22-
count: 0
15+
generate:
16+
mapping: |
17+
let favorite_animal = env("FAVORITE_ANIMAL")
18+
root = match $favorite_animal {
19+
"cat" => file("/config/cat.txt")
20+
"dog" => file("/config/dog.txt")
21+
_ => file("/config/dog.txt")
22+
}
23+
interval: 5s
24+
count: 0
2325

2426
pipeline:
2527
processors:
@@ -29,5 +31,11 @@ spec:
2931
stdout: {}
3032

3133
configFiles:
32-
meow.txt: |
34+
cat.txt: |
3335
meow
36+
dog.txt: |
37+
woof
38+
39+
env:
40+
- name: FAVORITE_ANIMAL
41+
value: cat

internal/pkg/resource/resource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func NewDeployment(name string, namespace string, scope captainv1.PipelineSpec)
5454
ReadOnly: true,
5555
},
5656
},
57+
Env: scope.Env,
5758
}},
5859
Volumes: []corev1.Volume{
5960
{

0 commit comments

Comments
 (0)