# Copyright 2023 Google LLC
#
# 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.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: greeter-intermediary
  namespace: xds # kpt-set: ${greeter-namespace}
  labels:
    app.kubernetes.io/component: greeter
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: greeter-intermediary
  template:
    metadata:
      labels:
        app.kubernetes.io/name: greeter-intermediary
        app.kubernetes.io/component: greeter
    spec:
      automountServiceAccountToken: false # No need to communicate with the Kubernetes API server.
      containers:
      - name: app
        image: greeter
        args: []
        env:
        - name: NEXT_HOP
          value: xds:///greeter-leaf
        ports:
        - containerPort: 50051
          name: app-port
        - containerPort: 50052
          name: health-port
      serviceAccountName: greeter-intermediary
      terminationGracePeriodSeconds: 10
      # Best effort scheduling of pods across separate zones and nodes.
      topologySpreadConstraints:
      - labelSelector:
          matchLabels:
            app.kubernetes.io/name: greeter-intermediary
        maxSkew: 1
        topologyKey: topology.kubernetes.io/zone
        whenUnsatisfiable: ScheduleAnyway
      - labelSelector:
          matchLabels:
            app.kubernetes.io/name: greeter-intermediary
        maxSkew: 1
        topologyKey: kubernetes.io/hostname
        whenUnsatisfiable: ScheduleAnyway
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: greeter-leaf
  namespace: xds # kpt-set: ${greeter-namespace}
  labels:
    app.kubernetes.io/component: greeter
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: greeter-leaf
  template:
    metadata:
      labels:
        app.kubernetes.io/name: greeter-leaf
        app.kubernetes.io/component: greeter
    spec:
      automountServiceAccountToken: false # No need to communicate with the Kubernetes API server.
      containers:
      - name: app
        image: greeter
        args: []
        env: []
        ports:
        - containerPort: 50051
          name: app-port
        - containerPort: 50052
          name: health-port
      serviceAccountName: greeter-leaf
      terminationGracePeriodSeconds: 10
      # Best effort scheduling of pods across separate zones and nodes.
      topologySpreadConstraints:
      - labelSelector:
          matchLabels:
            app.kubernetes.io/name: greeter-leaf
        maxSkew: 1
        topologyKey: topology.kubernetes.io/zone
        whenUnsatisfiable: ScheduleAnyway
      - labelSelector:
          matchLabels:
            app.kubernetes.io/name: greeter-leaf
        maxSkew: 1
        topologyKey: kubernetes.io/hostname
        whenUnsatisfiable: ScheduleAnyway
