-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: Add group size environment variable injection #208
Conversation
Practical use of local branches root@VM-0-8-ubuntu:/home/ubuntu/lws# kubectl get pods
NAME READY STATUS RESTARTS AGE
leaderworkerset-sample-0 1/1 Running 0 32s
leaderworkerset-sample-0-1 1/1 Running 0 32s
leaderworkerset-sample-0-2 1/1 Running 0 32s
leaderworkerset-sample-0-3 1/1 Running 0 32s
leaderworkerset-sample-1 1/1 Running 0 32s
leaderworkerset-sample-1-1 1/1 Running 0 32s
leaderworkerset-sample-1-2 1/1 Running 0 32s
leaderworkerset-sample-1-3 1/1 Running 0 32s
leaderworkerset-sample-2 1/1 Running 0 32s
leaderworkerset-sample-2-1 1/1 Running 0 32s
leaderworkerset-sample-2-2 1/1 Running 0 32s
leaderworkerset-sample-2-3 1/1 Running 0 32s
root@VM-0-8-ubuntu:/home/ubuntu/lws# kubectl describe pods leaderworkerset-sample-2
Name: leaderworkerset-sample-2
Namespace: default
Priority: 0
Service Account: default
Node: cluster1-worker2/172.18.0.3
Start Time: Wed, 04 Sep 2024 13:17:19 +0800
Labels: apps.kubernetes.io/pod-index=2
controller-revision-hash=leaderworkerset-sample-7b67975f84
leaderworkerset.sigs.k8s.io/group-index=2
leaderworkerset.sigs.k8s.io/group-key=ee0d9ef1ac6e34b19b82b1ec3c9df8128b804444
leaderworkerset.sigs.k8s.io/name=leaderworkerset-sample
leaderworkerset.sigs.k8s.io/template-revision-hash=97c9d753bb0b5993c9154ee9b9ea554e2ed3fb3d
leaderworkerset.sigs.k8s.io/worker-index=0
statefulset.kubernetes.io/pod-name=leaderworkerset-sample-2
Annotations: leaderworkerset.sigs.k8s.io/size: 4
Status: Running
IP: 10.6.2.13
IPs:
IP: 10.6.2.13
Controlled By: StatefulSet/leaderworkerset-sample
Containers:
nginx:
Container ID: containerd://c40aa91f558e0d045551bc14e4a805490eba881244c7e50b51d73f9e576bf5e7
Image: nginx:1.14.2
Image ID: docker.io/library/nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1df7563c3a2a6abe24160306b8d
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Wed, 04 Sep 2024 13:17:20 +0800
Ready: True
Restart Count: 0
Limits:
cpu: 100m
Requests:
cpu: 50m
Environment:
LWS_LEADER_ADDRESS: leaderworkerset-sample-2.leaderworkerset-sample.default
LWS_GROUP_SIZE: 4
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-fc46f (ro)
Conditions:
Type Status
PodReadyToStartContainers True
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-fc46f:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 40s default-scheduler Successfully assigned default/leaderworkerset-sample-2 to cluster1-worker2
Normal Pulled 39s kubelet Container image "nginx:1.14.2" already present on machine
Normal Created 39s kubelet Created container nginx
Normal Started 39s kubelet Started container nginx
root@VM-0-8-ubuntu:/home/ubuntu/lws#
|
pkg/utils/pod/pod_utils.go
Outdated
@@ -119,11 +125,24 @@ func AddLWSVariables(pod *corev1.Pod) error { | |||
Value: fmt.Sprintf("%s-%s.%s.%s", lwsName, groupIndex, lwsName, pod.ObjectMeta.Namespace), | |||
} | |||
|
|||
size, fount := pod.Annotations[leaderworkerset.SizeAnnotationKey] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
size, fount := pod.Annotations[leaderworkerset.SizeAnnotationKey] | |
size, found := pod.Annotations[leaderworkerset.SizeAnnotationKey] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
pkg/utils/pod/pod_utils.go
Outdated
@@ -119,11 +125,24 @@ func AddLWSVariables(pod *corev1.Pod) error { | |||
Value: fmt.Sprintf("%s-%s.%s.%s", lwsName, groupIndex, lwsName, pod.ObjectMeta.Namespace), | |||
} | |||
|
|||
size, fount := pod.Annotations[leaderworkerset.SizeAnnotationKey] | |||
if !fount { | |||
return fmt.Errorf("Failure constructing environment variables, no size annotation found for pod %v", pod.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return fmt.Errorf("Failure constructing environment variables, no size annotation found for pod %v", pod.Name) | |
return fmt.Errorf("Failure constructing environment variables, no size annotation found for pod %v", pod) |
Technically the pods can have the same name if they are in a different namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks. i use klog.KObj(pod)
.
pkg/utils/pod/pod_utils_test.go
Outdated
@@ -104,36 +104,43 @@ func TestAddLWSVariables(t *testing.T) { | |||
name string | |||
pod *corev1.Pod | |||
expectedLwsLeaderAddress string | |||
expectedGroupSize string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think having this as an int makes more sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/utils/pod/pod_utils_test.go
Outdated
}{ | ||
{ | ||
name: "Leader pod", | ||
pod: testutils.MakePodWithLabels("test-sample", "0", "", "default"), | ||
pod: testutils.MakePodWithLabels("test-sample", "0", "", "default", 2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have one case where you having different than two..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, Kevin. I don't quite understand what this suggestion means. Could you explain it more clearly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a different value from "2".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/retest |
7cc5660
to
4c09205
Compare
4c09205
to
6df8fcc
Compare
6df8fcc
to
44d877b
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: googs1025, liurupeng The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
What this PR does / why we need it
Which issue(s) this PR fixes
Fixes # #203
Special notes for your reviewer
Does this PR introduce a user-facing change?