generated from crossplane-contrib/provider-jet-template
-
Notifications
You must be signed in to change notification settings - Fork 4
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
displague
wants to merge
2
commits into
main
Choose a base branch
from
k3s
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: Composition | ||
metadata: | ||
name: k3sclusters.deployments.equinix.com | ||
spec: | ||
writeConnectionSecretsToNamespace: crossplane-system | ||
compositeTypeRef: | ||
apiVersion: deployments.equinix.com/v1alpha1 | ||
kind: K3sCluster | ||
resources: | ||
- name: k3s-project | ||
base: | ||
apiVersion: metal.equinix.jet.crossplane.io/v1alpha1 | ||
kind: Project | ||
patches: | ||
- type: FromCompositeFieldPath | ||
fromFieldPath: metadata.name | ||
toFieldPath: spec.forProvider.name | ||
- name: k3s-server | ||
base: | ||
apiVersion: metal.equinix.jet.crossplane.io/v1alpha1 | ||
kind: Device | ||
metadata: | ||
labels: | ||
k3s-server: 'true' | ||
spec: | ||
forProvider: | ||
hostname: k3s-server | ||
plan: c3.small.x86 | ||
operatingSystem: ubuntu_20_04 | ||
billingCycle: hourly | ||
locked: false | ||
networkType: hybrid | ||
tags: | ||
- crossplane | ||
projectIdSelector: | ||
matchControllerRef: true | ||
writeConnectionSecretToRef: | ||
name: server | ||
namespace: crossplane-system | ||
reclaimPolicy: Delete | ||
patches: | ||
- type: ToCompositeFieldPath | ||
fromFieldPath: status.atProvider.accessPublicIpv4 | ||
toFieldPath: status.serverIP | ||
- type: FromCompositeFieldPath | ||
fromFieldPath: spec.metro | ||
toFieldPath: spec.forProvider.metro | ||
- type: CombineFromComposite | ||
toFieldPath: spec.forProvider.userData | ||
combine: | ||
variables: | ||
- fromFieldPath: spec.k3stoken | ||
strategy: string | ||
string: | ||
fmt: | | ||
#cloud-config | ||
write_files: | ||
#- permissions: '0660' | ||
# path: /etc/rancher/k3s/config.yaml | ||
# content: | | ||
# # k3s config | ||
runcmd: | ||
- sudo apt update | ||
- sudo apt upgrade -y | ||
- curl -sfL https://get.k3s.io | \ | ||
INSTALL_K3S_EXEC="server" \ | ||
K3S_TOKEN="%s" sh - | ||
- name: k3s-agent | ||
base: | ||
apiVersion: metal.equinix.jet.crossplane.io/v1alpha1 | ||
kind: Device | ||
metadata: | ||
labels: | ||
k3s-agent: 'true' | ||
spec: | ||
forProvider: | ||
hostname: k3s-agent | ||
plan: c3.small.x86 | ||
operatingSystem: ubuntu_20_04 | ||
billingCycle: hourly | ||
locked: false | ||
networkType: hybrid | ||
tags: | ||
- crossplane | ||
projectIdSelector: | ||
matchControllerRef: true | ||
writeConnectionSecretToRef: | ||
name: crossplane-conformance | ||
namespace: crossplane-system | ||
reclaimPolicy: Delete | ||
patches: | ||
# TODO we reuse metro patches. create a 'patchtype' | ||
- type: FromCompositeFieldPath | ||
fromFieldPath: spec.metro | ||
toFieldPath: spec.forProvider.metro | ||
- type: CombineFromComposite | ||
toFieldPath: spec.forProvider.userData | ||
policy: | ||
fromFieldPath: Required | ||
combine: | ||
variables: | ||
- fromFieldPath: spec.k3stoken | ||
- fromFieldPath: status.serverIP | ||
strategy: string | ||
string: | ||
fmt: | | ||
#cloud-config | ||
write_files: | ||
#- permissions: '0660' | ||
# path: /etc/rancher/k3s/config.yaml | ||
# content: | | ||
# # k3s config | ||
runcmd: | ||
- sudo apt update | ||
- sudo apt upgrade -y | ||
- curl -sfL https://get.k3s.io | \ | ||
K3S_TOKEN="%s" \ | ||
K3S_URL=https://%s:6443 sh - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
apiVersion: apiextensions.crossplane.io/v1 | ||
kind: CompositeResourceDefinition | ||
metadata: | ||
name: k3sclusters.deployments.equinix.com | ||
spec: | ||
group: deployments.equinix.com | ||
names: | ||
kind: K3sCluster | ||
listKind: K3sClusterList | ||
plural: k3sclusters | ||
singular: k3scluster | ||
versions: | ||
- name: v1alpha1 | ||
served: true | ||
referenceable: true | ||
schema: | ||
openAPIV3Schema: | ||
description: Managed resources for provider-jet-equinix crossplane K3s Cluster. Creates a k3s server and agent node in a new project named after the composition resource. | ||
type: object | ||
properties: | ||
spec: | ||
type: object | ||
properties: | ||
metro: | ||
type: string | ||
description: metro | ||
k3stoken: | ||
type: string | ||
description: K3s Token | ||
required: | ||
- metro | ||
- k3stoken | ||
status: | ||
type: object | ||
properties: | ||
serverIP: | ||
type: string | ||
description: IPv4 of the K3s Server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apiVersion: deployments.equinix.com/v1alpha1 | ||
kind: K3sCluster | ||
metadata: | ||
name: k3s-sv | ||
spec: | ||
metro: sv | ||
k3stoken: t09s3cr37 # This is an example token. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 applyingThere was a problem hiding this comment.
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, isuserDataSecretRef
.This will have to be done using
writeConnectionSecretToRef
/connectionSecretKeys
/fromConnectionSecretKey
/FromConnectionSecretKey
.https://crossplane.io/docs/v1.9/reference/composition.html
There was a problem hiding this comment.
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 thanSecret
.