Skip to content
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

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

googs1025
Copy link
Member

What type of PR is this?

/kind feature

What this PR does / why we need it

  • Add group size environment variable injection

Which issue(s) this PR fixes

Fixes # #203

Special notes for your reviewer

Does this PR introduce a user-facing change?

Add LWS_GROUP_SIZE environment variable to all containers in a leaderworkerset.

@k8s-ci-robot k8s-ci-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Sep 4, 2024
@k8s-ci-robot k8s-ci-robot requested a review from ahg-g September 4, 2024 04:54
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 4, 2024
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 4, 2024
@googs1025
Copy link
Member Author

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#

@@ -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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
size, fount := pod.Annotations[leaderworkerset.SizeAnnotationKey]
size, found := pod.Annotations[leaderworkerset.SizeAnnotationKey]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Member Author

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).

@@ -104,36 +104,43 @@ func TestAddLWSVariables(t *testing.T) {
name string
pod *corev1.Pod
expectedLwsLeaderAddress string
expectedGroupSize string
Copy link
Contributor

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}{
{
name: "Leader pod",
pod: testutils.MakePodWithLabels("test-sample", "0", "", "default"),
pod: testutils.MakePodWithLabels("test-sample", "0", "", "default", 2),
Copy link
Contributor

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..

Copy link
Member Author

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?

Copy link
Contributor

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".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@kannon92
Copy link
Contributor

kannon92 commented Sep 4, 2024

/retest

@liurupeng
Copy link
Collaborator

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 5, 2024
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 5, 2024
@k8s-ci-robot k8s-ci-robot merged commit 58263b0 into kubernetes-sigs:main Sep 5, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants