k8s

package
v1.1.33 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2023 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Overview

Simple implementation of a KubeClient that caches reads and falls back to make direct API calls on failure. Write calls are not cached.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func KubeClientConfig added in v1.0.42

func KubeClientConfig(host string, auth Auth) (*restclient.Config, error)

KubeClientConfig ...

func NewDefaultKubeClient added in v0.5.37

func NewDefaultKubeClient(config *rest.Config) (core.KubeClient, error)

NewDefaultKubeClient creates a new KubeClient with default options set. This client caches reads and falls back to make API calls on failure. Write calls are not cached.

func NewKubeClient added in v0.5.37

func NewKubeClient(config *rest.Config, options Options) (core.KubeClient, error)

NewKubeClient creates a new KubeClient that caches reads and falls back to make API calls on failure. Write calls are not cached.

Types

type AbortBehavior added in v0.6.1

type AbortBehavior struct {
	// Optional override to the default k8s Resource being acted on.
	Resource       client.Object
	DeleteResource bool
	Update         *UpdateResourceOperation
	Patch          *PatchResourceOperation
	// Determines whether to delete the Resource if the specified operations return an error
	DeleteOnErr bool
}

Defines the overridden OnAbort behavior. The resource (by default, the underlying resource, although this can be overridden) can be either patched, updated, or deleted.

func AbortBehaviorDelete added in v0.6.1

func AbortBehaviorDelete(resource client.Object) AbortBehavior

AbortBehavior that deletes the specified resource

func AbortBehaviorDeleteDefaultResource added in v0.6.1

func AbortBehaviorDeleteDefaultResource() AbortBehavior

AbortBehavior that deletes the default resource

func AbortBehaviorPatch added in v0.6.1

func AbortBehaviorPatch(patchOperation PatchResourceOperation, deleteOnErr bool, resource client.Object) AbortBehavior

AbortBehavior that patches the specified resource

func AbortBehaviorPatchDefaultResource added in v0.6.1

func AbortBehaviorPatchDefaultResource(patchOperation PatchResourceOperation, deleteOnErr bool) AbortBehavior

AbortBehavior that patches the default resource

func AbortBehaviorUpdate added in v0.6.1

func AbortBehaviorUpdate(updateOperation UpdateResourceOperation, deleteOnErr bool, resource client.Object) AbortBehavior

AbortBehavior that updates the specified resource

func AbortBehaviorUpdateDefaultResource added in v0.6.1

func AbortBehaviorUpdateDefaultResource(updateOperation UpdateResourceOperation, deleteOnErr bool) AbortBehavior

AbortBehavior that updates the default resource

type Auth added in v1.0.42

type Auth struct {
	TokenPath  string `json:"tokenPath" pflag:", Token path"`
	CaCertPath string `json:"caCertPath" pflag:", Certificate path"`
}

func (Auth) GetCA added in v1.0.42

func (auth Auth) GetCA() ([]byte, error)

func (Auth) GetToken added in v1.0.42

func (auth Auth) GetToken() (string, error)

type ClientBuilder added in v1.0.10

type ClientBuilder interface {
	// WithUncached takes a list of runtime objects (plain or lists) that users don't want to cache
	// for this client. This function can be called multiple times, it should append to an internal slice.
	WithUncached(objs ...client.Object) ClientBuilder

	// Build returns a new client.
	Build(cache cache.Cache, config *rest.Config, options client.Options) (client.Client, error)
}

ClientBuilder builder is the interface for the client builder.

func NewFallbackClientBuilder added in v0.5.37

func NewFallbackClientBuilder() ClientBuilder

Creates a new k8s client that uses the cached client for reads and falls back to making API calls if it failed. Write calls will always go to raw client directly.

type ClusterConfig added in v1.0.42

type ClusterConfig struct {
	Name     string `json:"name" pflag:",Friendly name of the remote cluster"`
	Endpoint string `json:"endpoint" pflag:", Remote K8s cluster endpoint"`
	Auth     Auth   `json:"auth" pflag:"-, Auth setting for the cluster"`
	Enabled  bool   `json:"enabled" pflag:", Boolean flag to enable or disable"`
}

type Options added in v0.5.37

type Options struct {
	MapperProvider func(*rest.Config) (meta.RESTMapper, error)
	CacheOptions   *cache.Options
	ClientOptions  *client.Options
}

type PatchResourceOperation added in v0.6.1

type PatchResourceOperation struct {
	Patch   client.Patch
	Options []client.PatchOption
}

Defines a Patch operation on a Resource

type Plugin

type Plugin interface {
	// Defines a func to create a query object (typically just object and type meta portions) that's used to query k8s
	// resources.
	BuildIdentityResource(ctx context.Context, taskCtx pluginsCore.TaskExecutionMetadata) (client.Object, error)

	// Defines a func to create the full resource object that will be posted to k8s.
	BuildResource(ctx context.Context, taskCtx pluginsCore.TaskExecutionContext) (client.Object, error)

	// Analyses the k8s resource and reports the status as TaskPhase. This call is expected to be relatively fast,
	// any operations that might take a long time (limits are configured system-wide) should be offloaded to the
	// background.
	GetTaskPhase(ctx context.Context, pluginContext PluginContext, resource client.Object) (pluginsCore.PhaseInfo, error)

	// Properties desired by the plugin
	GetProperties() PluginProperties
}

Defines a simplified interface to author plugins for k8s resources.

type PluginAbortOverride added in v0.6.1

type PluginAbortOverride interface {
	OnAbort(ctx context.Context, tCtx pluginsCore.TaskExecutionContext, resource client.Object) (behavior AbortBehavior, err error)
}

An optional interface a Plugin can implement to override its default OnAbort finalizer (deletion of the underlying resource).

type PluginContext

type PluginContext interface {
	// Returns a TaskReader, to retrieve task details
	TaskReader() pluginsCore.TaskReader

	// Returns an input reader to retrieve input data
	InputReader() io.InputReader

	// Provides an output sync of type io.OutputWriter
	OutputWriter() io.OutputWriter

	// Returns a handle to the currently configured storage backend that can be used to communicate with the tasks or write metadata
	DataStore() *storage.DataStore

	// Returns the max allowed dataset size that the outputwriter will accept
	MaxDatasetSizeBytes() int64

	// Returns a handle to the Task's execution metadata.
	TaskExecutionMetadata() pluginsCore.TaskExecutionMetadata

	// Returns a reader that retrieves previously stored plugin internal state. the state itself is immutable
	PluginStateReader() pluginsCore.PluginStateReader
}

Special context passed in to plugins when checking task phase

type PluginEntry

type PluginEntry struct {
	// ID/Name of the plugin. This will be used to identify this plugin and has to be unique in the entire system
	// All functions like enabling and disabling a plugin use this ID
	ID pluginsCore.TaskType
	// A list of all the task types for which this plugin is applicable.
	RegisteredTaskTypes []pluginsCore.TaskType
	// An instance of the kubernetes resource this plugin is responsible for, for example v1.Pod{}
	ResourceToWatch client.Object
	// An instance of the plugin
	Plugin Plugin
	// Boolean that indicates if this plugin can be used as the default for unknown task types. There can only be
	// one default in the system
	IsDefault bool
	// Returns a new KubeClient to be used instead of the internal controller-runtime client.
	CustomKubeClient func(ctx context.Context) (pluginsCore.KubeClient, error)
}

PluginEntry is a structure that is used to indicate to the system a K8s plugin

type PluginProperties added in v0.5.40

type PluginProperties struct {
	// Disables the inclusion of OwnerReferences in kubernetes resources that this plugin is responsible for.
	// Disabling is only useful if resources will be created in a remote cluster.
	DisableInjectOwnerReferences bool
	// Boolean that indicates if finalizer injection should be disabled for resources that this plugin is
	// responsible for.
	DisableInjectFinalizer bool
	// Specifies the length of TaskExecutionID generated name. default: 50
	GeneratedNameMaxLength *int
	// DisableDeleteResourceOnFinalize disables deleting the created resource on finalize. That behavior is controllable
	// on the base K8sPluginConfig level but can be disabled for individual plugins. Plugins should generally not
	// override that behavior unless the resource that gets created for this plugin does not consume resources (cluster's
	// cpu/memory... etc. or external resources) once the plugin's Plugin.GetTaskPhase() returns a terminal phase.
	DisableDeleteResourceOnFinalize bool
}

System level properties that this Plugin supports

type PluginState added in v1.0.44

type PluginState struct {
	// Phase is the plugin phase.
	Phase pluginsCore.Phase
	// PhaseVersion is an number used to indicate reportable changes to state that have the same phase.
	PhaseVersion uint32
	// Reason is the message explaining the purpose for being in the reported state.
	Reason string
}

PluginState defines the state of a k8s plugin. This information must be maintained between propeller evaluations to determine if there have been any updates since the previously evaluation.

type UpdateResourceOperation added in v0.6.1

type UpdateResourceOperation struct {
	Options []client.UpdateOption
}

Defines an Update operation on a Resource

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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