Skip to content

Instantly share code, notes, and snippets.

@kevb
Created February 21, 2019 03:13
Show Gist options
  • Save kevb/7467e9a29d592a04036b7ffb06816b9d to your computer and use it in GitHub Desktop.
Save kevb/7467e9a29d592a04036b7ffb06816b9d to your computer and use it in GitHub Desktop.

Problem

Consider the following template:

version: '3.3'

services:
  swarm-sync:
    image: nginx:{{ nginx_tag }}
    deploy:
      labels:
        - "swarm-sync.managed=true"
        - "swarm-sync.image-pattern={{ nginx_tag_pattern }}"

We want the following:

  • swarm-pack can deploy it manually, and fill the value for nginx_tag (nginx_tag_pattern could be optional) from static values

  • swarm-sync can deploy it using swarm-pack, it could get the value of nginx_tag using the pattern to get the lastest tag

  • swarm-sync should be able to keep the image up to date later using the pattern (for now, it is in the label swarm-sync.image-pattern)

Using the current strategy, we define the stack file like this:

packs:
  - pack: nginx
    values:
      my_value: foo
      nginx_tag_pattern: 1.4.*
    autovalues:
      nginx_tag:
        type: image_tag_pattern
        image: nginx
        tag_pattern: 1.4.*

(n.b. autovalues represents types of values which can be created automatically based on the type and other values. In this case it is image_tag_pattern type which means it will hit docker registry for the latest value.

Problem: tag_pattern: 1.4.* & nginx_tag_pattern: 1.4.* are duplicates, and could be a problem when we change it we must remember to change it in both places.

@kevb
Copy link
Author

kevb commented Feb 21, 2019

More interesting stuff from Flux:

If the chart you're using in a HelmRelease lets you specify the particular images to run, you will usually be able to update them with Flux, the same way you can with Deployments and so on.

Flux interprets certain commonly used structures in the values section of a HelmRelease as referring to images. The following are understood (showing just the values section):

values:
  image: repo/image:version
values:
  image: repo/image
  tag: version
values:
  image:
    repository: repo/image
    tag: version

These can appear at the top level (immediately under values:), or in a subsection (under a key, itself under values:). Other values may be mixed in arbitrarily. Here's an example of a values section that specifies two images, along with some other configuration:

values:
  persistent: true

  # image that will be labeled "chart-image"
  image: repo/image1:version

  subsystem:
    # image that will be labeled "subsystem"
    image:
      repository: repo/image2
      tag: version
      imagePullPolicy: IfNotPresent
    port: 4040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment