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

Non-helm installation is not idempotent #1393

Closed
jwilner opened this issue Feb 2, 2021 · 2 comments · Fixed by #3656
Closed

Non-helm installation is not idempotent #1393

jwilner opened this issue Feb 2, 2021 · 2 comments · Fixed by #3656
Labels
question Further information is requested

Comments

@jwilner
Copy link

jwilner commented Feb 2, 2021

We can install and start pushing logs just fine using the "non-helm" mechanism. However, if we re-apply the configuration, it fails recreating the collection-sumologic-setup job.

Is there a recommended way to make this idempotent? If the job is run more than once, are there problematic side-effects?

@jwilner jwilner added the question Further information is requested label Feb 2, 2021
@perk-sumo
Copy link
Contributor

Hi!
The collection-sumologic-setup job is idempotent, in a sense: you should be safe to run it more than once and the result should be always the same.

It's actually the case when helm is used, whenever you run helm upgrade the setup job is run first, then the changes are applied.

That doesn't mean there is no bug somewhere that prevents it from being run in the first place.
Would you mind providing more information as what you see?

@jwilner
Copy link
Author

jwilner commented Feb 3, 2021

Thanks @perk-sumo. It's helpful to know the job is idempotent.

For more context, we manage our k8s config with kustomize and apply it all in regular intervals. We have a kustomize generator that constructs the necessary sumologic config and dumps it onto stdout, where it will be applied by kubectl.

Our generator logic, for the moment, looks like:

#Create the sumologic-agent namespace
echo 'apiVersion: v1
kind: Namespace
metadata:
  name: sumologic-agent
---'

# Use `helm template` to create a kubernetes configuration.
# For proper functioning of the sumo agent, we set the namespace on all `Kind`s
# using 'yq'.
helm template "${REPO_PATH}" \
	--name-template 'collection' \
	--namespace 'sumologic-agent' \
	--set sumologic.accessId="${sumologic_accessid}" \
	--set sumologic.accessKey="${sumologic_accesskey}" \
	--set sumologic.collectorName="$(yq eval .collector_name "${config_file}")" \
	--set sumologic.clusterName="$(yq eval .cluster_name "${config_file}")" \
	--set sumologic.metrics.enabled=false \
	--set sumologic.traces.enabled=false \
	--set fluentd.events.enabled=false \
	--set cleanupEnabled=true | yq eval '.metadata.namespace="sumologic-agent"' -

At the end of the YAML kustomize pipeline, there's a kubectl apply -f=-.

Of course, the general expectation with kubectl apply is that it should be idempotent.

That is not however true with the YAML your helm chart generates. Reapplying the YAML -- as our CI does regularly -- fails with messages to the effect of:

The Job "collection-sumologic-setup" is invalid:
--
* spec.template.metadata.labels[controller-uid]: Required value: must be '0f8969a9-b36d-459e-836b-e4ac15803a80'
* spec.template.metadata.labels[job-name]: Required value: must be 'collection-sumologic-setup'
* spec.template.metadata.labels: Invalid value: map[string]string(nil): `selector` does not match template `labels`
* spec.template: Invalid value: HUGE_GO_DATA_STRUCTURE: field is immutable

You can google and see that this is a common error occurring when trying to bash completed jobs: kubernetes/kubernetes#89657.

The job clearly has helm lifecycle annotations on it, which means that helm is aware of when to recreate it etc -- but it also means that you can't simply reapply the yaml as is. What we are going to end up doing for the moment instead is deleting the job before each application.

As that issue mentions, the real fix here is the k8s TTL controller; I am not sure, but that might be an avenue for you to less-tightly couple your installs to helm.

@perk-sumo perk-sumo modified the milestone: v2.2 Jun 7, 2021
@sumo-drosiek sumo-drosiek linked a pull request Apr 17, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
2 participants