kustomize-controller
kustomize-controller copied to clipboard
Replace variable which don't exist in substitute
Some of our components are Java based, and their variable are use ${} as the variable just like below.
<?xml version="1.0"?>
<configuration scan="true">
<!--Define several properties we will use later.-->
<property name="SERVICE_NAME" value="test-service" />
<property name="LOG_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [${SERVICE_NAME}] [%level] [%thread] [%logger{50}:%line] - %msg%n" />
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>
When I create a fluxv2 gitrepository and kustomization like below, it would relace the ${LOG_PATTERN}
as `` in the lab.
So we have to add the kustomize.toolkit.fluxcd.io/substitute: disabled
into annotation to avaid these replacement.
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: GitRepository
metadata:
name: jane
spec:
interval: 1m
url: https://github.com/JaneLiuL/flux-precheck.git
ref:
branch: dev
---
apiVersion: kustomize.toolkit.fluxcd.io/v1beta1
kind: Kustomization
metadata:
name: test
spec:
interval: 5m
path: "./testdata/"
prune: true
timeout: 2m
sourceRef:
kind: GitRepository
name: jane
postBuild:
substitute:
cluster_env: "prod"
As we know, we hope the substitute only replace the variable which is declare in the kustomize.toolkit.fluxcd.io/v1beta1
This is not a bug, this behaviour is documented in the API spec, that's how drones's varsub works.
@stefanprodan Thanks for the reply, yes, I fully understand, I check the drone, but for the Java component, we do can not use postBuild now. Could it possible to change the design, only relace the variable var exist in postbuild declare variable?
Could it possible to change the design, only relace the variable var exist in postbuild declare variable?
Are you proposing we fork drone and maintain our own package?
What's the issue with annotation that config map with kustomize.toolkit.fluxcd.io/substitute: disabled
?
Now we can only use annotation to disable to replace for workaround.
We have many variable like domainname, region and so on, and we have more than 10 labs, from the top kustomizations.kustomize.toolkit.fluxcd.io
to replace all the variable for so many labs.
If we use the annotation to disable to replace, then we can only hardcode the value in our gitrepository.
Otherwise, the Java application propertise will be replace...
If we use the annotation to disable to replace, then we can only hardcode the value in our gitrepository.
You would place that annotation only on the Kubernetes ConfigMap that contains the Java config. Besides that config, you can use the Flux vars on deployments and anything else.
Below is an example of one of the gitrepository: Tree A gitrepository:
|-- configs
| |-- application.yml
| `-- logback.xml
|-- deployment.yaml
|-- deployment_patch.yaml
|-- kustomization.yaml
`-- service.yaml
cat kustomization.yaml
as below
resources:
- deployment.yaml
- service.yaml
configMapGenerator:
- name: xx-cfg
files:
- configs/application.yml
- configs/logback.xml
generatorOptions:
annotations:
kustomize.toolkit.fluxcd.io/substitute: disabled
So we need to change our kustomization.yaml for the Java config :( .
Hello,
I have a similar problem for an otel-collector configmap with some variables to substitute and other not, in the same file.
As a workaround, you can double $
for variables you don't want to substitute, eg. $${LOG_PATTERN}
, this will replace them by ${LOG_PATTERN}
.