当前位置: 首页>>代码示例>>Golang>>正文


Golang v1alpha.NewPublicAPIClient函数代码示例

本文整理汇总了Golang中github.com/coreos/rkt/api/v1alpha.NewPublicAPIClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewPublicAPIClient函数的具体用法?Golang NewPublicAPIClient怎么用?Golang NewPublicAPIClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewPublicAPIClient函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: New

// New creates the rkt container runtime which implements the container runtime interface.
// It will test if the rkt binary is in the $PATH, and whether we can get the
// version of it. If so, creates the rkt container runtime, otherwise returns an error.
func New(config *Config,
	generator kubecontainer.RunContainerOptionsGenerator,
	recorder record.EventRecorder,
	containerRefManager *kubecontainer.RefManager,
	livenessManager proberesults.Manager,
	volumeGetter volumeGetter,
	imageBackOff *util.Backoff,
	serializeImagePulls bool,
) (*Runtime, error) {
	// Create dbus connection.
	systemd, err := newSystemd()
	if err != nil {
		return nil, fmt.Errorf("rkt: cannot create systemd interface: %v", err)
	}

	// TODO(yifan): Use secure connection.
	apisvcConn, err := grpc.Dial(defaultRktAPIServiceAddr, grpc.WithInsecure())
	if err != nil {
		return nil, fmt.Errorf("rkt: cannot connect to rkt api service: %v", err)
	}

	rktBinAbsPath := config.Path
	if rktBinAbsPath == "" {
		// No default rkt path was set, so try to find one in $PATH.
		var err error
		rktBinAbsPath, err = exec.LookPath("rkt")
		if err != nil {
			return nil, fmt.Errorf("cannot find rkt binary: %v", err)
		}
	}

	rkt := &Runtime{
		systemd:             systemd,
		rktBinAbsPath:       rktBinAbsPath,
		apisvcConn:          apisvcConn,
		apisvc:              rktapi.NewPublicAPIClient(apisvcConn),
		config:              config,
		dockerKeyring:       credentialprovider.NewDockerKeyring(),
		containerRefManager: containerRefManager,
		generator:           generator,
		recorder:            recorder,
		livenessManager:     livenessManager,
		volumeGetter:        volumeGetter,
	}
	if serializeImagePulls {
		rkt.imagePuller = kubecontainer.NewSerializedImagePuller(recorder, rkt, imageBackOff)
	} else {
		rkt.imagePuller = kubecontainer.NewImagePuller(recorder, rkt, imageBackOff)
	}

	if err := rkt.checkVersion(minimumRktBinVersion, recommendedRktBinVersion, minimumAppcVersion, minimumRktApiVersion, minimumSystemdVersion); err != nil {
		// TODO(yifan): Latest go-systemd version have the ability to close the
		// dbus connection. However the 'docker/libcontainer' package is using
		// the older go-systemd version, so we can't update the go-systemd version.
		rkt.apisvcConn.Close()
		return nil, err
	}
	return rkt, nil
}
开发者ID:knobunc,项目名称:kubernetes,代码行数:62,代码来源:rkt.go

示例2: newAPIClientOrFail

func newAPIClientOrFail(t *testing.T, address string) (v1alpha.PublicAPIClient, *grpc.ClientConn) {
	conn, err := grpc.Dial(address, grpc.WithInsecure())
	if err != nil {
		t.Fatalf("Unexpected error: %v", err)
	}
	c := v1alpha.NewPublicAPIClient(conn)
	return c, conn
}
开发者ID:aaronlevy,项目名称:rkt,代码行数:8,代码来源:rkt_tests.go

示例3: New

// New creates the rkt container runtime which implements the container runtime interface.
// It will test if the rkt binary is in the $PATH, and whether we can get the
// version of it. If so, creates the rkt container runtime, otherwise returns an error.
func New(config *Config,
	runtimeHelper kubecontainer.RuntimeHelper,
	recorder record.EventRecorder,
	containerRefManager *kubecontainer.RefManager,
	livenessManager proberesults.Manager,
	volumeGetter volumeGetter,
	imageBackOff *util.Backoff,
	serializeImagePulls bool,
) (*Runtime, error) {
	// Create dbus connection.
	systemd, err := newSystemd()
	if err != nil {
		return nil, fmt.Errorf("rkt: cannot create systemd interface: %v", err)
	}

	// TODO(yifan): Use secure connection.
	apisvcConn, err := grpc.Dial(defaultRktAPIServiceAddr, grpc.WithInsecure())
	if err != nil {
		return nil, fmt.Errorf("rkt: cannot connect to rkt api service: %v", err)
	}

	rktBinAbsPath := config.Path
	if rktBinAbsPath == "" {
		// No default rkt path was set, so try to find one in $PATH.
		var err error
		rktBinAbsPath, err = exec.LookPath("rkt")
		if err != nil {
			return nil, fmt.Errorf("cannot find rkt binary: %v", err)
		}
	}

	rkt := &Runtime{
		systemd:             systemd,
		rktBinAbsPath:       rktBinAbsPath,
		apisvcConn:          apisvcConn,
		apisvc:              rktapi.NewPublicAPIClient(apisvcConn),
		config:              config,
		dockerKeyring:       credentialprovider.NewDockerKeyring(),
		containerRefManager: containerRefManager,
		runtimeHelper:       runtimeHelper,
		recorder:            recorder,
		livenessManager:     livenessManager,
		volumeGetter:        volumeGetter,
	}
	if serializeImagePulls {
		rkt.imagePuller = kubecontainer.NewSerializedImagePuller(recorder, rkt, imageBackOff)
	} else {
		rkt.imagePuller = kubecontainer.NewImagePuller(recorder, rkt, imageBackOff)
	}

	if err := rkt.getVersions(); err != nil {
		return nil, fmt.Errorf("rkt: error getting version info: %v", err)
	}

	return rkt, nil
}
开发者ID:xiaohui,项目名称:kubernetes,代码行数:59,代码来源:rkt.go

示例4: main

func main() {
	// Create client.
	fmt.Println("Connecting to api service...")

	clientConn, err := grpc.Dial("localhost:15441", grpc.WithInsecure())
	if err != nil {
		panic(err)
	}
	defer clientConn.Close()
	client := v1alpha.NewPublicAPIClient(clientConn)
	fmt.Println("Successfully connected!")

	// Get version infos.
	fmt.Println("\nGet info")
	getInfo, err := client.GetInfo(context.Background(), &v1alpha.GetInfoRequest{})
	if err != nil {
		panic(err)
	}
	fmt.Println(getInfo)

	// Get pod list.
	fmt.Println("\nGet pod list")
	podInfos, err := client.ListPods(context.Background(), &v1alpha.ListPodsRequest{&v1alpha.PodFilter{States: []v1alpha.PodState{}}})
	if err != nil {
		panic(err)
	}
	for i, p := range podInfos.Pods {
		fmt.Printf("pod #%d: %v\n", i, p)
	}

	// Inspect pod.
	fmt.Println("\nInspect pod")
	podInfo, err := client.InspectPod(context.Background(), &v1alpha.InspectPodRequest{Id: podInfos.Pods[0].Id})
	if err != nil {
		panic(err)
	}
	fmt.Println(podInfo)

	// Get image list.
	fmt.Println("\nGet image list")
	imgInfos, err := client.ListImages(context.Background(), &v1alpha.ListImagesRequest{})
	if err != nil {
		panic(err)
	}
	for i, m := range imgInfos.Images {
		fmt.Printf("image #%d: %v\n", i, m)
	}

	// Inspect image
	fmt.Println("\nInspect image")
	imgInfo, err := client.InspectImage(context.Background(), &v1alpha.InspectImageRequest{Id: imgInfos.Images[0].Id})
	if err != nil {
		panic(err)
	}
	fmt.Println(imgInfo)
}
开发者ID:yifan-gu,项目名称:rkt_api_demo,代码行数:56,代码来源:main.go

示例5: main

func main() {
	followFlag := flag.Bool("follow", false, "enable 'follow' option on GetLogs")
	flag.Parse()

	conn, err := grpc.Dial("localhost:15441", grpc.WithInsecure())
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	c := v1alpha.NewPublicAPIClient(conn)
	defer conn.Close()

	// List pods.
	podResp, err := c.ListPods(context.Background(), &v1alpha.ListPodsRequest{
		// Specify the request: Fetch and print only running pods and their details.
		Detail: true,
		Filters: []*v1alpha.PodFilter{
			{
				States: []v1alpha.PodState{v1alpha.PodState_POD_STATE_RUNNING},
			},
		},
	})
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	for _, p := range podResp.Pods {
		if *followFlag {
			fmt.Printf("Pod %q is running. Following logs:\n", p.Id)
			getLogsWithFollow(c, p)
		} else {
			fmt.Printf("Pod %q is running.\n", p.Id)
			getLogsWithoutFollow(c, p)
		}
	}

	// List images.
	imgResp, err := c.ListImages(context.Background(), &v1alpha.ListImagesRequest{
		// In this request, we fetch the details of images whose names are prefixed with "coreos.com".
		Detail: true,
		Filters: []*v1alpha.ImageFilter{
			{
				Prefixes: []string{"coreos.com"},
			},
		},
	})
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	for _, im := range imgResp.Images {
		fmt.Printf("Found image %q\n", im.Name)
	}
}
开发者ID:CodeJuan,项目名称:kubernetes,代码行数:56,代码来源:client_example.go

示例6: main

func main() {
	conn, err := grpc.Dial("localhost:15441", grpc.WithInsecure())
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	c := v1alpha.NewPublicAPIClient(conn)
	defer conn.Close()

	// List pods.
	podResp, err := c.ListPods(context.Background(), &v1alpha.ListPodsRequest{
		// Specify the request: Fetch and print only running pods and their details.
		Detail: true,
		Filters: []*v1alpha.PodFilter{
			{
				States: []v1alpha.PodState{v1alpha.PodState_POD_STATE_RUNNING},
			},
		},
	})
	if err != nil {
		fmt.Println(err)
		os.Exit(2)
	}

	for _, p := range podResp.Pods {
		fmt.Printf("Pod %q is running\n", p.Id)
	}

	// List images.
	imgResp, err := c.ListImages(context.Background(), &v1alpha.ListImagesRequest{
		// In this request, we fetch the details of images whose names are prefixed with "coreos.com".
		Detail: true,
		Filters: []*v1alpha.ImageFilter{
			{
				Prefixes: []string{"coreos.com"},
			},
		},
	})
	if err != nil {
		fmt.Println(err)
		os.Exit(3)
	}

	for _, im := range imgResp.Images {
		fmt.Printf("Found image %q\n", im.Name)
	}
}
开发者ID:XiaoningDing,项目名称:UbernetesPOC,代码行数:47,代码来源:client_example.go

示例7: Client

func Client() (rktapi.PublicAPIClient, error) {
	once.Do(func() {
		conn, err := net.DialTimeout("tcp", defaultRktAPIServiceAddr, timeout)
		if err != nil {
			rktClient = nil
			rktClientErr = fmt.Errorf("rkt: cannot tcp Dial rkt api service: %v", err)
			return
		}

		conn.Close()

		apisvcConn, err := grpc.Dial(defaultRktAPIServiceAddr, grpc.WithInsecure(), grpc.WithTimeout(timeout))
		if err != nil {
			rktClient = nil
			rktClientErr = fmt.Errorf("rkt: cannot grpc Dial rkt api service: %v", err)
			return
		}

		apisvc := rktapi.NewPublicAPIClient(apisvcConn)

		resp, err := apisvc.GetInfo(context.Background(), &rktapi.GetInfoRequest{})
		if err != nil {
			rktClientErr = fmt.Errorf("rkt: GetInfo() failed: %v", err)
			return
		}

		binVersion, err := semver.Make(resp.Info.RktVersion)
		if err != nil {
			rktClientErr = fmt.Errorf("rkt: couldn't parse RtVersion: %v", err)
			return
		}
		if binVersion.LT(semver.MustParse(minimumRktBinVersion)) {
			rktClientErr = fmt.Errorf("rkt: binary version is too old(%v), requires at least %v", resp.Info.RktVersion, minimumRktBinVersion)
			return
		}

		rktClient = apisvc
	})

	return rktClient, rktClientErr
}
开发者ID:COLDTURNIP,项目名称:kubernetes,代码行数:41,代码来源:client.go

示例8: main

func main() {
	conn, err := grpc.Dial("localhost:15441", grpc.WithInsecure())
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	c := v1alpha.NewPublicAPIClient(conn)
	defer conn.Close()

	for {
		// List pods.
		resp, err := c.ListPods(context.Background(), &v1alpha.ListPodsRequest{Detail: true})
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		time.Sleep(time.Second)
		fmt.Println("num of pods", len(resp.Pods))

	}
}
开发者ID:yifan-gu,项目名称:benrkt,代码行数:21,代码来源:stress_api.go

示例9: Client

func Client() (rktapi.PublicAPIClient, error) {
	once.Do(func() {
		conn, err := net.DialTimeout("tcp", defaultRktAPIServiceAddr, timeout)
		if err != nil {
			rktClient = nil
			rktClientErr = fmt.Errorf("rkt: cannot tcp Dial rkt api service: %v", err)
			return
		}

		conn.Close()

		apisvcConn, err := grpc.Dial(defaultRktAPIServiceAddr, grpc.WithInsecure(), grpc.WithTimeout(timeout))
		if err != nil {
			rktClient = nil
			rktClientErr = fmt.Errorf("rkt: cannot grpc Dial rkt api service: %v", err)
			return
		}

		rktClient = rktapi.NewPublicAPIClient(apisvcConn)
	})

	return rktClient, rktClientErr
}
开发者ID:Clarifai,项目名称:kubernetes,代码行数:23,代码来源:client.go


注:本文中的github.com/coreos/rkt/api/v1alpha.NewPublicAPIClient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。