代码拉取完成,页面将自动刷新
package servicemonitor
import (
"fmt"
"strings"
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
util "github.com/rancher/rancher/pkg/controllers/user/workload"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
)
func (c *MetricsServiceController) ensureService(key string, svc *corev1.Service) (runtime.Object, error) {
if svc == nil || svc.DeletionTimestamp != nil {
parts := strings.Split(key, "/")
sms, err := c.smLister.List(parts[0], labels.NewSelector())
if err != nil {
return svc, err
}
for _, sm := range sms {
c.smClient.Controller().Enqueue(sm.Namespace, sm.Name)
}
return svc, nil
}
if _, ok := svc.Annotations[metricsServiceLabel]; !ok {
return svc, nil
}
var owner *monitoringv1.ServiceMonitor
var err error
for _, o := range svc.OwnerReferences {
if o.Kind == "ServiceMonitor" {
owner, err = c.smLister.Get(svc.Namespace, o.Name)
if err != nil {
return svc, err
}
}
}
ports := GetServicePortsFromEndpoint(owner.Spec.Endpoints)
if !util.ArePortsEqual(ports, svc.Spec.Ports) {
c.smClient.Controller().Enqueue(owner.Namespace, owner.Name)
}
return svc, nil
}
func (c *MetricsServiceController) ensureServiceMonitor(key string, obj *monitoringv1.ServiceMonitor) (runtime.Object, error) {
if obj == nil || obj.DeletionTimestamp != nil {
parts := strings.Split(key, "/")
return obj, c.workloadLister.EnqueueAllWorkloads(parts[0])
}
var workload *util.Workload
var err error
for _, owner := range obj.OwnerReferences {
key := fmt.Sprintf("%s:%s:%s", strings.ToLower(owner.Kind), obj.Namespace, owner.Name)
workload, err = c.workloadLister.GetByWorkloadID(key)
if err != nil {
continue
}
}
if workload == nil {
return obj, nil
}
c.workloadLister.EnqueueWorkload(workload)
return obj, nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。