apiVersion: apps/v1
kind: Deployment
metadata:
  name: tb3-bringup
  labels:
    app: ros
spec:
  replicas: 3
  selector:
    matchLabels:
      app: ros
  strategy:
    rollingUpdate:
      maxSurge: 0
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: ros
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - ros
            topologyKey: "kubernetes.io/hostname"
      imagePullSecrets:
      - name: regcred
      initContainers:
      - name: update-opencr
        image: rdbox/arm.opencr_updater:kinetic_1.0.0
        tty: true
        args:
        - /update.sh
        env:
        - name: OPENCR_VERSION
          value: "1.2.0"
        - name: OPENCR_PORT
          value: "/dev/ttyACM0"
        - name: ROS_HOSTNAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: ROS_MASTER_URI
          value: "http://$(ROS_HOSTNAME):11311"
        - name: ROS_NAMESPACE
          value: "$(ROS_HOSTNAME)"
        volumeMounts:
        - mountPath: "/dev/ttyACM0"
          name: "ttyacm0"
        securityContext:
          privileged: true
      containers:
      - name: roscore
        image: rdbox/arm.ros:kinetic-ros-base
        tty: true
        args:
        - roscore
        env:
        - name: ROS_HOSTNAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: ROS_MASTER_URI
          value: "http://$(ROS_HOSTNAME):11311"
        - name: ROS_NAMESPACE
          value: "$(ROS_HOSTNAME)"
      - name: turtlebot3-bringup-lidar
        image: rdbox/arm.turtlebot3_robot_side_bringup:kinetic_0.2.1
        tty: true
        args:
        - roslaunch
        - --screen
        - --wait
        - turtlebot3_bringup
        - turtlebot3_lidar.launch
        env:
        - name: ROS_HOSTNAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: ROS_MASTER_URI
          value: "http://$(ROS_HOSTNAME):11311"
        - name: ROS_NAMESPACE
          value: "$(ROS_HOSTNAME)"
        volumeMounts:
        - mountPath: "/dev/ttyUSB0"
          name: "ttyusb0"
        securityContext:
          privileged: true
      - name: turtlebot3-bringup-core
        image: rdbox/arm.turtlebot3_robot_side_bringup:kinetic_0.2.1
        tty: true
        args:
        - roslaunch
        - --screen
        - --wait
        - turtlebot3_bringup
        - turtlebot3_core.launch
        env:
        - name: ROS_HOSTNAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: ROS_MASTER_URI
          value: "http://$(ROS_HOSTNAME):11311"
        - name: ROS_NAMESPACE
          value: "$(ROS_HOSTNAME)"
        volumeMounts:
        - mountPath: "/dev/ttyACM0"
          name: "ttyacm0"
        securityContext:
          privileged: true
      - name: turtlebot3-sound
        image: rdbox/arm.turtlebot3_robot_side_sound:kinetic_0.2.1
        tty: true
        args:
        - roslaunch
        - --screen
        - --wait
        - launch_rostopic
        - pub_latch.launch
        - command:=pub
        - topic_name:=sound
        - topic_type:=turtlebot3_msgs/Sound
        - data:=1
        env:
        - name: ROS_HOSTNAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: ROS_MASTER_URI
          value: "http://$(ROS_HOSTNAME):11311"
        - name: ROS_NAMESPACE
          value: "$(ROS_HOSTNAME)"
      - name: multimaster-fkie-discovery
        image: rdbox/arm.multimaster_fkie:kinetic
        tty: true
        args:
        - roslaunch
        - --screen
        - --wait
        - multimaster_fkie_launch
        - master_discovery_fkie.launch
        env:
        - name: ROS_HOSTNAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: ROS_MASTER_URI
          value: "http://$(ROS_HOSTNAME):11311"
      - name: multimaster-fkie-sync
        image: rdbox/arm.multimaster_fkie:kinetic
        tty: true
        args:
        - roslaunch
        - --screen
        - --wait
        - multimaster_fkie_launch
        - master_sync_fkie.launch
        env:
        - name: ROS_HOSTNAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: ROS_MASTER_URI
          value: "http://$(ROS_HOSTNAME):11311"
      - name: topic-tools-transform
        image: rdbox/arm.topic_tools:kinetic
        tty: true
        args:
        - roslaunch
        - --screen
        - --wait
        - topic_tools_launch
        - transform.launch
        - input:=/cmd_vel
        - output_topic:=/$(ROS_HOSTNAME)/cmd_vel
        - output_type:=geometry_msgs/Twist
        - import_modules:=geometry_msgs
        - expression:='geometry_msgs.msg.Twist(geometry_msgs.msg.Vector3(m.linear.x, m.linear.y, m.linear.z), geometry_msgs.msg.Vector3(m.angular.x, m.angular.y, -m.angular.z))'
        env:
        - name: ROS_HOSTNAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: ROS_MASTER_URI
          value: "http://$(ROS_HOSTNAME):11311"
        - name: ROS_NAMESPACE
          value: "$(ROS_HOSTNAME)"
      hostNetwork: true
      nodeSelector:
        node.rdbox.com/model: "tb3"
      volumes:
      - name: "ttyusb0"
        hostPath:
          path: "/dev/ttyUSB0"
      - name: "ttyacm0"
        hostPath:
          path: "/dev/ttyACM0"
