Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion roles/openshift_setup/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,11 @@ cifmw_openshift_setup_digest_mirrors: []
cifmw_openshift_setup_operator_override_catalog_name: "redhat-operators-4.17"
cifmw_openshift_setup_operator_override_catalog_namespace: "openshift-marketplace"
cifmw_openshift_setup_operator_override_catalog_image: "registry.redhat.io/redhat/redhat-operator-index:v4.17"
cifmw_openshift_setup_apply_marketplace_fix: false
# NOTE(dpawlik): To avoid potential errors, where:
# oc wait pod --all --for=condition=Ready -n openshift-marketplace --timeout=1m
# never pass or operatorhub does not show any items or
# other errors like: " installPlanRef not found - subscription resolution may have failed"
# let's clean the marketplace each time.
cifmw_openshift_setup_apply_marketplace_fix: true
Comment thread
danpawlik marked this conversation as resolved.
cifmw_openshift_setup_marketplace_oneshot: false
cifmw_openshift_setup_marketplace_crontab: true
72 changes: 72 additions & 0 deletions roles/openshift_setup/files/marketplace-crontab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: cifmw-marketplace-fix
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: cifmw-marketplace-fix-sa
namespace: cifmw-marketplace-fix
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: cifmw-marketplace-fix-role
rules:
- apiGroups: [""]
resources: ["pods", "pods/log"]
verbs: ["get", "list", "watch", "delete"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["create"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: cifmw-marketplace-fix-binding
subjects:
- kind: ServiceAccount
name: cifmw-marketplace-fix-sa
namespace: cifmw-marketplace-fix
roleRef:
kind: ClusterRole
name: cifmw-marketplace-fix-role
apiGroup: rbac.authorization.k8s.io
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: cifmw-marketplace-fix-cron
namespace: cifmw-marketplace-fix
spec:
schedule: "*/5 * * * *"
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 3
jobTemplate:
spec:
backoffLimit: 0
template:
spec:
serviceAccountName: cifmw-marketplace-fix-sa
restartPolicy: Never
containers:
- name: cifmw-fix-marketplace
image: registry.redhat.io/openshift4/ose-cli:latest
command: ["/bin/bash", "-c"]
args:
- |
set -euo pipefail

echo "Checking if all pods in openshift-marketplace are Ready..."
if oc wait pod --all --for=condition=Ready -n openshift-marketplace --timeout=1m; then
echo "All pods are Ready - nothing to do."
exit 0
else
echo "Timeout or not all pods Ready, restarting marketplace pods..."
oc delete pods --all -n openshift-marketplace --grace-period=30 || true
echo "Delete command executed."
exit 1
fi
58 changes: 39 additions & 19 deletions roles/openshift_setup/tasks/fix_openshift_marketplace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,43 @@
- not cifmw_openshift_setup_dry_run
- cifmw_openshift_setup_apply_marketplace_fix
block:
- name: Delete the pods from openshift-marketplace namespace
kubernetes.core.k8s:
kind: Pod
state: absent
delete_all: true
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
namespace: openshift-marketplace
- name: Execute marketplace fix once
when: cifmw_openshift_setup_marketplace_oneshot
block:
- name: Delete the pods from openshift-marketplace namespace
kubernetes.core.k8s:
kind: Pod
state: absent
delete_all: true
kubeconfig: "{{ cifmw_openshift_kubeconfig }}"
namespace: openshift-marketplace

- name: Wait for openshift-marketplace pods to be running
environment:
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
PATH: "{{ cifmw_path }}"
ansible.builtin.command:
cmd: >-
oc wait pod --all --for=condition=Ready
-n openshift-marketplace --timeout=1m
register: _pod_status
retries: 4
delay: 10
until: _pod_status.rc == 0
- name: Wait for openshift-marketplace pods to be running
environment:
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
PATH: "{{ cifmw_path }}"
ansible.builtin.command:
cmd: >-
oc wait pod --all --for=condition=Ready
-n openshift-marketplace --timeout=1m
register: _pod_status
retries: 4
delay: 10
until: _pod_status.rc == 0

- name: Execute marketplace fix via crontab
when: cifmw_openshift_setup_marketplace_crontab
block:
- name: Copy marketplace-crontab.yml manifest
ansible.builtin.copy:
src: marketplace-crontab.yml
dest: /tmp/marketplace-crontab.yml
mode: "0644"

- name: Apply marketplace-crontab.yml manifest
ansible.builtin.command: |
oc apply -f /tmp/marketplace-crontab.yml
changed_when: false
environment:
KUBECONFIG: "{{ cifmw_openshift_kubeconfig }}"
PATH: "{{ cifmw_path }}"