gpt4 book ai didi

go - 列出服务

转载 作者:行者123 更新时间:2023-12-03 10:08:42 25 4
gpt4 key购买 nike

我正在尝试列出knative(v0.17.0)services,我有一个clientset,但是我不知道从哪里开始。
这是我为测试而启动的服务:

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
name: "helloworld"
spec:
runLatest:
configuration:
revisionTemplate:
spec:
container:
image: "gcr.io/knative-samples/helloworld-go"
env:
- name: "TARGET"
value: "world"
如果您有任何建议,教程或示例,那就太好了

最佳答案

基于this gist(适合于1.18后客户使用)和Serving clientset godoc:

import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/tools/clientcmd"
servingv1 "knative.dev/servig/pkg/client/clientset/versioned/typed/serving/v1"
}

func doIt() error {
config, err := clientcmd.BuildConfigFromFLags("", "") // Uses defaults
if err != nil {
return err
}

serving, err := servingv1.NewForConfig(config)
if err != nil {
return err
}

// Get services in the default namespace
list, err := serving.Services("default").List(context.Background(), metav1.ListOptions{})
if err != nil {
return err
}
// How to print them out.
fmt.Printf("There are %d services in the default namespace", len(list.Items))
for _, i := range list.Items {
fmt.Printf(" > Service %q", i.Name)
}
}

关于go - 列出服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66199455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com