kosmos-io / kosmos

The limitless expansion of Kubernetes. Make Kubernetes without boundaries
https://kosmos-io.github.io/kosmos-website/
Apache License 2.0
201 stars 49 forks source link

dynamic pod env can't pass-through to Leaf cluster #509

Closed village-way closed 5 months ago

village-way commented 5 months ago

What happened:

When Kafka statefulset resources are orchestrated across clusters using Kosmos, they utilize dynamic environment variables, such as obtaining the nodeName of the current pod. However, in the current version of Kosmos, when pods are dispatched to leaf clusters, they are assigned virtual node names instead of the actual leaf cluster node names. This discrepancy leads to operational issues with the pods.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      nodeName: kosmos-kafka
      tolerations:
        - key: kosmos.io/node
          operator: Equal
          value: "true"
      containers:
        - name: nginx
          image: nginx:latest
          ports:
            - containerPort: 80
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: JMX_PORT
              value: "9999"
            - name: NODEIP
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: status.hostIP
            - name: NODENAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: spec.nodeName
            - name: PODIP
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: status.podIP
            - name: IS_KAFKA_FROZEN
              value: "false"
            - name: KAFKA_HEAP_OPTS
              value: "-Xms8192 -Xmx8192M"
            - name: LOG_DIRS
              value: "/kafka/data-0"

What you expected to happen: the pod should get the real env

How to reproduce it (as minimally and precisely as possible):

image

Anything else we need to know?:

Environment: