Repository navigation
Add espejote-managed dynamic fact for cluster CA #12
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 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ad3ba0d
Add espejote-managed dynamic fact for cluster CA
HappyTetrahedron a573ee5
Apply batched suggestions from code review
HappyTetrahedron 9ca01b1
Regenerate golden tests
HappyTetrahedron 760ae2e
Add documentation
HappyTetrahedron 29e6f81
Fix output paths
HappyTetrahedron 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| local esp = import 'lib/espejote.libsonnet'; | ||
| local kap = import 'lib/kapitan.libjsonnet'; | ||
| local kube = import 'lib/kube.libjsonnet'; | ||
| local inv = kap.inventory(); | ||
|
|
||
| local params = inv.parameters.capi_provider_talos; | ||
| local ca_secret_name = '%s-ca' % params.clusterName; | ||
|
|
||
| local syn_namespace = 'syn'; | ||
|
|
||
| local sa = kube.ServiceAccount('cluster-ca-dynamic-fact-manager') { | ||
| metadata+: { | ||
| namespace: params.namespace, | ||
| }, | ||
| }; | ||
|
|
||
| local syn_role = kube.Role('cluster:ca-dynamic-fact-manager') { | ||
| metadata+: { | ||
| namespace: syn_namespace, | ||
| }, | ||
| rules: [ | ||
| { | ||
| apiGroups: [ '' ], | ||
| resources: [ 'configmaps' ], | ||
| verbs: [ 'get', 'list', 'watch' ], | ||
| }, | ||
| { | ||
| apiGroups: [ '' ], | ||
| resources: [ 'configmaps' ], | ||
| resourceNames: [ 'capi-ca-fact' ], | ||
|
HappyTetrahedron marked this conversation as resolved.
Outdated
|
||
| verbs: [ 'create', 'update', 'patch' ], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| local role = kube.Role('cluster:ca-dynamic-fact-manager') { | ||
|
HappyTetrahedron marked this conversation as resolved.
Outdated
|
||
| metadata+: { | ||
| namespace: params.namespace, | ||
| }, | ||
| rules: [ | ||
| { | ||
| apiGroups: [ '' ], | ||
| resources: [ 'secrets' ], | ||
| resourceNames: [ ca_secret_name ], | ||
| verbs: [ 'get', 'list', 'watch' ], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| local syn_rolebinding = | ||
| kube.RoleBinding('cluster:ca-dynamic-fact-manager') { | ||
|
HappyTetrahedron marked this conversation as resolved.
Outdated
|
||
| metadata+: { | ||
| namespace: syn_namespace, | ||
| }, | ||
| roleRef_: syn_role, | ||
| subjects_: [ sa ], | ||
| }; | ||
|
|
||
| local rolebinding = | ||
| kube.RoleBinding('cluster:ca-dynamic-fact-manager') { | ||
|
HappyTetrahedron marked this conversation as resolved.
Outdated
|
||
| metadata+: { | ||
| namespace: params.namespace, | ||
| }, | ||
| roleRef_: role, | ||
| subjects_: [ sa ], | ||
| }; | ||
|
|
||
|
|
||
| local mr = esp.managedResource('cluster-ca-dynamic-fact', params.namespace) { | ||
| spec: { | ||
| // Set force=true so we can take ownership of previously manually edited | ||
| // fields in `data`. | ||
| applyOptions: { force: true }, | ||
| serviceAccountRef: { name: sa.metadata.name }, | ||
| context: [ | ||
| { | ||
| name: 'source', | ||
| resource: { | ||
| apiVersion: 'v1', | ||
| kind: 'Secret', | ||
| name: ca_secret_name, | ||
| }, | ||
| }, | ||
| ], | ||
| triggers: [ | ||
| { | ||
| name: 'source', | ||
| watchContextResource: { | ||
| name: 'source', | ||
| }, | ||
| }, | ||
| { | ||
| name: 'target', | ||
| watchResource: { | ||
| apiVersion: 'v1', | ||
| kind: 'ConfigMap', | ||
| namespace: syn_namespace, | ||
| name: 'capi-ca-fact', | ||
|
HappyTetrahedron marked this conversation as resolved.
Outdated
|
||
| }, | ||
| }, | ||
| ], | ||
| template: importstr 'espejote-templates/manage-ca-fact.jsonnet', | ||
| }, | ||
| }; | ||
|
|
||
| if std.member(inv.applications, 'espejote') then { | ||
| cluster_ca_dynamic_fact: [ sa, role, rolebinding, syn_role, syn_rolebinding, mr ], | ||
| } else std.trace( | ||
| 'Not rendering Espejote-managed CA fact because component-espejote is missing.', | ||
| {} | ||
| ) | ||
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,22 @@ | ||
| local esp = import 'espejote.libsonnet'; | ||
| local src = | ||
| local srcs = esp.context().source; | ||
| assert std.length(srcs) == 1 : 'Expected source context to have length 1'; | ||
| srcs[0]; | ||
| { | ||
| apiVersion: 'v1', | ||
| kind: 'ConfigMap', | ||
| metadata: { | ||
| name: 'capi-ca-fact', | ||
|
HappyTetrahedron marked this conversation as resolved.
Outdated
|
||
| namespace: 'syn', | ||
| labels: { | ||
| 'app.kubernetes.io/managed-by': 'espejote', | ||
| 'steward.syn.tools/include-facts': '', | ||
| }, | ||
| }, | ||
| data: { | ||
| facts: std.manifestJsonMinified({ | ||
| talosAPICertificateAuthorityData: src.data['tls.crt'], | ||
| }), | ||
| }, | ||
| } | ||
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
144 changes: 144 additions & 0 deletions
144
tests/golden/defaults/capi-provider-talos/cluster_ca_dynamic_fact.yaml
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,144 @@ | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| annotations: {} | ||
| labels: | ||
| name: cluster-ca-dynamic-fact-manager | ||
| name: cluster-ca-dynamic-fact-manager | ||
| namespace: syn-cluster-api | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: Role | ||
| metadata: | ||
| annotations: {} | ||
| labels: | ||
| name: cluster-ca-dynamic-fact-manager | ||
| name: cluster:ca-dynamic-fact-manager | ||
| namespace: syn-cluster-api | ||
| rules: | ||
| - apiGroups: | ||
| - '' | ||
| resourceNames: | ||
| - c-green-test-1234-ca | ||
| resources: | ||
| - secrets | ||
| verbs: | ||
| - get | ||
| - list | ||
| - watch | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| annotations: {} | ||
| labels: | ||
| name: cluster-ca-dynamic-fact-manager | ||
| name: cluster:ca-dynamic-fact-manager | ||
| namespace: syn-cluster-api | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: Role | ||
| name: cluster:ca-dynamic-fact-manager | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: cluster-ca-dynamic-fact-manager | ||
| namespace: syn-cluster-api | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: Role | ||
| metadata: | ||
| annotations: {} | ||
| labels: | ||
| name: cluster-ca-dynamic-fact-manager | ||
| name: cluster:ca-dynamic-fact-manager | ||
| namespace: syn | ||
| rules: | ||
| - apiGroups: | ||
| - '' | ||
| resources: | ||
| - configmaps | ||
| verbs: | ||
| - get | ||
| - list | ||
| - watch | ||
| - apiGroups: | ||
| - '' | ||
| resourceNames: | ||
| - capi-ca-fact | ||
| resources: | ||
| - configmaps | ||
| verbs: | ||
| - create | ||
| - update | ||
| - patch | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: RoleBinding | ||
| metadata: | ||
| annotations: {} | ||
| labels: | ||
| name: cluster-ca-dynamic-fact-manager | ||
| name: cluster:ca-dynamic-fact-manager | ||
| namespace: syn | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: Role | ||
| name: cluster:ca-dynamic-fact-manager | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: cluster-ca-dynamic-fact-manager | ||
| namespace: syn-cluster-api | ||
| --- | ||
| apiVersion: espejote.io/v1alpha1 | ||
| kind: ManagedResource | ||
| metadata: | ||
| annotations: | ||
| argocd.argoproj.io/sync-options: SkipDryRunOnMissingResource=true | ||
| labels: | ||
| app.kubernetes.io/name: cluster-ca-dynamic-fact | ||
| name: cluster-ca-dynamic-fact | ||
| namespace: syn-cluster-api | ||
| spec: | ||
| applyOptions: | ||
| force: true | ||
| context: | ||
| - name: source | ||
| resource: | ||
| apiVersion: v1 | ||
| kind: Secret | ||
| name: c-green-test-1234-ca | ||
| serviceAccountRef: | ||
| name: cluster-ca-dynamic-fact-manager | ||
| template: | | ||
| local esp = import 'espejote.libsonnet'; | ||
| local src = | ||
| local srcs = esp.context().source; | ||
| assert std.length(srcs) == 1 : 'Expected source context to have length 1'; | ||
| srcs[0]; | ||
| { | ||
| apiVersion: 'v1', | ||
| kind: 'ConfigMap', | ||
| metadata: { | ||
| name: 'capi-ca-fact', | ||
| namespace: 'syn', | ||
| labels: { | ||
| 'app.kubernetes.io/managed-by': 'espejote', | ||
| 'steward.syn.tools/include-facts': '', | ||
| }, | ||
| }, | ||
| data: { | ||
| facts: std.manifestJsonMinified({ | ||
| talosAPICertificateAuthorityData: src.data['tls.crt'], | ||
| }), | ||
| }, | ||
| } | ||
| triggers: | ||
| - name: source | ||
| watchContextResource: | ||
| name: source | ||
| - name: target | ||
| watchResource: | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| name: capi-ca-fact | ||
| namespace: syn |
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.