event对应各类事件,比如删除pod,创建pod,所以如果有类似功能的模块,肯定会有eventrecord数据结构的。比如rc,在发现rc的参数和实际pod数量不一致,则调用kubeclient的api删除pod,并发布event

func (r RealPodControl) DeletePod(namespace string, podID string, object runtime.Object) error {
   accessor, err := meta.Accessor(object)
   if err != nil {
      return fmt.Errorf("object does not have ObjectMeta, %v", err)
   }
   if err := r.KubeClient.Core().Pods(namespace).Delete(podID, nil); err != nil {
      r.Recorder.Eventf(object, api.EventTypeWarning, "FailedDelete", "Error deleting: %v", err)
      return fmt.Errorf("unable to delete pods: %v", err)
   } else {
      glog.V(4).Infof("Controller %v deleted pod %v", accessor.GetName(), podID)
      r.Recorder.Eventf(object, api.EventTypeNormal, "SuccessfulDelete", "Deleted pod: %v", podID)
   }
   return nil
}

 

发布event其实通过event的函数发送给api server进行存储。通过eventBroadcaster.StartRecordingToSink()入参指定event发到哪

func (e *events) Create(event *api.Event) (*api.Event, error) {
   if e.namespace != "" && event.Namespace != e.namespace {
      return nil, fmt.Errorf("can't create an event with namespace '%v' in namespace '%v'", event.Namespace, e.namespace)
   }
   result := &api.Event{}
   err := e.client.Post().
      Namespace(event.Namespace).
      Resource("events").
      Body(event).
      Do().
      Into(result)
   return result, err
}
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐