refactor(metallb)!: use CRD instead of ConfigMap

Deprecated https://metallb.universe.tf/configuration/migration_to_crds
This commit is contained in:
Khue Doan 2023-05-19 11:37:15 +07:00
parent 177bac6345
commit a5ecaafe50
7 changed files with 46 additions and 54 deletions

View File

@ -3,10 +3,3 @@
roles:
- k3s
- automatic_upgrade
- name: Create some basic config
hosts: localhost
environment:
KUBECONFIG: ./kubeconfig.yaml
roles:
- metallb_config

View File

@ -1,9 +0,0 @@
metallb_namespace: metallb-system
metallb_subnet_cidr_prefix: 27 # /27
metallb_subnet_index: -1 # last subnet
metallb_addresses: | # Use the last subnet with the specified size from the network
{{
(ansible_default_ipv4.network + '/' + ansible_default_ipv4.netmask)
| ansible.utils.ipaddr('net')
| ansible.utils.ipsubnet(metallb_subnet_cidr_prefix, metallb_subnet_index)
}}

View File

@ -1,10 +0,0 @@
- name: Ensure MetalLB namespace exist
kubernetes.core.k8s:
api_version: v1
kind: Namespace
name: "{{ metallb_namespace }}"
state: present
- name: Create MetalLB config base on network info
kubernetes.core.k8s:
definition: "{{ lookup('template', 'configmap.yaml.j2') | from_yaml }}"

View File

@ -1,12 +0,0 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: metallb-config
namespace: {{ metallb_namespace }}
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- {{ metallb_addresses }}

46
scripts/configure vendored
View File

@ -13,10 +13,13 @@ import sys
from rich.prompt import Confirm, Prompt
default_seed_repo = "https://github.com/khuedoan/homelab"
default_domain = "khuedoan.com"
default_timezone = "Asia/Ho_Chi_Minh"
default_terraform_workspace = "khuedoan"
upstream_config = {
"seed_repo": "https://github.com/khuedoan/homelab",
"domain": "khuedoan.com",
"timezone": "Asia/Ho_Chi_Minh",
"terraform_workspace": "khuedoan",
"loadbalancer_ip_range": "192.168.1.224/27",
}
def check_python_version(required_version: str) -> None:
@ -43,12 +46,13 @@ def main() -> None:
)
editor = Prompt.ask("Select text editor", default='nvim')
domain = Prompt.ask("Enter your domain", default=default_domain)
seed_repo = Prompt.ask("Enter seed repo", default=default_seed_repo)
timezone = Prompt.ask("Enter time zone", default=default_timezone)
domain = Prompt.ask("Enter your domain", default=upstream_config['domain'])
seed_repo = Prompt.ask("Enter seed repo", default=upstream_config['seed_repo'])
timezone = Prompt.ask("Enter time zone", default=upstream_config['timezone'])
loadbalancer_ip_range = Prompt.ask("Enter IP range for load balancer", default=upstream_config['loadbalancer_ip_range'])
find_and_replace(
pattern=default_domain,
pattern=upstream_config['domain'],
replacement=domain,
paths=[
".ci",
@ -61,7 +65,7 @@ def main() -> None:
)
find_and_replace(
pattern=default_seed_repo,
pattern=upstream_config['seed_repo'],
replacement=seed_repo,
paths=[
"bootstrap",
@ -70,7 +74,7 @@ def main() -> None:
)
find_and_replace(
pattern=default_timezone,
pattern=upstream_config['timezone'],
replacement=timezone,
paths=[
"apps",
@ -79,21 +83,31 @@ def main() -> None:
]
)
find_and_replace(
pattern=upstream_config['loadbalancer_ip_range'],
replacement=loadbalancer_ip_range,
paths=[
"system/metallb-system/templates/ipaddresspool.yaml",
]
)
if Confirm.ask("Update server list?", default=True):
subprocess.run(
[editor, 'metal/inventories/prod.yml']
)
if Confirm.ask("Do you want to use managed services?"):
terraform_workspace = Prompt.ask("Enter Terraform Workspace", default=default_terraform_workspace)
terraform_workspace = Prompt.ask("Enter Terraform Workspace", default=upstream_config['terraform_workspace'])
find_and_replace(
pattern=default_terraform_workspace,
pattern=upstream_config['terraform_workspace'],
replacement=terraform_workspace,
paths=[
"external/versions.tf"
]
)
subprocess.run(
[editor, 'metal/inventories/prod.yml']
)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,8 @@
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: default
namespace: {{ .Release.Namespace }}
spec:
addresses:
- 192.168.1.224/27

View File

@ -0,0 +1,8 @@
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: default
namespace: {{ .Release.Namespace }}
spec:
ipAddressPools:
- default