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

add enhanced livenessprobe controller #1544

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

BH4AWS
Copy link
Collaborator

@BH4AWS BH4AWS commented Mar 26, 2024

Ⅰ. Describe what this PR does

A controller converts the pod livenessprobe config to nodePodProbe config.
This controller is the part of the enhanced livenessProbe solutions.

fix: #1535

Ⅱ. Does this pull request fix one issue?

Ⅲ. Describe how to verify it

when a pod with livenessProbe config is created, the native livenessProbe will be replaced to pod annotation and this controller converts to nodePodProbe config immediately.

Ⅳ. Special notes for reviews

@kruise-bot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign fei-guo for approval by writing /assign @fei-guo in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@BH4AWS BH4AWS force-pushed the add_enhanced_livenessprobe_controller_v2 branch 4 times, most recently from e06803a to aa96b38 Compare March 27, 2024 08:28
Copy link

codecov bot commented Mar 27, 2024

Codecov Report

Attention: Patch coverage is 48.57143% with 144 lines in your changes are missing coverage. Please review.

Project coverage is 47.89%. Comparing base (fd7e86e) to head (828c3fa).
Report is 9 commits behind head on master.

❗ Current head 828c3fa differs from pull request most recent head 689efee. Consider uploading reports for the commit 689efee to get more accurate results

Files Patch % Lines
...venessprobemapnodeprobe/probemapnodeprobe_utils.go 63.90% 46 Missing and 15 partials ⚠️
...nessprobemapnodeprobe/livenessprobemapnodeprobe.go 37.83% 38 Missing and 8 partials ⚠️
...apnodeprobe/probemapnodeprobe_pod_event_handler.go 0.00% 37 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1544      +/-   ##
==========================================
- Coverage   47.91%   47.89%   -0.02%     
==========================================
  Files         162      165       +3     
  Lines       23483    23771     +288     
==========================================
+ Hits        11252    11386     +134     
- Misses      11011    11139     +128     
- Partials     1220     1246      +26     
Flag Coverage Δ
unittests 47.89% <48.57%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BH4AWS BH4AWS force-pushed the add_enhanced_livenessprobe_controller_v2 branch from aa96b38 to 828c3fa Compare March 27, 2024 11:28
Signed-off-by: jicheng.sk <jicheng.sk@alibaba-inc.com>
@BH4AWS BH4AWS force-pushed the add_enhanced_livenessprobe_controller_v2 branch from 828c3fa to 689efee Compare April 7, 2024 08:32

const (
concurrentReconciles = 10
controllerName = "livenessprobemapnodeprobe-controller"
Copy link
Member

Choose a reason for hiding this comment

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

rename controller to more simplified form LivenessNodeProbeController , also plz rename the package and file name

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

podNewNppCloneSpec.PodProbes = newPodProbeTmp

// delete node pod probe
if len(podNewNppCloneSpec.PodProbes) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

if node still exists, it seems unnecessary to delete the nodepodprobe, just leave it empty seems enough

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done, remove
// delete node pod probe if len(podNewNppCloneSpec.PodProbes) == 0 { if err := r.Delete(context.TODO(), nppClone); err != nil { klog.Errorf("Failed to delete node pod probe for pod: %s/%s, err: %v", pod.Namespace, pod.Name, err) return err } return nil }

podContainerProbe.UID == fmt.Sprintf("%v", pod.UID) {
isHit = true
// diff the current pod container probes vs the npp container probes
if reflect.DeepEqual(podContainerProbe.Probes, generatePodContainersProbe(pod, containersLivenessProbeConfig)) {
Copy link
Member

Choose a reason for hiding this comment

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

duplicated calls to generatePodContainersProbe(3 times), just save the result of generatePodContainersProbe in a local variable e.g. newPodContainerProbes, and the isChanged is redundant if newPodContainerProbes is available


func (r *ReconcileEnhancedLivenessProbeMapNodeProbe) retryOnConflictDelNodeProbeConfig(pod *v1.Pod) error {
nppClone := &appsv1alpha1.NodePodProbe{}
err := retry.RetryOnConflict(retry.DefaultBackoff, func() error {
Copy link
Member

Choose a reason for hiding this comment

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

it is not necessary in a controller to retryonconflict, just return the error and reenqueue the pod

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.
retryOnConflictDelNodeProbeConfig -> delNodeProbeConfig

return nil
}

func (r *ReconcileEnhancedLivenessProbeMapNodeProbe) retryOnConflictAddNodeProbeConfig(pod *v1.Pod,
Copy link
Member

Choose a reason for hiding this comment

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

it is not necessary in a controller to retryonconflict, just return the error and reenqueue the pod

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.
retryOnConflictAddNodeProbeConfig -> addNodeProbeConfig

klog.Errorf("Failed to get node pod probe for pod: %s/%s, err: %v", pod.Namespace, pod.Name, err)
return err
}
newNppGenerated, err := r.generateNewNodePodProbe(pod)
Copy link
Member

Choose a reason for hiding this comment

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

pass plivenessProbeConfig to generateNewNodePodProbe, it is not necessary to parse the liveness probe twice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

func generateNewNodePodProbe(...) has been updated for using the podLivenessProbe from annotation as the paramater.

if !ok {
return
}
p.queue(q, new)
Copy link
Member

Choose a reason for hiding this comment

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

if pod liveness probe does not change, it seems not necessary to enqueue again

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done, details:
// check the livenessProbe config from new and old pod annotation whether is changed or not getNewPodConfig := getRawEnhancedLivenessProbeConfig(new) getOldPodConfig := getRawEnhancedLivenessProbeConfig(old) if !reflect.DeepEqual(getNewPodConfig, getOldPodConfig) { p.queue(q, new) }

}, 70*time.Second, time.Second).Should(gomega.Equal(util.DumpJSON(expectNodePodProbeSpec)))
})

framework.ConformanceIt("case:2 Create one pod with liveness probe config and update the", func() {
Copy link
Member

Choose a reason for hiding this comment

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

case:2 Create one pod with liveness probe config and update the -> case:2 Create one pod with liveness probe config and update the nodePodProbe

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

})

framework.ConformanceIt("case:2 Create one pod with liveness probe config and update the", func() {
ginkgo.By("New a new container with liveness probe config")
Copy link
Member

Choose a reason for hiding this comment

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

add case3, Create two pod with liveness probe config and delete one pod to update the nodePodProbe

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

1\add two pods and check the nodePodProbe config.
2\delete one pod and check the nodePodProbe config again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants