pilotdiscovery

package module
v0.0.0-...-e8099c6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2019 License: MIT Imports: 16 Imported by: 0

README

Pilot discovery

Subscribe to an Istio Pilot service and get available endpoints for a dns name.

Usage

/*
 * !! Pseudo-code
 */

import (
	"github.com/Stoakes/go-pkg/log"
	lb "github.com/Stoakes/go-pkg/grpc/pilotdiscovery"
	"github.com/Stoakes/go-pkg/grpc/pilotresolver"
)

func main() {
		pilotClient, err := lb.NewPilotClient(ctx, lb.PilotClientOptions{
			PilotURL: "localhost:15010", // assuming port-forward to istio-pilot on port 15010
			IP: "192.168.10.10",
			AppName: "front-service",
			Namespace: "default"})
		if err != nil {
			log.For(ctx).Fatalf("Cannot subscribe to pilot: %v", err)
		}
		pilotresolver.SetPilotClient(pilotClient)
		log.For(ctx).Info("Pilot subscription started")

		helloConnection, err := grpc.Dial(viper.GetString("hello-service"), []grpc.DialOption{
			grpc.WithBlock(),
			grpc.WithInsecure(),
			grpc.WithTimeout(10 * time.Second),
			grpc.WithBalancer(grpc.RoundRobin(&pilotresolver.Resolver{})),
        }...)
        if err != nil {
			log.For(ctx).Fatalf("Connection to hello-service error :%v", err)
		}
        helloClient := pb.NewGreeterClient(helloConnection)

		// Calls to helloClient will be load balanced accross every endpoints received via Pilot

		// You can also debug current state of Pilot client and known endpoints by exposing following router
		router := mux.NewRouter()
		router.HandleFunc("/debug/edsz", pilotClient.EdszHandler)
}

Documentation

Index

Constants

View Source
const (
	// TypePrefix is the grpc type prefix
	TypePrefix = "type.googleapis.com/envoy.api.v2."

	// ClusterType is used for cluster discovery. Typically first request received
	ClusterType = TypePrefix + "Cluster"
	// EndpointType is used for EDS and ADS endpoint discovery. Typically second request.
	EndpointType = TypePrefix + "ClusterLoadAssignment"
	// ListenerType is sent after clusters and endpoints.
	ListenerType = TypePrefix + "Listener"
	// RouteType is sent after listeners.
	RouteType = TypePrefix + "RouteConfiguration"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EndpointUpdate

type EndpointUpdate struct {
	IP     string // IP address of the endpoint
	Region string // Region of the IP (europe-west2)
	Zone   string //  zone/AZ of the IP (europe-west2-b)
}

EndpointUpdate is the representation of an endpoint and what will be sent to internal consumers

type PilotClient

type PilotClient interface {
	AddWatch(host string, namespace string, port string) (chan []EndpointUpdate, error)
	Shutdown()
	RefreshFromRemote() error
	EdszHandler(w http.ResponseWriter, req *http.Request)
}

PilotClient is a client to a Pilot Service Discovery Server

func NewPilotClient

func NewPilotClient(ctx context.Context, options PilotClientOptions) (PilotClient, error)

NewPilotClient starts a subscription (gRPC stream) to pilot. When using several gRPC connections, we do not want to open multiple subscriptions to pilot. Therefore, we open only one connection to pilot and use channels for intra-app communication

type PilotClientOptions

type PilotClientOptions struct {
	// PilotURL is a valid <hostname>:<port> connection string
	PilotURL string
	// IP is the IP address of the application running this library
	IP string
	// AppName is the application name of the application running this library
	AppName string
	// Namespace is the Kubernetes namespace in which the application using this library is running
	Namespace string
	// DialOpts are the grpc DialOptions to dial Pilot Server
	DialOptions []grpc.DialOption
	// Backoff mechanism is copied from gRPC
	// Initial retry is at random(0, initialBackoffMS).
	// In general, the nth attempt will occur at random(0, min(InitialBackoff*BackoffMultiplier**(n-1), MaxBackoff)).
	// InitialBackOff is the duration. Default to 1 second
	InitialBackoff time.Duration
	// MaxBackOff is the maximum duration between 2 connection attempts in case of Pilot disconnection. Default to 2 minutes
	MaxBackoff time.Duration
	// BackoffMultiplier is the progression multiplier between initial and max backoff. Default to 1.6
	BackoffMultiplier float64
}

PilotClientOptions is a struct gathering every option required to start a PilotClient

func (PilotClientOptions) Validate

Validate set defaults & check constraints on PilotClientOptions in case of nil error, the option struct is ready to be safely used by a Pilot client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL