當前位置: 首頁>>代碼示例>>Golang>>正文


Golang EventInterface.List方法代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/client/unversioned.EventInterface.List方法的典型用法代碼示例。如果您正苦於以下問題:Golang EventInterface.List方法的具體用法?Golang EventInterface.List怎麽用?Golang EventInterface.List使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在k8s/io/kubernetes/pkg/client/unversioned.EventInterface的用法示例。


在下文中一共展示了EventInterface.List方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: verifyNoEvents

// verifyNoEvents verifies there is no event generated
func verifyNoEvents(e client.EventInterface, options api.ListOptions) error {
	events, err := e.List(options)
	if err != nil {
		return err
	}
	if len(events.Items) != 0 {
		return fmt.Errorf("unexpected events: %v", events.Items)
	}
	return nil
}
開發者ID:AdoHe,項目名稱:kubernetes,代碼行數:11,代碼來源:node_problem_detector.go

示例2: verifyEvents

// verifyEvents verifies there are num specific events generated
func verifyEvents(e client.EventInterface, options api.ListOptions, num int, reason, message string) error {
	events, err := e.List(options)
	if err != nil {
		return err
	}
	count := 0
	for _, event := range events.Items {
		if event.Reason != reason || event.Message != message {
			return fmt.Errorf("unexpected event: %v", event)
		}
		count += int(event.Count)
	}
	if count != num {
		return fmt.Errorf("expect event number %d, got %d: %v", num, count, events.Items)
	}
	return nil
}
開發者ID:AdoHe,項目名稱:kubernetes,代碼行數:18,代碼來源:node_problem_detector.go

示例3: watchLoop

// watchLoop loops forever looking for new events.  If an error occurs it will close the channel and return.
func (eventSource *eventsSourceImpl) watchLoop(eventClient kubeclient.EventInterface, eventsChan chan<- eventsUpdate, errorChan chan<- error) {
	defer close(eventsChan)
	defer close(errorChan)
	events, err := eventClient.List(kubelabels.Everything(), kubefields.Everything())
	if err != nil {
		glog.Errorf("Failed to load events: %v", err)
		errorChan <- err
		return
	}
	resourceVersion := events.ResourceVersion
	eventsChan <- eventsUpdate{events: events}

	if err := eventSource.storeEventsInCache(events); err != nil {
		glog.Errorf("failed to store events in cache: %v", err)
		errorChan <- err
		return
	}

	watcher, err := eventClient.Watch(kubelabels.Everything(), kubefields.Everything(), resourceVersion)
	if err != nil {
		glog.Errorf("Failed to start watch for new events: %v", err)
		errorChan <- err
		return
	}
	defer watcher.Stop()

	watchChannel := watcher.ResultChan()
	for {
		watchUpdate, ok := <-watchChannel
		if !ok {
			err := errors.New("watchLoop channel closed")
			errorChan <- err
			return
		}

		if watchUpdate.Type == kubewatch.Error {
			if status, ok := watchUpdate.Object.(*kubeapiunv.Status); ok {
				err := fmt.Errorf("Error during watch: %#v", status)
				errorChan <- err
				return
			}
			err := fmt.Errorf("Received unexpected error: %#v", watchUpdate.Object)
			errorChan <- err
			return
		}

		if event, ok := watchUpdate.Object.(*kubeapi.Event); ok {

			switch watchUpdate.Type {
			case kubewatch.Added, kubewatch.Modified:
				eList := &kubeapi.EventList{Items: []kubeapi.Event{*event}}
				eventsChan <- eventsUpdate{eList}
				if err := eventSource.storeEventsInCache(eList); err != nil {
					glog.Errorf("failed to store events in cache: %v", err)
					errorChan <- err
					return
				}
			case kubewatch.Deleted:
				// Deleted events are silently ignored
			default:
				err := fmt.Errorf("Unknown watchUpdate.Type: %#v", watchUpdate.Type)
				errorChan <- err
				return
			}
			resourceVersion = event.ResourceVersion
			continue
		}
	}
}
開發者ID:MohamedFAhmed,項目名稱:heapster,代碼行數:70,代碼來源:kube_events.go


注:本文中的k8s/io/kubernetes/pkg/client/unversioned.EventInterface.List方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。