Search code examples
kuberneteskubernetes-helmskaffold

pass constant to skaffold


I am trying to use a constant in skaffold, and to access it in skaffold profile:

example export SOME_IP=199.99.99.99 && skaffold run -p dev

skaffold.yaml

...
deploy:
  helm:
    flags:
      global:
      - "--debug" 
    releases:
    - name: ***
      chartPath: ***
      imageStrategy:
        helm:
          explicitRegistry: true
      createNamespace: true
      namespace: "***"
      setValueTemplates:
        SKAFFOLD_SOME_IP: "{{.SOME_IP}}"

and in dev.yaml profile I need somehow to access it,
something like:
{{ .Template.SKAFFOLD_SOME_IP }} and it should be rendered as 199.99.99.99

I tried to use skaffold envTemplate and setValueTemplates fields, but could not get success, and could not find any example on web


Solution

  • Basically found a solution which I truly don't like, but it works:

    in dev profile: values.dev.yaml I added a placeholder

      _anchors_:
        - &_IPAddr_01 "<IPAddr_01_TAG>" # will be replaced with SOME_IP
    

    The <IPAddr_01_TAG> will be replaced with const SOME_IP which will become 199.99.99.99 at the skaffold run

    Now to run skaffold I will do:

    export SOME_IP=199.99.99.99
    sed -i "s/<IPAddr_01_TAG>/$SOME_IP/g" values/values.dev.yaml
    skaffold run -p dev
    

    so after the above sed, in dev profile: values.dev.yaml, we will see the SOME_IP const instead of placeholder

      _anchors_:
        - &_IPAddr_01 "199.99.99.99"