本文整理汇总了Golang中github.com/google/cadvisor/container.NewContainerHandler函数的典型用法代码示例。如果您正苦于以下问题:Golang NewContainerHandler函数的具体用法?Golang NewContainerHandler怎么用?Golang NewContainerHandler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewContainerHandler函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestNewContainerHandler_SecondMatches
func TestNewContainerHandler_SecondMatches(t *testing.T) {
container.ClearContainerHandlerFactories()
// Register one allways no and one always yes factory.
allwaysNo := &mockContainerHandlerFactory{
Name: "no",
CanHandleValue: false,
CanAcceptValue: true,
}
container.RegisterContainerHandlerFactory(allwaysNo, []watcher.ContainerWatchSource{watcher.Raw})
allwaysYes := &mockContainerHandlerFactory{
Name: "yes",
CanHandleValue: true,
CanAcceptValue: true,
}
container.RegisterContainerHandlerFactory(allwaysYes, []watcher.ContainerWatchSource{watcher.Raw})
// The yes factory should be asked to create the ContainerHandler.
mockContainer, err := mockFactory.NewContainerHandler(testContainerName, true)
if err != nil {
t.Error(err)
}
allwaysYes.On("NewContainerHandler", testContainerName).Return(mockContainer, nil)
cont, _, err := container.NewContainerHandler(testContainerName, watcher.Raw, true)
if err != nil {
t.Error(err)
}
if cont == nil {
t.Error("Expected container to not be nil")
}
}
开发者ID:zgfh,项目名称:cadvisor,代码行数:32,代码来源:factory_test.go
示例2: TestNewContainerHandler_Accept
func TestNewContainerHandler_Accept(t *testing.T) {
container.ClearContainerHandlerFactories()
// Register handler that can handle the container, but can't accept it.
cannotHandle := &mockContainerHandlerFactory{
Name: "no",
CanHandleValue: false,
CanAcceptValue: true,
}
container.RegisterContainerHandlerFactory(cannotHandle, []watcher.ContainerWatchSource{watcher.Raw})
cannotAccept := &mockContainerHandlerFactory{
Name: "no",
CanHandleValue: true,
CanAcceptValue: false,
}
container.RegisterContainerHandlerFactory(cannotAccept, []watcher.ContainerWatchSource{watcher.Raw})
_, accept, err := container.NewContainerHandler(testContainerName, watcher.Raw, true)
if err != nil {
t.Error("Expected NewContainerHandler to succeed")
}
if accept == true {
t.Error("Expected NewContainerHandler to ignore the container.")
}
}
开发者ID:zgfh,项目名称:cadvisor,代码行数:25,代码来源:factory_test.go
示例3: NewContainerData
func NewContainerData(containerName string) (*containerData, error) {
cont := &containerData{}
handler, err := container.NewContainerHandler(containerName)
if err != nil {
return nil, err
}
cont.handler = handler
cont.info.Name = containerName
cont.info.Stats = list.New()
cont.stop = make(chan bool, 1)
return cont, nil
}
开发者ID:kleopatra999,项目名称:cadvisor,代码行数:13,代码来源:container.go
示例4: createContainer
// Create a container.
func (m *manager) createContainer(containerName string) error {
handler, err := container.NewContainerHandler(containerName)
if err != nil {
return err
}
logUsage := *logCadvisorUsage && containerName == m.cadvisorContainer
cont, err := newContainerData(containerName, m.storageDriver, handler, m.loadReader, logUsage)
if err != nil {
return err
}
// Add to the containers map.
alreadyExists := func() bool {
m.containersLock.Lock()
defer m.containersLock.Unlock()
namespacedName := namespacedContainerName{
Name: containerName,
}
// Check that the container didn't already exist.
_, ok := m.containers[namespacedName]
if ok {
return true
}
// Add the container name and all its aliases. The aliases must be within the namespace of the factory.
m.containers[namespacedName] = cont
for _, alias := range cont.info.Aliases {
m.containers[namespacedContainerName{
Namespace: cont.info.Namespace,
Name: alias,
}] = cont
}
return false
}()
if alreadyExists {
return nil
}
glog.Infof("Added container: %q (aliases: %v, namespace: %q)", containerName, cont.info.Aliases, cont.info.Namespace)
// Start the container's housekeeping.
cont.Start()
return nil
}
开发者ID:rjnagal,项目名称:cadvisor,代码行数:47,代码来源:manager.go
示例5: NewContainerData
func NewContainerData(containerName string, driver storage.StorageDriver) (*containerData, error) {
if driver == nil {
return nil, fmt.Errorf("nil storage driver")
}
cont := &containerData{}
handler, err := container.NewContainerHandler(containerName)
if err != nil {
return nil, err
}
cont.handler = handler
ref, err := handler.ContainerReference()
if err != nil {
return nil, err
}
cont.info.Name = ref.Name
cont.info.Aliases = ref.Aliases
cont.storageDriver = driver
cont.stop = make(chan bool, 1)
return cont, nil
}
开发者ID:rayleyva,项目名称:cadvisor,代码行数:21,代码来源:container.go
示例6: createContainer
// Create a container.
func (m *manager) createContainer(containerName string) error {
handler, err := container.NewContainerHandler(containerName)
if err != nil {
return err
}
logUsage := *logCadvisorUsage && containerName == m.cadvisorContainer
cont, err := newContainerData(containerName, m.storageDriver, handler, logUsage)
if err != nil {
return err
}
// Add to the containers map.
alreadyExists := func() bool {
m.containersLock.Lock()
defer m.containersLock.Unlock()
// Check that the container didn't already exist.
_, ok := m.containers[containerName]
if ok {
return true
}
// Add the container name and all its aliases.
m.containers[containerName] = cont
for _, alias := range cont.info.Aliases {
m.containers[alias] = cont
}
return false
}()
if alreadyExists {
return nil
}
glog.Infof("Added container: %q (aliases: %s)", containerName, cont.info.Aliases)
// Start the container's housekeeping.
cont.Start()
return nil
}
开发者ID:wulibin163,项目名称:cadvisor,代码行数:40,代码来源:manager.go
示例7: TestNewContainerHandler_NoneMatch
func TestNewContainerHandler_NoneMatch(t *testing.T) {
container.ClearContainerHandlerFactories()
// Register two allways no factories.
allwaysNo1 := &mockContainerHandlerFactory{
Name: "no",
CanHandleValue: false,
CanAcceptValue: true,
}
container.RegisterContainerHandlerFactory(allwaysNo1, []watcher.ContainerWatchSource{watcher.Raw})
allwaysNo2 := &mockContainerHandlerFactory{
Name: "no",
CanHandleValue: false,
CanAcceptValue: true,
}
container.RegisterContainerHandlerFactory(allwaysNo2, []watcher.ContainerWatchSource{watcher.Raw})
_, _, err := container.NewContainerHandler(testContainerName, watcher.Raw, true)
if err == nil {
t.Error("Expected NewContainerHandler to fail")
}
}
开发者ID:zgfh,项目名称:cadvisor,代码行数:22,代码来源:factory_test.go
示例8: createContainer
// Create a container.
func (m *manager) createContainer(containerName string) error {
handler, accept, err := container.NewContainerHandler(containerName)
if err != nil {
return err
}
if !accept {
// ignoring this container.
glog.V(4).Infof("ignoring container %q", containerName)
return nil
}
collectorManager, err := collector.NewCollectorManager()
if err != nil {
return err
}
logUsage := *logCadvisorUsage && containerName == m.cadvisorContainer
cont, err := newContainerData(containerName, m.memoryCache, handler, m.loadReader, logUsage, collectorManager, m.maxHousekeepingInterval, m.allowDynamicHousekeeping)
if err != nil {
return err
}
// Add collectors
labels := handler.GetContainerLabels()
collectorConfigs := collector.GetCollectorConfigs(labels)
err = m.registerCollectors(collectorConfigs, cont)
if err != nil {
glog.Infof("failed to register collectors for %q: %v", containerName, err)
return err
}
// Add to the containers map.
alreadyExists := func() bool {
m.containersLock.Lock()
defer m.containersLock.Unlock()
namespacedName := namespacedContainerName{
Name: containerName,
}
// Check that the container didn't already exist.
_, ok := m.containers[namespacedName]
if ok {
return true
}
// Add the container name and all its aliases. The aliases must be within the namespace of the factory.
m.containers[namespacedName] = cont
for _, alias := range cont.info.Aliases {
m.containers[namespacedContainerName{
Namespace: cont.info.Namespace,
Name: alias,
}] = cont
}
return false
}()
if alreadyExists {
return nil
}
glog.V(3).Infof("Added container: %q (aliases: %v, namespace: %q)", containerName, cont.info.Aliases, cont.info.Namespace)
contSpec, err := cont.handler.GetSpec()
if err != nil {
return err
}
contRef, err := cont.handler.ContainerReference()
if err != nil {
return err
}
newEvent := &info.Event{
ContainerName: contRef.Name,
Timestamp: contSpec.CreationTime,
EventType: info.EventContainerCreation,
}
err = m.eventHandler.AddEvent(newEvent)
if err != nil {
return err
}
// Start the container's housekeeping.
cont.Start()
return nil
}
开发者ID:niclange,项目名称:cadvisor,代码行数:87,代码来源:manager.go
示例9: createContainer
// Create a container.
func (m *manager) createContainer(containerName string) error {
handler, err := container.NewContainerHandler(containerName)
if err != nil {
return err
}
logUsage := *logCadvisorUsage && containerName == m.cadvisorContainer
cont, err := newContainerData(containerName, m.memoryStorage, handler, m.loadReader, logUsage)
if err != nil {
return err
}
// Add to the containers map.
alreadyExists := func() bool {
m.containersLock.Lock()
defer m.containersLock.Unlock()
namespacedName := namespacedContainerName{
Name: containerName,
}
// Check that the container didn't already exist.
_, ok := m.containers[namespacedName]
if ok {
return true
}
// Add the container name and all its aliases. The aliases must be within the namespace of the factory.
m.containers[namespacedName] = cont
for _, alias := range cont.info.Aliases {
m.containers[namespacedContainerName{
Namespace: cont.info.Namespace,
Name: alias,
}] = cont
}
return false
}()
if alreadyExists {
return nil
}
glog.V(2).Infof("Added container: %q (aliases: %v, namespace: %q)", containerName, cont.info.Aliases, cont.info.Namespace)
contSpec, err := cont.handler.GetSpec()
if err != nil {
return err
}
if contSpec.CreationTime.After(m.startupTime) {
contRef, err := cont.handler.ContainerReference()
if err != nil {
return err
}
newEvent := &info.Event{
ContainerName: contRef.Name,
Timestamp: contSpec.CreationTime,
EventType: info.EventContainerCreation,
EventData: info.EventData{
Created: &info.CreatedEventData{
Spec: contSpec,
},
},
}
err = m.eventHandler.AddEvent(newEvent)
if err != nil {
return err
}
}
// Start the container's housekeeping.
cont.Start()
return nil
}
开发者ID:SivagnanamCiena,项目名称:calico-kubernetes,代码行数:75,代码来源:manager.go
注:本文中的github.com/google/cadvisor/container.NewContainerHandler函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论