代码拉取完成,页面将自动刷新
package podmonitor
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
// WatchPodMapper determines if we want to reconcile on a pod event. There are two limitiations:
// - the pod must be schedule on a matching nodeName
// - if the pod requests host networking, only reconcile if we want to enable host pods
type WatchPodMapper struct {
client client.Client
nodeName string
enableHostPods bool
}
// Map implements the handler.Mapper interface to emit reconciles for corev1.Pods. It effectively
// filters the pods by looking for a matching nodeName and filters them out if host networking is requested,
// but we don't want to enable those.
func (w *WatchPodMapper) Map(obj handler.MapObject) []reconcile.Request {
pod, ok := obj.Object.(*corev1.Pod)
if !ok {
return nil
}
if pod.Spec.NodeName != w.nodeName {
return nil
}
if pod.Spec.HostNetwork && !w.enableHostPods {
return nil
}
return []reconcile.Request{
{
NamespacedName: types.NamespacedName{
Name: pod.Name,
Namespace: pod.Namespace,
},
},
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。