util

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 42 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// BatchReleaseControlAnnotation is controller info about batchRelease when rollout
	BatchReleaseControlAnnotation = "batchrelease.rollouts.kruise.io/control-info"
	// InRolloutProgressingAnnotation marks workload as entering the rollout progressing process
	//and does not allow paused=false during this process
	InRolloutProgressingAnnotation = "rollouts.kruise.io/in-progressing"
	// RolloutHashAnnotation record observed rollout spec hash
	RolloutHashAnnotation = "rollouts.kruise.io/hash"
)

For Rollout and BatchRelease

View Source
const (
	// CanaryDeploymentLabel is to label canary deployment that is created by batchRelease controller
	CanaryDeploymentLabel = "rollouts.kruise.io/canary-deployment"
	// CanaryDeploymentFinalizer is a finalizer to resources patched by batchRelease controller
	CanaryDeploymentFinalizer = "finalizer.rollouts.kruise.io/batch-release"
	// KruiseRolloutFinalizer is a finalizer for deployment/service/ingress/gateway/etc
	KruiseRolloutFinalizer = "rollouts.kruise.io/rollout"
	// WorkloadTypeLabel is a label to identify workload type
	WorkloadTypeLabel = "rollouts.kruise.io/workload-type"
	// DeploymentRevisionAnnotation is the revision annotation of a deployment's replica sets which records its rollout sequence
	DeploymentRevisionAnnotation = "deployment.kubernetes.io/revision"
)

For Workloads

View Source
const (

	// CloneSetType DeploymentType and StatefulSetType are values to WorkloadTypeLabel
	CloneSetType    WorkloadType = "cloneset"
	DeploymentType  WorkloadType = "deployment"
	StatefulSetType WorkloadType = "statefulset"
	DaemonSetType   WorkloadType = "daemonset"

	AddFinalizerOpType    FinalizerOpType = "Add"
	RemoveFinalizerOpType FinalizerOpType = "Remove"
)

For Others

View Source
const (
	// NoNeedUpdatePodLabel will be patched to pod when rollback in batches if the pods no need to rollback
	NoNeedUpdatePodLabel = "rollouts.kruise.io/no-need-update"
)

For Pods

View Source
const (
	TrafficRoutingFinalizer = "rollouts.kruise.io/trafficrouting"
)

Variables

View Source
var (
	ControllerKindRS           = apps.SchemeGroupVersion.WithKind("ReplicaSet")
	ControllerKindDep          = apps.SchemeGroupVersion.WithKind("Deployment")
	ControllerKindSts          = apps.SchemeGroupVersion.WithKind("StatefulSet")
	ControllerKruiseKindCS     = appsv1alpha1.SchemeGroupVersion.WithKind("CloneSet")
	ControllerKruiseKindDS     = appsv1alpha1.SchemeGroupVersion.WithKind("DaemonSet")
	ControllerKruiseKindSts    = appsv1beta1.SchemeGroupVersion.WithKind("StatefulSet")
	ControllerKruiseOldKindSts = appsv1alpha1.SchemeGroupVersion.WithKind("StatefulSet")
)

Functions

func AddWatcherDynamically added in v0.2.0

func AddWatcherDynamically(c controller.Controller, h handler.EventHandler, gvk schema.GroupVersionKind) (bool, error)

func AddWorkloadWatcher added in v0.2.0

func AddWorkloadWatcher(c controller.Controller, handler handler.EventHandler) error

func ComputeHash

func ComputeHash(template *v1.PodTemplateSpec, collisionCount *int32) string

ComputeHash returns a hash value calculated from pod template and a collisionCount to avoid hash collision. The hash will be safe encoded to avoid bad words.

func DeepHashObject

func DeepHashObject(hasher hash.Hash, objectToWrite interface{})

DeepHashObject writes specified object to hash using the spew library which follows pointers and prints actual values of the nested objects ensuring the hash does not change when a pointer changes.

func DeploymentMaxUnavailable added in v0.3.0

func DeploymentMaxUnavailable(deployment *apps.Deployment) int32

DeploymentMaxUnavailable returns the maximum unavailable pods a rolling deployment can take.

func DiscoverGVK

func DiscoverGVK(gvk schema.GroupVersionKind) bool

func DumpJSON

func DumpJSON(o interface{}) string

func EncodeHash added in v0.3.0

func EncodeHash(data string) string

hash hashes `data` with sha256 and returns the hex string

func EqualIgnoreHash

func EqualIgnoreHash(template1, template2 *v1.PodTemplateSpec) bool

EqualIgnoreHash compare template without pod-template-hash label

func EqualIgnoreSpecifyMetadata added in v0.4.0

func EqualIgnoreSpecifyMetadata(template1, template2 *v1.PodTemplateSpec, ignoreLabels, ignoreAnno []string) bool

func FilterActiveDeployment

func FilterActiveDeployment(ds []*apps.Deployment) []*apps.Deployment

FilterActiveDeployment will filter out terminating deployment

func FilterActivePods added in v0.2.0

func FilterActivePods(pods []*v1.Pod) []*v1.Pod

FilterActivePods will filter out terminating pods

func FindCanaryAndStableReplicaSet added in v0.3.0

func FindCanaryAndStableReplicaSet(rss []*apps.ReplicaSet, d *apps.Deployment) (*apps.ReplicaSet, *apps.ReplicaSet)

FindCanaryAndStableReplicaSet find the canary and stable replicaset for the deployment - canary replicaset: the template equals to deployment's; - stable replicaset: an active replicaset(replicas>0) with the smallest revision.

func GetDeploymentExtraStatus added in v0.3.0

func GetDeploymentExtraStatus(deployment *apps.Deployment) v1alpha1.DeploymentExtraStatus

GetDeploymentExtraStatus decode the extra-status object for advanced deployment from the annotation rollouts.kruise.io/deployment-extra-status

func GetDeploymentStrategy added in v0.3.0

func GetDeploymentStrategy(deployment *apps.Deployment) v1alpha1.DeploymentStrategy

GetDeploymentStrategy decode the strategy object for advanced deployment from the annotation rollouts.kruise.io/deployment-strategy

func GetEmptyObjectWithKey added in v0.3.0

func GetEmptyObjectWithKey(object client.Object) client.Object

GetEmptyObjectWithKey return an empty object with the same namespaced name

func GetEmptyWorkloadObject added in v0.2.0

func GetEmptyWorkloadObject(gvk schema.GroupVersionKind) client.Object

GetEmptyWorkloadObject return specific object based on the given gvk

func GetGVKFrom added in v0.2.0

func GetGVKFrom(workloadRef *rolloutv1beta1.ObjectRef) schema.GroupVersionKind

func GetLuaConfigurationContent added in v0.3.0

func GetLuaConfigurationContent(key string) string

func GetMetadata added in v0.3.0

func GetMetadata(object client.Object) *metav1.ObjectMeta

GetMetadata can parse the whole metadata field from client workload object

func GetOwnerWorkload added in v0.2.0

func GetOwnerWorkload(r client.Reader, object client.Object) (client.Object, error)

GetOwnerWorkload return the top-level workload that is controlled by rollout, if the object has no owner, just return nil

func GetPodCondition added in v0.2.0

func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)

GetPodCondition extracts the provided condition from the given status and returns that. Returns nil and -1 if the condition is not present, and the index of the located condition.

func GetPodConditionFromList added in v0.2.0

func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodConditionType) (int, *v1.PodCondition)

GetPodConditionFromList extracts the provided condition from the given list of condition and returns the index of the condition and the condition. Returns -1 and nil if the condition is not present.

func GetPodReadyCondition added in v0.2.0

func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition

GetPodReadyCondition extracts the pod ready condition from the given status and returns that. Returns nil if the condition is not present.

func GetReplicas added in v0.3.0

func GetReplicas(object client.Object) int32

GetReplicas return replicas from client workload object

func GetRolloutCondition

func GetRolloutCondition(status v1beta1.RolloutStatus, condType v1beta1.RolloutConditionType) *v1beta1.RolloutCondition

GetRolloutCondition returns the condition with the provided type.

func GetRolloutNamespace added in v0.3.0

func GetRolloutNamespace() string

func GetStatefulSetPartition added in v0.2.0

func GetStatefulSetPartition(object client.Object) int32

GetStatefulSetPartition get partition of object

func GetTemplate added in v0.3.0

func GetTemplate(object client.Object) *corev1.PodTemplateSpec

GetTemplate return pod template spec for client workload object

func GetTypeMeta added in v0.4.0

func GetTypeMeta(object client.Object) *metav1.TypeMeta

GetTypeMeta can parse the whole TypeMeta field from client workload object

func HashReleasePlanBatches

func HashReleasePlanBatches(releasePlan *rolloutv1beta1.ReleasePlan) string

func IsCompletedPod added in v0.2.0

func IsCompletedPod(pod *v1.Pod) bool

IsCompletedPod return true if pod is at Failed or Succeeded phase

func IsConsistentWithRevision added in v0.2.0

func IsConsistentWithRevision(pod *v1.Pod, revision string) bool

IsConsistentWithRevision return true iff pod is match the revision

func IsEqualRevision added in v0.3.0

func IsEqualRevision(a, b *v1.Pod) bool

IsEqualRevision return true if a and b have equal revision label

func IsOwnedBy added in v0.2.0

func IsOwnedBy(r client.Reader, child, parent client.Object) (bool, error)

IsOwnedBy will return true if the child is owned by parent directly or indirectly.

func IsPodReady added in v0.2.0

func IsPodReady(pod *v1.Pod) bool

IsPodReady returns true if a pod is ready; false otherwise.

func IsPodReadyConditionTrue added in v0.2.0

func IsPodReadyConditionTrue(status v1.PodStatus) bool

IsPodReadyConditionTrue returns true if a pod is ready; false otherwise.

func IsRollbackInBatchPolicy added in v0.3.0

func IsRollbackInBatchPolicy(rollout *rolloutv1beta1.Rollout, labels map[string]string) bool

func IsStatefulSetRollingUpdate added in v0.2.0

func IsStatefulSetRollingUpdate(object client.Object) bool

IsStatefulSetRollingUpdate return true if updateStrategy of object is rollingUpdate type.

func IsStatefulSetUnorderedUpdate added in v0.3.0

func IsStatefulSetUnorderedUpdate(object client.Object) bool

IsStatefulSetUnorderedUpdate return true if the updateStrategy of object is unordered update

func IsSupportedWorkload added in v0.2.0

func IsSupportedWorkload(gvk schema.GroupVersionKind) bool

IsSupportedWorkload return true if the kind of workload can be processed by Rollout

func IsWorkloadType added in v0.2.0

func IsWorkloadType(object client.Object, t WorkloadType) bool

IsWorkloadType return true is object matches the workload type

func ListOwnedPods added in v0.2.0

func ListOwnedPods(c client.Client, workload client.Object) ([]*v1.Pod, error)

ListOwnedPods will list all pods belong to workload, including terminating pods

func NewRolloutCondition

func NewRolloutCondition(condType v1beta1.RolloutConditionType, status corev1.ConditionStatus, reason, message string) *v1beta1.RolloutCondition

NewRolloutCondition creates a new rollout condition.

func ProgressingRolloutFinalizer added in v0.4.0

func ProgressingRolloutFinalizer(name string) string

func RemoveRolloutCondition

func RemoveRolloutCondition(status *v1beta1.RolloutStatus, condType v1beta1.RolloutConditionType)

func SafeEncodeString

func SafeEncodeString(s string) string

SafeEncodeString encodes s using the same characters as rand.String. This reduces the chances of bad words and ensures that strings generated from hash functions appear consistent throughout the API.

func SetRolloutCondition

func SetRolloutCondition(status *v1beta1.RolloutStatus, condition v1beta1.RolloutCondition) bool

SetRolloutCondition updates the rollout to include the provided condition. If the condition that we are about to add already exists and has the same status and reason, then we are not going to update by returning false. Returns true if the condition was updated

func SetStatefulSetPartition added in v0.2.0

func SetStatefulSetPartition(object client.Object, partition int32)

SetStatefulSetPartition set partition to object

func UpdateFinalizer

func UpdateFinalizer(c client.Client, object client.Object, op FinalizerOpType, finalizer string) error

UpdateFinalizer add/remove a finalizer from a object

func WrappedPodCount added in v0.3.0

func WrappedPodCount(pods []*v1.Pod, filter func(pod *v1.Pod) bool) int

WrappedPodCount return the number of pods which satisfy the filter

Types

type ControllerFinder

type ControllerFinder struct {
	client.Client
}

func NewControllerFinder

func NewControllerFinder(c client.Client) *ControllerFinder

func (*ControllerFinder) GetReplicaSetsForDeployment

func (r *ControllerFinder) GetReplicaSetsForDeployment(obj *apps.Deployment) ([]*apps.ReplicaSet, error)

func (*ControllerFinder) GetWorkloadForRef

func (r *ControllerFinder) GetWorkloadForRef(rollout *rolloutv1beta1.Rollout) (*Workload, error)

type ControllerFinderFunc

type ControllerFinderFunc func(namespace string, ref *rolloutv1beta1.ObjectRef) (*Workload, error)

ControllerFinderFunc is a function type that maps a pod to a list of controllers and their scale.

type FinalizerOpType

type FinalizerOpType string

type RolloutState

type RolloutState struct {
	RolloutName string `json:"rolloutName"`
}

RolloutState is annotation[rollouts.kruise.io/in-progressing] value

type Workload

type Workload struct {
	metav1.TypeMeta
	metav1.ObjectMeta

	// replicas
	Replicas int32
	// stable revision
	StableRevision string
	// canary revision
	CanaryRevision string
	// pod template hash is used as service selector hash
	PodTemplateHash string
	// Revision hash key
	RevisionLabelKey string

	// Is it in rollback phase
	IsInRollback bool
	// indicate whether the workload can enter the rollout process
	// 1. workload.Spec.Paused = true
	// 2. the Deployment is not in a stable version (only one version of RS)
	InRolloutProgressing bool

	// whether the status consistent with the spec
	// workload.generation == status.observedGeneration
	IsStatusConsistent bool
}

Workload is used to return (controller, scale, selector) fields from the controller finder functions.

type WorkloadInfo added in v0.2.0

type WorkloadInfo struct {
	metav1.TypeMeta
	metav1.ObjectMeta
	LogKey   string
	Replicas int32
	Status   WorkloadStatus
}

func ParseWorkload added in v0.3.0

func ParseWorkload(object client.Object) *WorkloadInfo

ParseWorkload parse workload as WorkloadInfo

func (*WorkloadInfo) IsPromoted added in v0.3.0

func (w *WorkloadInfo) IsPromoted() bool

IsPromoted return true if replicas == updatedReplicas

func (*WorkloadInfo) IsRevisionNotEqual added in v0.3.0

func (w *WorkloadInfo) IsRevisionNotEqual(observed string) bool

IsRevisionNotEqual this function will return true if observed update revision != update revision.

func (*WorkloadInfo) IsRollback added in v0.3.0

func (w *WorkloadInfo) IsRollback(observedStable, observedUpdate string) bool

IsRollback return true if workload stable revision equals to update revision. this function is edge-triggerred.

func (*WorkloadInfo) IsScaling added in v0.3.0

func (w *WorkloadInfo) IsScaling(observed int32) bool

IsScaling return true if observed replicas != replicas

func (*WorkloadInfo) IsStable added in v0.3.0

func (w *WorkloadInfo) IsStable() bool

IsStable return ture if observed generation >= generation

type WorkloadStatus added in v0.2.0

type WorkloadStatus struct {
	Replicas             int32
	ReadyReplicas        int32
	UpdatedReplicas      int32
	UpdatedReadyReplicas int32
	AvailableReplicas    int32
	ObservedGeneration   int64
	UpdateRevision       string
	StableRevision       string
}

func ParseWorkloadStatus added in v0.2.0

func ParseWorkloadStatus(object client.Object) *WorkloadStatus

ParseWorkloadStatus parse status of object as WorkloadStatus

type WorkloadType added in v0.2.0

type WorkloadType string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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