# Original ESRE teaching fixture. Use only in a disposable Kubernetes cluster.
# The queue address is a startup setting; this fixture never contacts a queue.
apiVersion: v1
kind: Namespace
metadata:
  name: esre-crashlab
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: worker
  namespace: esre-crashlab
spec:
  replicas: 1
  selector:
    matchLabels:
      app: esre-worker
  template:
    metadata:
      labels:
        app: esre-worker
    spec:
      securityContext:
        runAsNonRoot: true
        runAsUser: 1000
        runAsGroup: 1000
        fsGroup: 1000
      containers:
        - name: worker
          image: busybox:1.37.0
          command:
            - sh
            - -c
            - |
              if [ -z "${QUEUE_URL:-}" ]; then
                echo 'startup failed: QUEUE_URL is required' >&2
                exit 1
              fi
              mkdir -p /tmp/site
              printf 'ok\n' > /tmp/site/health
              echo 'startup complete: serving the teaching health endpoint'
              exec httpd -f -p 8080 -h /tmp/site
          ports:
            - containerPort: 8080
          readinessProbe:
            httpGet:
              path: /health
              port: 8080
            periodSeconds: 2
          resources:
            requests:
              cpu: 10m
              memory: 16Mi
            limits:
              cpu: 100m
              memory: 64Mi
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: true
            capabilities:
              drop: [ALL]
          volumeMounts:
            - name: temporary-files
              mountPath: /tmp
      volumes:
        - name: temporary-files
          emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
  name: worker
  namespace: esre-crashlab
spec:
  selector:
    app: esre-worker
  ports:
    - port: 8080
      targetPort: 8080
