resource

package
v1.1.16 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2021 License: Apache-2.0 Imports: 41 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteAnyExistingObject

func DeleteAnyExistingObject(c client.Client, key client.ObjectKey, obj hivev1.MetaRuntimeObject, logger log.FieldLogger) error

DeleteAnyExistingObject will look for any object that exists that matches the passed in 'obj' and will delete it if it exists

func GenerateClientConfigFromRESTConfig

func GenerateClientConfigFromRESTConfig(name string, restConfig *rest.Config) *configapi.Config

GenerateClientConfigFromRESTConfig generates a new kubeconfig using a given rest.Config. The rest.Config may come from in-cluster config (as in a pod) or an existing kubeconfig.

func Serialize added in v1.0.9

func Serialize(obj runtime.Object, scheme *runtime.Scheme) ([]byte, error)

Serialize uses a custom JSON extension to properly determine whether metav1.Time should be serialized or not. In cases where a metav1.Time is labeled as 'omitempty', the default json marshaler still outputs a "null" value because it is considered a struct. The json-iterator/go marshaler will first check whether a value is empty and if its tag says 'omitempty' it will not output it. This is needed for us to prevent patching from happening unnecessarily when applying resources that don't have a timeCreated timestamp. With the default serializer, they output a `timeCreated: null` which always causes a mismatch with whatever's already in the server.

Types

type ApplyResult

type ApplyResult string

ApplyResult indicates what type of change was performed by calling the Apply function

const (
	// ConfiguredApplyResult is returned when a patch was submitted
	ConfiguredApplyResult ApplyResult = "configured"

	// UnchangedApplyResult is returned when no change occurred
	UnchangedApplyResult ApplyResult = "unchanged"

	// CreatedApplyResult is returned when a resource was created
	CreatedApplyResult ApplyResult = "created"

	// UnknownApplyResult is returned when the resulting action could not be determined
	UnknownApplyResult ApplyResult = "unknown"
)

type Helper

type Helper interface {
	// Apply applies the given resource bytes to the target cluster specified by kubeconfig
	Apply(obj []byte) (ApplyResult, error)
	// ApplyRuntimeObject serializes an object and applies it to the target cluster specified by the kubeconfig.
	ApplyRuntimeObject(obj runtime.Object, scheme *runtime.Scheme) (ApplyResult, error)
	CreateOrUpdate(obj []byte) (ApplyResult, error)
	CreateOrUpdateRuntimeObject(obj runtime.Object, scheme *runtime.Scheme) (ApplyResult, error)
	Create(obj []byte) (ApplyResult, error)
	CreateRuntimeObject(obj runtime.Object, scheme *runtime.Scheme) (ApplyResult, error)
	// Info determines the name/namespace and type of the passed in resource bytes
	Info(obj []byte) (*Info, error)
	// Patch invokes the kubectl patch command with the given resource, patch and patch type
	Patch(name types.NamespacedName, kind, apiVersion string, patch []byte, patchType string) error
	Delete(apiVersion, kind, namespace, name string) error
}

func NewFakeHelper added in v1.0.17

func NewFakeHelper(logger log.FieldLogger) Helper

NewFakeHelper returns a new fake helper object that does not actually communicate with the cluster.

func NewHelper

func NewHelper(kubeconfig []byte, logger log.FieldLogger) (Helper, error)

NewHelper returns a new object that allows apply and patch operations

func NewHelperFromRESTConfig

func NewHelperFromRESTConfig(restConfig *rest.Config, logger log.FieldLogger) (Helper, error)

NewHelperFromRESTConfig returns a new object that allows apply and patch operations

func NewHelperWithMetricsFromRESTConfig

func NewHelperWithMetricsFromRESTConfig(restConfig *rest.Config, controllerName hivev1.ControllerName, logger log.FieldLogger) (Helper, error)

NewHelperWithMetricsFromRESTConfig returns a new object that allows apply and patch operations, with metrics tracking enabled.

type Info

type Info struct {
	Name       string
	Namespace  string
	APIVersion string
	Kind       string
	Resource   string
	Object     *unstructured.Unstructured
}

Info contains information obtained from a resource submitted to the Apply function

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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