Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move server config from command flags to configmap #1127

Merged
merged 7 commits into from
Apr 11, 2022

Conversation

ishustava
Copy link
Contributor

@ishustava ishustava commented Mar 30, 2022

Changes proposed in this PR:
Move as much of the server config into config map as possible. Things that could not be moved into config maps are flags that contain env variables and that are being scripted inside the command (e.g. DNS recursors).

The motivation for this change is to make the configuration more readable and consolidate it in one place as much as possible. For historical context, we were not doing that from the beginning because when you update the config map, the server stateful set would not be automatically updated and so we were using command flags instead to ensure that servers will be restarted. However, this has changed with hashicorp/consul-helm#550, but we never went back and updated it.

This change could be easier to read via commits:

Note: the client configmap and flags will be potentially updated in a future PR

How I've tested this PR:

  • unit & acceptance tests
  • some manual testing to ensure that servers get rolled when configmap changes

How I expect reviewers to test this PR:
👀

Checklist:

  • Tests added
  • CHANGELOG entry added

    HashiCorp engineers only, community PRs should not add a changelog entry.
    Entries should use present tense (e.g. Add support for...)

We don't need to join individual server instances as the headless service
DNS will resolve to all the server pod IPs, and consul will use that
to join the other agents.
@ishustava ishustava force-pushed the ishustava/refactor-tls-config branch from e8687b2 to 5be3b40 Compare March 31, 2022 20:51
@ishustava ishustava changed the title refactor: move server TLS config to configmap refactor: move server config from command flags to configmap Mar 31, 2022
@ishustava ishustava marked this pull request as ready for review March 31, 2022 23:01
@ishustava ishustava requested review from a team, jmurret and ndhanushkodi and removed request for a team March 31, 2022 23:01
Copy link
Member

@jmurret jmurret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! What is the glue that binds these config maps to where consul reads them? Does the config-checksum annotation lay these out similar to having .json files in the -config-dir?

{{- range $index := until (.Values.server.replicas | int) }}
-retry-join="${CONSUL_FULLNAME}-server-{{ $index }}.${CONSUL_FULLNAME}-server.${NAMESPACE}.svc:{{ $serverSerfLANPort }}" \
{{- end }}
-retry-join="${CONSUL_FULLNAME}-server.${NAMESPACE}.svc:{{ .Values.server.ports.serflan.port }}" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@ishustava
Copy link
Contributor Author

What is the glue that binds these config maps to where consul reads them?

Configmap is mounted as a volume to pods (similar to secrets):

- name: config
configMap:
name: {{ template "consul.fullname" . }}-server-config

- name: config
mountPath: /consul/config

All files from the configmap will be in that /consul/config directory we mount to the server pod. So by default it will be:

/consul/consul-config:
- server.json
- central-config.json
- ui-config.json
etc

Then we pass the entire config dir to consul via -config-dir flag:

-config-dir=/consul/config \

Consul will consume all files in alphabetical order and merge them all into one configuration.

Does the config-checksum annotation lay these out similar to having .json files in the -config-dir?

The config-checksum is there to detect that update server statefulset when configmap changes. For example, let's say you had an installation without TLS and now you want to enable TLS.

Without this annotation, if you run helm upgrade consul --set global.tls.enabled=true hashicorp/consul, it will just update the configmap, but the user will have to upgrade the servers themselves to apply the configmap changes.

With an annotation, when run helm upgrade, the checksum of the configmap will change and so the helm upgrade will need to update the checksum annotation on your server statefulset pods, which will trigger a restart of the pods.

@jmurret
Copy link
Member

jmurret commented Apr 1, 2022

@ishustava Thank you. This is cool.

Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! The commit by commit readability made it so nice to review!

@ishustava ishustava merged commit 857a6b5 into main Apr 11, 2022
@ishustava ishustava deleted the ishustava/refactor-tls-config branch April 11, 2022 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants