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


Golang Container.Labels方法代碼示例

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


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

示例1: createAPIContainer

func createAPIContainer(c runtime.Container, getPids bool) (*types.Container, error) {
	processes, err := c.Processes()
	if err != nil {
		return nil, grpc.Errorf(codes.Internal, "get processes for container: "+err.Error())
	}
	var procs []*types.Process
	for _, p := range processes {
		oldProc := p.Spec()
		stdio := p.Stdio()
		proc := &types.Process{
			Pid:       p.ID(),
			SystemPid: uint32(p.SystemPid()),
			Terminal:  oldProc.Terminal,
			Args:      oldProc.Args,
			Env:       oldProc.Env,
			Cwd:       oldProc.Cwd,
			Stdin:     stdio.Stdin,
			Stdout:    stdio.Stdout,
			Stderr:    stdio.Stderr,
		}
		proc.User = &types.User{
			Uid:            oldProc.User.UID,
			Gid:            oldProc.User.GID,
			AdditionalGids: oldProc.User.AdditionalGids,
		}
		proc.Capabilities = oldProc.Capabilities
		proc.ApparmorProfile = oldProc.ApparmorProfile
		proc.SelinuxLabel = oldProc.SelinuxLabel
		proc.NoNewPrivileges = oldProc.NoNewPrivileges
		for _, rl := range oldProc.Rlimits {
			proc.Rlimits = append(proc.Rlimits, &types.Rlimit{
				Type: rl.Type,
				Soft: rl.Soft,
				Hard: rl.Hard,
			})
		}
		procs = append(procs, proc)
	}
	var pids []int
	state, err := c.Status()
	if err != nil {
		return nil, grpc.Errorf(codes.Internal, "get status for container: "+err.Error())
	}

	if getPids && (state == runtime.Running || state == runtime.Paused) {
		if pids, err = c.Pids(); err != nil {
			return nil, grpc.Errorf(codes.Internal, "get all pids for container: "+err.Error())
		}
	}
	return &types.Container{
		Id:         c.ID(),
		BundlePath: c.Path(),
		Processes:  procs,
		Labels:     c.Labels(),
		Status:     string(state),
		Pids:       toUint32(pids),
		Runtime:    c.Runtime(),
	}, nil
}
開發者ID:Altiscale,項目名稱:containerd,代碼行數:59,代碼來源:server.go

示例2: createAPIContainer

func createAPIContainer(c runtime.Container, getPids bool) (*types.Container, error) {
	processes, err := c.Processes()
	if err != nil {
		return nil, grpc.Errorf(codes.Internal, "get processes for container: "+err.Error())
	}
	var procs []*types.Process
	for _, p := range processes {
		oldProc := p.Spec()
		stdio := p.Stdio()
		appendToProcs := &types.Process{
			Pid:       p.ID(),
			SystemPid: uint32(p.SystemPid()),
			Terminal:  oldProc.Terminal,
			Args:      oldProc.Args,
			Env:       oldProc.Env,
			Cwd:       oldProc.Cwd,
			Stdin:     stdio.Stdin,
			Stdout:    stdio.Stdout,
			Stderr:    stdio.Stderr,
		}
		setUserFieldsInProcess(appendToProcs, oldProc)
		procs = append(procs, appendToProcs)
	}
	var pids []int
	state := c.State()
	if getPids && (state == runtime.Running || state == runtime.Paused) {
		if pids, err = c.Pids(); err != nil {
			return nil, grpc.Errorf(codes.Internal, "get all pids for container: "+err.Error())
		}
	}
	return &types.Container{
		Id:         c.ID(),
		BundlePath: c.Path(),
		Processes:  procs,
		Labels:     c.Labels(),
		Status:     string(state),
		Pids:       toUint32(pids),
		Runtime:    c.Runtime(),
	}, nil
}
開發者ID:carriercomm,項目名稱:containerd,代碼行數:40,代碼來源:server.go


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