-
Notifications
You must be signed in to change notification settings - Fork 0
Initial implementation #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -1,10 +1,71 @@ | ||
| // main template for talos-backup | ||
| local com = import 'lib/commodore.libjsonnet'; | ||
| local kap = import 'lib/kapitan.libjsonnet'; | ||
| local kube = import 'lib/kube.libjsonnet'; | ||
| local lib = import 'talos-backup.libsonnet'; | ||
| local inv = kap.inventory(); | ||
| // The hiera parameters for the component | ||
| local params = inv.parameters.talos_backup; | ||
|
|
||
| // Define outputs below | ||
| local componentName = inv.parameters._instance; | ||
|
|
||
| assert | ||
| std.length(params.age_recipient_public_keys) > 0 | ||
| : 'talos_backup: age_recipient_public_keys must contain at least one public key'; | ||
| assert | ||
| params.s3.bucket != '' | ||
| : 'talos_backup: s3.bucket must be set'; | ||
| assert | ||
| !params.s3.credentials.create | ||
| || (params.s3.credentials.access_key_id != '' && params.s3.credentials.secret_access_key != '') | ||
| : 'talos_backup: s3.credentials.create=true requires access_key_id and secret_access_key'; | ||
|
|
||
| local commonLabels = { | ||
| 'app.kubernetes.io/component': componentName, | ||
| 'app.kubernetes.io/managed-by': 'commodore', | ||
| 'app.kubernetes.io/part-of': 'syn', | ||
| }; | ||
|
|
||
| local commonMetadata = { | ||
| labels+: commonLabels, | ||
| }; | ||
|
|
||
| local namespace = kube.Namespace(params.namespace.name) { | ||
| metadata: commonMetadata + com.makeMergeable({ | ||
| name: params.namespace.name, | ||
| annotations: params.namespace.annotations, | ||
| labels: params.namespace.labels { | ||
| 'app.kubernetes.io/name': params.namespace.name, | ||
| }, | ||
| }), | ||
| }; | ||
|
|
||
| local talosServiceAccount = lib.TalosServiceAccount() { | ||
| metadata: commonMetadata + com.makeMergeable({ | ||
| name: params.talos_service_account.name, | ||
| namespace: params.namespace.name, | ||
| labels: { 'app.kubernetes.io/name': params.talos_service_account.name }, | ||
| }), | ||
| }; | ||
|
|
||
| local cronjob = lib.CronJob(params) { | ||
| metadata: commonMetadata + com.makeMergeable({ | ||
| name: componentName, | ||
| namespace: params.namespace.name, | ||
| labels: { 'app.kubernetes.io/name': componentName }, | ||
| }), | ||
| }; | ||
|
|
||
| local s3Secret = lib.S3CredentialsSecret(params) { | ||
| metadata: commonMetadata + com.makeMergeable({ | ||
| name: params.s3.credentials.name, | ||
| namespace: params.namespace.name, | ||
| labels: { 'app.kubernetes.io/name': params.s3.credentials.name }, | ||
| }), | ||
| }; | ||
|
|
||
| { | ||
| '00_namespace': namespace, | ||
| '10_talos_serviceaccount': talosServiceAccount, | ||
| [if params.s3.credentials.create then '10_s3_credentials']: s3Secret, | ||
| '20_cronjob': cronjob, | ||
| } |
This file contains hidden or 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,120 @@ | ||
| /** | ||
| * Library with public helper methods provided by component talos-backup. | ||
| */ | ||
|
|
||
| local kube = import 'lib/kube.libjsonnet'; | ||
|
|
||
| local talosApiGroup = 'talos.dev'; | ||
|
|
||
| local TalosServiceAccount() = { | ||
| apiVersion: '%s/v1alpha1' % talosApiGroup, | ||
| kind: 'ServiceAccount', | ||
| spec: { | ||
| roles: [ 'os:etcd:backup' ], | ||
| }, | ||
| }; | ||
|
|
||
| local S3CredentialsSecret(params) = kube.Secret(params.s3.credentials.name) { | ||
| stringData: { | ||
| AWS_ACCESS_KEY_ID: params.s3.credentials.access_key_id, | ||
| AWS_SECRET_ACCESS_KEY: params.s3.credentials.secret_access_key, | ||
| }, | ||
| }; | ||
|
|
||
| local image(params) = | ||
| '%(registry)s/%(repository)s:%(tag)s' % params.images.talos_backup; | ||
|
|
||
| local envFromParams(params) = | ||
| local fromSecret(k) = { | ||
| name: k, | ||
| valueFrom: { | ||
| secretKeyRef: { | ||
| name: params.s3.credentials.name, | ||
| key: k, | ||
| }, | ||
| }, | ||
| }; | ||
| local kv(k, v) = { name: k, value: std.toString(v) }; | ||
| local optional(k, v) = if v != '' && v != null then [ kv(k, v) ] else []; | ||
| [ | ||
| fromSecret('AWS_ACCESS_KEY_ID'), | ||
| fromSecret('AWS_SECRET_ACCESS_KEY'), | ||
| kv('AWS_REGION', params.s3.region), | ||
| kv('BUCKET', params.s3.bucket), | ||
| kv('USE_PATH_STYLE', params.s3.use_path_style), | ||
| kv('ENABLE_COMPRESSION', params.enable_compression), | ||
| // Set both env vars to the same value: upstream Split("", ",") returns | ||
| // [""] from an unset var, poisoning the recipient list. Duplicates harmless. | ||
| kv('AGE_RECIPIENT_PUBLIC_KEY', std.join(',', params.age_recipient_public_keys)), | ||
| kv('AGE_X25519_PUBLIC_KEY', std.join(',', params.age_recipient_public_keys)), | ||
| ] | ||
| + optional('CUSTOM_S3_ENDPOINT', params.s3.endpoint) | ||
| + optional('S3_PREFIX', params.s3.prefix) | ||
| + optional('CLUSTER_NAME', params.cluster_name) | ||
| + [ kv(k, params.extra_env[k]) for k in std.objectFields(params.extra_env) ]; | ||
|
|
||
| local CronJob(params) = { | ||
| apiVersion: 'batch/v1', | ||
| kind: 'CronJob', | ||
| spec: { | ||
| schedule: params.schedule, | ||
| concurrencyPolicy: params.concurrency_policy, | ||
| successfulJobsHistoryLimit: params.successful_jobs_history_limit, | ||
| failedJobsHistoryLimit: params.failed_jobs_history_limit, | ||
| jobTemplate: { | ||
| spec: { | ||
| template: { | ||
| spec: { | ||
| restartPolicy: 'OnFailure', | ||
| automountServiceAccountToken: false, | ||
| securityContext: { | ||
| runAsNonRoot: true, | ||
| runAsUser: 1000, | ||
| runAsGroup: 1000, | ||
| fsGroup: 1000, | ||
| seccompProfile: { type: 'RuntimeDefault' }, | ||
| }, | ||
| [if params.node_selector != {} then 'nodeSelector']: params.node_selector, | ||
| [if params.tolerations != [] then 'tolerations']: params.tolerations, | ||
| [if params.affinity != {} then 'affinity']: params.affinity, | ||
| containers: [ { | ||
| name: 'talos-backup', | ||
| image: image(params), | ||
| imagePullPolicy: params.images.talos_backup.pull_policy, | ||
| workingDir: '/tmp', | ||
| command: [ '/talos-backup' ], | ||
| env: envFromParams(params), | ||
| resources: params.resources, | ||
| securityContext: { | ||
| allowPrivilegeEscalation: false, | ||
| readOnlyRootFilesystem: true, | ||
| capabilities: { drop: [ 'ALL' ] }, | ||
| }, | ||
| volumeMounts: [ | ||
| { mountPath: '/tmp', name: 'tmp' }, | ||
| { mountPath: '/.talos', name: 'talos' }, | ||
| { mountPath: '/var/run/secrets/talos.dev', name: 'talos-secrets' }, | ||
| ], | ||
| } ], | ||
| volumes: [ | ||
| { name: 'tmp', emptyDir: {} }, | ||
| { name: 'talos', emptyDir: {} }, | ||
| { | ||
| name: 'talos-secrets', | ||
| secret: { secretName: params.talos_service_account.name }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| { | ||
| TalosServiceAccount: TalosServiceAccount, | ||
| S3CredentialsSecret: S3CredentialsSecret, | ||
| CronJob: CronJob, | ||
|
|
||
| talosApiGroup: talosApiGroup, | ||
| } |
Empty file.
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,36 @@ | ||
| = Talos Linux aware etcd snapshotter. | ||
| = talos-backup | ||
|
|
||
| talos-backup is a Commodore component to manage Talos Linux aware etcd snapshotter.. | ||
| talos-backup is a Commodore component that deploys | ||
| https://github.com/siderolabs/talos-backup[siderolabs/talos-backup] | ||
| as a Kubernetes `CronJob` on a Talos Linux cluster. | ||
| It periodically snapshots etcd through the Talos API, encrypts the snapshot | ||
| with https://age-encryption.org[age], and pushes it to an S3-compatible | ||
| object store. | ||
|
|
||
| See the xref:references/parameters.adoc[parameters] reference for further details. | ||
| == Prerequisites | ||
|
|
||
| The Talos machine configuration must allow the Kubernetes-side Talos API | ||
| access for the `os:etcd:backup` role in the namespace where the component | ||
| is deployed: | ||
|
|
||
| [source,yaml] | ||
| ---- | ||
| machine: | ||
| features: | ||
| kubernetesTalosAPIAccess: | ||
| enabled: true | ||
| allowedRoles: | ||
| - os:etcd:backup | ||
| allowedKubernetesNamespaces: | ||
| - syn-talos-backup | ||
| ---- | ||
|
|
||
| You also need: | ||
|
|
||
| * An age keypair (`age-keygen`). The public key(s) are passed to the | ||
| component; the private key is kept by the operator to decrypt backups. | ||
| * An S3 bucket and credentials. A lifecycle policy on the bucket is the | ||
| recommended way to enforce retention. | ||
|
|
||
| See the xref:references/parameters.adoc[parameters] reference for the full | ||
| list of configurable options. |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.