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

add k3s server + agent example composition #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

add k3s server + agent example composition #12

wants to merge 2 commits into from

Conversation

displague
Copy link
Collaborator

Description of your changes

Adds an example composition that creates a new project with a K3s server and agent within it.

Fixes #

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Signed-off-by: Marques Johansson <mjohansson@equinix.com>
fromFieldPath: spec.metro
toFieldPath: spec.forProvider.metro
- type: CombineFromComposite
toFieldPath: spec.forProvider.userData
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The userData patch is not applying

Copy link
Collaborator Author

@displague displague Oct 2, 2022

Choose a reason for hiding this comment

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

TF user_data is sensitive. The field, as defined in the CRD, is userDataSecretRef.

This will have to be done using writeConnectionSecretToRef / connectionSecretKeys / fromConnectionSecretKey / FromConnectionSecretKey.

https://crossplane.io/docs/v1.9/reference/composition.html

Copy link
Member

Choose a reason for hiding this comment

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

I see that the script requires only the token as variable. Would it make sense to store the whole script in a Secret and only take a reference of that secret in your claim? It will force the claim author to know rest of the content but at least the token won't appear in a resource other than Secret.

Signed-off-by: Marques Johansson <mjohansson@equinix.com>
toFieldPath: metadata.namespace
fromFieldPath: spec.secretNamespace
- type: CombineFromComposite
toFieldPath: data.userdata
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
toFieldPath: data.userdata
toFieldPath: stringData.userdata

data requires the content to be base64 encoded.

- name: k3s-userdata
base:
apiVersion: v1
kind: Secret
Copy link
Member

Choose a reason for hiding this comment

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

This may work but composition is designed to work with MRs. So I'd suggest using Object from provider-kubernetes. Though that'd force you to have the whole secret YAML as raw template in CombineFromComposite patch since Object accepts raw YAML.

name: k3s-sv
spec:
metro: sv
k3stoken: t09s3cr37 # This is an example token.
Copy link
Member

Choose a reason for hiding this comment

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

This isn't ideal since token is in a resource that is not Secret but only thing I could come up as solution would be to ask for a whole Secret including the rest of the script, which I guess you don't want to do, right?

runcmd:
- sudo apt update
- sudo apt upgrade -y
- curl -sfL https://get.k3s.io | \
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Certificates for the Kubernetes cluster should be sourced from Secrets which could then be managed by cert-manager. This will keep the user in control of secrets rather than having them only available within the servers (and therefor difficult to get access to from a Crossplane composition).

Crossplane compositions would also benefit from this K8s managed certificate for managing helm installs within the created cluster.

@displague
Copy link
Collaborator Author

displague commented Feb 26, 2024

Curious about the role https://kubernetes.io/docs/concepts/configuration/secret/#ssh-authentication-secrets (SSH Key secrets) could play in this

and if k3s tokens could/should be stored as https://kubernetes.io/docs/concepts/configuration/secret/#bootstrap-token-secrets

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.

None yet

2 participants