Skip to content

Commit

Permalink
✨ Migrate Pathfinder assessments and remove Pathfinder
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Montleon <jmontleo@redhat.com>
  • Loading branch information
jmontleon committed Oct 31, 2023
1 parent 6ca464a commit b06c420
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 68 deletions.
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
ARG OPERATOR_SDK_VERSION=v1.28.1
FROM quay.io/operator-framework/ansible-operator:$OPERATOR_SDK_VERSION

USER 0
COPY tools/upgrades/migrate-pathfinder-assessments.py /usr/local/bin/migrate-pathfinder-assessments.py
COPY tools/upgrades/jwt.sh /usr/local/bin/jwt.sh
RUN dnf -y install openssl && dnf clean all
USER 1001

COPY requirements.yml ${HOME}/requirements.yml
RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \
&& chmod -R ug+rwx ${HOME}/.ansible
Expand Down
1 change: 0 additions & 1 deletion roles/tackle/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ app_version: "{{ lookup('env', 'VERSION') }}"
feature_auth_required: "{{ false if app_profile == 'konveyor' else true }}"
feature_auth_type: keycloak
feature_isolate_namespace: true
feature_pathfinder: true

# Environment
openshift_cluster: false
Expand Down
145 changes: 78 additions & 67 deletions roles/tackle/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,72 +272,6 @@
retries: 30
delay: 5

- when:
- feature_pathfinder|bool
block:
- name: "Setup PathFinder PostgreSQL PersistentVolume"
k8s:
state: present
definition: "{{ lookup('template', 'persistentvolumeclaim-pathfinder-postgresql.yml.j2') }}"

- name: "Check if PathFinder PostgreSQL Secret exists already so we don't update it"
k8s_info:
api_version: v1
kind: Secret
name: "{{ pathfinder_database_secret_name }}"
namespace: "{{ app_namespace }}"
register: pathfinder_database_secret_status

- when: (pathfinder_database_secret_status.resources | length) == 0
block:
- name: "Generate random values for PathFinder PostgreSQL username and password"
set_fact:
pathfinder_database_db_username: "user-{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=4') }}"
pathfinder_database_db_password: "{{ lookup('password', '/dev/null chars=ascii_lowercase,ascii_uppercase,digits length=16') }}"

- name: "Encode PathFinder PostgreSQL username and password"
set_fact:
pathfinder_database_db_username_b64: "{{ pathfinder_database_db_username | b64encode }}"
pathfinder_database_db_password_b64: "{{ pathfinder_database_db_password | b64encode }}"

- name: "Setup PathFinder PostgreSQL Secret"
k8s:
state: present
definition: "{{ lookup('template', 'secret-pathfinder-postgresql.yml.j2') }}"

- name: "Setup PathFinder PostgreSQL Service"
k8s:
state: present
definition: "{{ lookup('template', 'service-pathfinder-postgresql.yml.j2') }}"

- name: "Setup PathFinder PostgreSQL Deployment"
k8s:
state: present
definition: "{{ lookup('template', 'deployment-pathfinder-postgresql.yml.j2') }}"

- name: "Check status of PathFinder PostgreSQL"
kubernetes.core.k8s_info:
api_version: v1
kind: Pod
namespace: "{{ app_namespace }}"
label_selectors:
- app.kubernetes.io/name = {{ pathfinder_database_service_name }}
wait: true
wait_condition:
type: "Ready"
status: "True"
wait_timeout: 240

- name: "Setup PathFinder Service"
k8s:
state: present
definition: "{{ lookup('template', 'service-pathfinder.yml.j2') }}"

- name: "Setup PathFinder Deployment"
k8s:
state: present
definition: "{{ lookup('template', 'deployment-pathfinder.yml.j2') }}"

- name: "Setup Hub API Database PersistentVolumeClaim"
k8s:
state: present
Expand Down Expand Up @@ -392,7 +326,6 @@
state: present
definition: "{{ lookup('template', 'secret-hub.yml.j2') }}"


- name: "Look up Keycloak DB Secret for Hashing"
set_fact:
keycloak_db_secret:
Expand Down Expand Up @@ -519,3 +452,81 @@
when:
- hub_metrics_enabled|bool
- openshift_cluster|bool

- name: "Check if pathfinder exists"
kubernetes.core.k8s_info:
api_version: v1
kind: Pod
namespace: "{{ app_namespace }}"
label_selectors:
- app.kubernetes.io/name = {{ app_name }}-{{ pathfinder_component_name }}
register: pathfinder_pod

- when:
- (pathfinder_pod.resources | length) > 0

Check warning on line 466 in roles/tackle/tasks/main.yml

View workflow job for this annotation

GitHub Actions / build

yaml[indentation]

Wrong indentation: expected 4 but found 2
block:
- name: "Wait for Pathfinder to be Ready"

Check warning on line 468 in roles/tackle/tasks/main.yml

View workflow job for this annotation

GitHub Actions / build

yaml[indentation]

Wrong indentation: expected 4 but found 2
kubernetes.core.k8s_info:
api_version: v1
kind: Pod
namespace: "{{ app_namespace }}"
label_selectors:
- app.kubernetes.io/name = {{ app_name }}-{{ pathfinder_component_name }}
wait: true
wait_condition:
type: "Ready"
status: "True"
wait_timeout: 240

- name: "Wait for the Hub to be Ready"
kubernetes.core.k8s_info:
api_version: v1
kind: Pod
namespace: "{{ app_namespace }}"
label_selectors:
- app.kubernetes.io/name = {{ app_name }}-{{ hub_component_name }}
wait: true
wait_condition:
type: "Ready"
status: "True"
wait_timeout: 240

- name: Retrieve Hub Secret
kubernetes.core.k8s_info:
api_version: v1
kind: Secret
name: "{{ hub_secret_name }}"
namespace: "{{ app_namespace }}"
register: hub_secret

- name: Set Hub Token
set_fact:
hub_key: "{{ hub_secret.resources[0].data.addon_token | b64decode }}"

- name: Migrate assessments

Check failure on line 506 in roles/tackle/tasks/main.yml

View workflow job for this annotation

GitHub Actions / build

no-changed-when

Commands should not change things if nothing needs doing.
shell: /usr/local/bin/migrate-pathfinder-assessments.py -p http://{{ pathfinder_service_name }}:8080/pathfinder -b http://{{ hub_service_name }}:8080 -t $(/usr/local/bin/jwt.sh {{ hub_key }})

Check warning on line 507 in roles/tackle/tasks/main.yml

View workflow job for this annotation

GitHub Actions / build

yaml[line-length]

Line too long (195 > 160 characters)

- name: "Remove PathFinder PostgreSQL Secret"
k8s:
state: absent
definition: "{{ lookup('template', 'secret-pathfinder-postgresql.yml.j2') }}"

- name: "Remove PathFinder PostgreSQL Service"
k8s:
state: absent
definition: "{{ lookup('template', 'service-pathfinder-postgresql.yml.j2') }}"

- name: "Remove PathFinder PostgreSQL Deployment"
k8s:
state: absent
definition: "{{ lookup('template', 'deployment-pathfinder-postgresql.yml.j2') }}"

- name: "Remove PathFinder Service"
k8s:
state: absent
definition: "{{ lookup('template', 'service-pathfinder.yml.j2') }}"

- name: "Remove PathFinder Deployment"
k8s:
state: absent
definition: "{{ lookup('template', 'deployment-pathfinder.yml.j2') }}"
28 changes: 28 additions & 0 deletions tools/upgrades/jwt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
#
# Usage: jwt.sh <key> <scope>
#
# scope - (string) space-separated scopes. (default: *:*).
#
key=$1
scope="${2:-*:*}"
header='{"typ":"JWT","alg":"HS512"}'
payload="{\"user\":\"operator\",\"scope\":\"${scope}\"}"
headerStr=$(echo -n ${header} \
| base64 -w 0 \
| sed s/\+/-/g \
| sed 's/\//_/g' \
| sed -E s/=+$//)
payloadStr=$(echo -n ${payload} \
| base64 -w 0 \
| sed s/\+/-/g \
| sed 's/\//_/g' \
| sed -E s/=+$//)
signStr=$(echo -n "${headerStr}.${payloadStr}" \
| openssl dgst -sha512 -hmac ${key} -binary \
| base64 -w 0 \
| sed s/\+/-/g \
| sed 's/\//_/g' \
| sed -E s/=+$//)
token="${headerStr}.${payloadStr}.${signStr}"
echo "${token}"

0 comments on commit b06c420

Please sign in to comment.