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

Only support default partition in server cluster #721

Merged
merged 2 commits into from
Sep 14, 2021

Conversation

thisisnotashwin
Copy link
Contributor

@thisisnotashwin thisisnotashwin commented Sep 10, 2021

Changes proposed in this PR:

  • Fail if the user attempts to update the admin partition name on the server cluster to a value that isn't "default"
  • Create an immutable configmap with the partition name which will cause helm upgrade to fail if the admin partition name is updated between the install and the upgrade.

Questions:
Even though the helm upgrade fails when the partition name is changed, the partition-init job runs and the agents get reassigned. I could make the partition-init job a pre-install job and not a pre-upgrade job, BUT the drawback of doing so would be anyone trying to upgrade an existing non-partition cluster to a partitioned cluster cannot. Should we ignore this use case? Ignore the upgrade use-case will ensure that the partition-init job will not run thereby not creating a new partition.

FOLLOW UP:
After conversations with the team, it was decided that in the near term, we will not support updating to a partition that is non-default. Removing the pre-upgrade hook from partition-init job. This will ensure we don't create a partition when a user errantly updates the partition-name and performs a helm upgrade.

How I've tested this PR:
Manual testing.
Bats tests

How I expect reviewers to test this PR:
Code review
Would love to hear thoughts on the above questions.

Checklist:

  • Tests added

@thisisnotashwin thisisnotashwin requested review from lkysow, a team, sadjamz and kschoche and removed request for a team and sadjamz September 10, 2021 20:48
lawliet89 pushed a commit to lawliet89/consul-k8s that referenced this pull request Sep 13, 2021
In almost all cases, users want to set bootstrapExpect to the number of
server replicas. This change defaults it to null in values.yaml and then
in the template if it's left as null, then we set the -bootstrap-expect
flag to the number of server replicas.

This is backwards compatible, if users have been setting this it will
continue to be set.

Also error out if bootstrapExpect is less than the number of replicas
because this is definitely a misconfiguration as the servers won't wait
until the proper number have started before electing a leader.
cd `chart_dir`
assert_empty helm template \
-s templates/partition-init-role.yaml \
--set 'global.adminPartitions.enabled=true' \
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the description or the test is wrong here on whether or not adminPartitions.enabled is true or false!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

--set 'global.adminPartitions.name=test' \
.

[ "$status" -eq 1 ]
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this test!

Copy link
Contributor

@kschoche kschoche left a comment

Choose a reason for hiding this comment

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

Great work.
I left a couple comments before you merge but otherwise it's good to go!
On a meta note : I wish there was a better way to make the $serverEnabled := easier to read, thx Helm!

@thisisnotashwin thisisnotashwin changed the base branch from partitions to main September 14, 2021 20:32
@thisisnotashwin thisisnotashwin changed the base branch from main to partitions September 14, 2021 20:32
@thisisnotashwin thisisnotashwin force-pushed the default-partitions branch 2 times, most recently from 171379f to 7bb77a2 Compare September 14, 2021 21:05
Copy link
Member

@lkysow lkysow left a comment

Choose a reason for hiding this comment

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

The docs should be updated for the values to state that:

  1. Only default is allowed for server cluster.
  2. Can't change the partition name
  3. Only supported on initial installation, can't enable partitions after initial installation.

@@ -1,5 +1,7 @@
{{- if (or (and (ne (.Values.client.enabled | toString) "-") .Values.client.enabled) (and (eq (.Values.client.enabled | toString) "-") .Values.global.enabled)) }}
{{- if (and (and .Values.global.tls.enabled .Values.global.tls.httpsOnly) (and .Values.global.metrics.enabled .Values.global.metrics.enableAgentMetrics))}}{{ fail "global.metrics.enableAgentMetrics cannot be enabled if TLS (HTTPS only) is enabled" }}{{ end -}}
{{- $serverEnabled := (or (and (ne (.Values.server.enabled | toString) "-") .Values.server.enabled) (and (eq (.Values.server.enabled | toString) "-") .Values.global.enabled)) -}}
{{- if (and .Values.global.adminPartitions.enabled $serverEnabled (ne (.Values.global.adminPartitions.name | toString) "default"))}}{{ fail "global.adminPartitions.name has to be \"default\" in the server cluster" }}{{ end -}}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
{{- if (and .Values.global.adminPartitions.enabled $serverEnabled (ne (.Values.global.adminPartitions.name | toString) "default"))}}{{ fail "global.adminPartitions.name has to be \"default\" in the server cluster" }}{{ end -}}
{{- if (and .Values.global.adminPartitions.enabled $serverEnabled (ne .Values.global.adminPartitions.name "default"))}}{{ fail "global.adminPartitions.name has to be \"default\" in the server cluster" }}{{ end -}}

Does it need toString?

apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "consul.fullname" . }}-partition-configmap
Copy link
Member

Choose a reason for hiding this comment

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

Can we drop the configmap suffix since we don't need the type as it will be implied by the kind of the resource.

Comment on lines 40 to 44
# The name of the Admin Partition. Must be "default" in the server cluster ie the Kubernetes cluster that
# the Consul server pods are deployed onto.
name: "default"
Copy link
Member

Choose a reason for hiding this comment

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

Should note that:

  1. Can be something other than default in "non-server" clusters
  2. Can't be changed after initial installation. If they wish to change it they need to uninstall Consul.

- This does not cause the parition-init job from running or the agents
  from attempting to join the new partition, but the helm upgrade stays
in a failed state until an upgrade is run with the partition name
reverted.
@thisisnotashwin thisisnotashwin merged commit ea23808 into partitions Sep 14, 2021
@thisisnotashwin thisisnotashwin deleted the default-partitions branch September 14, 2021 23:07
thisisnotashwin pushed a commit that referenced this pull request Sep 16, 2021
* Fail if agents in server cluster are created in a partition not
"default"

* Fail helm upgrades if partition name is updated.

- This does not cause the parition-init job from running or the agents
  from attempting to join the new partition, but the helm upgrade stays
in a failed state until an upgrade is run with the partition name
reverted.
thisisnotashwin pushed a commit that referenced this pull request Sep 17, 2021
* Fail if agents in server cluster are created in a partition not
"default"

* Fail helm upgrades if partition name is updated.

- This does not cause the parition-init job from running or the agents
  from attempting to join the new partition, but the helm upgrade stays
in a failed state until an upgrade is run with the partition name
reverted.
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