status

package
v0.36.0-flux.4 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package kstatus contains functionality for computing the status of Kubernetes resources.

The statuses defined in this package are:

  • InProgress
  • Current
  • Failed
  • Terminating
  • NotFound
  • Unknown

Computing the status of a resources can be done by calling the Compute function in the status package.

import (
  "github.com/fluxcd/cli-utils/pkg/kstatus/status"
)

res, err := status.Compute(resource)

The package also defines a set of new conditions:

  • InProgress
  • Failed

These conditions have been chosen to follow the "abnormal-true" pattern where conditions should be set to true for error/abnormal conditions and the absence of a condition means things are normal.

The Augment function augments any unstructured resource with the standard conditions described above. The values of these conditions are decided based on other status information available in the resources.

import (
  "github.com/fluxcd/cli-utils/pkg/kstatus/status
)

err := status.Augment(resource)

Index

Constants

View Source
const (
	// The set of standard conditions defined in this package. These follow the "abnormality-true"
	// convention where conditions should have a true value for abnormal/error situations and the absence
	// of a condition should be interpreted as a false value, i.e. everything is normal.
	ConditionStalled     ConditionType = "Stalled"
	ConditionReconciling ConditionType = "Reconciling"

	// The set of status conditions which can be assigned to resources.
	InProgressStatus  Status = "InProgress"
	FailedStatus      Status = "Failed"
	CurrentStatus     Status = "Current"
	TerminatingStatus Status = "Terminating"
	NotFoundStatus    Status = "NotFound"
	UnknownStatus     Status = "Unknown"
)
View Source
const (

	// How long a pod can be unscheduled before it is reported as
	// unschedulable.
	ScheduleWindow = 15 * time.Second
)

Variables

Functions

func Augment

func Augment(u *unstructured.Unstructured) error

Augment takes a resource and augments the resource with the standard status conditions.

func GetIntField

func GetIntField(obj map[string]interface{}, fieldPath string, defaultValue int) int

GetIntField return field as string defaulting to value if not found

func GetStringField

func GetStringField(obj map[string]interface{}, fieldPath string, defaultValue string) string

GetStringField return field as string defaulting to value if not found

Types

type BasicCondition

type BasicCondition struct {
	// Type Condition type
	Type string `json:"type" yaml:"type"`
	// Status is one of True,False,Unknown
	Status corev1.ConditionStatus `json:"status" yaml:"status"`
	// Reason simple single word reason in CamleCase
	// +optional
	Reason string `json:"reason,omitempty" yaml:"reason"`
	// Message human readable reason
	// +optional
	Message string `json:"message,omitempty" yaml:"message"`
}

BasicCondition fields that are expected in a condition

type Condition

type Condition struct {
	// Type condition type
	Type ConditionType `json:"type,omitempty"`
	// Status String that describes the condition status
	Status corev1.ConditionStatus `json:"status,omitempty"`
	// Reason one work CamelCase reason
	Reason string `json:"reason,omitempty"`
	// Message Human readable reason string
	Message string `json:"message,omitempty"`
}

Condition defines the general format for conditions on Kubernetes resources. In practice, each kubernetes resource defines their own format for conditions, but most (maybe all) follows this structure.

type ConditionStatus

type ConditionStatus struct {
	// Array of Conditions as expected to be present in kubernetes resources
	Conditions []BasicCondition `json:"conditions" yaml:"conditions"`
}

ConditionStatus represent status with condition array

type ConditionType

type ConditionType string

ConditionType defines the set of condition types allowed inside a Condition struct.

func (ConditionType) String

func (c ConditionType) String() string

String returns the ConditionType as a string.

type GetConditionsFn

type GetConditionsFn func(*unstructured.Unstructured) (*Result, error)

GetConditionsFn defines the signature for functions to compute the status of a built-in resource.

func GetLegacyConditionsFn

func GetLegacyConditionsFn(u *unstructured.Unstructured) GetConditionsFn

GetLegacyConditionsFn returns a function that can compute the status for the given resource, or nil if the resource type is not known.

type ObjWithConditions

type ObjWithConditions struct {
	// Status as expected to be present in most compliant kubernetes resources
	Status ConditionStatus `json:"status" yaml:"status"`
}

ObjWithConditions Represent meta object with status.condition array

func GetObjectWithConditions

func GetObjectWithConditions(in map[string]interface{}) (*ObjWithConditions, error)

GetObjectWithConditions return typed object

type Result

type Result struct {
	// Status
	Status Status
	// Message
	Message string
	// Conditions list of extracted conditions from Resource
	Conditions []Condition
}

Result contains the results of a call to compute the status of a resource.

func Compute

func Compute(u *unstructured.Unstructured) (*Result, error)

Compute finds the status of a given unstructured resource. It does not fetch the state of the resource from a cluster, so the provided unstructured must have the complete state, including status.

The returned result contains the status of the resource, which will be one of

  • InProgress
  • Current
  • Failed
  • Terminating

It also contains a message that provides more information on why the resource has the given status. Finally, the result also contains a list of standard resources that would belong on the given resource.

type Status

type Status string

Status defines the set of statuses a resource can have.

func FromStringOrDie

func FromStringOrDie(text string) Status

StatusFromString turns a string into a Status. Will panic if the provided string is not a valid status.

func (Status) String

func (s Status) String() string

String returns the status as a string.

Jump to

Keyboard shortcuts

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