kruise icon indicating copy to clipboard operation
kruise copied to clipboard

Are there plans to make the ordinal index for a statefulset available dynamically within a config file?

Open l-duan opened this issue 2 years ago • 3 comments

It would be good if there were some templating format so that the property could be set directly in the config file. E.g. (simplified):

apiVersion: apps.kruise.io/v1beta1
kind: StatefulSet
metadata:
  name: zk
spec:
  serviceName: zk-headless
  replicas: 3
  template:
    metadata:
      labels:
        app: zk
    spec:
      containers:
      - name: zk
        imagePullPolicy: Always
        image: zookeeper
        resources:
        env:
        - name : ZOO_MY_ID
          value: ${{ordinal}}
        - name : ZOO_SERVERS
          value: server.0=zk-0:2888:3888 server.1=zk-1:2888:3888 server.2=zk-2:2888:3888
        - name : ZOO_TICK_TIME
          value: "2000"
        - name : ZOO_INIT_LIMIT
          value: "10"
        - name : ZOO_SYNC_LIMIT
          value: "5"

What would you like to be added:

Why is this needed:

l-duan avatar May 30 '22 12:05 l-duan

you can use the downward api populated env to get pod name which has suffix of ordinals

apiVersion: apps.kruise.io/v1beta1
kind: StatefulSet
metadata:
  name: zk
spec:
  serviceName: zk-headless
  replicas: 3
  template:
    metadata:
      labels:
        app: zk
    spec:
      containers:
      - name: zk
        imagePullPolicy: Always
        image: zookeeper
        resources:
        env:
        - name : ZOO_MY_ID
           valueFrom:
               fieldRef:
                 fieldPath: metadata.name
        - name : ZOO_SERVERS
          value: server.0=zk-0:2888:3888 server.1=zk-1:2888:3888 server.2=zk-2:2888:3888
        - name : ZOO_TICK_TIME
          value: "2000"
        - name : ZOO_INIT_LIMIT
          value: "10"
        - name : ZOO_SYNC_LIMIT
          value: "5"

furykerry avatar May 30 '22 12:05 furykerry

is there anyway/anyplans to get that ordinal directly at creation-time, instead at runtime? well,I want to set ordinal index to env, but not working.

16539058142883

l-duan avatar May 30 '22 13:05 l-duan

@l-duan Different containers in a same pod have different environments, so you can not export the env from init container to another container.

FillZpp avatar Jun 01 '22 02:06 FillZpp

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 31 '22 00:08 stale[bot]