k8sresource

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteAnnotation

func DeleteAnnotation(o Object, key string)

func GetAnnotation

func GetAnnotation(o Object, key string) (string, bool)

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

func ObjectKey

func ObjectKey(o Object) client.ObjectKey

func SetAnnotation

func SetAnnotation(o Object, key, val string)

Types

type Config

type Config struct {
	Client k8sclient.Interface
	Logger micrologger.Logger
}

type Object

type Object interface {
	runtime.Object

	GetAnnotations() map[string]string
	GetName() string
	GetNamespace() string
	SetAnnotations(map[string]string)
	GetObjectKind() schema.ObjectKind
}

type Service

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

func New

func New(config Config) (*Service, error)

func (*Service) EnsureCreated

func (s *Service) EnsureCreated(ctx context.Context, hashAnnotation string, desired client.Object) error

func (*Service) EnsureDeleted added in v0.2.4

func (s *Service) EnsureDeleted(ctx context.Context, obj client.Object) error

func (*Service) GroupVersionKind

func (s *Service) GroupVersionKind(o Object) (schema.GroupVersionKind, error)

func (*Service) Kind added in v0.2.4

func (s *Service) Kind(o Object) string

Kind is a best effort approach to extract object kind. It should serve only logging purposes.

func (*Service) Modify

func (s *Service) Modify(ctx context.Context, key client.ObjectKey, obj client.Object, modifyFunc func() error, backOff backoff.BackOff) error

Modify gets the object for the given key. It sets the most recent version of the object to provided obj pointer and calls modifyFunc which is supposed to apply changes to the pointer.

  • The modifyFunc is called on every try.
  • The obj variable is reset and populated before every try.
  • There are no retries if the object defined by the key does not exist.

Example usage:

key := client.ObjectKey{Namespace: "giantswarm", Name: "my-operator"}
current := &v1alpha1.App{}
modifyFunc := func() error {
	current.Spec.Version = "2.0.0"
	return nil
}
err := h.resource.Modify(ctx, key, current, modifyFunc, nil)
if err != nil {
	...
}

func (*Service) ModifyStatus added in v0.2.4

func (s *Service) ModifyStatus(ctx context.Context, key client.ObjectKey, obj client.Object, modifyFunc func() error, backOff backoff.BackOff) error

ModifyStatus works exactly like Modify but updates the status subresource.

Jump to

Keyboard shortcuts

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