-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: playbook to update the letsencrypt certificate on the ocp cluster #366
Open
jacobdotcosta
wants to merge
4
commits into
snowdrop:main
Choose a base branch
from
jacobdotcosta:issue-365
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6a3505a
feat: playbook to update the letsencrypt certificate on the ocp cluster
jacobdotcosta d94ac8a
docs: improved the information for the sample
jacobdotcosta 774f2c6
docs: improved the information for the sample
jacobdotcosta 781bb29
docs: improved the information for the sample
jacobdotcosta 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
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,108 @@ | ||
--- | ||
- name: "Get TLS information" | ||
hosts: "{{ source_host | default(['localhost']) }}" | ||
gather_facts: yes | ||
|
||
pre_tasks: | ||
- name: "Check site_name variables" | ||
assert: | ||
that: lookup('varnames', 'site_name') | length > 0 | ||
fail_msg: "site_name is not defined." | ||
quiet: true | ||
|
||
- name: "Check cluster_type variables" | ||
assert: | ||
that: cluster_type is undefined or cluster_type == 'kubernetes' or cluster_type == 'openshift' | ||
fail_msg: "cluster_type must either be kubernetes or openshift (default: openshift)" | ||
quiet: true | ||
|
||
- name: Define Kubeconfig | ||
ansible.builtin.set_fact: | ||
kubeconfig_source: "{{ source_kubeconfig | default('~/.kube/config') }}" | ||
target_cluster_type: "{{ cluster_type | default('openshift') }}" | ||
|
||
- name: Source kubeconfig file | ||
ansible.builtin.debug: | ||
var: kubeconfig_source | ||
|
||
tasks: | ||
|
||
# kubectl -n snowdrop-site get secret www-snowdrop-dev-tls -o json | jq -r '.data["^Cs.key"]' | ||
# k get secret/qshift-snowdrop-dev-tls -n snowdrop-site -ojson | jq -r '.data."tls.crt"' | base64 -d > tls.crt | ||
# k get secret/qshift-snowdrop-dev-tls -n snowdrop-site -ojson | jq -r '.data."tls.key"' | base64 -d > tls.key | ||
- name: Get TLS secret | ||
kubernetes.core.k8s_info: | ||
kubeconfig: "{{ kubeconfig_source }}" | ||
kind: Secret | ||
name: "{{ site_name }}-snowdrop-dev-tls" | ||
namespace: snowdrop-site | ||
register: tls_info | ||
|
||
- name: Print TLS secret | ||
ansible.builtin.debug: | ||
var: tls_info | ||
|
||
- name: Get TLS certificate and key | ||
ansible.builtin.set_fact: | ||
tls_certificate: "{{ tls_info.resources[0].data['tls.crt'] | b64decode }}" | ||
tls_key: "{{ tls_info.resources[0].data['tls.key'] | b64decode }}" | ||
|
||
- name: Print TLS data | ||
ansible.builtin.debug: | ||
msg: | ||
- "{{ tls_certificate }}" | ||
- "{{ tls_key }}" | ||
|
||
- name: "Update certificate on target" | ||
hosts: "{{ target_host | default(['localhost']) }}" | ||
gather_facts: yes | ||
|
||
pre_tasks: | ||
- name: Define Kubeconfig | ||
ansible.builtin.set_fact: | ||
kubeconfig_target: "{{ target_kubeconfig | default('~/.kube/config') }}" | ||
|
||
tasks: | ||
- name: Define target variables for OpenShift | ||
ansible.builtin.set_fact: | ||
target_namespace: openshift-ingress | ||
target_secret_name: "{{ site_name }}-console" | ||
when: target_cluster_type == 'openshift' | ||
|
||
- name: Define target variables for Kubernetes (TBD) | ||
ansible.builtin.set_fact: | ||
target_namespace: ingress-nginx | ||
target_secret_name: "{{ site_name }}-console" | ||
when: target_cluster_type == 'kubernetes' | ||
|
||
# k -n openshift-ingress delete secret/qshift-console | ||
- name: Remove the ingress console secret | ||
kubernetes.core.k8s: | ||
kubeconfig: "{{ kubeconfig_target }}" | ||
state: absent | ||
api_version: v1 | ||
kind: Secret | ||
namespace: openshift-ingress | ||
name: "{{ target_secret_name }}" | ||
|
||
# k -n openshift-ingress create secret tls qshift-console --cert=pki/tls.crt --key=pki/tls.key # --dry-run="client" -oyaml | ||
- name: Create the ingress console secret | ||
kubernetes.core.k8s: | ||
kubeconfig: "{{ kubeconfig_target }}" | ||
state: present | ||
definition: | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: "{{ target_secret_name }}" | ||
namespace: openshift-ingress | ||
# labels: | ||
# app: galaxy | ||
# service: web | ||
type: kubernetes.io/tls | ||
data: | ||
tls.crt: "{{ tls_certificate | b64encode }}" | ||
tls.key: "{{ tls_key | b64encode }}" | ||
|
||
... | ||
# ansible-playbook ansible/playbook/update_letsencrypt_certificate.yml -e source_kubeconfig=${HOME}/.kube/snowdrop-rhosp-snowdrop-k8s-config --check |
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 |
---|---|---|
|
@@ -20,4 +20,7 @@ collections: | |
|
||
- name: ansible.posix | ||
version: 1.5.4 | ||
|
||
- name: kubernetes.core | ||
version: 2.4.1 | ||
... |
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 |
---|---|---|
|
@@ -6,3 +6,6 @@ yq ~= 3.2.2 | |
#ansible >=7.0.0,<8.0.0 | ||
ansible ~= 8.0.0 | ||
ansible-lint | ||
kubernetes >= 12.0.0 | ||
PyYAML >= 3.11 | ||
jsonpatch |
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.
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.
This wording is a bit confusing: "Name of the site". What is a site ? Is it a domain name, something else ?
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.
That's a tough one, it's the name of the prefix given to the TLS secret which coincides with the OCP cluster name.
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.
Ok. That corresponds to a TLS secret which has been created part of a namespace.
Historically the certificate's related stuffs have been created under 2 namespaces using an ansible playbook:
snowdrop-site
andhalkyon-site
.I'm not against the fact to keep this convention and that we create additional secrets, certificates request under the namespace which match a DNS domain (example: snowdrop-site => snowdrop.dev) BUT that should be clear to the user and that they know which namespace they should use. As we only manage one domain name, we could set as default
snowdrop-site
to avoid issues. WDYT ? @jacobdotcosta