diff --git a/README.md b/README.md index 3a924c1..c36fb03 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,14 @@ 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: @@ -33,9 +37,13 @@ spec: 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 diff --git a/api/v1alpha1/pipeline_types.go b/api/v1alpha1/pipeline_types.go index a1bc371..f66762f 100644 --- a/api/v1alpha1/pipeline_types.go +++ b/api/v1alpha1/pipeline_types.go @@ -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 diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 4b88841..728767b 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -76,6 +76,13 @@ func (in *PipelineSpec) DeepCopyInto(out *PipelineSpec) { *out = new(v1.JSON) (*in).DeepCopyInto(*out) } + if in.ConfigFiles != nil { + in, out := &in.ConfigFiles, &out.ConfigFiles + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PipelineSpec. diff --git a/config/crd/bases/captain.benthos.dev_pipelines.yaml b/config/crd/bases/captain.benthos.dev_pipelines.yaml index f214fdb..2cf046d 100644 --- a/config/crd/bases/captain.benthos.dev_pipelines.yaml +++ b/config/crd/bases/captain.benthos.dev_pipelines.yaml @@ -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. diff --git a/config/samples/captain_v1alpha1_pipeline.yaml b/config/samples/captain_v1alpha1_pipeline.yaml index d4cc9f0..c1dab07 100644 --- a/config/samples/captain_v1alpha1_pipeline.yaml +++ b/config/samples/captain_v1alpha1_pipeline.yaml @@ -12,10 +12,14 @@ 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: @@ -23,3 +27,7 @@ spec: output: stdout: {} + + configFiles: + meow.txt: | + meow diff --git a/internal/controller/pipeline_controller.go b/internal/controller/pipeline_controller.go index 297a905..1859519 100644 --- a/internal/controller/pipeline_controller.go +++ b/internal/controller/pipeline_controller.go @@ -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) @@ -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 {