Skip to content
Draft
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
19 changes: 18 additions & 1 deletion ansible/roles-infra/infra-openshift-cnv-resources/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ Service item (for `instances[].services` and `containers[].services`):

- `name` (string)
- `ports` (YAML list body inserted under `spec.ports`)
- `type` (string, optional; default `ClusterIP`)
- Each port can include: `port`, `targetPort`, `protocol`, `name`
- For NodePort services: optionally include `nodePort` (30000-32767 range)
- `type` (string, optional; default `ClusterIP`, supports `ClusterIP`, `NodePort`, `LoadBalancer`)

Route item (for `instances[].routes` and `containers[].routes`):

Expand Down Expand Up @@ -133,6 +135,21 @@ Example provisioning excerpt:
ports:
- port: 22
targetPort: 22
- name: node-ssh-nodeport
type: NodePort
ports:
- port: 22
protocol: TCP
targetPort: 22
name: ssh
nodePort: 30022 # Optional - omit for auto-assignment
- name: node-web-lb
type: LoadBalancer
ports:
- port: 80
protocol: TCP
targetPort: 8080
name: http
routes:
- name: node-ssh
service: node-ssh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,69 @@
when:
- service.type | default('ClusterIP') == "LoadBalancer"

- name: If exist set the external IP for the instance and the ports
- name: Set external IP and ports for LoadBalancer service
set_fact:
_instance_external_ip: "{{ svc_fip.resources[0].status.loadBalancer.ingress[0].ip }}"
_instance_external_ports: "{{ service.ports | map(attribute='port') | join(',') }}"
when:
- service.type | default('ClusterIP') == "LoadBalancer"
- svc_fip.resources | length > 0
- svc_fip.resources[0].status.loadBalancer.ingress is defined
- svc_fip.resources[0].status.loadBalancer.ingress | length > 0

- name: Get NodePort service details
register: svc_nodeport
kubernetes.core.k8s_info:
api_version: v1
kind: Service
name: "{{ service.name }}"
namespace: "{{ openshift_cnv_namespace }}"
until: svc_nodeport is success and svc_nodeport.resources | length > 0
retries: 10
delay: 2
when:
- service.type | default('ClusterIP') == "NodePort"

- name: Get worker node IP for NodePort access
register: node_info
kubernetes.core.k8s_info:
api_version: v1
kind: Node
label_selectors:
- "node-role.kubernetes.io/worker"
until: node_info is success and node_info.resources | length > 0
retries: 5
delay: 2
when:
- service.type | default('ClusterIP') == "NodePort"

- name: Fallback to any schedulable node for NodePort access if no workers found
register: node_info
kubernetes.core.k8s_info:
api_version: v1
kind: Node
until: node_info is success and node_info.resources | length > 0
retries: 5
delay: 2
when:
- service.type | default('ClusterIP') == "NodePort"
- node_info.resources | default([]) | length == 0

- name: Set external IP and NodePort values for NodePort service
set_fact:
_instance_external_ip: "{{ node_info.resources[0].status.addresses | selectattr('type', 'equalto', 'InternalIP') | map(attribute='address') | first }}"
_instance_external_ports: "{{ svc_nodeport.resources[0].spec.ports | map(attribute='nodePort') | join(',') }}"
when:
- service.type | default('ClusterIP') == "NodePort"
- svc_nodeport.resources | length > 0
- node_info.resources | length > 0
- node_info.resources[0].status.addresses is defined

- name: Add external_ip and external_ports to the instance
when:
- service.type | default('ClusterIP') == "LoadBalancer"
- service.type | default('ClusterIP') in ["LoadBalancer", "NodePort"]
- _instance_external_ip is defined
- _instance_external_ports is defined
kubernetes.core.k8s:
state: patched
api_version: v1
Expand Down
Loading