Skip to content

Commit

Permalink
Add metalLB
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristian-ZH authored and hardys committed Nov 2, 2023
1 parent d0ee9cf commit cfaae36
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 4 deletions.
6 changes: 6 additions & 0 deletions playbooks/setup_metal3_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
import_role:
name: local-path-provisioner

- name: Deploy metallb
import_role:
name: metallb
vars:
metal3_core_ironic_ip: "{{ metal3_core_ironic_ip }}"

- name: Deploy capi
import_role:
name: capi
Expand Down
1 change: 0 additions & 1 deletion requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ collections:
- name: community.libvirt
- name: containers.podman
- name: kubernetes.core

3 changes: 3 additions & 0 deletions roles/local-path-provisioner/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
local_path_provisioner_repo_url: https://github.com/rancher/local-path-provisioner.git
local_path_provisioner_branch: master

local_path_provisioner_namespace: local-path-storage
local_path_provisioner_release: local-path-provisioner
4 changes: 2 additions & 2 deletions roles/local-path-provisioner/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
- name: Deploy local-path-provisioner via helm
shell: >-
env HELM_EXPERIMENTAL_OCI=1 \
helm upgrade --install local-path-provisioner ./deploy/chart/local-path-provisioner \
--create-namespace --namespace local-path-storage \
helm upgrade --install {{ local_path_provisioner_release }} ./deploy/chart/local-path-provisioner \
--create-namespace --namespace {{ local_path_provisioner_namespace }} \
--atomic --timeout 10m
args:
chdir: ~/local-path-provisioner
1 change: 0 additions & 1 deletion roles/media/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
env HELM_EXPERIMENTAL_OCI=1 \
helm upgrade --install media media \
--create-namespace --namespace metal-cubed \
--values ~/media_helm_overrides.yml \
--atomic --timeout 10m
args:
chdir: ~/charts
7 changes: 7 additions & 0 deletions roles/metallb/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
metallb_helm_repo_name: edge
metallb_helm_repo_url: https://suse-edge.github.io/charts
metallb_helm_chart_ref: edge/metallb

metallb_namespace: metallb-system
metallb_release: metallb
2 changes: 2 additions & 0 deletions roles/metallb/tasks/_suse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---

64 changes: 64 additions & 0 deletions roles/metallb/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
# NOTE(gyee): we'll only include the first one that matches. The rest will be ignored.
- name: Include OS family vars
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_os_family }}.yml"
- "{{ ansible_os_family | lower }}.yml"
- "main.yml"

- name: Include OS distribution vars
include_vars: "{{ item }}"
with_first_found:
- "{{ ansible_distribution | lower | replace(' ', '_') }}.yml"
- "{{ ansible_distribution | replace(' ', '_') }}.yml"
- "main.yml"

- name: Include platform-specific common tasks
include_tasks: "_{{ ansible_os_family | lower }}.yml"

- name: Add metallb helm repo
kubernetes.core.helm_repository:
repo_url: "{{ metallb_helm_repo_url }}"
name: "{{ metallb_helm_repo_name }}"

- name: Deploy metallb helm chart
shell: |
env HELM_EXPERIMENTAL_OCI=1 \
helm upgrade --install {{ metallb_release }} {{ metallb_helm_chart_ref }} \
--create-namespace --namespace {{ metallb_namespace }} \
--atomic --timeout 10m
- name: Wait for metallb to be rolled out
shell: >
kubectl -n {{ metallb_namespace }} rollout status deploy/metallb-controller
register: metallb_rollout_result
retries: 5
delay: 10
until: "'successfully rolled out' in metallb_rollout_result.stdout"

- name: Apply IPAddressPool with kubectl
shell: |
cat <<-EOF | kubectl apply -f -
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: ip-pool
namespace: {{ metallb_namespace }}
spec:
addresses:
- {{ metal3_core_ironic_ip }}/32
EOF
- name: Apply L2Advertisement with kubectl
shell: |
cat <<-EOF | kubectl apply -f -
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: ip-pool-l2-adv
namespace: {{ metallb_namespace }}
spec:
ipAddressPools:
- ip-pool
EOF
1 change: 1 addition & 0 deletions roles/metallb/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
---

0 comments on commit cfaae36

Please sign in to comment.