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

Ignition fails to detect cloud-config when jinja templates are used #953

Open
hrak opened this issue Jan 27, 2023 · 4 comments
Open

Ignition fails to detect cloud-config when jinja templates are used #953

hrak opened this issue Jan 27, 2023 · 4 comments
Labels
kind/bug Something isn't working

Comments

@hrak
Copy link

hrak commented Jan 27, 2023

Description

Ignition's isCloudConfig function doesn't properly detect cloud-config when using jinja templates. For example, Kubernetes cluster-api uses jinja templates for cloud-config. The user-data fetched from metadata service looks like this (gzipped):

## template: jinja
#cloud-config

write_files:
-   path: /etc/kubernetes/pki/ca.crt
    owner: root:root
    permissions: '0640'
    content: |
      -----BEGIN CERTIFICATE-----
      <snip snip>
      -----END CERTIFICATE-----
      etc. etc.

The isCloudConfig function only looks for the first line of the config to contain #cloud-config:

func isCloudConfig(userdata []byte) bool {
	header := strings.SplitN(string(decompressIfGzipped(userdata)), "\n", 2)[0]

	// Trim trailing whitespaces
	header = strings.TrimRightFunc(header, unicode.IsSpace)

	return (header == "#cloud-config")
}

But in the case of Jinja templates, the first header is ## template: jinja. The function isCloudConfig will have to be adapted to check in at least the first 2 lines for #cloud-config.

Impact

cloud-config is not detected, resulting in config.Parse attempting to handle the user-data as raw json, which it isn't (its gzipped yaml), resulting in a boot failure and emergency mode

Screenshot 2023-01-26 at 13 45 43

Environment and steps to reproduce

  1. Set-up:
    flatcar-stable-3374.2.3 running in Cloudstack (KVM virt)
  2. Task: booting a control plane node using Kubernetes cluster-api
  3. Action(s):
    a. boot an instance with user-data containing a cloud-config using jinja templates
  4. Error: see above

Expected behavior

Proper boot and processing of cloud-config

Additional information

Please add any information here that does not fit the above format.

@hrak hrak added the kind/bug Something isn't working label Jan 27, 2023
@pothos
Copy link
Member

pothos commented Jan 27, 2023

Thanks for reporting, that's something we need to fix upstream but could already backport it, maybe to Flatcar Alpha/Beta if not Stable

@jepio
Copy link
Member

jepio commented Jan 27, 2023

I see where you're coming from but there are a couple of issues getting mixed up here:

So this is not something that will work, even if ignition accepts it.

@pothos
Copy link
Member

pothos commented Jan 27, 2023

Ah right, coreos-cloudinit couldn't handle it anyway^^ So unless running the real cloud-init on Flatcar is a thing, we don't need this for Flatcar. (Still it would be nice to fix the detection.)

@hrak
Copy link
Author

hrak commented Jan 27, 2023

I see where you're coming from but there are a couple of issues getting mixed up here:

* the way cluster-api works with Flatcar is you need to pass `format: ignition` (https://github.com/kubernetes-sigs/cluster-api-provider-aws/blob/main/templates/cluster-template-flatcar.yaml#L61-L62). This is the relevant file https://github.com/kubernetes-sigs/cluster-api/blob/5c6fb4bc89efb6325852392e8369ba6aa767881b/bootstrap/kubeadm/internal/ignition/ignition.go

* coreos-cloudinit, which is the only cloudinit that works on flatcar, does not support jinja templates (because it is not implemented in python)

So this is not something that will work, even if ignition accepts it.

Aah, thanks for pointing that out. I will try ignition instead!

Fixing the detection might indeed be nice, though if it results in a broken cloud-config it might not be that useful. Maybe throw an error to indicate that jinja is unsupported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
Development

No branches or pull requests

3 participants