util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: Apache-2.0 Imports: 32 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"
)
View Source
const (
	CanaryDeploymentLabel         = "rollouts.kruise.io/canary-deployment"
	BatchReleaseControlAnnotation = "batchrelease.rollouts.kruise.io/control-info"
	StashCloneSetPartition        = "batchrelease.rollouts.kruise.io/stash-partition"
	CanaryDeploymentLabelKey      = "rollouts.kruise.io/canary-deployment"
	CanaryDeploymentFinalizer     = "finalizer.rollouts.kruise.io/batch-release"
)

Variables

View Source
var (
	ControllerKindDep      = apps.SchemeGroupVersion.WithKind("Deployment")
	ControllerKruiseKindCS = appsv1alpha1.SchemeGroupVersion.WithKind("CloneSet")
)
View Source
var (
	CloneSetGVK = appsv1alpha1.SchemeGroupVersion.WithKind("CloneSet")
)

Functions

func CalculateNewBatchTarget

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

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 GenRandomStr

func GenRandomStr(length int) string

func GetRolloutCondition

GetRolloutCondition returns the condition with the provided type.

func HashReleasePlanBatches

func HashReleasePlanBatches(releasePlan *v1alpha1.ReleasePlan) string

func IsControlledBy

func IsControlledBy(object, owner metav1.Object) bool

func NewRegistry

func NewRegistry(c *rest.Config) error

NewRegistry creates clientset by client-go

func NewRolloutCondition

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

NewRolloutCondition creates a new rollout condition.

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 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 GenericClientset

type GenericClientset struct {
	DiscoveryClient discovery.DiscoveryInterface
	KubeClient      kubeclientset.Interface
	KruiseClient    kruiseclientset.Interface
}

GenericClientset defines a generic client

func GetGenericClient

func GetGenericClient() *GenericClientset

GetGenericClient returns default clientset

type RolloutState

type RolloutState struct {
	RolloutName string
}

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.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
	// canary replicas
	CanaryReplicas int32
	// canary ready replicas
	CanaryReadyReplicas int32

	// 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.

Jump to

Keyboard shortcuts

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