# Copyright 2022 The Dapr Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#     http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# You may obtain a copy of the License at
#     https://github.com/tailscale/tailscale/blob/main/LICENSE
# Source code from
#     https://github.com/tailscale/tailscale/tree/main/docs/k8s

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tailscale-subnet-router
  labels:
    app: tailscale-subnet-router
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tailscale-subnet-router
  template:
    metadata:
      labels:
        app: tailscale-subnet-router
    spec:
      serviceAccountName: tailscale
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: kubernetes.io/os
                    operator: In
                    values:
                      - linux
      containers:
        - name: tailscale
          imagePullPolicy: Always
          image: "ghcr.io/tailscale/tailscale:latest"
          env:
            # Store the state in a k8s secret
            - name: TS_KUBE_SECRET
              value: "tailscale-auth"
            - name: TS_USERSPACE
              value: "true"
            - name: TS_AUTH_KEY
              valueFrom:
                secretKeyRef:
                  name: tailscale-auth
                  key: TS_AUTH_KEY
            - name: TS_ROUTES
              value: "{{TS_ROUTES}}"
          securityContext:
            runAsUser: 1000
            runAsGroup: 1000
          resources:
            limits:
              cpu: "1000m"
              memory: "256Mi"
            requests:
              cpu: "700m"
              memory: "128Mi"
