kustomize-controller icon indicating copy to clipboard operation
kustomize-controller copied to clipboard

Replace variable which don't exist in substitute

Open JaneLiuL opened this issue 2 years ago • 7 comments

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

JaneLiuL avatar Aug 02 '21 06:08 JaneLiuL

This is not a bug, this behaviour is documented in the API spec, that's how drones's varsub works.

stefanprodan avatar Aug 05 '21 07:08 stefanprodan

@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?

JaneLiuL avatar Aug 05 '21 08:08 JaneLiuL

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?

stefanprodan avatar Aug 05 '21 08:08 stefanprodan

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...

JaneLiuL avatar Aug 05 '21 08:08 JaneLiuL

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.

stefanprodan avatar Aug 05 '21 08:08 stefanprodan

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 :( .

JaneLiuL avatar Aug 05 '21 09:08 JaneLiuL

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}.

vlaborie avatar Mar 04 '24 15:03 vlaborie