k8s

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 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

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

KubeClientConfig ...

func NewDefaultKubeClient

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

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

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

func AbortBehaviorDelete(resource client.Object) AbortBehavior

AbortBehavior that deletes the specified resource

func AbortBehaviorDeleteDefaultResource

func AbortBehaviorDeleteDefaultResource() AbortBehavior

AbortBehavior that deletes the default resource

func AbortBehaviorPatch

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

AbortBehavior that patches the specified resource

func AbortBehaviorPatchDefaultResource

func AbortBehaviorPatchDefaultResource(patchOperation PatchResourceOperation, deleteOnErr bool) AbortBehavior

AbortBehavior that patches the default resource

func AbortBehaviorUpdate

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

AbortBehavior that updates the specified resource

func AbortBehaviorUpdateDefaultResource

func AbortBehaviorUpdateDefaultResource(updateOperation UpdateResourceOperation, deleteOnErr bool) AbortBehavior

AbortBehavior that updates the default resource

type Auth

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

func (Auth) GetCA

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

func (Auth) GetToken

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

type ClusterConfig

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

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

type PatchResourceOperation

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

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

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

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

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