kevydotvinu / openshift-network-playground

The OpenShift Network Playground is built for advanced OpenShift users who needs to quickly build and test different OpenShift network scenarios.
https://kevy.gitbook.io/onp
MIT License
3 stars 1 forks source link

Add sno4 Make target #22

Closed kevydotvinu closed 1 year ago

kevydotvinu commented 1 year ago
kevydotvinu commented 1 year ago
$ cat .Makefile
sno4: ssh-pullsecret
        @echo "Creating SNO4 cluster ..."
        @openshift-network-playground/sno.sh ${RELEASE} sno4
        @/usr/local/bin/openshift-install --log-level=${LOGLEVEL} \
                                                    --dir=$(SCRIPT_DIR)/openshift-network-playground/sno4 create single-node-ignition-config
        @sudo podman run --privileged \
                  --quiet \
                  --pull always \
                  --rm \
                  -v /dev:/dev \
                  -v /run/udev:/run/udev \
                  -v /:/data \
                  -w /data \
                  quay.io/coreos/coreos-installer:release iso ignition embed -fi \
                  var/home/onp/openshift-network-playground/sno4/bootstrap-in-place-for-live-iso.ign \
                  opt/openshift-network-playground/libvirt/sno4/rhcos-live.iso
        @sudo podman run --privileged \
                  --quiet \
                  --pull always \
                  --rm \
                  -v /dev:/dev \
                  -v /run/udev:/run/udev \
                  -v /:/data \
                  -w /data \
                  quay.io/coreos/coreos-installer:release iso network embed -fk \
                  var/home/onp/openshift-network-playground/sno4-enp1s0.nmconnection \
                  opt/openshift-network-playground/libvirt/sno4/rhcos-live.iso
        @sudo virt-install --name sno4 \
                                 --quiet \
                                 --os-variant fedora-coreos-stable \
                                 --vcpu 4 \
                                 --memory 16384 \
                                 --boot menu=on \
                                 --pxe \
                                 --disk /opt/openshift-network-playground/libvirt/sno4/sno4.img,bus=scsi \
                                 --cdrom /opt/openshift-network-playground/libvirt/sno4/rhcos-live.iso \
                                 --network bridge=sno0 \
                                 --noautoconsole \
                                 --graphics spice,listen=0.0.0.0
        @$(SCRIPT_DIR)/openshift-network-playground/sno-restart.sh sno4
        @/usr/local/bin/openshift-install --log-level=${LOGLEVEL} \
                                                    --dir=$(SCRIPT_DIR)/openshift-network-playground/sno4 wait-for install-complete
$ cat .Makefile
sno6: ssh-pullsecret
        @echo "Creating SNO6 cluster ..."
        @openshift-network-playground/sno.sh ${RELEASE} sno6
        @/usr/local/bin/openshift-install --log-level=${LOGLEVEL} \
                                                    --dir=$(SCRIPT_DIR)/openshift-network-playground/sno6 create single-node-ignition-config
        @sudo podman run --privileged \
                  --quiet \
                  --pull always \
                  --rm \
                  -v /dev:/dev \
                  -v /run/udev:/run/udev \
                  -v /:/data \
                  -w /data \
                  quay.io/coreos/coreos-installer:release iso ignition embed -fi \
                  var/home/onp/openshift-network-playground/sno6/bootstrap-in-place-for-live-iso.ign \
                  opt/openshift-network-playground/libvirt/sno6/rhcos-live.iso
        @sudo podman run --privileged \
                  --quiet \
                  --pull always \
                  --rm \
                  -v /dev:/dev \
                  -v /run/udev:/run/udev \
                  -v /:/data \
                  -w /data \
                  quay.io/coreos/coreos-installer:release iso network embed -fk \
                  var/home/onp/openshift-network-playground/sno6-enp1s0.nmconnection \
                  opt/openshift-network-playground/libvirt/sno6/rhcos-live.iso
        @sudo virt-install --name sno6 \
                                 --quiet \
                                 --os-variant fedora-coreos-stable \
                                 --vcpu 4 \
                                 --memory 16384 \
                                 --boot menu=on \
                                 --pxe \
                                 --disk /opt/openshift-network-playground/libvirt/sno4/sno4.img,bus=scsi \
                                 --cdrom /opt/openshift-network-playground/libvirt/sno4/rhcos-live.iso \
                                 --network bridge=sno0 \
                                 --noautoconsole \
                                 --graphics spice,listen=0.0.0.0
        @$(SCRIPT_DIR)/openshift-network-playground/sno-restart.sh sno6
        @/usr/local/bin/openshift-install --log-level=${LOGLEVEL} \
                                                    --dir=$(SCRIPT_DIR)/openshift-network-playground/sno6 wait-for install-complete
$ cat .Makefile
sno64: ssh-pullsecret
        @echo "Creating SNO64 cluster ..."
        @openshift-network-playground/sno.sh ${RELEASE} sno64
        @/usr/local/bin/openshift-install --log-level=${LOGLEVEL} \
                                                    --dir=$(SCRIPT_DIR)/openshift-network-playground/sno64 create single-node-ignition-config
        @sudo podman run --privileged \
                  --quiet \
                  --pull always \
                  --rm \
                  -v /dev:/dev \
                  -v /run/udev:/run/udev \
                  -v /:/data \
                  -w /data \
                  quay.io/coreos/coreos-installer:release iso ignition embed -fi \
                  var/home/onp/openshift-network-playground/sno64/bootstrap-in-place-for-live-iso.ign \
                  opt/openshift-network-playground/libvirt/sno64/rhcos-live.iso
        @sudo podman run --privileged \
                  --quiet \
                  --pull always \
                  --rm \
                  -v /dev:/dev \
                  -v /run/udev:/run/udev \
                  -v /:/data \
                  -w /data \
                  quay.io/coreos/coreos-installer:release iso network embed -fk \
                  var/home/onp/openshift-network-playground/sno64-enp1s0.nmconnection \
                  opt/openshift-network-playground/libvirt/sno64/rhcos-live.iso
        @sudo virt-install --name sno64 \
                                 --quiet \
                                 --os-variant fedora-coreos-stable \
                                 --vcpu 4 \
                                 --memory 16384 \
                                 --boot menu=on \
                                 --pxe \
                                 --disk /opt/openshift-network-playground/libvirt/sno4/sno64.img,bus=scsi \
                                 --cdrom /opt/openshift-network-playground/libvirt/sno64/rhcos-live.iso \
                                 --network bridge=sno0 \
                                 --noautoconsole \
                                 --graphics spice,listen=0.0.0.0
        @$(SCRIPT_DIR)/openshift-network-playground/sno-restart.sh sno64
        @/usr/local/bin/openshift-install --log-level=${LOGLEVEL} \
                                                    --dir=$(SCRIPT_DIR)/openshift-network-playground/sno64 wait-for install-complete
$ sudo cat /opt/openshift-network-playground/dns64/named.conf
options {
listen-on port 53 { 192.168.126.1; };
listen-on-v6 port 53 { fd00:dead:beef::1; };
directory       "/var/named";
allow-query     { 192.168.126.0/24; fd00:dead:beef::/96; };
forwarders { 127.0.0.1; };
dns64 2001:db8:1:ffff::/96 {
        clients { fd00:dead:beef::/96; };
        exclude { !fd00:dead:beef::/96; any; };
};
recursion yes;
};

zone "example.local" IN {
        type master;
        file "/example.local.forward";
};

zone "126.168.192.in-addr.arpa" IN {
        type master;
        file "/example.local.reverse.v4";
};

zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.f.e.e.b.d.a.e.d.0.0.d.f.ip6.arpa" IN {
        type master;
        file "/example.local.reverse.v6";
};
$ sudo cat /opt/openshift-network-playground/dns64/Containerfile
FROM fedora
MAINTAINER "Vinu K" <vkochuku@redhat.com>
COPY named.conf \
    example.local.forward \
    example.local.reverse.v4 \
    example.local.reverse.v6 \
    /
RUN yum install -y bind
ENTRYPOINT ["/usr/sbin/named", "-c", "/named.conf", "-g", "-u", "named"]
sudo cat /opt/openshift-network-playground/dns64/example.local.forward
$TTL 86400
@               IN      SOA     example.local. root.example.local (
                                2001062501  ; serial
                                21600       ; refresh after 6 hours
                                3600        ; retry after 1 hour
                                604800      ; expire after 1 week
                                86400 )     ; minimum TTL of 1 day
                IN      NS      ns1.example.local.

ns1             IN      A       192.168.126.1
node.sno4       IN      A       192.168.126.2
node.sno6       IN      AAAA    fd00:dead:beef::2
node.sno64      IN      A       192.168.126.3
                IN      AAAA    fd00:dead:beef::3
api.sno4        IN      A       192.168.126.2
api.sno6        IN      AAAA    fd00:dead:beef::2
api.sno64       IN      A       192.168.126.3
                IN      AAAA    fd00:dead:beef::3
api-int.sno4    IN      A       192.168.126.2
api-int.sno6    IN      AAAA    fd00:dead:beef::2
api-int.sno64   IN      A       192.168.126.3
                IN      AAAA    fd00:dead:beef::3
*.apps.sno4     IN      A       192.168.126.2
*.apps.sno6     IN      AAAA    fd00:dead:beef::2
*.apps.sno64    IN      A       192.168.126.3
                IN      AAAA    fd00:dead:beef::3
$ sudo cat /opt/openshift-network-playground/dns64/example.local.reverse.v4
$TTL 86400
@       IN      SOA     example.local. root.example.local (
                                2001062501  ; serial
                                21600       ; refresh after 6 hours
                                3600        ; retry after 1 hour
                                604800      ; expire after 1 week
                                86400 )     ; minimum TTL of 1 day
        IN      NS      ns1.example.local.

1       IN      PTR     ns1.example.local.
2       IN      PTR     node.sno4.example.local.
3       IN      PTR     node.sno64.example.local.
$ sudo cat /opt/openshift-network-playground/dns64/example.local.reverse.v6
$TTL 86400
@       IN      SOA     example.local. root.example.local (
                                2001062501  ; serial
                                21600       ; refresh after 6 hours
                                3600        ; retry after 1 hour
                                604800      ; expire after 1 week
                                86400 )     ; minimum TTL of 1 day
        IN      NS      ns1.example.local.

1       IN      PTR     ns1.example.local.
2       IN      PTR     node.sno6.example.local.
3       IN      PTR     node.sno64.example.local.
$ cat openshift-network-playground/sno4-enp1s0.nmconnection
[connection]
id=ens3
type=ethernet
autoconnect=yes
interface-name=enp1s0
[ipv6]
method=disabled
[ipv4]
method=manual
addresses=192.168.126.2
dns=192.168.126.1
gateway=192.168.126.1
$ cat openshift-network-playground/sno6-enp1s0.nmconnection
[connection]
id=ens3
type=ethernet
autoconnect=yes
interface-name=enp1s0
[ipv6]
method=manual
addresses=fd00:dead:beef::2
dns=fd00:dead:beef::1
gateway=fd00:dead:beef::1
[ipv4]
method=disabled
$ cat openshift-network-playground/sno64-enp1s0.nmconnection
[connection]
id=ens3
type=ethernet
autoconnect=yes
interface-name=enp1s0
[ipv6]
method=manual
addresses=fd00:dead:beef::3
dns=fd00:dead:beef::1
gateway=fd00:dead:beef::1
[ipv4]
method=manual
addresses=192.168.126.3
dns=192.168.126.1
gateway=192.168.126.1
$ cat openshift-network-playground/sno.sh
set -euo pipefail

ONPDIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )"
VERSION=${1}
NAME=${2}

rm -rf ${ONPDIR}/${NAME}
rm -rf ${ONPDIR}/${NAME}.yaml
echo "Downloading oc binary ..."
curl -s https://mirror.openshift.com/pub/openshift-v4/clients/ocp/$VERSION/openshift-client-linux.tar.gz | tar zxf - -C ${ONPDIR} oc
sudo mv ${ONPDIR}/oc /usr/local/bin
echo "✔ Downloaded!"
echo "Downloading openshift-install binary ..."
curl -s https://mirror.openshift.com/pub/openshift-v4/clients/ocp/$VERSION/openshift-install-linux.tar.gz | tar zxf - -C ${ONPDIR} openshift-install
sudo mv ${ONPDIR}/openshift-install /usr/local/bin
echo "✔ Downloaded!"
echo "Downloading RHCOS ISO ..."
sudo mkdir -p /opt/openshift-network-playground/libvirt/${NAME}
sudo rm -f /opt/openshift-network-playground/libvirt/sno4/rhcos-live.iso
sudo rm -f /opt/openshift-network-playground/libvirt/sno6/rhcos-live.iso
sudo rm -f /opt/openshift-network-playground/libvirt/sno64/rhcos-live.iso
sudo curl -sLo /opt/openshift-network-playground/libvirt/${NAME}/rhcos-live.iso $(/usr/local/bin/openshift-install coreos print-stream-json | grep location | grep x86_64 | grep iso | cut -d\" -f4)
echo "✔ Downloaded!"
echo "Generating install-config.yaml file ..."
case ${NAME} in
sno4)
cat << EOF > ${ONPDIR}/${NAME}.yaml
apiVersion: v1
baseDomain: example.local
metadata:
  name: ${NAME}
networking:
  clusterNetwork:
  - cidr: 10.128.0.0/14
    hostPrefix: 23
  machineNetwork:
  - cidr: 192.168.123.0/24
  networkType: OVNKubernetes
  serviceNetwork:
  - 172.30.0.0/16
compute:
- name: worker
  replicas: 0
controlPlane:
  name: master
  replicas: 1
platform:
  none: {}
bootstrapInPlace:
  installationDisk: /dev/sda
pullSecret: '$(cat ${ONPDIR}/pullsecret)'
sshKey: '$(cat ${ONPDIR}/id_ed25519.pub)'
EOF
;;
sno6)
cat << EOF > ${ONPDIR}/${NAME}.yaml
apiVersion: v1
baseDomain: example.local
metadata:
  name: ${NAME}
networking:
  machineNetwork:
  - cidr: fd00:dead:beef::/96
  clusterNetwork:
  - cidr: fd01::/48
    hostPrefix: 64
  serviceNetwork:
  - fd02::/112
  networkType: OVNKubernetes
compute:
- name: worker
  replicas: 0
controlPlane:
  name: master
  replicas: 1
platform:
  none: {}
bootstrapInPlace:
  installationDisk: /dev/sda
pullSecret: '$(cat ${ONPDIR}/pullsecret)'
sshKey: '$(cat ${ONPDIR}/id_ed25519.pub)'
EOF
;;
sno64)
cat << EOF > ${ONPDIR}/${NAME}.yaml
apiVersion: v1
baseDomain: example.local
metadata:
  name: ${NAME}
networking:
  machineNetwork:
  - cidr: 192.168.123.0/24
  - cidr: fd00:dead:beef::/96
  clusterNetwork:
  - cidr: 10.128.0.0/14
    hostPrefix: 23
  - cidr: fd01::/48
    hostPrefix: 64
  serviceNetwork:
  - 172.30.0.0/16
  - fd02::/112
  networkType: OVNKubernetes
compute:
- name: worker
  replicas: 0
controlPlane:
  name: master
  replicas: 1
platform:
  none: {}
bootstrapInPlace:
  installationDisk: /dev/sda
pullSecret: '$(cat ${ONPDIR}/pullsecret)'
sshKey: '$(cat ${ONPDIR}/id_ed25519.pub)'
EOF
;;
*) # do nothing
;;
esac
echo "✔ Generated!"
mkdir -p ${ONPDIR}/${NAME}
echo "Copying install-config.yaml file to the installation directory ..."
cp ${ONPDIR}/${NAME}.yaml ${ONPDIR}/${NAME}/install-config.yaml
echo "✔ Copied!"
sudo virsh -q destroy sno4 2>/dev/null || true
sudo virsh -q destroy sno6 2>/dev/null || true
sudo virsh -q destroy sno64 2>/dev/null || true
sudo virsh -q undefine sno4 2>/dev/null || true
sudo virsh -q undefine sno6 2>/dev/null || true
sudo virsh -q undefine sno64 2>/dev/null || true
sudo rm -f /opt/openshift-network-playground/libvirt/sno4/sno4.img
sudo rm -f /opt/openshift-network-playground/libvirt/sno6/sno6.img
sudo rm -f /opt/openshift-network-playground/libvirt/sno64/sno64.img
sudo qemu-img create /opt/openshift-network-playground/libvirt/${NAME}/${NAME}.img 120G
$ cat openshift-network-playground/sno-restart.sh
#!/bin/bash

NAME=${1}

function WAIT_FOR_REBOOT {
sp='/-\|'
sc=0

spin() {
   printf "\r[${sp:sc++:1}] $1"
   ((sc==${#sp})) && sc=0
}

endspin() {
   printf "\r%s\n" "$@"
}

until [[ $(sudo virsh -q list | grep -o ${NAME} | wc -c) -eq 0 ]]
do spin "Waiting for the installation and restart ..."
sleep 0.5
done
endspin
}

function START_NODE {
        sudo virsh start ${NAME} > /dev/null
        echo "[✔] Installation completed!"
}

WAIT_FOR_REBOOT
START_NODE