resolver

package
v0.0.0-...-8868a4c Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

README

Usage

Full example

errOut := make(chan error, 100)
k8sResolver, err := resolver.NewFromOutOfCluster("", errOut)
if err != nil {
    logger.Log.Errorf("error creating k8s resolver %s", err)
}

ctx, cancel := context.WithCancel(context.Background())
k8sResolver.Start(ctx)

resolvedName := k8sResolver.Resolve("10.107.251.91") // will always return `nil` in real scenarios as the internal map takes a moment to populate after `Start` is called
if resolvedName != nil {
    logger.Log.Errorf("resolved 10.107.251.91=%s", *resolvedName)
} else {
    logger.Log.Error("Could not find a resolved name for 10.107.251.91")
}

for {
    select {
        case err := <- errOut:
            logger.Log.Errorf("name resolving error %s", err)
    }
}

In cluster authentication

Create resolver using the function NewFromInCluster(errOut chan error)

Out of cluster authentication

Create resolver using the function NewFromOutOfCluster(kubeConfigPath string, errOut chan error)

the kubeConfigPath param is optional, pass an empty string "" for resolver to auto locate the default kubeconfig file

Error handling

Please ensure there is always a thread reading from the errOut channel, not doing so will result in the resolver threads getting blocked and the resolver will fail to update.

Also note that any error you receive through this channel does not necessarily mean that resolver is no longer running. the resolver will infinitely retry watching k8s resources until the provided context is cancelled.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ResolvedObjectInfo

type ResolvedObjectInfo struct {
	FullAddress string
	Namespace   string
}

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

func NewFromInCluster

func NewFromInCluster(errOut chan error, namespace string) (*Resolver, error)

func (*Resolver) CheckIsServiceIP

func (resolver *Resolver) CheckIsServiceIP(address string) bool

func (*Resolver) GetMap

func (resolver *Resolver) GetMap() cmap.ConcurrentMap

func (*Resolver) Resolve

func (resolver *Resolver) Resolve(name string) *ResolvedObjectInfo

func (*Resolver) Start

func (resolver *Resolver) Start(ctx context.Context)

Jump to

Keyboard shortcuts

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