本文整理匯總了Golang中k8s/io/kubernetes/pkg/client/unversioned.Client.Endpoints方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Endpoints方法的具體用法?Golang Client.Endpoints怎麽用?Golang Client.Endpoints使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/client/unversioned.Client
的用法示例。
在下文中一共展示了Client.Endpoints方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: testOne
func testOne(t *testing.T, client *kclient.Client, namespace, addrType string, success bool) *kapi.Endpoints {
testEndpoint := &kapi.Endpoints{}
testEndpoint.GenerateName = "test"
testEndpoint.Subsets = []kapi.EndpointSubset{
{
Addresses: []kapi.EndpointAddress{
{
IP: exampleAddresses[addrType],
},
},
Ports: []kapi.EndpointPort{
{
Port: 9999,
Protocol: kapi.ProtocolTCP,
},
},
},
}
ep, err := client.Endpoints(namespace).Create(testEndpoint)
if err != nil && success {
t.Fatalf("unexpected error creating %s network endpoint: %v", addrType, err)
} else if err == nil && !success {
t.Fatalf("unexpected success creating %s network endpoint", addrType)
}
return ep
}
示例2: createEndpoint
func createEndpoint(client *kubeclient.Client, meta kube.ObjectMeta, dnsIP string, dnsPort int32) error {
endpoints := &kube.Endpoints{
ObjectMeta: meta,
Subsets: []kube.EndpointSubset{
{
Addresses: []kube.EndpointAddress{
{IP: dnsIP},
},
Ports: []kube.EndpointPort{
{
Name: "dns",
Port: dnsPort,
},
{
Name: "dns-tcp",
Port: dnsPort,
},
},
},
},
}
_, err := client.Endpoints(meta.Namespace).Create(endpoints)
if err != nil {
return err
}
return nil
}
示例3: runMasterServiceTest
func runMasterServiceTest(client *client.Client) {
time.Sleep(12 * time.Second)
svcList, err := client.Services(api.NamespaceDefault).List(labels.Everything())
if err != nil {
glog.Fatalf("unexpected error listing services: %v", err)
}
var foundRW bool
found := util.StringSet{}
for i := range svcList.Items {
found.Insert(svcList.Items[i].Name)
if svcList.Items[i].Name == "kubernetes" {
foundRW = true
}
}
if foundRW {
ep, err := client.Endpoints(api.NamespaceDefault).Get("kubernetes")
if err != nil {
glog.Fatalf("unexpected error listing endpoints for kubernetes service: %v", err)
}
if countEndpoints(ep) == 0 {
glog.Fatalf("no endpoints for kubernetes service: %v", ep)
}
} else {
glog.Errorf("no RW service found: %v", found)
glog.Fatal("Kubernetes service test failed")
}
glog.Infof("Master service test passed.")
}
示例4: endpointsSet
func endpointsSet(c *client.Client, serviceNamespace, serviceID string, endpointCount int) wait.ConditionFunc {
return func() (bool, error) {
endpoints, err := c.Endpoints(serviceNamespace).Get(serviceID)
if err != nil {
glog.Infof("Error getting endpoints: %v", err)
return false, nil
}
count := 0
for _, ss := range endpoints.Subsets {
for _, addr := range ss.Addresses {
for _, port := range ss.Ports {
count++
glog.Infof("%s/%s endpoint: %s:%d %#v", serviceNamespace, serviceID, addr.IP, port.Port, addr.TargetRef)
}
}
}
return count == endpointCount, nil
}
}
示例5: CheckService
// CheckService waits for the specified service to be ready by returning an error until the service is up
// The check is done by polling the endpoint associated with the service and when the endpoint exists, returning no error->service-online
// Credits: https://github.com/kubernetes/minikube/blob/v0.9.0/cmd/minikube/cmd/service.go#L89
func CheckService(ns string, service string, c *k8sclient.Client) error {
svc, err := c.Services(ns).Get(service)
if err != nil {
return err
}
url := svc.ObjectMeta.Annotations[exposeURLAnnotation]
if url == "" {
util.Info(".")
return errors.New("")
}
endpoints := c.Endpoints(ns)
if endpoints == nil {
util.Errorf("No endpoints found in namespace %s\n", ns)
}
endpoint, err := endpoints.Get(service)
if err != nil {
util.Errorf("No endpoints found for service %s\n", service)
return err
}
return CheckEndpointReady(endpoint)
}
示例6: copyEndpoints
func copyEndpoints(c *k8sclient.Client, fromNs string, toNs string, names []string) error {
var answer error
for _, name := range names {
item, err := c.Endpoints(fromNs).Get(name)
if err != nil {
util.Warnf("No endpoint called %s found in namespace %s", name, fromNs)
answer = err
}
name := item.Name
objectMeta := item.ObjectMeta
current, err := c.Endpoints(toNs).Get(name)
if current == nil || err != nil {
// lets create the endpoint
newEndpoints := &api.Endpoints{
ObjectMeta: api.ObjectMeta{
Name: name,
Labels: objectMeta.Labels,
Annotations: objectMeta.Annotations,
},
Subsets: item.Subsets,
}
_, err = c.Endpoints(toNs).Create(newEndpoints)
if err != nil {
return err
}
util.Infof("Created endpoint %s in namespace %s\n", name, toNs)
}
}
return answer
}
示例7: getMaster
func getMaster(c *client.Client) string {
master := ""
switch framework.TestContext.Provider {
case "gce":
eps, err := c.Endpoints(api.NamespaceDefault).Get("kubernetes")
if err != nil {
framework.Failf("Fail to get kubernetes endpoinds: %v", err)
}
if len(eps.Subsets) != 1 || len(eps.Subsets[0].Addresses) != 1 {
framework.Failf("There are more than 1 endpoints for kubernetes service: %+v", eps)
}
master = eps.Subsets[0].Addresses[0].IP
case "gke":
master = strings.TrimPrefix(framework.TestContext.Host, "https://")
case "aws":
// TODO(justinsb): Avoid hardcoding this.
master = "172.20.0.9"
default:
framework.Failf("This test is not supported for provider %s and should be disabled", framework.TestContext.Provider)
}
return master
}
示例8: validateEndpointsOrFail
func validateEndpointsOrFail(c *client.Client, namespace, serviceName string, expectedEndpoints PortsByPodName) {
By(fmt.Sprintf("waiting up to %v for service %s in namespace %s to expose endpoints %v", serviceStartTimeout, serviceName, namespace, expectedEndpoints))
i := 1
for start := time.Now(); time.Since(start) < serviceStartTimeout; time.Sleep(1 * time.Second) {
endpoints, err := c.Endpoints(namespace).Get(serviceName)
if err != nil {
Logf("Get endpoints failed (%v elapsed, ignoring for 5s): %v", time.Since(start), err)
continue
}
// Logf("Found endpoints %v", endpoints)
portsByPodUID := getContainerPortsByPodUID(endpoints)
// Logf("Found port by pod UID %v", portsByPodUID)
expectedPortsByPodUID := translatePodNameToUIDOrFail(c, namespace, expectedEndpoints)
if len(portsByPodUID) == len(expectedEndpoints) {
validatePortsOrFail(portsByPodUID, expectedPortsByPodUID)
Logf("successfully validated that service %s in namespace %s exposes endpoints %v (%v elapsed)",
serviceName, namespace, expectedEndpoints, time.Since(start))
return
}
if i%5 == 0 {
Logf("Unexpected endpoints: found %v, expected %v (%v elapsed, will retry)", portsByPodUID, expectedEndpoints, time.Since(start))
}
i++
}
if pods, err := c.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything()); err == nil {
for _, pod := range pods.Items {
Logf("Pod %s\t%s\t%s\t%s", pod.Namespace, pod.Name, pod.Spec.NodeName, pod.DeletionTimestamp)
}
} else {
Logf("Can't list pod debug info: %v", err)
}
Failf("Timed out waiting for service %s in namespace %s to expose endpoints %v (%v elapsed)", serviceName, namespace, expectedEndpoints, serviceStartTimeout)
}
示例9: getWebserverEndpoints
//getWebserverEndpoints returns the webserver endpoints as a set of String, each in the format like "http://{ip}:{port}"
func getWebserverEndpoints(client *client.Client) sets.String {
endpoints, err := client.Endpoints(*namespace).Get(*service)
eps := sets.String{}
if err != nil {
state.Logf("Unable to read the endpoints for %v/%v: %v.", *namespace, *service, err)
return eps
}
for _, ss := range endpoints.Subsets {
for _, a := range ss.Addresses {
for _, p := range ss.Ports {
eps.Insert(fmt.Sprintf("http://%s:%d", a.IP, p.Port))
}
}
}
return eps
}
示例10:
mkpath := func(file string) string {
return filepath.Join(testContext.RepoRoot, "examples/guestbook-go", file)
}
controllerJson := mkpath("redis-master-controller.json")
nsFlag := fmt.Sprintf("--namespace=%v", ns)
redisPort := 6379
By("creating Redis RC")
runKubectl("create", "-f", controllerJson, nsFlag)
forEachPod(c, ns, "app", "redis", func(pod api.Pod) {
lookForStringInLog(ns, pod.Name, "redis-master", "The server is now ready to accept connections", podStartTimeout)
})
validateService := func(name string, servicePort int, timeout time.Duration) {
err := wait.Poll(poll, timeout, func() (bool, error) {
endpoints, err := c.Endpoints(ns).Get(name)
if err != nil {
if apierrs.IsNotFound(err) {
err = nil
}
Logf("Get endpoints failed (interval %v): %v", poll, err)
return false, err
}
uidToPort := getContainerPortsByPodUID(endpoints)
if len(uidToPort) == 0 {
Logf("No endpoint found, retrying")
return false, nil
}
if len(uidToPort) > 1 {
Fail("Too many endpoints found")
示例11:
{
IP: serverIP,
},
},
Ports: []api.EndpointPort{
{
Name: "gluster",
Port: 24007,
Protocol: api.ProtocolTCP,
},
},
},
},
}
endClient := c.Endpoints(config.namespace)
defer func() {
if clean {
endClient.Delete(config.prefix + "-server")
}
}()
if _, err := endClient.Create(&endpoints); err != nil {
framework.Failf("Failed to create endpoints for Gluster server: %v", err)
}
volume := api.VolumeSource{
Glusterfs: &api.GlusterfsVolumeSource{
EndpointsName: config.prefix + "-server",
// 'test_vol' comes from test/images/volumes-tester/gluster/run_gluster.sh
示例12: endpointsWatchFunc
func endpointsWatchFunc(c *client.Client, ns string) func(options api.ListOptions) (watch.Interface, error) {
return func(options api.ListOptions) (watch.Interface, error) {
return c.Endpoints(ns).Watch(options)
}
}
示例13: endpointsListFunc
func endpointsListFunc(c *client.Client, ns string) func(api.ListOptions) (runtime.Object, error) {
return func(opts api.ListOptions) (runtime.Object, error) {
return c.Endpoints(ns).List(opts)
}
}
示例14: runPatchTest
//.........這裏部分代碼省略.........
}
if len(svc.Labels) != 2 || svc.Labels["foo"] != "bar" || svc.Labels["baz"] != "qux" {
glog.Fatalf("Failed updating patchservice with patch type %s: labels are: %v", k, svc.Labels)
}
// remove one label
err = execPatch(k, v.RemoveLabelBody)
if err != nil {
glog.Fatalf("Failed updating patchservice with patch type %s: %v", k, err)
}
svc, err = services.Get(name)
if err != nil {
glog.Fatalf("Failed getting patchservice: %v", err)
}
if len(svc.Labels) != 1 || svc.Labels["baz"] != "qux" {
glog.Fatalf("Failed updating patchservice with patch type %s: labels are: %v", k, svc.Labels)
}
// remove all labels
err = execPatch(k, v.RemoveAllLabelsBody)
if err != nil {
glog.Fatalf("Failed updating patchservice with patch type %s: %v", k, err)
}
svc, err = services.Get(name)
if err != nil {
glog.Fatalf("Failed getting patchservice: %v", err)
}
if svc.Labels != nil {
glog.Fatalf("Failed remove all labels from patchservice with patch type %s: %v", k, svc.Labels)
}
}
// Test patch with a resource that allows create on update
endpointTemplate := &api.Endpoints{
ObjectMeta: api.ObjectMeta{Name: "patchendpoint"},
Subsets: []api.EndpointSubset{
{
Addresses: []api.EndpointAddress{{IP: "1.2.3.4"}},
Ports: []api.EndpointPort{{Port: 80, Protocol: api.ProtocolTCP}},
},
},
}
patchEndpoint := func(json []byte) (runtime.Object, error) {
return c.Patch(api.MergePatchType).Resource("endpoints").Namespace(api.NamespaceDefault).Name("patchendpoint").Body(json).Do().Get()
}
// Make sure patch doesn't get to CreateOnUpdate
{
endpointJSON, err := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), endpointTemplate)
if err != nil {
glog.Fatalf("Failed creating endpoint JSON: %v", err)
}
if obj, err := patchEndpoint(endpointJSON); !apierrors.IsNotFound(err) {
glog.Fatalf("Expected notfound creating from patch, got error=%v and object: %#v", err, obj)
}
}
// Create the endpoint (endpoints set AllowCreateOnUpdate=true) to get a UID and resource version
createdEndpoint, err := c.Endpoints(api.NamespaceDefault).Update(endpointTemplate)
if err != nil {
glog.Fatalf("Failed creating endpoint: %v", err)
}
// Make sure identity patch is accepted
{