英文:
Fetch ingress metadata in kubernetes
问题
我有以下的Go代码,用于打印我的Kubernetes部署元数据:
package test
import (
"context"
"fmt"
"os"
"testing"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
func TestEksStandaloneModule(t *testing.T) {
namespace := fmt.Sprintf("%v-%v", "project", "dit")
kubeconfig := os.Getenv("HOME") + "/KUBECONFIG"
clientCfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
t.Error(err)
}
clientset, err := kubernetes.NewForConfig(clientCfg)
appDeployment, err := clientset.AppsV1().Deployments(namespace).Get(context.TODO(), "deploymentname", v1.GetOptions{})
fmt.Println(appDeployment)
}
有人可以帮我编写一个打印Ingress元数据的函数吗?我对Go不太熟悉。
英文:
I have below go code that print my kubernetes deployment metadata,
package test
import (
"context"
"fmt"
"os"
"testing"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
func TestEksStandaloneModule(t *testing.T) {
namespace := fmt.Sprintf("%v-%v", "project", "dit")
kubeconfig := os.Getenv("HOME") + "/KUBECONFIG"
clientCfg, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
t.Error(err)
}
clientset, err := kubernetes.NewForConfig(clientCfg)
appDeployment, err := clientset.AppsV1().Deployments(namespace).Get(context.TODO(), "deploymentname", v1.GetOptions{})
fmt.Println(appDeployment)
}
Can any one please help me get a function that prints ingress metadata?
I am new to go.
答案1
得分: 1
我能够通过以下方式使其工作:
appIngress, err := clientset.NetworkingV1().Ingresses(namespace).Get(context.TODO(), "helloworldspringbootssl-ap145385", v1.GetOptions{})
fmt.Println(appIngress)
请注意,这是一个Go语言的代码片段。
英文:
I was able to make it work by
appIngress, err := clientset.NetworkingV1().Ingresses(namespace).Get(context.TODO(), "helloworldspringbootssl-ap145385", v1.GetOptions{})
fmt.Println(appIngress)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论