Preprocessing and postprocessing Stitch transformation
When user wants to generate additional documents based on the content of the deployment plugin uses preprocessing or postprocessing stitch transformation. Preprocessing should be used if generated documents should go through regular stitch transformations and postprocessing should be used when no additional transformation is expected.
Plugins that support this are:
For user to trigger the preprocessing transformation one needs to add
condition: preProcessing: true
or, for postprocessing transformation
condition: postProcessing: true
to the list of conditions in stitch rules. Input and output to processors for this transformations should always be an array. A helpful processor which can be used is AddYamlObject which will append yaml object to input (see stitch processors).
A use case is when kubernetes deployment doesn’t have Ingress resource, and we want users to be able to generate it. Or when user wants to add PDB (Pod Disruption Budget), secrets, config maps, etc. based on the content of YAML that Stitch analyzes. A simple configuration to add Ingress and PDB resources could loo like this:
kind: Rules metadata: namespace: k8s-add-labels spec: - name: "k8s.AddResourcesInPreprocessing" condition: deployedType: k8s.Resources preProcessing: true processor: - type: freemarker description: "Initialize empty array for pre processing" merge: type: none phase: PRE_FLIGHT weight: 0 parameters: template:  - type: addYamlObject description: "Using add yaml object processor to add Ingress resource" merge: type: none parameters: yaml: | apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: minimal-ingress annotations: nginx.ingress.kubernetes.io/rewrite-target: / spec: rules: - http: paths: - path: /testpath pathType: Prefix backend: service: name: test port: number: 80 - name: "k8s.AddResourcesInPostprocessing" condition: deployedType: k8s.Resources postProcessing: true processor: - type: freemarker description: "Initialize empty array for post processing" merge: type: none phase: PRE_FLIGHT weight: 0 parameters: template:  - type: addYamlObject description: "Using add yaml object processor to add PDB resource" merge: type: none parameters: yaml: | apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: name: zk-pdb spec: minAvailable: 2 selector: matchLabels: app: petclinic