resources

package
v0.0.0-...-4f3f676 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 23 Imported by: 4

Documentation

Index

Constants

View Source
const (
	PodReasonCompleted                = "Completed"
	PodReasonContainerCreating        = "ContainerCreating"
	PodReasonContainersNotInitialized = "ContainersNotInitialized"
	PodReasonContainersNotReady       = "ContainersNotReady"
	PodReasonCrashLoopBackoff         = "CrashLoopBackOff"
	PodReasonError                    = "Error"
	PodReasonImagePull                = "ErrImagePull"
	PodReasonInitializing             = "PodInitializing"
)
View Source
const (
	// JujuFieldManager marks the resource changes were made by Juju.
	JujuFieldManager = "juju"
)

Variables

View Source
var (
	// ClaimJujuOwnership asserts that the Kubernetes object has labels that
	// in line with Juju management "ownership".
	ClaimJujuOwnership = ClaimAggregateOr(
		ClaimFn(claimIsManagedByJuju),
		ClaimFn(claimHasJujuLabel),
	)
)

Functions

func ListEventsForObject

func ListEventsForObject(
	ctx context.Context, client kubernetes.Interface, namespace, name, kind string,
) ([]corev1.Event, error)

ListEventsForObject returns all the events for the specified object.

func PodToJujuStatus

func PodToJujuStatus(
	pod corev1.Pod,
	now time.Time,
	events EventGetter,
) (string, status.Status, time.Time, error)

PodToJujuStatus takes a Kubernetes pod and translates it to a known Juju status. If this function can't determine the reason for a pod's state either a status of error or unknown is returned. Function returns the status message, juju status, the time of the status event and any errors that occurred.

Types

type Applier

type Applier interface {
	// Apply adds apply operations to the applier.
	Apply(...Resource)
	// Delete adds delete operations to the applier.
	Delete(...Resource)
	// ApplySet deletes Resources in the current slice that don't exist in the
	// desired slice. All items in the desired slice are applied.
	ApplySet(current []Resource, desired []Resource)
	// Run processes the slice of the operations.
	Run(ctx context.Context, client kubernetes.Interface, noRollback bool) error
}

Applier defines methods for processing a slice of resource operations.

func NewApplier

func NewApplier() Applier

NewApplier creates a new applier.

type Claim

type Claim interface {
	// Assert defines the assertion to run. Returns true if a claim is asserted
	// over the provided object or if an error occurred where a claim can not be
	// made.
	Assert(obj interface{}) (bool, error)
}

Claim represents an assertion over a generic Kubernetes object to assert ownership. These are used in Juju for cluster scoped resources to assert that that Juju is not going to take ownership of an object that was not created by itself.

func ClaimAggregateOr

func ClaimAggregateOr(claims ...Claim) Claim

ClaimAggregateOr runs multiple claims looking for the first true condition. If no claims are provided or no claim returns true false is returned. The first claim to error stops execution.

func RunClaims

func RunClaims(claims ...Claim) Claim

RunClaims runs the provided claims until the first true condition is found or the first error occurs. If no claims are provided then true is returned.

type ClaimFn

type ClaimFn func(obj interface{}) (bool, error)

ClaimFn is a helper type for making Claim types out of functions. See Claim

func (ClaimFn) Assert

func (c ClaimFn) Assert(obj interface{}) (bool, error)

type ClusterRole

type ClusterRole struct {
	rbacv1.ClusterRole
}

ClusterRole extends the k8s cluster role.

func NewClusterRole

func NewClusterRole(name string, in *rbacv1.ClusterRole) *ClusterRole

NewClusterRole creates a new cluster role resource.

func (*ClusterRole) Apply

func (r *ClusterRole) Apply(ctx context.Context, client kubernetes.Interface) error

Apply patches the resource change.

func (*ClusterRole) Clone

func (r *ClusterRole) Clone() Resource

Clone returns a copy of the resource.

func (*ClusterRole) ComputeStatus

ComputeStatus returns a juju status for the resource.

func (*ClusterRole) Delete

func (r *ClusterRole) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*ClusterRole) Ensure

func (r *ClusterRole) Ensure(
	ctx context.Context,
	client kubernetes.Interface,
	claims ...Claim,
) ([]func(), error)

Ensure ensures this cluster role exists in it's desired form inside the cluster. If the object does not exist it's updated and if the object exists it's updated. The method also takes an optional set of claims to test the exisiting Kubernetes object with to assert ownership before overwriting it.

func (*ClusterRole) Events

func (r *ClusterRole) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*ClusterRole) Get

func (r *ClusterRole) Get(ctx context.Context, client kubernetes.Interface) error

Get refreshes the resource.

func (*ClusterRole) ID

func (r *ClusterRole) ID() ID

ID returns a comparable ID for the Resource

func (*ClusterRole) Update

func (r *ClusterRole) Update(ctx context.Context, client kubernetes.Interface) error

Update updates the object in the Kubernetes cluster to the new representation

type ClusterRoleBinding

type ClusterRoleBinding struct {
	rbacv1.ClusterRoleBinding
}

ClusterRoleBinding extends the k8s cluster role binding.

func NewClusterRoleBinding

func NewClusterRoleBinding(name string, in *rbacv1.ClusterRoleBinding) *ClusterRoleBinding

NewClusterRoleBinding creates a new role resource.

func (*ClusterRoleBinding) Apply

Apply patches the resource change.

func (*ClusterRoleBinding) Clone

func (rb *ClusterRoleBinding) Clone() Resource

Clone returns a copy of the resource.

func (*ClusterRoleBinding) ComputeStatus

ComputeStatus returns a juju status for the resource.

func (*ClusterRoleBinding) Delete

func (rb *ClusterRoleBinding) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*ClusterRoleBinding) Ensure

func (rb *ClusterRoleBinding) Ensure(
	ctx context.Context,
	client kubernetes.Interface,
	claims ...Claim,
) ([]func(), error)

Ensure ensures this cluster role exists in it's desired form inside the cluster. If the object does not exist it's updated and if the object exists it's updated. The method also takes an optional set of claims to test the existing Kubernetes object with to assert ownership before overwriting it.

func (*ClusterRoleBinding) Events

func (rb *ClusterRoleBinding) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*ClusterRoleBinding) Get

Get refreshes the resource.

func (*ClusterRoleBinding) ID

func (rb *ClusterRoleBinding) ID() ID

ID returns a comparable ID for the Resource

func (*ClusterRoleBinding) Update

func (rb *ClusterRoleBinding) Update(ctx context.Context, client kubernetes.Interface) error

Update updates the object in the Kubernetes cluster to the new representation

type DaemonSet

type DaemonSet struct {
	appsv1.DaemonSet
}

DaemonSet extends the k8s daemonset.

func NewDaemonSet

func NewDaemonSet(name string, namespace string, in *appsv1.DaemonSet) *DaemonSet

NewDaemonSet creates a new daemonSet resource.

func (*DaemonSet) Apply

func (ds *DaemonSet) Apply(ctx context.Context, client kubernetes.Interface) error

Apply patches the resource change.

func (*DaemonSet) Clone

func (ds *DaemonSet) Clone() Resource

Clone returns a copy of the resource.

func (*DaemonSet) ComputeStatus

func (ds *DaemonSet) ComputeStatus(ctx context.Context, client kubernetes.Interface, now time.Time) (string, status.Status, time.Time, error)

ComputeStatus returns a juju status for the resource.

func (*DaemonSet) Delete

func (ds *DaemonSet) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*DaemonSet) Events

func (ds *DaemonSet) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*DaemonSet) Get

func (ds *DaemonSet) Get(ctx context.Context, client kubernetes.Interface) error

Get refreshes the resource.

func (*DaemonSet) ID

func (ds *DaemonSet) ID() ID

ID returns a comparable ID for the Resource

type Deployment

type Deployment struct {
	appsv1.Deployment
}

Deployment extends the k8s deployment.

func NewDeployment

func NewDeployment(name string, namespace string, in *appsv1.Deployment) *Deployment

NewDeployment creates a new deployment resource.

func (*Deployment) Apply

func (d *Deployment) Apply(ctx context.Context, client kubernetes.Interface) error

Apply patches the resource change.

func (*Deployment) Clone

func (d *Deployment) Clone() Resource

Clone returns a copy of the resource.

func (*Deployment) ComputeStatus

func (d *Deployment) ComputeStatus(ctx context.Context, client kubernetes.Interface, now time.Time) (string, status.Status, time.Time, error)

ComputeStatus returns a juju status for the resource.

func (*Deployment) Delete

func (d *Deployment) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*Deployment) Events

func (d *Deployment) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*Deployment) Get

func (d *Deployment) Get(ctx context.Context, client kubernetes.Interface) error

Get refreshes the resource.

func (*Deployment) ID

func (d *Deployment) ID() ID

ID returns a comparable ID for the Resource

type EventGetter

type EventGetter func() ([]corev1.Event, error)

type ID

type ID struct {
	Type      string
	Name      string
	Namespace string
}

ID represents a compareable identifier for Resources.

type PersistentVolume

type PersistentVolume struct {
	corev1.PersistentVolume
}

PersistentVolume extends the k8s persistentVolume.

func NewPersistentVolume

func NewPersistentVolume(name string, in *corev1.PersistentVolume) *PersistentVolume

NewPersistentVolume creates a new persistent volume resource.

func (*PersistentVolume) Apply

func (pv *PersistentVolume) Apply(ctx context.Context, client kubernetes.Interface) error

Apply patches the resource change.

func (*PersistentVolume) Clone

func (pv *PersistentVolume) Clone() Resource

Clone returns a copy of the resource.

func (*PersistentVolume) ComputeStatus

func (pv *PersistentVolume) ComputeStatus(ctx context.Context, client kubernetes.Interface, now time.Time) (string, status.Status, time.Time, error)

ComputeStatus returns a juju status for the resource.

func (*PersistentVolume) Delete

func (pv *PersistentVolume) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*PersistentVolume) Events

func (pv *PersistentVolume) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*PersistentVolume) Get

Get refreshes the resource.

func (*PersistentVolume) ID

func (pv *PersistentVolume) ID() ID

ID returns a comparable ID for the Resource

type PersistentVolumeClaim

type PersistentVolumeClaim struct {
	corev1.PersistentVolumeClaim
}

PersistentVolumeClaim extends the k8s persistentVolumeClaim.

func ListPersistentVolumeClaims

func ListPersistentVolumeClaims(ctx context.Context, client kubernetes.Interface, namespace string, opts metav1.ListOptions) ([]PersistentVolumeClaim, error)

ListPersistentVolumeClaims returns a list of persistent volume claims.

func NewPersistentVolumeClaim

func NewPersistentVolumeClaim(name string, namespace string, in *corev1.PersistentVolumeClaim) *PersistentVolumeClaim

NewPersistentVolumeClaim creates a new persistent volume claim resource.

func (*PersistentVolumeClaim) Apply

Apply patches the resource change.

func (*PersistentVolumeClaim) Clone

func (pvc *PersistentVolumeClaim) Clone() Resource

Clone returns a copy of the resource.

func (*PersistentVolumeClaim) ComputeStatus

func (pvc *PersistentVolumeClaim) ComputeStatus(ctx context.Context, client kubernetes.Interface, now time.Time) (string, status.Status, time.Time, error)

ComputeStatus returns a juju status for the resource.

func (*PersistentVolumeClaim) Delete

Delete removes the resource.

func (*PersistentVolumeClaim) Events

Events emitted by the resource.

func (*PersistentVolumeClaim) Get

Get refreshes the resource.

func (*PersistentVolumeClaim) ID

func (pvc *PersistentVolumeClaim) ID() ID

ID returns a comparable ID for the Resource

type Pod

type Pod struct {
	corev1.Pod
}

Pod extends the k8s service.

func ListPods

func ListPods(ctx context.Context, client kubernetes.Interface, namespace string, opts metav1.ListOptions) ([]Pod, error)

ListPods returns a list of Pods.

func NewPod

func NewPod(name string, namespace string, in *corev1.Pod) *Pod

NewPod creates a new service resource.

func (*Pod) Apply

func (p *Pod) Apply(ctx context.Context, client kubernetes.Interface) error

Apply patches the resource change.

func (*Pod) Clone

func (p *Pod) Clone() Resource

Clone returns a copy of the resource.

func (*Pod) ComputeStatus

func (p *Pod) ComputeStatus(ctx context.Context, client kubernetes.Interface, now time.Time) (string, status.Status, time.Time, error)

ComputeStatus returns a juju status for the resource.

func (*Pod) Delete

func (p *Pod) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*Pod) Events

func (p *Pod) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*Pod) Get

func (p *Pod) Get(ctx context.Context, client kubernetes.Interface) error

Get refreshes the resource.

func (*Pod) ID

func (p *Pod) ID() ID

ID returns a comparable ID for the Resource

type Resource

type Resource interface {
	metav1.ObjectMetaAccessor
	// Clone returns a copy of the resource.
	Clone() Resource
	// Apply patches the resource change.
	Apply(ctx context.Context, client kubernetes.Interface) error
	// Get refreshes the resource.
	Get(ctx context.Context, client kubernetes.Interface) error
	// Delete removes the resource.
	Delete(ctx context.Context, client kubernetes.Interface) error
	// String returns a string format containing the name and type of the resource.
	String() string
	// ComputeStatus returns a juju status for the resource.
	ComputeStatus(ctx context.Context, client kubernetes.Interface, now time.Time) (string, status.Status, time.Time, error)
	// Events emitted by the object.
	Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)
	// ID returns a comparable ID for the Resource
	ID() ID
}

Resource defines methods for manipulating a k8s resource.

type Role

type Role struct {
	rbacv1.Role
}

Role extends the k8s role.

func NewRole

func NewRole(name string, namespace string, in *rbacv1.Role) *Role

NewRole creates a new role resource.

func (*Role) Apply

func (r *Role) Apply(ctx context.Context, client kubernetes.Interface) error

Apply patches the resource change.

func (*Role) Clone

func (r *Role) Clone() Resource

Clone returns a copy of the resource.

func (*Role) ComputeStatus

func (r *Role) ComputeStatus(_ context.Context, _ kubernetes.Interface, now time.Time) (string, status.Status, time.Time, error)

ComputeStatus returns a juju status for the resource.

func (*Role) Delete

func (r *Role) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*Role) Events

func (r *Role) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*Role) Get

func (r *Role) Get(ctx context.Context, client kubernetes.Interface) error

Get refreshes the resource.

func (*Role) ID

func (r *Role) ID() ID

ID returns a comparable ID for the Resource

type RoleBinding

type RoleBinding struct {
	rbacv1.RoleBinding
}

RoleBinding extends the k8s role binding.

func NewRoleBinding

func NewRoleBinding(name string, namespace string, in *rbacv1.RoleBinding) *RoleBinding

NewRoleBinding creates a new role resource.

func (*RoleBinding) Apply

func (rb *RoleBinding) Apply(ctx context.Context, client kubernetes.Interface) error

Apply patches the resource change.

func (*RoleBinding) Clone

func (rb *RoleBinding) Clone() Resource

Clone returns a copy of the resource.

func (*RoleBinding) ComputeStatus

ComputeStatus returns a juju status for the resource.

func (*RoleBinding) Delete

func (rb *RoleBinding) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*RoleBinding) Events

func (rb *RoleBinding) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*RoleBinding) Get

func (rb *RoleBinding) Get(ctx context.Context, client kubernetes.Interface) error

Get refreshes the resource.

func (*RoleBinding) ID

func (rb *RoleBinding) ID() ID

ID returns a comparable ID for the Resource

type Secret

type Secret struct {
	corev1.Secret
}

Secret extends the k8s secret.

func ListSecrets

func ListSecrets(ctx context.Context, client kubernetes.Interface, namespace string, opts metav1.ListOptions) ([]Secret, error)

ListSecrets returns a list of Secrets.

func NewSecret

func NewSecret(name string, namespace string, in *corev1.Secret) *Secret

NewSecret creates a new secret resource.

func (*Secret) Apply

func (s *Secret) Apply(ctx context.Context, client kubernetes.Interface) error

Apply patches the resource change.

func (*Secret) Clone

func (s *Secret) Clone() Resource

Clone returns a copy of the resource.

func (*Secret) ComputeStatus

func (s *Secret) ComputeStatus(ctx context.Context, client kubernetes.Interface, now time.Time) (string, status.Status, time.Time, error)

ComputeStatus returns a juju status for the resource.

func (*Secret) Delete

func (s *Secret) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*Secret) Events

func (s *Secret) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*Secret) Get

func (s *Secret) Get(ctx context.Context, client kubernetes.Interface) error

Get refreshes the resource.

func (*Secret) ID

func (s *Secret) ID() ID

ID returns a comparable ID for the Resource

type Service

type Service struct {
	corev1.Service
	PatchType *types.PatchType
}

Service extends the k8s service.

func NewService

func NewService(name string, namespace string, in *corev1.Service) *Service

NewService creates a new service resource.

func (*Service) Apply

func (s *Service) Apply(ctx context.Context, client kubernetes.Interface) error

Apply patches the resource change.

func (*Service) Clone

func (s *Service) Clone() Resource

Clone returns a copy of the resource.

func (*Service) ComputeStatus

func (s *Service) ComputeStatus(ctx context.Context, client kubernetes.Interface, now time.Time) (string, status.Status, time.Time, error)

ComputeStatus returns a juju status for the resource.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*Service) Events

func (s *Service) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*Service) Get

func (s *Service) Get(ctx context.Context, client kubernetes.Interface) error

Get refreshes the resource.

func (*Service) ID

func (s *Service) ID() ID

ID returns a comparable ID for the Resource

type ServiceAccount

type ServiceAccount struct {
	corev1.ServiceAccount
}

ServiceAccount extends the k8s service account.

func NewServiceAccount

func NewServiceAccount(name string, namespace string, in *corev1.ServiceAccount) *ServiceAccount

NewServiceAccount creates a new service account resource.

func (*ServiceAccount) Apply

func (sa *ServiceAccount) Apply(ctx context.Context, client kubernetes.Interface) error

Apply patches the resource change.

func (*ServiceAccount) Clone

func (sa *ServiceAccount) Clone() Resource

Clone returns a copy of the resource.

func (*ServiceAccount) ComputeStatus

ComputeStatus returns a juju status for the resource.

func (*ServiceAccount) Delete

func (sa *ServiceAccount) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*ServiceAccount) Ensure

func (sa *ServiceAccount) Ensure(
	ctx context.Context,
	client kubernetes.Interface,
	claims ...Claim,
) ([]func(), error)

func (*ServiceAccount) Events

func (sa *ServiceAccount) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*ServiceAccount) Get

func (sa *ServiceAccount) Get(ctx context.Context, client kubernetes.Interface) error

Get refreshes the resource.

func (*ServiceAccount) ID

func (sa *ServiceAccount) ID() ID

ID returns a comparable ID for the Resource

func (*ServiceAccount) Update

func (sa *ServiceAccount) Update(
	ctx context.Context,
	client kubernetes.Interface,
) error

type StatefulSet

type StatefulSet struct {
	appsv1.StatefulSet
}

StatefulSet extends the k8s statefulSet.

func NewStatefulSet

func NewStatefulSet(name string, namespace string, in *appsv1.StatefulSet) *StatefulSet

NewStatefulSet creates a new statefulset resource.

func (*StatefulSet) Apply

func (ss *StatefulSet) Apply(ctx context.Context, client kubernetes.Interface) (err error)

Apply patches the resource change.

func (*StatefulSet) Clone

func (ss *StatefulSet) Clone() Resource

Clone returns a copy of the resource.

func (*StatefulSet) ComputeStatus

func (ss *StatefulSet) ComputeStatus(ctx context.Context, client kubernetes.Interface, now time.Time) (string, status.Status, time.Time, error)

ComputeStatus returns a juju status for the resource.

func (*StatefulSet) Delete

func (ss *StatefulSet) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*StatefulSet) Events

func (ss *StatefulSet) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*StatefulSet) Get

func (ss *StatefulSet) Get(ctx context.Context, client kubernetes.Interface) error

Get refreshes the resource.

func (*StatefulSet) ID

func (ss *StatefulSet) ID() ID

ID returns a comparable ID for the Resource

type StorageClass

type StorageClass struct {
	storagev1.StorageClass
}

StorageClass extends the k8s storageClass.

func ListStorageClass

func ListStorageClass(ctx context.Context, client kubernetes.Interface, opts metav1.ListOptions) ([]StorageClass, error)

ListStorageClass returns a list of storage classes.

func NewStorageClass

func NewStorageClass(name string, in *storagev1.StorageClass) *StorageClass

NewStorageClass creates a new storage class resource.

func (*StorageClass) Apply

func (sc *StorageClass) Apply(ctx context.Context, client kubernetes.Interface) error

Apply patches the resource change.

func (*StorageClass) Clone

func (sc *StorageClass) Clone() Resource

Clone returns a copy of the resource.

func (*StorageClass) ComputeStatus

func (sc *StorageClass) ComputeStatus(ctx context.Context, client kubernetes.Interface, now time.Time) (string, status.Status, time.Time, error)

ComputeStatus returns a juju status for the resource.

func (*StorageClass) Delete

func (sc *StorageClass) Delete(ctx context.Context, client kubernetes.Interface) error

Delete removes the resource.

func (*StorageClass) Events

func (sc *StorageClass) Events(ctx context.Context, client kubernetes.Interface) ([]corev1.Event, error)

Events emitted by the resource.

func (*StorageClass) Get

func (sc *StorageClass) Get(ctx context.Context, client kubernetes.Interface) error

Get refreshes the resource.

func (*StorageClass) ID

func (sc *StorageClass) ID() ID

ID returns a comparable ID for the Resource

Directories

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

Jump to

Keyboard shortcuts

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