Skip to content

Commit

Permalink
pod probe marker controller (#1075)
Browse files Browse the repository at this point in the history
Signed-off-by: liheng.zms <[email protected]>

Signed-off-by: liheng.zms <[email protected]>
  • Loading branch information
zmberg authored Sep 20, 2022
1 parent 16277db commit 984d649
Show file tree
Hide file tree
Showing 15 changed files with 2,744 additions and 14 deletions.
6 changes: 2 additions & 4 deletions apis/apps/v1alpha1/node_pod_probe_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ type PodProbe struct {
}

type ContainerProbe struct {
// probe name, unique within the Pod(Even between different containers, they cannot be the same)
// Name is podProbeMarker.Name#probe.Name
Name string `json:"name"`
// container name
ContainerName string `json:"containerName"`
// container probe spec
Probe ContainerProbeSpec `json:"probe"`
// Used for NodeProbeProbe to quickly find the corresponding PodProbeMarker resource.
PodProbeMarkerName string `json:"podProbeMarkerName,omitempty"`
}

type NodePodProbeStatus struct {
Expand All @@ -64,7 +62,7 @@ type PodProbeStatus struct {
}

type ContainerProbeState struct {
// probe name
// Name is podProbeMarker.Name#probe.Name
Name string `json:"name"`
// container probe exec state, True or False
State ProbeState `json:"state"`
Expand Down
9 changes: 2 additions & 7 deletions config/crd/bases/apps.kruise.io_nodepodprobes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ spec:
description: container name
type: string
name:
description: probe name, unique within the Pod(Even between
different containers, they cannot be the same)
type: string
podProbeMarkerName:
description: Used for NodeProbeProbe to quickly find the
corresponding PodProbeMarker resource.
description: Name is podProbeMarker.Name#probe.Name
type: string
probe:
description: container probe spec
Expand Down Expand Up @@ -243,7 +238,7 @@ spec:
error message
type: string
name:
description: probe name
description: Name is podProbeMarker.Name#probe.Name
type: string
state:
description: container probe exec state, True or False
Expand Down
2 changes: 2 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ resources:
- bases/apps.kruise.io_workloadspreads.yaml
- bases/apps.kruise.io_ephemeraljobs.yaml
- bases/apps.kruise.io_persistentpodstates.yaml
- bases/apps.kruise.io_podprobemarkers.yaml
- bases/apps.kruise.io_nodepodprobes.yaml
# +kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand Down
40 changes: 40 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,26 @@ rules:
- get
- patch
- update
- apiGroups:
- apps.kruise.io
resources:
- nodepodprobes
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps.kruise.io
resources:
- nodepodprobes/status
verbs:
- get
- patch
- update
- apiGroups:
- apps.kruise.io
resources:
Expand All @@ -325,6 +345,26 @@ rules:
- get
- patch
- update
- apiGroups:
- apps.kruise.io
resources:
- podprobemarkers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps.kruise.io
resources:
- podprobemarkers/status
verbs:
- get
- patch
- update
- apiGroups:
- apps.kruise.io
resources:
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (
"github.com/openkruise/kruise/pkg/controller/ephemeraljob"
"github.com/openkruise/kruise/pkg/controller/imagepulljob"
"github.com/openkruise/kruise/pkg/controller/nodeimage"
"github.com/openkruise/kruise/pkg/controller/nodepodprobe"
"github.com/openkruise/kruise/pkg/controller/persistentpodstate"
"github.com/openkruise/kruise/pkg/controller/podprobemarker"
"github.com/openkruise/kruise/pkg/controller/podreadiness"
"github.com/openkruise/kruise/pkg/controller/podunavailablebudget"
"github.com/openkruise/kruise/pkg/controller/resourcedistribution"
Expand Down Expand Up @@ -59,6 +61,8 @@ func init() {
controllerAddFuncs = append(controllerAddFuncs, ephemeraljob.Add)
controllerAddFuncs = append(controllerAddFuncs, containerlauchpriority.Add)
controllerAddFuncs = append(controllerAddFuncs, persistentpodstate.Add)
controllerAddFuncs = append(controllerAddFuncs, podprobemarker.Add)
controllerAddFuncs = append(controllerAddFuncs, nodepodprobe.Add)
}

func SetupWithManager(m manager.Manager) error {
Expand Down
13 changes: 13 additions & 0 deletions pkg/controller/nodeimage/nodeimage_event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

const (
VirtualKubelet = "virtual-kubelet"
)

type nodeHandler struct {
client.Reader
}
Expand All @@ -41,6 +45,9 @@ var _ handler.EventHandler = &nodeHandler{}

func (e *nodeHandler) Create(evt event.CreateEvent, q workqueue.RateLimitingInterface) {
node := evt.Object.(*v1.Node)
if node.Labels["type"] == VirtualKubelet {
return
}
if node.DeletionTimestamp != nil {
e.nodeDelete(node, q)
return
Expand All @@ -53,6 +60,9 @@ func (e *nodeHandler) Generic(evt event.GenericEvent, q workqueue.RateLimitingIn

func (e *nodeHandler) Update(evt event.UpdateEvent, q workqueue.RateLimitingInterface) {
node := evt.ObjectNew.(*v1.Node)
if node.Labels["type"] == VirtualKubelet {
return
}
if node.DeletionTimestamp != nil {
e.nodeDelete(node, q)
} else {
Expand All @@ -62,6 +72,9 @@ func (e *nodeHandler) Update(evt event.UpdateEvent, q workqueue.RateLimitingInte

func (e *nodeHandler) Delete(evt event.DeleteEvent, q workqueue.RateLimitingInterface) {
node := evt.Object.(*v1.Node)
if node.Labels["type"] == VirtualKubelet {
return
}
e.nodeDelete(node, q)
}

Expand Down
Loading

0 comments on commit 984d649

Please sign in to comment.