Skip to content

Commit

Permalink
add property configFiles to API (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebaum authored May 4, 2024
1 parent 1569df0 commit f4e4748
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,28 @@ spec:
replicas: 2
config:
input:
generate:
mapping: root = "woof"
interval: 5s
count: 0
broker:
inputs:
- file:
paths: ["./config/meow.txt"]
- generate:
mapping: root = "woof"
interval: 10s
count: 0

pipeline:
processors:
- mapping: root = content().uppercase()

output:
stdout: {}

configFiles:
meow.txt: |
meow
```
Once the resource is deployed, you can monitor the state of the resoure:
Once the resource is deployed, you can monitor the state of the resource:
```bash
kubectl get pipelines
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ type PipelineSpec struct {
// Image defines the image and tag to use for the Benthos deployment.
// +optional
Image string `json:"image,omitempty"`

// ConfigFiles Additional configuration, as Key/Value pairs, that will be mounted as files with the /config
// directory on the pod. The key should be the file name and the value should be its content.
ConfigFiles map[string]string `json:"configFiles,omitempty"`
}

// PipelineStatus defines the observed state of Pipeline
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions config/crd/bases/captain.benthos.dev_pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ spec:
config:
description: Config defines the Benthos configuration as a string.
x-kubernetes-preserve-unknown-fields: true
configFiles:
additionalProperties:
type: string
description: |-
ConfigFiles Additional configuration, as Key/Value pairs, that will be mounted as files with the /config
directory on the pod. The key should be the file name and the value should be it's content.
type: object
image:
description: Image defines the image and tag to use for the Benthos
deployment.
Expand Down
16 changes: 12 additions & 4 deletions config/samples/captain_v1alpha1_pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@ spec:
replicas: 1
config:
input:
generate:
mapping: root = "woof"
interval: 5s
count: 0
broker:
inputs:
- file:
paths: ["./config/meow.txt"]
- generate:
mapping: root = "woof"
interval: 10s
count: 0

pipeline:
processors:
- mapping: root = content().uppercase()

output:
stdout: {}

configFiles:
meow.txt: |
meow
5 changes: 4 additions & 1 deletion internal/controller/pipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ func (r *PipelineReconciler) createOrPatchConfigMap(scope *PipelineScope) (ctrl.
sc.Data = map[string]string{
"benthos.yaml": string(scope.Pipeline.Spec.Config.Raw),
}
for file, config := range scope.Pipeline.Spec.ConfigFiles {
sc.Data[file] = config
}
err := controllerutil.SetControllerReference(scope.Pipeline, sc, r.Scheme)
if err != nil {
return errors.Wrapf(err, "Failed to set controller reference on configmap %s", name)
Expand All @@ -267,7 +270,7 @@ func (r *PipelineReconciler) createOrPatchConfigMap(scope *PipelineScope) (ctrl.
return reconcile.Result{}, errors.Wrapf(err, "Failed to reconcile config map %s", name)
}

scope.Log.Info("Succesfully reconciled config map", "name", name, "operation", op)
scope.Log.Info("Successfully reconciled config map", "name", name, "operation", op)

// rollout the deployment if the configmap changes
if op == controllerutil.OperationResultUpdated {
Expand Down

0 comments on commit f4e4748

Please sign in to comment.