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

2022-03-03

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

示例1:
examples_test.go开发语言: Go项目名称: kubernetes代码行数: 233
45		}
46	case *api.Service:
47		if t.Namespace == "" {
51		errors = validation.ValidateService(t)
52	case *api.ServiceList:
53		for i := range t.Items {
105			"pod-list":         &api.PodList{},
106			"service":          &api.Service{},
107			"external-service": &api.Service{},
108			"service-list":     &api.ServiceList{},
109		},
113			"redis-master-controller": &api.ReplicationController{},
114			"frontend-service":        &api.Service{},
115			"redis-master-service":    &api.Service{},
示例2:
validation_test.go开发语言: Go项目名称: kubernetes代码行数: 2544
1090		name     string
1091		svc      api.Service
1092		existing api.ServiceList
1096			name: "missing id",
1097			svc: api.Service{
1098				ObjectMeta: api.ObjectMeta{Namespace: api.NamespaceDefault},
1099				Spec: api.ServiceSpec{
1100					Port:            8675,
1110			name: "missing protocol",
1111			svc: api.Service{
1112				ObjectMeta: api.ObjectMeta{Name: "abc123", Namespace: api.NamespaceDefault},
1113				Spec: api.ServiceSpec{
1114					Port:            8675,
示例3:
rest_test.go开发语言: Go项目名称: kubernetes代码行数: 601
45	storage := NewREST(registry, fakeCloud, registrytest.NewMinionRegistry(machines, api.NodeResources{}), makeIPNet(t))
46	svc := &api.Service{
47		Port:     6502,
53	created_svc := <-c
54	created_service := created_svc.(*api.Service)
55	if created_service.ID != "foo" {
81	storage := NewREST(registry, nil, nil, makeIPNet(t))
82	failureCases := map[string]api.Service{
83		"empty ID": {
108	registry := registrytest.NewServiceRegistry()
109	registry.CreateService(ctx, &api.Service{
110		Port:     6502,
114	storage := NewREST(registry, nil, nil, makeIPNet(t))
115	c, err := storage.Update(ctx, &api.Service{
116		Port:     6502,
示例4:
calendar-gen.go开发语言: Go项目名称: google-api-go-client-git代码行数: 3553
1// Package calendar provides access to the Calendar API.
2//
3// See http://code.google.com/apis/calendar/v3/using.html
4//
5// Usage example:
6//
7//   import "google-api-go-client.googlecode.com/hg/calendar/v3"
8//   ...
9//   calendarService, err := calendar.New(oauthHttpClient)
10package calendar
11
12import (
13	"bytes"
14	"fmt"
15	"http"
示例5:
config_test.go开发语言: Go项目名称: kubernetes代码行数: 241
36type ServiceHandlerMock struct {
37	services []api.Service
38}
40func NewServiceHandlerMock() ServiceHandlerMock {
41	return ServiceHandlerMock{services: make([]api.Service, 0)}
42}
43
44func (impl ServiceHandlerMock) OnUpdate(services []api.Service) {
45	impl.services = services
47
48func (impl ServiceHandlerMock) ValidateServices(t *testing.T, expectedServices []api.Service) {
49	if reflect.DeepEqual(impl.services, expectedServices) {
71
72func CreateServiceUpdate(op Operation, services ...api.Service) ServiceUpdate {
73	ret := ServiceUpdate{Op: op}
示例6:
etcd.go开发语言: Go项目名称: kubernetes代码行数: 228
66	// Initially, just wait for the etcd to come up before doing anything more complicated.
67	var services []api.Service
68	var endpoints []api.Endpoints
111// This operation is akin to a set a known good at regular intervals.
112func (impl ConfigSourceEtcd) GetServices() ([]api.Service, []api.Endpoints, error) {
113	response, err := impl.client.Get(RegistryRoot+"/specs", true, false)
118	if response.Node.Dir == true {
119		retServices := make([]api.Service, len(response.Node.Nodes))
120		retEndpoints := make([]api.Endpoints, len(response.Node.Nodes))
124		for i, node := range response.Node.Nodes {
125			var svc api.Service
126			err = json.Unmarshal([]byte(node.Value), &svc)
207			log.Printf("Deleting service: %s", parts[3])
208			serviceUpdate := ServiceUpdate{Op: REMOVE, Services: []api.Service{api.Service{JSONBase: api.JSONBase{ID: parts[3]}}}}
209			impl.serviceChannel <- serviceUpdate
示例7:
etcd.go开发语言: Go项目名称: kubernetes代码行数: 228
66	// Initially, just wait for the etcd to come up before doing anything more complicated.
67	var services []api.Service
68	var endpoints []api.Endpoints
111// This operation is akin to a set a known good at regular intervals.
112func (impl ConfigSourceEtcd) GetServices() ([]api.Service, []api.Endpoints, error) {
113	response, err := impl.client.Get(RegistryRoot+"/specs", true, false)
115		log.Printf("Failed to get the key %s: %v", RegistryRoot, err)
116		return make([]api.Service, 0), make([]api.Endpoints, 0), err
117	}
118	if response.Node.Dir == true {
119		retServices := make([]api.Service, len(response.Node.Nodes))
120		retEndpoints := make([]api.Endpoints, len(response.Node.Nodes))
124		for i, node := range response.Node.Nodes {
125			var svc api.Service
126			err = json.Unmarshal([]byte(node.Value), &svc)
示例8:
integration.go开发语言: Go项目名称: kubernetes代码行数: 746
318func runSelfLinkTestOnNamespace(c *client.Client, namespace string) {
319	var svc api.Service
320	err := c.Post().
322		Resource("services").Body(
323		&api.Service{
324			ObjectMeta: api.ObjectMeta{
330			},
331			Spec: api.ServiceSpec{
332				Port: 12345,
350
351	var svcList api.ServiceList
352	err = c.Get().NamespaceIfScoped(namespace, len(namespace) > 0).Resource("services").Do().Into(&svcList)
383func runAtomicPutTest(c *client.Client) {
384	var svc api.Service
385	err := c.Post().Resource("services").Body(
示例9:
etcd.go开发语言: Go项目名称: kubernetes代码行数: 410
194// ListServices obtains a list of Services.
195func (r *Registry) ListServices(ctx api.Context) (*api.ServiceList, error) {
196	list := &api.ServiceList{}
201// CreateService creates a new Service.
202func (r *Registry) CreateService(ctx api.Context, svc *api.Service) error {
203	key, err := makeServiceKey(ctx, svc.Name)
211// GetService obtains a Service specified by its name.
212func (r *Registry) GetService(ctx api.Context, name string) (*api.Service, error) {
213	key, err := makeServiceKey(ctx, name)
216	}
217	var svc api.Service
218	err = r.ExtractObj(key, &svc, false)
272// UpdateService replaces an existing Service.
273func (r *Registry) UpdateService(ctx api.Context, svc *api.Service) error {
274	key, err := makeServiceKey(ctx, svc.Name)
示例10:
etcd_test.go开发语言: Go项目名称: kubernetes代码行数: 1042
394					{
395						Value: runtime.EncodeOrDie(latest.Codec, &api.Service{ObjectMeta: api.ObjectMeta{Name: "foo"}}),
396					},
397					{
398						Value: runtime.EncodeOrDie(latest.Codec, &api.Service{ObjectMeta: api.ObjectMeta{Name: "bar"}}),
399					},
419	registry := NewTestEtcdRegistry(fakeClient)
420	err := registry.CreateService(ctx, &api.Service{
421		ObjectMeta: api.ObjectMeta{Name: "foo"},
432
433	var service api.Service
434	err = latest.Codec.DecodeInto([]byte(resp.Node.Value), &service)
447	key, _ := makeServiceKey(ctx, "foo")
448	fakeClient.Set(key, runtime.EncodeOrDie(latest.Codec, &api.Service{ObjectMeta: api.ObjectMeta{Name: "foo"}}), 0)
449	registry := NewTestEtcdRegistry(fakeClient)

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