kube

package
v0.0.0-...-97dd610 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildConfig

func BuildConfig(kubecfgPath string, ctx string) (*rest.Config, error)

BuildConfig loading rules: 1. kubeconfig if it not empty string 2. Config(s) in KUBECONFIG environment variable 3. In cluster config if running in-cluster 4. Use $HOME/.kube/config

func CompareObject

func CompareObject(objA, objB *Object) (string, error)

CompareObject compares two objects and returns diff.

func CompareObjects

func CompareObjects(objsA, objsB Objects) (string, string, string)

CompareObjects compares object lists and returns diff, add, err using util.DiffYAML. It compares objects with same hash value(Namespace:Kind:Name) and returns diff. For objects that only one list have, it returns add. For objects that could not be parsed successfully, it returns err. Refer to TestCompareObjects for examples.

func OverlayObject

func OverlayObject(base *unstructured.Unstructured, overlay *unstructured.Unstructured) error

OverlayObject uses JSON patch strategy to overlay two unstructured objects

Types

type CtlClient

type CtlClient struct {
	client.Client
	// contains filtered or unexported fields
}

CtlClient wraps controller-runtime client and is used by dubboctl

func NewCtlClient

func NewCtlClient(opts ...CtlClientOption) (*CtlClient, error)

func (*CtlClient) ApplyManifest

func (cli *CtlClient) ApplyManifest(manifest string, ns string) error

ApplyManifest applies manifest to certain namespace If there is not this namespace, create it first

func (*CtlClient) ApplyObject

func (cli *CtlClient) ApplyObject(obj *unstructured.Unstructured) error

ApplyObject creates or updates unstructured object

func (*CtlClient) RemoveManifest

func (cli *CtlClient) RemoveManifest(manifest string, ns string) error

func (*CtlClient) RemoveObject

func (cli *CtlClient) RemoveObject(obj *unstructured.Unstructured) error

type CtlClientOption

type CtlClientOption func(*CtlClientOptions)

func WithCli

func WithCli(cli client.Client) CtlClientOption

func WithContext

func WithContext(ctx string) CtlClientOption

func WithKubeConfigPath

func WithKubeConfigPath(path string) CtlClientOption

type CtlClientOptions

type CtlClientOptions struct {
	// for normal use
	// path to kubeconfig
	KubeConfigPath string
	// specify cluster in kubeconfig to use
	Context string

	// for test
	Cli client.Client
}

type Object

type Object struct {
	Namespace string
	Name      string
	Group     string
	Kind      string
	// contains filtered or unexported fields
}

Object wraps k8s Unstructured and exposes the fields we need

func NewObject

func NewObject(obj *unstructured.Unstructured, yamlStr string) *Object

func ParseObjectFromManifest

func ParseObjectFromManifest(manifest string) (*Object, error)

ParseObjectFromManifest parse Object from manifest which represents a single K8s object

func (*Object) Hash

func (obj *Object) Hash() string

func (*Object) IsEqual

func (obj *Object) IsEqual(another *Object) bool

func (*Object) IsValid

func (obj *Object) IsValid() bool

func (*Object) SetNamespace

func (obj *Object) SetNamespace(ns string)

func (*Object) Unstructured

func (obj *Object) Unstructured() *unstructured.Unstructured

func (*Object) YAML

func (obj *Object) YAML() string

type Objects

type Objects []*Object

func ParseObjectsFromManifest

func ParseObjectsFromManifest(manifest string, continueOnErr bool) (Objects, error)

ParseObjectsFromManifest parse Objects from manifest which divided by YAML separator "\n---\n"

func (Objects) SortMap

func (objs Objects) SortMap() (map[string]*Object, []string)

SortMap generates corresponding map and sorted keys

type PortForward

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

func NewPortForward

func NewPortForward(podName, namespace, localAddress string, localPort, podPort int, cfg *rest.Config) (*PortForward, error)

func (*PortForward) Run

func (pf *PortForward) Run() error

func (*PortForward) Stop

func (pf *PortForward) Stop()

Stop close stopCh and free up resources

func (*PortForward) Wait

func (pf *PortForward) Wait()

Wait wait for closing stopCh which means that Stop function is the only way to trigger

Jump to

Keyboard shortcuts

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