本文整理汇总了Golang中k8s/io/kubernetes/pkg/client/unversioned.Interface.Nodes方法的典型用法代码示例。如果您正苦于以下问题:Golang Interface.Nodes方法的具体用法?Golang Interface.Nodes怎么用?Golang Interface.Nodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类k8s/io/kubernetes/pkg/client/unversioned.Interface
的用法示例。
在下文中一共展示了Interface.Nodes方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makeNNodes
func makeNNodes(c client.Interface, N int) {
baseNode := &api.Node{
ObjectMeta: api.ObjectMeta{
GenerateName: "scheduler-test-node-",
},
Spec: api.NodeSpec{
ExternalID: "foobar",
},
Status: api.NodeStatus{
Capacity: api.ResourceList{
api.ResourcePods: *resource.NewQuantity(32, resource.DecimalSI),
api.ResourceCPU: resource.MustParse("4"),
api.ResourceMemory: resource.MustParse("32Gi"),
},
Phase: api.NodeRunning,
Conditions: []api.NodeCondition{
{Type: api.NodeReady, Status: api.ConditionTrue},
},
},
}
for i := 0; i < N; i++ {
if _, err := c.Nodes().Create(baseNode); err != nil {
panic("error creating node: " + err.Error())
}
}
}
示例2: unloadNodeLabel
func unloadNodeLabel(client kclient.Interface, application *api.Application, labelSelector labels.Selector) error {
resourceList, _ := client.Nodes().List(kapi.ListOptions{LabelSelector: labelSelector, FieldSelector: fields.Everything()})
errs := []error{}
for _, resource := range resourceList.Items {
if !hasItem(application.Spec.Items, api.Item{Kind: "Node", Name: resource.Name}) {
delete(resource.Labels, fmt.Sprintf("%s.application.%s", application.Namespace, application.Name))
if _, err := client.Nodes().Update(&resource); err != nil {
errs = append(errs, err)
}
}
}
return nil
}
示例3: GetNodeDetail
// GetNodeDetail gets node details.
func GetNodeDetail(client k8sClient.Interface, heapsterClient client.HeapsterClient, name string) (*NodeDetail, error) {
log.Printf("Getting details of %s node", name)
node, err := client.Nodes().Get(name)
if err != nil {
return nil, err
}
// Download standard metrics. Currently metrics are hard coded, but it is possible to replace
// dataselect.StdMetricsDataSelect with data select provided in the request.
_, metricPromises := dataselect.GenericDataSelectWithMetrics(toCells([]api.Node{*node}),
dataselect.StdMetricsDataSelect,
dataselect.NoResourceCache, &heapsterClient)
pods, err := getNodePods(client, *node)
if err != nil {
return nil, err
}
podList, err := GetNodePods(client, heapsterClient, dataselect.DefaultDataSelect, name)
eventList, err := event.GetNodeEvents(client, dataselect.DefaultDataSelect, node.Name)
if err != nil {
return nil, err
}
allocatedResources, err := getNodeAllocatedResources(*node, pods)
if err != nil {
return nil, err
}
metrics, _ := metricPromises.GetMetrics()
nodeDetails := toNodeDetail(*node, podList, eventList, allocatedResources, metrics)
return &nodeDetails, nil
}
示例4: GetNodeDetail
// GetNodeDetail gets node details.
func GetNodeDetail(client k8sClient.Interface, heapsterClient client.HeapsterClient, name string) (
*NodeDetail, error) {
log.Printf("Getting details of %s node", name)
node, err := client.Nodes().Get(name)
if err != nil {
return nil, err
}
pods, err := getNodePods(client, *node)
if err != nil {
return nil, err
}
podList := pod.CreatePodList(pods.Items, heapsterClient)
events, err := event.GetNodeEvents(client, node.Name)
if err != nil {
return nil, err
}
allocatedResources, err := getNodeAllocatedResources(*node, pods)
if err != nil {
return nil, err
}
nodeDetails := toNodeDetail(*node, podList, events, allocatedResources)
return &nodeDetails, nil
}
示例5: GetNodeList
// GetNodeList returns a list of all Nodes in the cluster.
func GetNodeList(client client.Interface) (*NodeList, error) {
log.Printf("Getting list of all nodes in the cluster")
nodes, err := client.Nodes().List(api.ListOptions{
LabelSelector: labels.Everything(),
FieldSelector: fields.Everything(),
})
if err != nil {
return nil, err
}
return toNodeList(nodes.Items), nil
}
示例6: GetNodePods
func GetNodePods(client k8sClient.Interface, heapsterClient client.HeapsterClient, dsQuery *dataselect.DataSelectQuery, name string) (*pod.PodList, error) {
node, err := client.Nodes().Get(name)
if err != nil {
return nil, err
}
pods, err := getNodePods(client, *node)
if err != nil {
return nil, err
}
podList := pod.CreatePodList(pods.Items, dsQuery, heapsterClient)
return &podList, nil
}
示例7: GetNodeEvents
// GetNodeEvents gets events associated to node with given name.
func GetNodeEvents(client client.Interface, dsQuery *dataselect.DataSelectQuery, nodeName string) (*common.EventList, error) {
var eventList common.EventList
mc := client.Nodes()
node, _ := mc.Get(nodeName)
if ref, err := api.GetReference(node); err == nil {
ref.UID = types.UID(ref.Name)
events, _ := client.Events(api.NamespaceAll).Search(ref)
eventList = CreateEventList(events.Items, dsQuery)
} else {
log.Print(err)
}
return &eventList, nil
}
示例8: GetNodeEvents
// GetNodeEvents gets events associated to node with given name.
func GetNodeEvents(client client.Interface, nodeName string) (common.EventList, error) {
eventList := common.EventList{
Namespace: api.NamespaceAll,
Events: make([]common.Event, 0),
}
mc := client.Nodes()
node, _ := mc.Get(nodeName)
if ref, err := api.GetReference(node); err == nil {
ref.UID = types.UID(ref.Name)
events, _ := client.Events(api.NamespaceAll).Search(ref)
AppendEvents(events.Items, eventList)
} else {
log.Print(err)
}
return eventList, nil
}
示例9: GetReplicationControllerDetail
// GetReplicationControllerDetail returns detailed information about the given replication
// controller in the given namespace.
func GetReplicationControllerDetail(client client.Interface, heapsterClient HeapsterClient,
namespace, name string) (*ReplicationControllerDetail, error) {
log.Printf("Getting details of %s replication controller in %s namespace", name, namespace)
replicationControllerWithPods, err := getRawReplicationControllerWithPods(client, namespace, name)
if err != nil {
return nil, err
}
replicationController := replicationControllerWithPods.ReplicationController
pods := replicationControllerWithPods.Pods
replicationControllerMetricsByPod, err := getReplicationControllerPodsMetrics(pods, heapsterClient, namespace, name)
if err != nil {
log.Printf("Skipping Heapster metrics because of error: %s\n", err)
}
services, err := client.Services(namespace).List(api.ListOptions{
LabelSelector: labels.Everything(),
FieldSelector: fields.Everything(),
})
if err != nil {
return nil, err
}
replicationControllerDetail := &ReplicationControllerDetail{
Name: replicationController.Name,
Namespace: replicationController.Namespace,
Labels: replicationController.ObjectMeta.Labels,
LabelSelector: replicationController.Spec.Selector,
PodInfo: getReplicationControllerPodInfo(replicationController, pods.Items),
}
matchingServices := getMatchingServices(services.Items, replicationController)
// Anonymous callback function to get nodes by their names.
getNodeFn := func(nodeName string) (*api.Node, error) {
return client.Nodes().Get(nodeName)
}
for _, service := range matchingServices {
replicationControllerDetail.Services = append(replicationControllerDetail.Services,
getServiceDetail(service, *replicationController, pods.Items, getNodeFn))
}
for _, container := range replicationController.Spec.Template.Spec.Containers {
replicationControllerDetail.ContainerImages = append(replicationControllerDetail.ContainerImages,
container.Image)
}
for _, pod := range pods.Items {
podDetail := ReplicationControllerPod{
Name: pod.Name,
PodPhase: pod.Status.Phase,
StartTime: pod.CreationTimestamp,
PodIP: pod.Status.PodIP,
NodeName: pod.Spec.NodeName,
RestartCount: getRestartCount(pod),
}
if replicationControllerMetricsByPod != nil {
metric := replicationControllerMetricsByPod.MetricsMap[pod.Name]
podDetail.Metrics = &metric
replicationControllerDetail.HasMetrics = true
}
replicationControllerDetail.Pods = append(replicationControllerDetail.Pods, podDetail)
}
return replicationControllerDetail, nil
}