---
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2022-03-08T10:38:11Z"
  generateName: ovs-
  labels:
    app: ovs
    component: network
    controller-revision-hash: 79d97b545c
    openshift.io/component: network
    pod-template-generation: "1"
    type: infra
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:generateName: {}
        f:labels:
          .: {}
          f:app: {}
          f:component: {}
          f:controller-revision-hash: {}
          f:openshift.io/component: {}
          f:pod-template-generation: {}
          f:type: {}
        f:ownerReferences:
          .: {}
          k:{"uid":"bb69a0b2-e1b9-40de-be1a-2ef10cd41b70"}:
            .: {}
            f:apiVersion: {}
            f:blockOwnerDeletion: {}
            f:controller: {}
            f:kind: {}
            f:name: {}
            f:uid: {}
      f:spec:
        f:affinity:
          .: {}
          f:nodeAffinity:
            .: {}
            f:requiredDuringSchedulingIgnoredDuringExecution:
              .: {}
              f:nodeSelectorTerms: {}
        f:containers:
          k:{"name":"openvswitch"}:
            .: {}
            f:command: {}
            f:image: {}
            f:imagePullPolicy: {}
            f:name: {}
            f:readinessProbe:
              .: {}
              f:exec:
                .: {}
                f:command: {}
              f:failureThreshold: {}
              f:initialDelaySeconds: {}
              f:periodSeconds: {}
              f:successThreshold: {}
              f:timeoutSeconds: {}
            f:resources:
              .: {}
              f:requests:
                .: {}
                f:cpu: {}
                f:memory: {}
            f:securityContext:
              .: {}
              f:privileged: {}
            f:terminationMessagePath: {}
            f:terminationMessagePolicy: {}
            f:volumeMounts:
              .: {}
              k:{"mountPath":"/etc/openvswitch"}:
                .: {}
                f:mountPath: {}
                f:name: {}
              k:{"mountPath":"/host"}:
                .: {}
                f:mountPath: {}
                f:name: {}
                f:readOnly: {}
              k:{"mountPath":"/lib/modules"}:
                .: {}
                f:mountPath: {}
                f:name: {}
                f:readOnly: {}
              k:{"mountPath":"/run"}:
                .: {}
                f:mountPath: {}
                f:name: {}
              k:{"mountPath":"/sys"}:
                .: {}
                f:mountPath: {}
                f:name: {}
                f:readOnly: {}
        f:dnsPolicy: {}
        f:enableServiceLinks: {}
        f:hostNetwork: {}
        f:nodeSelector:
          .: {}
          f:kubernetes.io/os: {}
        f:priorityClassName: {}
        f:restartPolicy: {}
        f:schedulerName: {}
        f:securityContext: {}
        f:serviceAccount: {}
        f:serviceAccountName: {}
        f:terminationGracePeriodSeconds: {}
        f:tolerations: {}
        f:volumes:
          .: {}
          k:{"name":"host-config-openvswitch"}:
            .: {}
            f:hostPath:
              .: {}
              f:path: {}
              f:type: {}
            f:name: {}
          k:{"name":"host-modules"}:
            .: {}
            f:hostPath:
              .: {}
              f:path: {}
              f:type: {}
            f:name: {}
          k:{"name":"host-run"}:
            .: {}
            f:hostPath:
              .: {}
              f:path: {}
              f:type: {}
            f:name: {}
          k:{"name":"host-slash"}:
            .: {}
            f:hostPath:
              .: {}
              f:path: {}
              f:type: {}
            f:name: {}
          k:{"name":"host-sys"}:
            .: {}
            f:hostPath:
              .: {}
              f:path: {}
              f:type: {}
            f:name: {}
    manager: kube-controller-manager
    operation: Update
    time: "2022-03-08T10:38:11Z"
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:status:
        f:conditions:
          k:{"type":"ContainersReady"}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:status: {}
            f:type: {}
          k:{"type":"Initialized"}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:status: {}
            f:type: {}
          k:{"type":"Ready"}:
            .: {}
            f:lastProbeTime: {}
            f:lastTransitionTime: {}
            f:status: {}
            f:type: {}
        f:containerStatuses: {}
        f:hostIP: {}
        f:phase: {}
        f:podIP: {}
        f:podIPs:
          .: {}
          k:{"ip":"10.0.94.119"}:
            .: {}
            f:ip: {}
        f:startTime: {}
    manager: kubelet
    operation: Update
    time: "2022-03-08T10:38:41Z"
  name: ovs-jxg8z
  namespace: openshift-sdn
  ownerReferences:
  - apiVersion: apps/v1
    blockOwnerDeletion: true
    controller: true
    kind: DaemonSet
    name: ovs
    uid: bb69a0b2-e1b9-40de-be1a-2ef10cd41b70
  resourceVersion: "5705"
  selfLink: /api/v1/namespaces/openshift-sdn/pods/ovs-jxg8z
  uid: 1d257323-d453-4c3b-b0ff-139604528773
spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchFields:
          - key: metadata.name
            operator: In
            values:
            - master-0.case03116926.lab.upshift.rdu2.redhat.com
  containers:
  - command:
    - /bin/bash
    - -c
    - |
      #!/bin/bash
      set -euo pipefail
      export SYSTEMD_IGNORE_CHROOT=yes

      # systemctl cannot be used in a separate PID namespace to reach
      # the systemd running in PID 1. Therefore we need to use the dbus API
      systemctl_restart(){
        gdbus call \
          --system \
          --dest org.freedesktop.systemd1 \
          --object-path /org/freedesktop/systemd1/unit/"$(svc_encode_name ${1})"_2eservice \
          --method org.freedesktop.systemd1.Unit.Restart "replace"
      }
      svc_encode_name(){
        # systemd encodes some characters, so far we only need to encode
        # the character "-" but there may be more in the future.
        echo "${1//-/_2d}"
      }

      # Check to see if ovs is provided by the node:
      if [ -f /host/var/run/ovs-config-executed ]; then
        echo "openvswitch is running in systemd"
        # In some very strange corner cases, the owner for /run/openvswitch
        # can be wrong, so we need to clean up and restart.
        ovs_uid=$(chroot /host id -u openvswitch)
        ovs_gid=$(chroot /host id -g openvswitch)
        chown -R "${ovs_uid}:${ovs_gid}" /run/openvswitch
        if [[ ! -S /run/openvswitch/db.sock ]]; then
          systemctl_restart ovsdb-server
        fi
        # Don't need to worry about restoring flows; this can only change if we've rebooted
        exec tail -F /host/var/log/openvswitch/ovs-vswitchd.log /host/var/log/openvswitch/ovsdb-server.log
      else
        echo "openvswitch is running in container"
        # if another process is listening on the cni-server socket, wait until it exits
        retries=0
        while true; do
          if /usr/share/openvswitch/scripts/ovs-ctl status &>/dev/null; then
            echo "warning: Another process is currently managing OVS, waiting 15s ..." 2>&1
            sleep 15 & wait
            (( retries += 1 ))
          else
            break
          fi
          if [[ "${retries}" -gt 40 ]]; then
            echo "error: Another process is currently managing OVS, exiting" 2>&1
            exit 1
          fi
        done

        function quit {
            # Save the flows
            echo "$(date -u "+%Y-%m-%d %H:%M:%S") info: Saving flows ..." 2>&1
            bridges=$(ovs-vsctl -- --real list-br)
            TMPDIR=/var/run/openvswitch /usr/share/openvswitch/scripts/ovs-save save-flows $bridges > /var/run/openvswitch/flows.sh
            echo "$(date -u "+%Y-%m-%d %H:%M:%S") info: Saved flows" 2>&1

            # Don't allow ovs-vswitchd to clear datapath flows on exit
            kill -9 $(cat /var/run/openvswitch/ovs-vswitchd.pid 2>/dev/null) 2>/dev/null || true
            kill $(cat /var/run/openvswitch/ovsdb-server.pid 2>/dev/null) 2>/dev/null || true
            exit 0
        }
        trap quit SIGTERM

        function deletePid {
            rm /var/run/openvswitch/ovs-vswitchd.pid
            rm /var/run/openvswitch/ovsdb-server.pid
        }
        trap deletePid EXIT

        chown -R openvswitch:openvswitch /var/run/openvswitch
        chown -R openvswitch:openvswitch /etc/openvswitch

        # launch OVS
        # Start the ovsdb so that we can prep it before we start the ovs-vswitchd
        /usr/share/openvswitch/scripts/ovs-ctl start --ovs-user=openvswitch:openvswitch --no-ovs-vswitchd --system-id=random --no-monitor

        # Set the flow-restore-wait to true so ovs-vswitchd will wait till flows are restored
        ovs-vsctl --no-wait set Open_vSwitch . other_config:flow-restore-wait=true

        # Restrict the number of pthreads ovs-vswitchd creates to reduce the
        # amount of RSS it uses on hosts with many cores
        # https://bugzilla.redhat.com/show_bug.cgi?id=1571379
        # https://bugzilla.redhat.com/show_bug.cgi?id=1572797
        if [[ `nproc` -gt 12 ]]; then
            ovs-vsctl --no-wait set Open_vSwitch . other_config:n-revalidator-threads=4
            ovs-vsctl --no-wait set Open_vSwitch . other_config:n-handler-threads=10
        fi

        # And finally start the ovs-vswitchd now the DB is prepped
        /usr/share/openvswitch/scripts/ovs-ctl start --ovs-user=openvswitch:openvswitch --no-ovsdb-server --system-id=random --no-monitor

        # Load any flows that we saved
        echo "$(date -u "+%Y-%m-%d %H:%M:%S") info: Loading previous flows ..." 2>&1
        if [[ -f /var/run/openvswitch/flows.sh ]]; then

          # There's a bug in the ovs-save script which causes flows.sh to specify
          # OpenFlow14, replace that to OpenFlow13 which is the only version we support.
          sed -i 's/OpenFlow[0-9][0-9]/OpenFlow13/g' /var/run/openvswitch/flows.sh

          echo "$(date -u "+%Y-%m-%d %H:%M:%S") info: Adding br0 if it doesn't exist ..." 2>&1
          /usr/bin/ovs-vsctl --may-exist add-br br0 -- set Bridge br0 fail_mode=secure protocols=OpenFlow13
          echo "$(date -u "+%Y-%m-%d %H:%M:%S") info: Created br0, now adding flows ..." 2>&1
          mv /var/run/openvswitch/flows.sh /var/run/openvswitch/flows-old.sh
          sh -x /var/run/openvswitch/flows-old.sh
          echo "$(date -u "+%Y-%m-%d %H:%M:%S") info: Done restoring the existing flows ..." 2>&1
          rm /var/run/openvswitch/flows-old.sh
        fi

        echo "$(date -u "+%Y-%m-%d %H:%M:%S") info: Remove other config ..." 2>&1
        ovs-vsctl --no-wait --if-exists remove Open_vSwitch . other_config flow-restore-wait=true
        echo "$(date -u "+%Y-%m-%d %H:%M:%S") info: Removed other config ..." 2>&1

        tail -F --pid=$(cat /var/run/openvswitch/ovs-vswitchd.pid) /var/log/openvswitch/ovs-vswitchd.log &
        tail -F --pid=$(cat /var/run/openvswitch/ovsdb-server.pid) /var/log/openvswitch/ovsdb-server.log &
        wait
      fi
    image: quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:980d20b31cdcd9db0a94e393b53799985ea399bbe8dbd552bf2e27e32cf0be7e
    imagePullPolicy: IfNotPresent
    name: openvswitch
    readinessProbe:
      exec:
        command:
        - /bin/bash
        - -c
        - |
          #!/bin/bash
          /usr/bin/ovs-vsctl -t 5 show > /dev/null
      failureThreshold: 3
      initialDelaySeconds: 15
      periodSeconds: 5
      successThreshold: 1
      timeoutSeconds: 6
    resources:
      requests:
        cpu: 100m
        memory: 400Mi
    securityContext:
      privileged: true
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: FallbackToLogsOnError
    volumeMounts:
    - mountPath: /lib/modules
      name: host-modules
      readOnly: true
    - mountPath: /run
      name: host-run
    - mountPath: /sys
      name: host-sys
      readOnly: true
    - mountPath: /etc/openvswitch
      name: host-config-openvswitch
    - mountPath: /host
      name: host-slash
      readOnly: true
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: sdn-token-45pnf
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  hostNetwork: true
  nodeName: master-0.case03116926.lab.upshift.rdu2.redhat.com
  nodeSelector:
    kubernetes.io/os: linux
  preemptionPolicy: PreemptLowerPriority
  priority: 2000001000
  priorityClassName: system-node-critical
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: sdn
  serviceAccountName: sdn
  terminationGracePeriodSeconds: 30
  tolerations:
  - operator: Exists
  volumes:
  - hostPath:
      path: /lib/modules
      type: ""
    name: host-modules
  - hostPath:
      path: /run
      type: ""
    name: host-run
  - hostPath:
      path: /sys
      type: ""
    name: host-sys
  - hostPath:
      path: /var/lib/openvswitch
      type: DirectoryOrCreate
    name: host-config-openvswitch
  - hostPath:
      path: /
      type: ""
    name: host-slash
  - name: sdn-token-45pnf
    secret:
      defaultMode: 420
      secretName: sdn-token-45pnf
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2022-03-08T10:38:11Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2022-03-08T10:38:41Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2022-03-08T10:38:41Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2022-03-08T10:38:11Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: cri-o://d82691ddf15db969d02cb07bd6dc4e6790d9fe15f671d5f517d386aff854a718
    image: quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:980d20b31cdcd9db0a94e393b53799985ea399bbe8dbd552bf2e27e32cf0be7e
    imageID: quay.io/openshift-release-dev/ocp-v4.0-art-dev@sha256:980d20b31cdcd9db0a94e393b53799985ea399bbe8dbd552bf2e27e32cf0be7e
    lastState: {}
    name: openvswitch
    ready: true
    restartCount: 0
    started: true
    state:
      running:
        startedAt: "2022-03-08T10:38:21Z"
  hostIP: 10.0.94.119
  phase: Running
  podIP: 10.0.94.119
  podIPs:
  - ip: 10.0.94.119
  qosClass: Burstable
  startTime: "2022-03-08T10:38:11Z"
