util

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: Apache-2.0 Imports: 37 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// InRolloutProgressingAnnotation marks workload as entering the rollout progressing process
	//and does not allow paused=false during this process
	InRolloutProgressingAnnotation = "rollouts.kruise.io/in-progressing"
	// finalizer
	KruiseRolloutFinalizer = "rollouts.kruise.io/rollout"
	// rollout spec hash
	RolloutHashAnnotation = "rollouts.kruise.io/hash"
	// RolloutIDLabel is designed to distinguish each workload revision publications.
	// The value of RolloutIDLabel corresponds Rollout.Spec.RolloutID.
	RolloutIDLabel = "apps.kruise.io/rollout-id"
	// RolloutBatchIDLabel is the label key of batch id that will be patched to pods during rollout.
	// Only when RolloutIDLabel is set, RolloutBatchIDLabel will be patched.
	// Users can use RolloutIDLabel and RolloutBatchIDLabel to select the pods that are upgraded in some certain batch and release.
	RolloutBatchIDLabel = "apps.kruise.io/rollout-batch-id"
	WorkloadTypeLabel   = "rollouts.kruise.io/workload-type"
)
View Source
const (
	// BatchReleaseControlAnnotation is controller info about batchRelease when rollout
	BatchReleaseControlAnnotation = "batchrelease.rollouts.kruise.io/control-info"
	// 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"
)

Variables

View Source
var (
	ControllerKindRS           = apps.SchemeGroupVersion.WithKind("ReplicaSet")
	ControllerKindDep          = apps.SchemeGroupVersion.WithKind("Deployment")
	ControllerKindSts          = apps.SchemeGroupVersion.WithKind("StatefulSet")
	ControllerKruiseKindCS     = appsv1alpha1.SchemeGroupVersion.WithKind("CloneSet")
	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 CalculateNewBatchTarget

func CalculateNewBatchTarget(rolloutSpec *v1alpha1.ReleasePlan, workloadReplicas, currentBatch int) int

func ClaimWorkload added in v0.2.0

func ClaimWorkload(c client.Client, planController *v1alpha1.BatchRelease, object client.Object, patchUpdateStrategy map[string]interface{}) 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 DiscoverGVK

func DiscoverGVK(gvk schema.GroupVersionKind) bool

func DumpJSON

func DumpJSON(o interface{}) string

func EqualIgnoreHash

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

func FilterActiveDeployment

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

func FilterActivePods added in v0.2.0

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

func GenRandomStr

func GenRandomStr(length int) string

func GetEmptyWorkloadObject added in v0.2.0

func GetEmptyWorkloadObject(gvk schema.GroupVersionKind) client.Object

func GetGVKFrom added in v0.2.0

func GetGVKFrom(workloadRef *rolloutv1alpha1.WorkloadRef) schema.GroupVersionKind

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 GetRolloutCondition

GetRolloutCondition returns the condition with the provided type.

func GetStatefulSetMaxUnavailable added in v0.2.0

func GetStatefulSetMaxUnavailable(object *unstructured.Unstructured) *intstr.IntOrString

func GetStatefulSetPartition added in v0.2.0

func GetStatefulSetPartition(object *unstructured.Unstructured) int32

func HashReleasePlanBatches

func HashReleasePlanBatches(releasePlan *v1alpha1.ReleasePlan) string

func IsCompletedPod added in v0.2.0

func IsCompletedPod(pod *v1.Pod) bool

func IsConsistentWithRevision added in v0.2.0

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

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 IsStatefulSetRollingUpdate added in v0.2.0

func IsStatefulSetRollingUpdate(object *unstructured.Unstructured) bool

func IsSupportedWorkload added in v0.2.0

func IsSupportedWorkload(gvk schema.GroupVersionKind) bool

func IsWorkloadType added in v0.2.0

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

func ListOwnedPods added in v0.2.0

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

func NewRolloutCondition

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

NewRolloutCondition creates a new rollout condition.

func ParseReplicasFrom added in v0.2.0

func ParseReplicasFrom(object *unstructured.Unstructured) int32

ParseReplicasFrom parses replicas from unstructured workload object

func ParseStatusIntFrom added in v0.2.0

func ParseStatusIntFrom(object *unstructured.Unstructured, field string) int64

ParseStatusIntFrom can parse some fields with int type from unstructured workload object status

func ParseStatusStringFrom added in v0.2.0

func ParseStatusStringFrom(object *unstructured.Unstructured, field string) string

ParseStatusStringFrom can parse some fields with string type from unstructured workload object status

func ParseTemplateFrom added in v0.2.0

func ParseTemplateFrom(object *unstructured.Unstructured) *v1.PodTemplateSpec

ParseTemplateFrom parses template from unstructured workload object

func PatchPodBatchLabel added in v0.2.0

func PatchPodBatchLabel(c client.Client, pods []*v1.Pod, rolloutID string, batchID int32, updateRevision string, canaryGoal int32, logKey types.NamespacedName) (bool, error)

func PatchSpec added in v0.2.0

func PatchSpec(c client.Client, object client.Object, spec map[string]interface{}) error

func ReleaseWorkload added in v0.2.0

func ReleaseWorkload(c client.Client, object client.Object) error

func RemoveRolloutCondition

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

RemoveRolloutCondition removes the rollout condition with the provided type.

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 *rolloutv1alpha1.RolloutStatus, condition rolloutv1alpha1.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 *unstructured.Unstructured, partition int32)

func UpdateFinalizer

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

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(namespace string, ref *rolloutv1alpha1.WorkloadRef) (*Workload, error)

type ControllerFinderFunc

type ControllerFinderFunc func(namespace string, ref *rolloutv1alpha1.WorkloadRef) (*Workload, error)

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

type FinalizerOpType

type FinalizerOpType string
const (
	AddFinalizerOpType    FinalizerOpType = "Add"
	RemoveFinalizerOpType FinalizerOpType = "Remove"
)

type RolloutState

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

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

func GetRolloutState

func GetRolloutState(annotations map[string]string) (*RolloutState, error)

type Workload

type Workload struct {
	metav1.ObjectMeta

	// replicas
	Replicas int32
	// stable revision
	StableRevision string
	// canary revision
	CanaryRevision string
	// pod template hash is used as service selector hash
	PodTemplateHash string
	// canary replicas
	CanaryReplicas int32
	// canary ready replicas
	CanaryReadyReplicas int32
	// 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 {
	Paused         bool
	Replicas       *int32
	GVKWithName    string
	Selector       labels.Selector
	MaxUnavailable *intstr.IntOrString
	Metadata       *metav1.ObjectMeta
	Status         *WorkloadStatus
}

func NewWorkloadInfo added in v0.2.0

func NewWorkloadInfo() *WorkloadInfo

func ParseStatefulSetInfo added in v0.2.0

func ParseStatefulSetInfo(object *unstructured.Unstructured, namespacedName types.NamespacedName) *WorkloadInfo

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

type WorkloadType added in v0.2.0

type WorkloadType string
const (
	StatefulSetType WorkloadType = "statefulset"
	DeploymentType  WorkloadType = "deployment"
	CloneSetType    WorkloadType = "cloneset"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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