Skip to content

Commit

Permalink
Merge branch 'master' into sonic-healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
robertvolkmann authored Feb 26, 2025
2 parents b9e6a08 + d5509d1 commit dd38f54
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 32 deletions.
72 changes: 63 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
.DEFAULT_GOAL := up
.EXPORT_ALL_VARIABLES:

-include .env

# Commands
YQ=docker run --rm -i -v $(shell pwd):/workdir mikefarah/yq:4

Expand Down Expand Up @@ -127,10 +129,16 @@ external_network:
--driver=bridge \
--gateway=203.0.113.1 \
--subnet=203.0.113.0/24 \
--ip-range=203.0.113.0/26 \
--ipv6 \
--gateway=2001:db8::1 \
--subnet=2001:db8::/48 \
--opt "com.docker.network.driver.mtu=9000" \
--opt "com.docker.network.bridge.name=mini_lab_ext" \
--opt "com.docker.network.bridge.enable_ip_masquerade=true" && \
sudo ip route add 203.0.113.128/25 via 203.0.113.128 dev mini_lab_ext; fi
sudo ip route add 203.0.113.128/25 via 203.0.113.128 dev mini_lab_ext && \
sudo ip -6 route add 2001:db8:0:113::/64 via 2001:db8:0:1::1 dev mini_lab_ext; \
fi

.PHONY: env
env:
Expand All @@ -157,17 +165,44 @@ cleanup-partition:
_privatenet: env
docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network list --name user-private-network | grep user-private-network || docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network allocate --partition mini-lab --project 00000000-0000-0000-0000-000000000001 --name user-private-network

.PHONY: update-userdata
update-userdata:
cat files/ignition.yaml | docker run --rm -i ghcr.io/metal-stack/metal-deployment-base:$$DEPLOYMENT_BASE_IMAGE_TAG ct | jq > files/ignition.json

.PHONY: machine
machine: _privatenet
docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl machine create --description test --name test --hostname test --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image $(MACHINE_OS) --size v1-small-x86 --userdata "@/tmp/ignition.json" --networks $(shell docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}')
machine: _privatenet update-userdata
docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl machine create \
--description test \
--name test \
--hostname test \
--project 00000000-0000-0000-0000-000000000001 \
--partition mini-lab \
--image $(MACHINE_OS) \
--size v1-small-x86 \
--userdata "@/tmp/ignition.json" \
--networks $(shell docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}')

.PHONY: firewall
firewall: _privatenet
docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl firewall create --description fw --name fw --hostname fw --project 00000000-0000-0000-0000-000000000001 --partition mini-lab --image firewall-ubuntu-3.0 --size v1-small-x86 --userdata "@/tmp/ignition.json" --firewall-rules-file=/tmp/rules.yaml --networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}')
firewall: _privatenet update-userdata
docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl firewall create \
--description fw \
--name fw \
--hostname fw \
--project 00000000-0000-0000-0000-000000000001 \
--partition mini-lab \
--image firewall-ubuntu-3.0 \
--size v1-small-x86 \
--userdata "@/tmp/ignition.json" \
--firewall-rules-file=/tmp/rules.yaml \
--networks internet-mini-lab,$(shell docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network list --name user-private-network -o template --template '{{ .id }}')

.PHONY: public-ip
public-ip:
@docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network ip create --name test --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 -o template --template "{{ .ipaddress }}"
@docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network ip create --name test --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --addressfamily IPv4 -o template --template "{{ .ipaddress }}"

.PHONY: public-ipv6
public-ipv6:
@docker compose run $(DOCKER_COMPOSE_RUN_ARG) metalctl network ip create --name test --network internet-mini-lab --project 00000000-0000-0000-0000-000000000001 --addressfamily IPv6 -o template --template "{{ .ipaddress }}"

.PHONY: ls
ls: env
Expand Down Expand Up @@ -276,7 +311,7 @@ ssh-machine:
.PHONY: test-connectivity-to-external-service
test-connectivity-to-external-service:
@for i in $$(seq 1 $(MAX_RETRIES)); do \
if $(MAKE) ssh-machine COMMAND="sudo curl --connect-timeout 1 --fail --silent http://203.0.113.10" > /dev/null 2>&1; then \
if $(MAKE) ssh-machine COMMAND="sudo curl --connect-timeout 1 --fail --silent http://203.0.113.100" > /dev/null 2>&1; then \
echo "Connected successfully"; \
exit 0; \
else \
Expand All @@ -291,12 +326,31 @@ test-connectivity-to-external-service:
fi; \
done

.PHONY: test-connectivity-to-external-service-via-ipv6
test-connectivity-to-external-service-via-ipv6:
@for i in $$(seq 1 $(MAX_RETRIES)); do \
if $(MAKE) ssh-machine COMMAND="sudo curl --connect-timeout 1 --fail --silent http://[2001:db8::10]" > /dev/null 2>&1; then \
echo "Connected successfully"; \
exit 0; \
else \
echo "Connection failed"; \
if [ $$i -lt $(MAX_RETRIES) ]; then \
echo "Retrying in 2 seconds..."; \
sleep 2; \
else \
echo "Max retries reached"; \
exit 1; \
fi; \
fi; \
done


## DEV TARGETS ##

.PHONY: dev-env
dev-env:
@echo "export METALCTL_API_URL=http://api.172.17.0.1.nip.io:8080/metal"
@echo "export METALCTL_HMAC=metal-admin"
@echo "export METALCTL_API_URL=${METALCTL_API_URL}"
@echo "export METALCTL_HMAC=${METALCTL_HMAC}"
@echo "export KUBECONFIG=$(KUBECONFIG)"

## Gardener integration
Expand Down
1 change: 1 addition & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ services:
environment:
- METALCTL_HMAC=${METALCTL_HMAC}
- METALCTL_API_URL=${METALCTL_API_URL}
- METALCTL_HMAC_AUTH_TYPE=${METALCTL_HMAC_AUTH_TYPE}
volumes:
- ./files/ssh:/root/.ssh:ro
- ./files/ignition.json:/tmp/ignition.json
Expand Down
4 changes: 4 additions & 0 deletions deploy_control_plane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
tags: ipam-db
- name: metal-roles/control-plane/roles/masterdata-db
tags: masterdata-db
- name: metal-roles/control-plane/roles/auditing-timescaledb
when: metal_auditing_timescaledb_enabled
tags: auditing
- name: metal-roles/control-plane/roles/auditing-meili
when: metal_auditing_meili_enabled
tags: auditing
- name: metal-roles/control-plane/roles/metal
tags: metal
Expand Down
2 changes: 1 addition & 1 deletion docs/network.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion files/certs/grpc/server.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"CN": "metal-api",
"hosts": [
"172.17.0.1"
"172.17.0.1",
"203.0.113.1"
],
"key": {
"algo": "rsa",
Expand Down
11 changes: 11 additions & 0 deletions files/exit/frr.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ log syslog informational
vrf vrfInternet
vni 104009
ip route 0.0.0.0/0 203.0.113.1
ipv6 route ::/0 2001:db8::1
exit-vrf
!
interface eth1
Expand All @@ -18,6 +19,7 @@ interface eth2
!
interface mini_lab_ext
ip address 203.0.113.128/24
ipv6 address 2001:db8:0:1::1/48
!
interface lo
ip address 10.0.0.21/32
Expand All @@ -35,6 +37,10 @@ router bgp 4200000021
redistribute connected route-map LOOPBACKS
exit-address-family
!
address-family ipv6 unicast
redistribute connected route-map LOOPBACKS
exit-address-family
!
address-family l2vpn evpn
advertise-all-vni
neighbor FABRIC activate
Expand All @@ -49,8 +55,13 @@ router bgp 4200000021 vrf vrfInternet
redistribute static
exit-address-family
!
address-family ipv6 unicast
redistribute static
exit-address-family
!
address-family l2vpn evpn
advertise ipv4 unicast
advertise ipv6 unicast
exit-address-family
!
route-map LOOPBACKS permit 10
Expand Down
2 changes: 2 additions & 0 deletions files/exit/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ bridge vlan del vid 1 untagged pvid dev vniInternet
bridge vlan add vid 1000 dev vniInternet
bridge vlan add vid 1000 untagged pvid dev vniInternet
ip link set up dev vniInternet

sysctl -w net.ipv6.conf.all.forwarding=1
4 changes: 3 additions & 1 deletion files/external_service/network.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh
set -o errexit -o xtrace

ip addr add 203.0.113.10/24 dev mini_lab_ext
ip addr add 203.0.113.100/24 dev mini_lab_ext
ip route add 203.0.113.128/25 via 203.0.113.128 dev mini_lab_ext
ip -6 addr add 2001:db8::10/48 dev mini_lab_ext
ip -6 route add 2001:db8:0:113::/64 via 2001:db8:0:1::1 dev mini_lab_ext
10 changes: 6 additions & 4 deletions files/ignition.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"ignition": {
"config": {},
"security": {},
"security": {
"tls": {}
},
"timeouts": {},
"version": "2.3.0"
"version": "2.2.0"
},
"networkd": {},
"passwd": {},
Expand All @@ -14,10 +16,10 @@
"path": "/etc/hosts.allow",
"append": true,
"contents": {
"source": "data:,ALL%3A%20%5Bfe80%3A%3A%5D%2F10%0D%0AALL%3A%20203.0.113.1%0D%0A",
"source": "data:,ALL%3A%20%5Bfe80%3A%3A%5D%2F10%0AALL%3A%20203.0.113.1%0AALL%3A%20%5B2001%3Adb8%3A%3A1%5D%0A",
"verification": {}
},
"mode": 644
"mode": 420
}
]
},
Expand Down
11 changes: 11 additions & 0 deletions files/ignition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
storage:
files:
- path: /etc/hosts.allow
filesystem: root
append: true
mode: 0644
contents:
inline: |
ALL: [fe80::]/10
ALL: 203.0.113.1
ALL: [2001:db8::1]
25 changes: 25 additions & 0 deletions files/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ egress:
- comment: allow outgoing http and https
ports:
- 80
protocol: TCP
to:
- 0.0.0.0/0
- comment: allow outgoing http
ports:
- 80
protocol: TCP
to:
- ::/0
- comment: allow outgoing https
ports:
- 443
protocol: TCP
to:
- 0.0.0.0/0
- comment: allow outgoing https
ports:
- 443
protocol: TCP
to:
- ::/0
- comment: allow outgoing dns via tcp
ports:
- 53
Expand Down Expand Up @@ -38,3 +55,11 @@ ingress:
- 203.0.113.0/24
to:
- 203.0.113.128/25
- comment: allow incoming ssh
ports:
- 22
protocol: TCP
from:
- 2001:db8::1/128
to:
- 2001:db8:0:113::/64
21 changes: 20 additions & 1 deletion images/sonic/launch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python3
import fcntl
import glob
import ipaddress
import json
import logging
import os
Expand Down Expand Up @@ -227,6 +228,8 @@ def wait_until_all_interfaces_are_connected(interfaces: int) -> None:
time.sleep(1)


# This function works only for IPv4 interfaces.
# See: man 7 netdevice
def get_ip_address(iface: str) -> str:
# Source: https://bit.ly/3dROGBN
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand All @@ -237,6 +240,20 @@ def get_ip_address(iface: str) -> str:
)[20:24])


# This function works only for IPv4 interfaces
# See: man 7 netdevice
def get_netmask(iface: str) -> str:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
netmask = socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x891b, # SIOCGIFNETMASK
struct.pack('256s', iface.encode('utf-8'))
)[20:24])
return str(ipaddress.ip_network(f"0.0.0.0/{netmask}").prefixlen)


# This function works only for IPv4 interfaces
# Set: man 7 netdevice
def get_mac_address(iface: str) -> str:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
mac = fcntl.ioctl(
Expand All @@ -247,6 +264,7 @@ def get_mac_address(iface: str) -> str:
return ':'.join('%02x' % b for b in mac)


# This function works only for IPv4 interfaces
def get_default_gateway() -> str:
# Source: https://splunktool.com/python-get-default-gateway-for-a-local-interfaceip-address-in-linux
with open("/proc/net/route") as fh:
Expand Down Expand Up @@ -295,6 +313,7 @@ def parse_port_config() -> dict[str, dict]:


def create_config_db(hwsku: str) -> dict:
mgmt_interface_cidr = get_ip_address("eth0") + "/" + get_netmask("eth0")
return {
'AUTO_TECHSUPPORT': {
'GLOBAL': {
Expand Down Expand Up @@ -326,7 +345,7 @@ def create_config_db(hwsku: str) -> dict:
}
},
'MGMT_INTERFACE': {
f'eth0|{get_ip_address("eth0")}/16': {
f'eth0|{mgmt_interface_cidr}': {
'gwaddr': get_default_gateway(),
}
},
Expand Down
14 changes: 12 additions & 2 deletions inventories/group_vars/all/images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ setup_yaml:
# metal_masterdata_api_image_tag:
# metal_console_image_name:
# metal_console_image_tag:
# metal_core_image_name:
# metal_core_image_tag:
# ...
#
# further overrides can be looked up in the metal-role projects where the mapping is defined:
# https://github.com/metal-stack/metal-roles/blob/master/defaults/main.yaml

##
## for ansible roles
Expand All @@ -30,3 +30,13 @@ setup_yaml:
# ansible_common_version:
# metal_roles_version:
# metal_ansible_modules_version:

##
## helm charts
##

# metal_helm_chart_version:
# metal_helm_chart_repo:

# further overrides can be looked up in the metal-role projects where the mapping is defined:
# https://github.com/metal-stack/metal-roles/blob/master/defaults/main.yaml
3 changes: 3 additions & 0 deletions inventories/group_vars/control-plane/auditing.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
---
auditing_timescaledb_storage_size: 10Gi
auditing_timescaledb_resources: {}

auditing_meili_storage_size: 10Gi
auditing_meili_resources: {}
Loading

0 comments on commit dd38f54

Please sign in to comment.