k8s/io/kubernetes/pkg/api.Node 示例代码

2022-03-03

以下示例是关于golang中包含api.Node用法的示例代码,想了解api.Node的具体用法?api.Node怎么用?api.Node使用的例子?那么可以参考以下10个相关示例代码来学习它的具体使用方法。

示例1:
nodecontroller_test.go开发语言: Go项目名称: kubernetes代码行数: 970
57
58func (m *FakeNodeHandler) Create(node *api.Node) (*api.Node, error) {
59	defer func() { m.RequestCount++ }()
108
109func (m *FakeNodeHandler) Update(node *api.Node) (*api.Node, error) {
110	nodeCopy := *node
598		{
599			nodes:      &api.NodeList{Items: []api.Node{*newNode("node0"), *newNode("node1")}},
600			fakeCloud:  &fake_cloud.FakeCloud{IP: net.ParseIP("1.2.3.4")},
603		{
604			nodes:      &api.NodeList{Items: []api.Node{*newNode("node0"), *newNode("node1")}},
605			fakeCloud:  &fake_cloud.FakeCloud{Err: ErrQueryIPAddress},
961
962func contains(node *api.Node, nodes []*api.Node) bool {
963	for i := 0; i < len(nodes); i++ {
示例2:
nodecontroller.go开发语言: Go项目名称: kubernetes代码行数: 417
219// PopulateIPs queries IPs for given list of nodes.
220func (s *NodeController) PopulateIPs(nodes *api.NodeList) (*api.NodeList, error) {
221	if s.isRunningCloudProvider() {
270// DoCheck performs health checking for given node.
271func (s *NodeController) DoCheck(node *api.Node) []api.NodeCondition {
272	var conditions []api.NodeCondition
301// checkNodeReady checks raw node ready condition, without transition timestamp set.
302func (s *NodeController) checkNodeReady(node *api.Node) *api.NodeCondition {
303	switch status, err := s.kubeletClient.HealthCheck(node.Name); {
399// canonicalizeName takes a node list and lowercases all nodes' name.
400func (s *NodeController) canonicalizeName(nodes *api.NodeList) *api.NodeList {
401	for i := range nodes.Items {
408// type, nil if the condition is not set.
409func (s *NodeController) getCondition(node *api.Node, conditionType api.NodeConditionType) *api.NodeCondition {
410	for i := range node.Status.Conditions {
示例3:
etcd_test.go开发语言: Go项目名称: kubernetes代码行数: 1042
819					{
820						Value: runtime.EncodeOrDie(latest.Codec, &api.Node{
821							ObjectMeta: api.ObjectMeta{Name: "foo"},
824					{
825						Value: runtime.EncodeOrDie(latest.Codec, &api.Node{
826							ObjectMeta: api.ObjectMeta{Name: "bar"},
848	registry := NewTestEtcdRegistry(fakeClient)
849	err := registry.CreateMinion(ctx, &api.Node{
850		ObjectMeta: api.ObjectMeta{Name: "foo"},
860
861	var minion api.Node
862	err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &minion)
874	fakeClient := tools.NewFakeEtcdClient(t)
875	fakeClient.Set("/registry/minions/foo", runtime.EncodeOrDie(latest.Codec, &api.Node{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
876	registry := NewTestEtcdRegistry(fakeClient)
示例4:
priorities_test.go开发语言: Go项目名称: kubernetes代码行数: 367
27
28func makeMinion(node string, milliCPU, memory int64) api.Node {
29	return api.Node{
30		ObjectMeta: api.ObjectMeta{Name: node},
31		Spec: api.NodeSpec{
32			Capacity: api.ResourceList{
98		pods         []api.Pod
99		nodes        []api.Node
100		expectedList HostPriorityList
115			pod:          api.Pod{Spec: noResources},
116			nodes:        []api.Node{makeMinion("machine1", 4000, 10000), makeMinion("machine2", 4000, 10000)},
117			expectedList: []HostPriority{{"machine1", 10}, {"machine2", 10}},
132			pod:          api.Pod{Spec: cpuAndMemory},
133			nodes:        []api.Node{makeMinion("machine1", 4000, 10000), makeMinion("machine2", 6000, 10000)},
134			expectedList: []HostPriority{{"machine1", 3}, {"machine2", 5}},
示例5:
predicates_test.go开发语言: Go项目名称: kubernetes代码行数: 577
27
28type FakeNodeInfo api.Node
29
30func (n FakeNodeInfo) GetNodeInfo(nodeName string) (*api.Node, error) {
31	node := api.Node(n)
32	return &node, nil
34
35type FakeNodeListInfo []api.Node
36
37func (nodes FakeNodeListInfo) GetNodeInfo(nodeName string) (*api.Node, error) {
38	for _, node := range nodes {
122	for _, test := range tests {
123		node := api.Node{Spec: api.NodeSpec{Capacity: makeResources(10, 20).Capacity}}
124
示例6:
pod_cache_test.go开发语言: Go项目名称: kubernetes代码行数: 524
163			Info: api.PodInfo{"bar": api.ContainerStatus{}}},
164		nodes: []api.Node{*makeHealthyNode("machine", "1.2.3.5")},
165		pod:   pod1,
197	c.fakeNodes = &client.Fake{
198		MinionsList: api.NodeList{
199			Items: c.nodes,
222
223func makeHealthyNode(name string, ip string) *api.Node {
224	return &api.Node{
225		ObjectMeta: api.ObjectMeta{Name: name},
226		Status: api.NodeStatus{
227			HostIP: ip,
237		ObjectMeta: api.ObjectMeta{Name: name},
238		Status: api.NodeStatus{Conditions: []api.NodeCondition{
239			{Type: api.NodeReady, Status: api.ConditionNone},
示例7:
predicates.go开发语言: Go项目名称: kubernetes代码行数: 343
28type NodeInfo interface {
29	GetNodeInfo(nodeID string) (*api.Node, error)
30}
32type StaticNodeInfo struct {
33	*api.NodeList
34}
35
36func (nodes StaticNodeInfo) GetNodeInfo(nodeID string) (*api.Node, error) {
37	for ix := range nodes.Items {
48
49func (nodes ClientNodeInfo) GetNodeInfo(nodeID string) (*api.Node, error) {
50	return nodes.Nodes().Get(nodeID)
示例8:
factory_test.go开发语言: Go项目名称: kubernetes代码行数: 362
50	table := []struct {
51		minions       []api.Node
52		expectedCount int
54		{
55			minions: []api.Node{
56				{
57					ObjectMeta: api.ObjectMeta{Name: "foo"},
58					Status: api.NodeStatus{
59						Conditions: []api.NodeCondition{
60							{Type: api.NodeReady, Status: api.ConditionFull},
61						},
65					ObjectMeta: api.ObjectMeta{Name: "bar"},
66					Status: api.NodeStatus{
67						Conditions: []api.NodeCondition{
示例9:
rest_test.go开发语言: Go项目名称: kubernetes代码行数: 171
29func TestMinionRegistryREST(t *testing.T) {
30	ms := NewREST(registrytest.NewMinionRegistry([]string{"foo", "bar"}, api.NodeResources{}))
31	ctx := api.NewContext()
32	if obj, err := ms.Get(ctx, "foo"); err != nil || obj.(*api.Node).Name != "foo" {
33		t.Errorf("missing expected object")
34	}
35	if obj, err := ms.Get(ctx, "bar"); err != nil || obj.(*api.Node).Name != "bar" {
36		t.Errorf("missing expected object")
41
42	obj, err := ms.Create(ctx, &api.Node{ObjectMeta: api.ObjectMeta{Name: "baz"}})
43	if err != nil {
45	}
46	if !api.HasObjectMetaSystemFieldValues(&obj.(*api.Node).ObjectMeta) {
47		t.Errorf("storage did not populate object meta field values")
示例10:
minion.go开发语言: Go项目名称: kubernetes代码行数: 117
31	Minion  string
32	Minions api.NodeList
33
37// MakeMinionList constructs api.MinionList from list of minion names and a NodeResource.
38func MakeMinionList(minions []string, nodeResources api.NodeResources) *api.NodeList {
39	list := api.NodeList{
40		Items: make([]api.Node, len(minions)),
41	}
48
49func NewMinionRegistry(minions []string, nodeResources api.NodeResources) *MinionRegistry {
50	return &MinionRegistry{
60
61func (r *MinionRegistry) ListMinions(ctx api.Context) (*api.NodeList, error) {
62	r.Lock()

本文地址:https://www.itbaoku.cn/snippets/415656.html