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

sync status of pod #1913

Merged
merged 1 commit into from
Jun 13, 2022
Merged

sync status of pod #1913

merged 1 commit into from
Jun 13, 2022

Conversation

xyz2277
Copy link
Contributor

@xyz2277 xyz2277 commented May 30, 2022

Signed-off-by: bruce [email protected]

What type of PR is this?
/kind feature

What this PR does / why we need it:
When I try to propagate or promote a pod, I found that the status of pod is always pending and never changed.
5c31

Which issue(s) this PR fixes:
Fixes #1988

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

`karmada-controller-manager`:  `interpreter framework` starts to support Pod status aggregation.  

@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label May 30, 2022
@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 30, 2022
Comment on lines 275 to 307
newStatus := &corev1.PodStatus{}
for _, item := range aggregatedStatusItems {
if item.Status == nil {
continue
}
if err = json.Unmarshal(item.Status.Raw, newStatus); err != nil {
return nil, err
}
klog.V(3).Infof("Grab pod(%s/%s) status from cluster(%s), phase: %s, qosClass: %s", newStatus.Phase, newStatus.QOSClass)
}
Copy link
Member

Choose a reason for hiding this comment

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

This logic looks like it only unmarshals the latest object in the items.

Actually, we have not found a good method to aggregate the pod status. The PodStatus can not represent the pod status in multiple clusters figuratively.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic looks like it only unmarshals the latest object in the items.

Actually, we have not found a good method to aggregate the pod status. The PodStatus can not represent the pod status in multiple clusters figuratively.

This loop only exec once. And aggregating the pod status do not involve multiple clusters.This is just a independent pod resource, not pod in deployment or something else.

Copy link
Member

Choose a reason for hiding this comment

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

When we propagate to more than one cluster, there will be more than one item.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we propagate to more than one cluster, there will be more than one item.

you are right.
So can i set Pod status Ready only when all Pods are in that state?

Copy link
Member

Choose a reason for hiding this comment

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

I think it's maybe okay.

@xyz2277
Copy link
Contributor Author

xyz2277 commented May 30, 2022

This is how I propagate a pod.
11d
22d
@RainbowMango @XiShanYongYe-Chang

@karmada-bot karmada-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 31, 2022
@RainbowMango
Copy link
Member

@xyz2277
Copy link
Contributor Author

xyz2277 commented May 31, 2022

@xyz2277 xyz2277 force-pushed the karmada-zyx-11 branch 2 times, most recently from 3984c62 to ca50789 Compare May 31, 2022 07:30
@xyz2277
Copy link
Contributor Author

xyz2277 commented May 31, 2022

@XiShanYongYe-Chang
Copy link
Member

@xyz2277 thanks for your contribution.

/assign


for _, containerStatus := range temp.ContainerStatuses {
tempStatus := containerStatus
newStatus.ContainerStatuses = append(newStatus.ContainerStatuses, tempStatus)
Copy link
Member

Choose a reason for hiding this comment

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

IMOP, the status of the collection container does not appear to be required.

Copy link
Contributor Author

@xyz2277 xyz2277 Jun 1, 2022

Choose a reason for hiding this comment

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

IMOP, the status of the collection container does not appear to be required.

The status of containers is needed to be collected. Or the column of READY will always be 0/1.

Copy link
Member

Choose a reason for hiding this comment

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

The status of containers is needed to be collected. Or the column of READY will always be 0/1.

I'm not sure about it. I thought the Ready status is based on the .status.phase. @lonelyCZ might know it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The status of containers is needed to be collected. Or the column of READY will always be 0/1.

I'm not sure about it. I thought the Ready status is based on the .status.phase. @lonelyCZ might know it.

I've already tried. ready status is based on the status of the container.

Copy link
Member

Choose a reason for hiding this comment

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

Hi @xyz2277, how about only collecting the fields we need.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @xyz2277, how about only collecting the fields we need.

I tried too. When you see pod details, a lot of empty field will be found.

Copy link
Member

Choose a reason for hiding this comment

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

It will be ok.

Comment on lines 301 to 304
if reflect.DeepEqual(pod.Status, *newStatus) {
klog.V(3).Infof("ignore update pod(%s/%s) status as up to date", pod.Namespace, pod.Name)
return object, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

This logic maybe needs to move back after newStatus.Phase assignment.

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

The kubectl output format for Pod resource looks like:

# kubectl get po
NAME    READY   STATUS    RESTARTS   AGE
nginx   2/1     Running   0          9m19s


for _, containerStatus := range temp.ContainerStatuses {
tempStatus := containerStatus
newStatus.ContainerStatuses = append(newStatus.ContainerStatuses, tempStatus)
Copy link
Member

Choose a reason for hiding this comment

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

Hi @xyz2277, how about only collecting the fields we need.

for _, containerStatus := range temp.ContainerStatuses {
tempStatus := containerStatus
newStatus.ContainerStatuses = append(newStatus.ContainerStatuses, tempStatus)
if containerStatus.Ready {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here judgement can refer to: https://github.com/kubernetes/kubernetes/blob/8415ae647d2c433c89910a0e677094e3a20ffb2b/pkg/printers/internalversion/printers.go#L822-L824

do you mean when container is ready, then we can collect that containerStatus?

Copy link
Member

Choose a reason for hiding this comment

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

The judgment here may not be strong enough.

container.Ready && container.State.Running != nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The judgment here may not be strong enough.

container.Ready && container.State.Running != nil

got it~

@RainbowMango
Copy link
Member

Just a reminder, please don't forget to add a unit test for it and update the documents I mentioned above.

@xyz2277
Copy link
Contributor Author

xyz2277 commented Jun 2, 2022

Just a reminder, please don't forget to add a unit test for it and update the documents I mentioned above.

Got it!

@karmada-bot karmada-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 6, 2022
@xyz2277
Copy link
Contributor Author

xyz2277 commented Jun 6, 2022

/cc @RainbowMango

@RainbowMango
Copy link
Member

Can you share the test report with the new patch? Such as propagating a Pod to at least 2 clusters.

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

How about modify like this:

        newStatus := &corev1.PodStatus{}
        newStatus.ContainerStatuses = make([]corev1.ContainerStatus, 0)
-       readySum := 0
-       containerSum := 0
+       runningFlag := true
        for _, item := range aggregatedStatusItems {
                if item.Status == nil {
+                       runningFlag = false
                        continue
                }

@@ -286,19 +286,22 @@ func aggregatePodStatus(object *unstructured.Unstructured, aggregatedStatusItems
                        return nil, err
                }

+               if temp.Phase != corev1.PodRunning {
+                       runningFlag = false
+               }
+
                for _, containerStatus := range temp.ContainerStatuses {
-                       tempStatus := containerStatus
-                       newStatus.ContainerStatuses = append(newStatus.ContainerStatuses, tempStatus)
-                       if containerStatus.Ready && containerStatus.State.Running != nil {
-                               readySum++
+                       tempStatus := corev1.ContainerStatus{
+                               Ready: containerStatus.Ready,
+                               State: containerStatus.State,
                        }
-                       containerSum++
+                       newStatus.ContainerStatuses = append(newStatus.ContainerStatuses, tempStatus)
                }
                klog.V(3).Infof("Grab pod(%s/%s) status from cluster(%s), phase: %s", pod.Namespace,
                        pod.Name, item.ClusterName, temp.Phase)
        }

-       if containerSum == readySum {
+       if runningFlag {
                newStatus.Phase = corev1.PodRunning

@xyz2277
Copy link
Contributor Author

xyz2277 commented Jun 7, 2022

Can you share the test report with the new patch? Such as propagating a Pod to at least 2 clusters.

case1:1 cluster, 1 pod
31
32
33

case2: 2 clusters,1 pod
41
42
43

case3: 2 clusters, 1 pod(one pod failed in one cluster)
52
53

@xyz2277
Copy link
Contributor Author

xyz2277 commented Jun 7, 2022

How about modify like this:

        newStatus := &corev1.PodStatus{}
        newStatus.ContainerStatuses = make([]corev1.ContainerStatus, 0)
-       readySum := 0
-       containerSum := 0
+       runningFlag := true
        for _, item := range aggregatedStatusItems {
                if item.Status == nil {
+                       runningFlag = false
                        continue
                }

@@ -286,19 +286,22 @@ func aggregatePodStatus(object *unstructured.Unstructured, aggregatedStatusItems
                        return nil, err
                }

+               if temp.Phase != corev1.PodRunning {
+                       runningFlag = false
+               }
+
                for _, containerStatus := range temp.ContainerStatuses {
-                       tempStatus := containerStatus
-                       newStatus.ContainerStatuses = append(newStatus.ContainerStatuses, tempStatus)
-                       if containerStatus.Ready && containerStatus.State.Running != nil {
-                               readySum++
+                       tempStatus := corev1.ContainerStatus{
+                               Ready: containerStatus.Ready,
+                               State: containerStatus.State,
                        }
-                       containerSum++
+                       newStatus.ContainerStatuses = append(newStatus.ContainerStatuses, tempStatus)
                }
                klog.V(3).Infof("Grab pod(%s/%s) status from cluster(%s), phase: %s", pod.Namespace,
                        pod.Name, item.ClusterName, temp.Phase)
        }

-       if containerSum == readySum {
+       if runningFlag {
                newStatus.Phase = corev1.PodRunning

yeah, it looks more clean and concise

@RainbowMango
Copy link
Member

kindly ping @xyz2277

@chaunceyjiang
Copy link
Member

#1913 (comment)

Why not collect all the information?

karmada 的目标不是像操作单集群一下操作多集群嘛?

如果不收集这些信息,对一些可视化页面可能不是友好。

HostIP
Phase
PodIP 
QOSClass 
PodIPs 
Conditions 

@RainbowMango
Copy link
Member

并不是所有信息都可以汇聚到resource template的,比如HostIP,如果Pod分布于多个集群,多个HostIP无法同时体现在resource template中。状态汇聚是有局限性的。具体需要什么状态根据实际应用场景再行考虑。

@chaunceyjiang
Copy link
Member

并不是所有信息都可以汇聚到resource template的,比如HostIP,如果Pod分布于多个集群,多个HostIP无法同时体现在resource template中。状态汇聚是有局限性的。具体需要什么状态根据实际应用场景再行考虑。

Got it

Signed-off-by: bruce <[email protected]>
@xyz2277
Copy link
Contributor Author

xyz2277 commented Jun 13, 2022

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

/lgtm

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Jun 13, 2022
@RainbowMango RainbowMango added kind/feature Categorizes issue or PR as related to a new feature. and removed kind/bug Categorizes issue or PR as related to a bug. labels Jun 13, 2022
Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/approve

Note: I updated the PR description.(kind and release notes.)

@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 13, 2022
@karmada-bot karmada-bot merged commit 9a0ccad into karmada-io:master Jun 13, 2022
@RainbowMango RainbowMango added this to the v1.3 milestone Aug 30, 2022
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why does Built-in Interpreter AggregateStatus not contain Pod
5 participants