apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: StatefulSet 
metadata:
  name: open5gs-pgw-deployment
  namespace: open5gs
  labels:
    epc-mode: pgw
spec:
  replicas: 1
  serviceName: "open5gs-pgw-svc-pool"
  selector:
    matchLabels:
      epc-mode: pgw
  template:
    metadata:          
      labels:
        epc-mode: pgw
    spec:
      containers:
        - name: pgw
          image: fjvicens/open5gs-base:v0.1
          securityContext:
            privileged: true
            #sysctls:
            #- name: net.ipv6.conf.all.disable_ipv6
            #  value: 0
            capabilities:
              add: ["NET_ADMIN"]
          imagePullPolicy: Always
          command: ["/bin/sh", "-c"]
          args:
            - ip tuntap add name ogstun mode tun;
              ip addr add 45.45.0.1/16 dev ogstun;
              sysctl -w net.ipv6.conf.all.disable_ipv6=0;
              ip addr add cafe::1/64 dev ogstun;
              ip link set ogstun up;
              sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward";
              iptables -t nat -A POSTROUTING -s 45.45.0.0/16 ! -o ogstun -j MASQUERADE;
              open5gs-pgwd -c /open5gs/config-map/pgw.yaml;
          volumeMounts:
          - name: open5gs-pgw-config
            mountPath: /open5gs/config-map/pgw.yaml
            subPath: "pgw.yaml"
          - mountPath: /dev/net/tun
            name: dev-net-tun
          - name: open5gs-pgw-diameter
            mountPath: /open5gs/config-map/diameter-pgw.conf
            subPath: "diameter-pgw.conf"             
      volumes:
        - name: open5gs-pgw-config
          configMap:
            name: open5gs-pgw-config
        - name: open5gs-pgw-diameter
          configMap:
            name: open5gs-pgw-diameter            
        - name: dev-net-tun
          hostPath:
            path: /dev/net/tun
