From cf241c055f6de48be7964f87a21f2873ca3dbc63 Mon Sep 17 00:00:00 2001 From: etamarw Date: Wed, 6 Oct 2021 18:39:09 +0300 Subject: [PATCH 01/12] add rolloutStrategy to the scaledjob controller Signed-off-by: etamarw --- controllers/keda/scaledjob_controller.go | 45 +++++++++++++----------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/controllers/keda/scaledjob_controller.go b/controllers/keda/scaledjob_controller.go index 37b546fd7a9..eaa631db501 100644 --- a/controllers/keda/scaledjob_controller.go +++ b/controllers/keda/scaledjob_controller.go @@ -155,30 +155,35 @@ func (r *ScaledJobReconciler) reconcileScaledJob(logger logr.Logger, scaledJob * return "ScaledJob is defined correctly and is ready to scaling", nil } -// Delete Jobs owned by the previous version of the scaledJob +// Delete Jobs owned by the previous version of the scaledJob based on the rolloutStartegy func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) (string, error) { - opts := []client.ListOption{ - client.InNamespace(scaledJob.GetNamespace()), - client.MatchingLabels(map[string]string{"scaledjob.keda.sh/name": scaledJob.GetName()}), - } - jobs := &batchv1.JobList{} - err := r.Client.List(context.TODO(), jobs, opts...) - if err != nil { - return "Cannot get list of Jobs owned by this scaledJob", err - } - - if jobs.Size() > 0 { - logger.Info("Deleting jobs owned by the previous version of the scaledJob", "Number of jobs to delete", jobs.Size()) - } - for _, job := range jobs.Items { - job := job - err = r.Client.Delete(context.TODO(), &job, client.PropagationPolicy(metav1.DeletePropagationBackground)) + switch scaledJob.Spec.RolloutStrategy { + default: + opts := []client.ListOption { + client.InNamespace(scaledJob.GetNamespace()), + client.MatchingLabels(map[string]string{"scaledjob.keda.sh/name": scaledJob.GetName()}), + } + jobs := &batchv1.JobList{} + err := r.Client.List(context.TODO(), jobs, opts...) if err != nil { - return "Not able to delete job: " + job.Name, err + return "Cannot get list of Jobs owned by this scaledJob", err } - } - return fmt.Sprintf("Deleted jobs owned by the previous version of the scaleJob: %d jobs deleted", jobs.Size()), nil + if len(jobs.Items) > 0 { + logger.Info("RolloutStrategy: immediate, Deleting jobs owned by the previous version of the scaledJob", "Number of jobs to delete", len(jobs.Items)) + } + for _, job := range jobs.Items { + job := job + err = r.Client.Delete(context.TODO(), &job, client.PropagationPolicy(metav1.DeletePropagationBackground)) + if err != nil { + return "Not able to delete job: " + job.Name, err + } + } + return fmt.Sprintf("RolloutStrategy: immediate, deleted jobs owned by the previous version of the scaleJob: %d jobs deleted", len(jobs.Items)), nil + case "gradual": + logger.Info("RolloutStrategy: gradual, Not deleteing jobs owned by the previous version of the scaleJob") + } + return fmt.Sprintf("RolloutStrategy: %s", scaledJob.Spec.RolloutStrategy), nil } // requestScaleLoop request ScaleLoop handler for the respective ScaledJob From 4d077e289639aed46450da72622330c37d477994 Mon Sep 17 00:00:00 2001 From: etamarw Date: Wed, 6 Oct 2021 18:40:59 +0300 Subject: [PATCH 02/12] add rolloutStrategy to the scaledjob types Signed-off-by: etamarw --- apis/keda/v1alpha1/scaledjob_types.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apis/keda/v1alpha1/scaledjob_types.go b/apis/keda/v1alpha1/scaledjob_types.go index 946cfe9a248..df867eb2e04 100644 --- a/apis/keda/v1alpha1/scaledjob_types.go +++ b/apis/keda/v1alpha1/scaledjob_types.go @@ -51,6 +51,8 @@ type ScaledJobSpec struct { // +optional FailedJobsHistoryLimit *int32 `json:"failedJobsHistoryLimit,omitempty"` // +optional + RolloutStrategy string `json:"rolloutStrategy,omitempty"` + // +optional EnvSourceContainerName string `json:"envSourceContainerName,omitempty"` // +optional MaxReplicaCount *int32 `json:"maxReplicaCount,omitempty"` From f636f7ca78f769e0941837babc35c2b27c6f922f Mon Sep 17 00:00:00 2001 From: etamarw Date: Mon, 11 Oct 2021 18:43:39 +0300 Subject: [PATCH 03/12] add generated crds and deepcopy obj Signed-off-by: etamarw --- adapter/generated/openapi/zz_generated.openapi.go | 5 ++--- apis/keda/v1alpha1/zz_generated.deepcopy.go | 1 - config/crd/bases/keda.sh_clustertriggerauthentications.yaml | 4 +++- config/crd/bases/keda.sh_scaledjobs.yaml | 4 +++- config/crd/bases/keda.sh_scaledobjects.yaml | 2 +- config/crd/bases/keda.sh_triggerauthentications.yaml | 4 +++- controllers/keda/scaledjob_controller.go | 2 +- go.mod | 2 +- 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/adapter/generated/openapi/zz_generated.openapi.go b/adapter/generated/openapi/zz_generated.openapi.go index 4535e7cf4b4..fd629cb2226 100644 --- a/adapter/generated/openapi/zz_generated.openapi.go +++ b/adapter/generated/openapi/zz_generated.openapi.go @@ -1,4 +1,3 @@ -//go:build !autogenerated // +build !autogenerated /* @@ -14784,7 +14783,7 @@ func schema_pkg_apis_metrics_v1beta1_NodeMetrics(ref common.ReferenceCallback) c }, "window": { SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, + Default: 0, Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Duration"), }, }, @@ -14899,7 +14898,7 @@ func schema_pkg_apis_metrics_v1beta1_PodMetrics(ref common.ReferenceCallback) co }, "window": { SchemaProps: spec.SchemaProps{ - Default: map[string]interface{}{}, + Default: 0, Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.Duration"), }, }, diff --git a/apis/keda/v1alpha1/zz_generated.deepcopy.go b/apis/keda/v1alpha1/zz_generated.deepcopy.go index d6e286bf9e8..53d00a01491 100644 --- a/apis/keda/v1alpha1/zz_generated.deepcopy.go +++ b/apis/keda/v1alpha1/zz_generated.deepcopy.go @@ -1,4 +1,3 @@ -//go:build !ignore_autogenerated // +build !ignore_autogenerated /* diff --git a/config/crd/bases/keda.sh_clustertriggerauthentications.yaml b/config/crd/bases/keda.sh_clustertriggerauthentications.yaml index a33408d758d..c871e853d2c 100644 --- a/config/crd/bases/keda.sh_clustertriggerauthentications.yaml +++ b/config/crd/bases/keda.sh_clustertriggerauthentications.yaml @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.1 + controller-gen.kubebuilder.io/version: v0.6.1 creationTimestamp: null name: clustertriggerauthentications.keda.sh spec: @@ -90,6 +90,8 @@ spec: type: object mount: type: string + namespace: + type: string role: type: string secrets: diff --git a/config/crd/bases/keda.sh_scaledjobs.yaml b/config/crd/bases/keda.sh_scaledjobs.yaml index 511680bc103..19edd6ca0d6 100644 --- a/config/crd/bases/keda.sh_scaledjobs.yaml +++ b/config/crd/bases/keda.sh_scaledjobs.yaml @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.1 + controller-gen.kubebuilder.io/version: v0.6.1 creationTimestamp: null name: scaledjobs.keda.sh spec: @@ -7354,6 +7354,8 @@ spec: pollingInterval: format: int32 type: integer + rolloutStrategy: + type: string scalingStrategy: description: ScalingStrategy defines the strategy of Scaling properties: diff --git a/config/crd/bases/keda.sh_scaledobjects.yaml b/config/crd/bases/keda.sh_scaledobjects.yaml index 0781a3e86d0..1ff6f64fd0c 100644 --- a/config/crd/bases/keda.sh_scaledobjects.yaml +++ b/config/crd/bases/keda.sh_scaledobjects.yaml @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.1 + controller-gen.kubebuilder.io/version: v0.6.1 creationTimestamp: null name: scaledobjects.keda.sh spec: diff --git a/config/crd/bases/keda.sh_triggerauthentications.yaml b/config/crd/bases/keda.sh_triggerauthentications.yaml index 4f4b4226470..eccd7862528 100644 --- a/config/crd/bases/keda.sh_triggerauthentications.yaml +++ b/config/crd/bases/keda.sh_triggerauthentications.yaml @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.4.1 + controller-gen.kubebuilder.io/version: v0.6.1 creationTimestamp: null name: triggerauthentications.keda.sh spec: @@ -89,6 +89,8 @@ spec: type: object mount: type: string + namespace: + type: string role: type: string secrets: diff --git a/controllers/keda/scaledjob_controller.go b/controllers/keda/scaledjob_controller.go index eaa631db501..bff286966e1 100644 --- a/controllers/keda/scaledjob_controller.go +++ b/controllers/keda/scaledjob_controller.go @@ -159,7 +159,7 @@ func (r *ScaledJobReconciler) reconcileScaledJob(logger logr.Logger, scaledJob * func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) (string, error) { switch scaledJob.Spec.RolloutStrategy { default: - opts := []client.ListOption { + opts := []client.ListOption{ client.InNamespace(scaledJob.GetNamespace()), client.MatchingLabels(map[string]string{"scaledjob.keda.sh/name": scaledJob.GetName()}), } diff --git a/go.mod b/go.mod index 8d7e63ca0c7..ae1f7fdea08 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( google.golang.org/api v0.56.0 google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 google.golang.org/grpc v1.40.0 - google.golang.org/protobuf v1.27.1 // indirect + google.golang.org/protobuf v1.27.1 k8s.io/api v0.22.1 k8s.io/apimachinery v0.22.1 k8s.io/apiserver v0.22.1 From 156df975c0ab00beaba98f56b9283e3b5f164113 Mon Sep 17 00:00:00 2001 From: etamarw Date: Mon, 11 Oct 2021 18:55:50 +0300 Subject: [PATCH 04/12] fix typo deleteing -> deleting Signed-off-by: etamarw --- controllers/keda/scaledjob_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/keda/scaledjob_controller.go b/controllers/keda/scaledjob_controller.go index bff286966e1..504d42ea8d8 100644 --- a/controllers/keda/scaledjob_controller.go +++ b/controllers/keda/scaledjob_controller.go @@ -181,7 +181,7 @@ func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(logger logr.Logger, } return fmt.Sprintf("RolloutStrategy: immediate, deleted jobs owned by the previous version of the scaleJob: %d jobs deleted", len(jobs.Items)), nil case "gradual": - logger.Info("RolloutStrategy: gradual, Not deleteing jobs owned by the previous version of the scaleJob") + logger.Info("RolloutStrategy: gradual, Not deleting jobs owned by the previous version of the scaleJob") } return fmt.Sprintf("RolloutStrategy: %s", scaledJob.Spec.RolloutStrategy), nil } From 15685dd8dacaaadab38c7418d580e1e83a1ae83f Mon Sep 17 00:00:00 2001 From: etamarw <54352064+etamarw@users.noreply.github.com> Date: Wed, 20 Oct 2021 18:57:29 +0300 Subject: [PATCH 05/12] set logger message according to best practices Co-authored-by: Aaron Schlesinger <70865+arschles@users.noreply.github.com> Signed-off-by: etamarw --- controllers/keda/scaledjob_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/keda/scaledjob_controller.go b/controllers/keda/scaledjob_controller.go index 504d42ea8d8..7515c239856 100644 --- a/controllers/keda/scaledjob_controller.go +++ b/controllers/keda/scaledjob_controller.go @@ -170,7 +170,7 @@ func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(logger logr.Logger, } if len(jobs.Items) > 0 { - logger.Info("RolloutStrategy: immediate, Deleting jobs owned by the previous version of the scaledJob", "Number of jobs to delete", len(jobs.Items)) + logger.Info("RolloutStrategy: immediate, Deleting jobs owned by the previous version of the scaledJob", "numJobsToDelete", len(jobs.Items)) } for _, job := range jobs.Items { job := job From cc1c9dfd78a3022f7d50fd142a5a4aa50b0cb2ec Mon Sep 17 00:00:00 2001 From: etamarw <54352064+etamarw@users.noreply.github.com> Date: Wed, 20 Oct 2021 18:57:38 +0300 Subject: [PATCH 06/12] set logger messages according to best practices Co-authored-by: Aaron Schlesinger <70865+arschles@users.noreply.github.com> Signed-off-by: etamarw --- controllers/keda/scaledjob_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/keda/scaledjob_controller.go b/controllers/keda/scaledjob_controller.go index 7515c239856..93b3eeb40f4 100644 --- a/controllers/keda/scaledjob_controller.go +++ b/controllers/keda/scaledjob_controller.go @@ -155,7 +155,7 @@ func (r *ScaledJobReconciler) reconcileScaledJob(logger logr.Logger, scaledJob * return "ScaledJob is defined correctly and is ready to scaling", nil } -// Delete Jobs owned by the previous version of the scaledJob based on the rolloutStartegy +// Delete Jobs owned by the previous version of the scaledJob based on the rolloutStrategy given for this scaledJob, if any func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) (string, error) { switch scaledJob.Spec.RolloutStrategy { default: From cb2d68e967b5534fd4c44c23b8ceb47406d3f02c Mon Sep 17 00:00:00 2001 From: etamarw Date: Wed, 20 Oct 2021 19:03:39 +0300 Subject: [PATCH 07/12] remove redundant files Signed-off-by: etamarw --- ...keda.sh_clustertriggerauthentications.yaml | 158 -------- config/crd/bases/keda.sh_scaledobjects.yaml | 371 ------------------ 2 files changed, 529 deletions(-) delete mode 100644 config/crd/bases/keda.sh_clustertriggerauthentications.yaml delete mode 100644 config/crd/bases/keda.sh_scaledobjects.yaml diff --git a/config/crd/bases/keda.sh_clustertriggerauthentications.yaml b/config/crd/bases/keda.sh_clustertriggerauthentications.yaml deleted file mode 100644 index c871e853d2c..00000000000 --- a/config/crd/bases/keda.sh_clustertriggerauthentications.yaml +++ /dev/null @@ -1,158 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.6.1 - creationTimestamp: null - name: clustertriggerauthentications.keda.sh -spec: - group: keda.sh - names: - kind: ClusterTriggerAuthentication - listKind: ClusterTriggerAuthenticationList - plural: clustertriggerauthentications - shortNames: - - cta - - clustertriggerauth - singular: clustertriggerauthentication - scope: Cluster - versions: - - additionalPrinterColumns: - - jsonPath: .spec.podIdentity.provider - name: PodIdentity - type: string - - jsonPath: .spec.secretTargetRef[*].name - name: Secret - type: string - - jsonPath: .spec.env[*].name - name: Env - type: string - - jsonPath: .spec.hashiCorpVault.address - name: VaultAddress - type: string - name: v1alpha1 - schema: - openAPIV3Schema: - description: ClusterTriggerAuthentication defines how a trigger can authenticate - globally - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: TriggerAuthenticationSpec defines the various ways to authenticate - properties: - env: - items: - description: AuthEnvironment is used to authenticate using environment - variables in the destination ScaleTarget spec - properties: - containerName: - type: string - name: - type: string - parameter: - type: string - required: - - name - - parameter - type: object - type: array - hashiCorpVault: - description: HashiCorpVault is used to authenticate using Hashicorp - Vault - properties: - address: - type: string - authentication: - description: VaultAuthentication contains the list of Hashicorp - Vault authentication methods - type: string - credential: - description: Credential defines the Hashicorp Vault credentials - depending on the authentication method - properties: - serviceAccount: - type: string - token: - type: string - type: object - mount: - type: string - namespace: - type: string - role: - type: string - secrets: - items: - description: VaultSecret defines the mapping between the path - of the secret in Vault to the parameter - properties: - key: - type: string - parameter: - type: string - path: - type: string - required: - - key - - parameter - - path - type: object - type: array - required: - - address - - authentication - - secrets - type: object - podIdentity: - description: AuthPodIdentity allows users to select the platform native - identity mechanism - properties: - provider: - description: PodIdentityProvider contains the list of providers - type: string - required: - - provider - type: object - secretTargetRef: - items: - description: AuthSecretTargetRef is used to authenticate using a - reference to a secret - properties: - key: - type: string - name: - type: string - parameter: - type: string - required: - - key - - name - - parameter - type: object - type: array - type: object - required: - - spec - type: object - served: true - storage: true - subresources: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] diff --git a/config/crd/bases/keda.sh_scaledobjects.yaml b/config/crd/bases/keda.sh_scaledobjects.yaml deleted file mode 100644 index 1ff6f64fd0c..00000000000 --- a/config/crd/bases/keda.sh_scaledobjects.yaml +++ /dev/null @@ -1,371 +0,0 @@ - ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.6.1 - creationTimestamp: null - name: scaledobjects.keda.sh -spec: - group: keda.sh - names: - kind: ScaledObject - listKind: ScaledObjectList - plural: scaledobjects - shortNames: - - so - singular: scaledobject - scope: Namespaced - versions: - - additionalPrinterColumns: - - jsonPath: .status.scaleTargetKind - name: ScaleTargetKind - type: string - - jsonPath: .spec.scaleTargetRef.name - name: ScaleTargetName - type: string - - jsonPath: .spec.minReplicaCount - name: Min - type: integer - - jsonPath: .spec.maxReplicaCount - name: Max - type: integer - - jsonPath: .spec.triggers[*].type - name: Triggers - type: string - - jsonPath: .spec.triggers[*].authenticationRef.name - name: Authentication - type: string - - jsonPath: .status.conditions[?(@.type=="Ready")].status - name: Ready - type: string - - jsonPath: .status.conditions[?(@.type=="Active")].status - name: Active - type: string - - jsonPath: .status.conditions[?(@.type=="Fallback")].status - name: Fallback - type: string - - jsonPath: .metadata.creationTimestamp - name: Age - type: date - name: v1alpha1 - schema: - openAPIV3Schema: - description: ScaledObject is a specification for a ScaledObject resource - properties: - apiVersion: - description: 'APIVersion defines the versioned schema of this representation - of an object. Servers should convert recognized schemas to the latest - internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' - type: string - kind: - description: 'Kind is a string value representing the REST resource this - object represents. Servers may infer this from the endpoint the client - submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' - type: string - metadata: - type: object - spec: - description: ScaledObjectSpec is the spec for a ScaledObject resource - properties: - advanced: - description: AdvancedConfig specifies advance scaling options - properties: - horizontalPodAutoscalerConfig: - description: HorizontalPodAutoscalerConfig specifies horizontal - scale config - properties: - behavior: - description: HorizontalPodAutoscalerBehavior configures the - scaling behavior of the target in both Up and Down directions - (scaleUp and scaleDown fields respectively). - properties: - scaleDown: - description: scaleDown is scaling policy for scaling Down. - If not set, the default value is to allow to scale down - to minReplicas pods, with a 300 second stabilization - window (i.e., the highest recommendation for the last - 300sec is used). - properties: - policies: - description: policies is a list of potential scaling - polices which can be used during scaling. At least - one policy must be specified, otherwise the HPAScalingRules - will be discarded as invalid - items: - description: HPAScalingPolicy is a single policy - which must hold true for a specified past interval. - properties: - periodSeconds: - description: PeriodSeconds specifies the window - of time for which the policy should hold true. - PeriodSeconds must be greater than zero and - less than or equal to 1800 (30 min). - format: int32 - type: integer - type: - description: Type is used to specify the scaling - policy. - type: string - value: - description: Value contains the amount of change - which is permitted by the policy. It must - be greater than zero - format: int32 - type: integer - required: - - periodSeconds - - type - - value - type: object - type: array - selectPolicy: - description: selectPolicy is used to specify which - policy should be used. If not set, the default value - MaxPolicySelect is used. - type: string - stabilizationWindowSeconds: - description: 'StabilizationWindowSeconds is the number - of seconds for which past recommendations should - be considered while scaling up or scaling down. - StabilizationWindowSeconds must be greater than - or equal to zero and less than or equal to 3600 - (one hour). If not set, use the default values: - - For scale up: 0 (i.e. no stabilization is done). - - For scale down: 300 (i.e. the stabilization window - is 300 seconds long).' - format: int32 - type: integer - type: object - scaleUp: - description: 'scaleUp is scaling policy for scaling Up. - If not set, the default value is the higher of: * - increase no more than 4 pods per 60 seconds * double - the number of pods per 60 seconds No stabilization is - used.' - properties: - policies: - description: policies is a list of potential scaling - polices which can be used during scaling. At least - one policy must be specified, otherwise the HPAScalingRules - will be discarded as invalid - items: - description: HPAScalingPolicy is a single policy - which must hold true for a specified past interval. - properties: - periodSeconds: - description: PeriodSeconds specifies the window - of time for which the policy should hold true. - PeriodSeconds must be greater than zero and - less than or equal to 1800 (30 min). - format: int32 - type: integer - type: - description: Type is used to specify the scaling - policy. - type: string - value: - description: Value contains the amount of change - which is permitted by the policy. It must - be greater than zero - format: int32 - type: integer - required: - - periodSeconds - - type - - value - type: object - type: array - selectPolicy: - description: selectPolicy is used to specify which - policy should be used. If not set, the default value - MaxPolicySelect is used. - type: string - stabilizationWindowSeconds: - description: 'StabilizationWindowSeconds is the number - of seconds for which past recommendations should - be considered while scaling up or scaling down. - StabilizationWindowSeconds must be greater than - or equal to zero and less than or equal to 3600 - (one hour). If not set, use the default values: - - For scale up: 0 (i.e. no stabilization is done). - - For scale down: 300 (i.e. the stabilization window - is 300 seconds long).' - format: int32 - type: integer - type: object - type: object - type: object - restoreToOriginalReplicaCount: - type: boolean - type: object - cooldownPeriod: - format: int32 - type: integer - fallback: - description: Fallback is the spec for fallback options - properties: - failureThreshold: - format: int32 - type: integer - replicas: - format: int32 - type: integer - required: - - failureThreshold - - replicas - type: object - idleReplicaCount: - format: int32 - type: integer - maxReplicaCount: - format: int32 - type: integer - minReplicaCount: - format: int32 - type: integer - pollingInterval: - format: int32 - type: integer - scaleTargetRef: - description: ScaleTarget holds the a reference to the scale target - Object - properties: - apiVersion: - type: string - envSourceContainerName: - type: string - kind: - type: string - name: - type: string - required: - - name - type: object - triggers: - items: - description: ScaleTriggers reference the scaler that will be used - properties: - authenticationRef: - description: ScaledObjectAuthRef points to the TriggerAuthentication - or ClusterTriggerAuthentication object that is used to authenticate - the scaler with the environment - properties: - kind: - description: Kind of the resource being referred to. Defaults - to TriggerAuthentication. - type: string - name: - type: string - required: - - name - type: object - fallback: - format: int32 - type: integer - metadata: - additionalProperties: - type: string - type: object - name: - type: string - type: - type: string - required: - - metadata - - type - type: object - type: array - required: - - scaleTargetRef - - triggers - type: object - status: - description: ScaledObjectStatus is the status for a ScaledObject resource - properties: - conditions: - description: Conditions an array representation to store multiple - Conditions - items: - description: Condition to store the condition state - properties: - message: - description: A human readable message indicating details about - the transition. - type: string - reason: - description: The reason for the condition's last transition. - type: string - status: - description: Status of the condition, one of True, False, Unknown. - type: string - type: - description: Type of condition - type: string - required: - - status - - type - type: object - type: array - externalMetricNames: - items: - type: string - type: array - health: - additionalProperties: - description: HealthStatus is the status for a ScaledObject's health - properties: - numberOfFailures: - format: int32 - type: integer - status: - description: HealthStatusType is an indication of whether the - health status is happy or failing - type: string - type: object - type: object - lastActiveTime: - format: date-time - type: string - originalReplicaCount: - format: int32 - type: integer - resourceMetricNames: - items: - type: string - type: array - scaleTargetGVKR: - description: GroupVersionKindResource provides unified structure for - schema.GroupVersionKind and Resource - properties: - group: - type: string - kind: - type: string - resource: - type: string - version: - type: string - required: - - group - - kind - - resource - - version - type: object - scaleTargetKind: - type: string - type: object - required: - - spec - type: object - served: true - storage: true - subresources: - status: {} -status: - acceptedNames: - kind: "" - plural: "" - conditions: [] - storedVersions: [] From f10cfbc528f8d8e54cac0af81acd275372d63a8a Mon Sep 17 00:00:00 2001 From: etamarw Date: Wed, 20 Oct 2021 19:09:14 +0300 Subject: [PATCH 08/12] nit: set case before the default Signed-off-by: etamarw --- controllers/keda/scaledjob_controller.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controllers/keda/scaledjob_controller.go b/controllers/keda/scaledjob_controller.go index 93b3eeb40f4..a63bb9d4773 100644 --- a/controllers/keda/scaledjob_controller.go +++ b/controllers/keda/scaledjob_controller.go @@ -158,6 +158,8 @@ func (r *ScaledJobReconciler) reconcileScaledJob(logger logr.Logger, scaledJob * // Delete Jobs owned by the previous version of the scaledJob based on the rolloutStrategy given for this scaledJob, if any func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) (string, error) { switch scaledJob.Spec.RolloutStrategy { + case "gradual": + logger.Info("RolloutStrategy: gradual, Not deleting jobs owned by the previous version of the scaleJob") default: opts := []client.ListOption{ client.InNamespace(scaledJob.GetNamespace()), @@ -180,8 +182,6 @@ func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(logger logr.Logger, } } return fmt.Sprintf("RolloutStrategy: immediate, deleted jobs owned by the previous version of the scaleJob: %d jobs deleted", len(jobs.Items)), nil - case "gradual": - logger.Info("RolloutStrategy: gradual, Not deleting jobs owned by the previous version of the scaleJob") } return fmt.Sprintf("RolloutStrategy: %s", scaledJob.Spec.RolloutStrategy), nil } From ec1b43808fe76e761f5544c7f82acce800429e69 Mon Sep 17 00:00:00 2001 From: etamarw Date: Mon, 25 Oct 2021 18:43:11 +0300 Subject: [PATCH 09/12] restore relevant files Signed-off-by: etamarw --- ...keda.sh_clustertriggerauthentications.yaml | 156 ++++++++ config/crd/bases/keda.sh_scaledobjects.yaml | 371 ++++++++++++++++++ 2 files changed, 527 insertions(+) create mode 100644 config/crd/bases/keda.sh_clustertriggerauthentications.yaml create mode 100644 config/crd/bases/keda.sh_scaledobjects.yaml diff --git a/config/crd/bases/keda.sh_clustertriggerauthentications.yaml b/config/crd/bases/keda.sh_clustertriggerauthentications.yaml new file mode 100644 index 00000000000..a33408d758d --- /dev/null +++ b/config/crd/bases/keda.sh_clustertriggerauthentications.yaml @@ -0,0 +1,156 @@ + +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.4.1 + creationTimestamp: null + name: clustertriggerauthentications.keda.sh +spec: + group: keda.sh + names: + kind: ClusterTriggerAuthentication + listKind: ClusterTriggerAuthenticationList + plural: clustertriggerauthentications + shortNames: + - cta + - clustertriggerauth + singular: clustertriggerauthentication + scope: Cluster + versions: + - additionalPrinterColumns: + - jsonPath: .spec.podIdentity.provider + name: PodIdentity + type: string + - jsonPath: .spec.secretTargetRef[*].name + name: Secret + type: string + - jsonPath: .spec.env[*].name + name: Env + type: string + - jsonPath: .spec.hashiCorpVault.address + name: VaultAddress + type: string + name: v1alpha1 + schema: + openAPIV3Schema: + description: ClusterTriggerAuthentication defines how a trigger can authenticate + globally + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: TriggerAuthenticationSpec defines the various ways to authenticate + properties: + env: + items: + description: AuthEnvironment is used to authenticate using environment + variables in the destination ScaleTarget spec + properties: + containerName: + type: string + name: + type: string + parameter: + type: string + required: + - name + - parameter + type: object + type: array + hashiCorpVault: + description: HashiCorpVault is used to authenticate using Hashicorp + Vault + properties: + address: + type: string + authentication: + description: VaultAuthentication contains the list of Hashicorp + Vault authentication methods + type: string + credential: + description: Credential defines the Hashicorp Vault credentials + depending on the authentication method + properties: + serviceAccount: + type: string + token: + type: string + type: object + mount: + type: string + role: + type: string + secrets: + items: + description: VaultSecret defines the mapping between the path + of the secret in Vault to the parameter + properties: + key: + type: string + parameter: + type: string + path: + type: string + required: + - key + - parameter + - path + type: object + type: array + required: + - address + - authentication + - secrets + type: object + podIdentity: + description: AuthPodIdentity allows users to select the platform native + identity mechanism + properties: + provider: + description: PodIdentityProvider contains the list of providers + type: string + required: + - provider + type: object + secretTargetRef: + items: + description: AuthSecretTargetRef is used to authenticate using a + reference to a secret + properties: + key: + type: string + name: + type: string + parameter: + type: string + required: + - key + - name + - parameter + type: object + type: array + type: object + required: + - spec + type: object + served: true + storage: true + subresources: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] diff --git a/config/crd/bases/keda.sh_scaledobjects.yaml b/config/crd/bases/keda.sh_scaledobjects.yaml new file mode 100644 index 00000000000..0781a3e86d0 --- /dev/null +++ b/config/crd/bases/keda.sh_scaledobjects.yaml @@ -0,0 +1,371 @@ + +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.4.1 + creationTimestamp: null + name: scaledobjects.keda.sh +spec: + group: keda.sh + names: + kind: ScaledObject + listKind: ScaledObjectList + plural: scaledobjects + shortNames: + - so + singular: scaledobject + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .status.scaleTargetKind + name: ScaleTargetKind + type: string + - jsonPath: .spec.scaleTargetRef.name + name: ScaleTargetName + type: string + - jsonPath: .spec.minReplicaCount + name: Min + type: integer + - jsonPath: .spec.maxReplicaCount + name: Max + type: integer + - jsonPath: .spec.triggers[*].type + name: Triggers + type: string + - jsonPath: .spec.triggers[*].authenticationRef.name + name: Authentication + type: string + - jsonPath: .status.conditions[?(@.type=="Ready")].status + name: Ready + type: string + - jsonPath: .status.conditions[?(@.type=="Active")].status + name: Active + type: string + - jsonPath: .status.conditions[?(@.type=="Fallback")].status + name: Fallback + type: string + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1alpha1 + schema: + openAPIV3Schema: + description: ScaledObject is a specification for a ScaledObject resource + properties: + apiVersion: + description: 'APIVersion defines the versioned schema of this representation + of an object. Servers should convert recognized schemas to the latest + internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' + type: string + kind: + description: 'Kind is a string value representing the REST resource this + object represents. Servers may infer this from the endpoint the client + submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' + type: string + metadata: + type: object + spec: + description: ScaledObjectSpec is the spec for a ScaledObject resource + properties: + advanced: + description: AdvancedConfig specifies advance scaling options + properties: + horizontalPodAutoscalerConfig: + description: HorizontalPodAutoscalerConfig specifies horizontal + scale config + properties: + behavior: + description: HorizontalPodAutoscalerBehavior configures the + scaling behavior of the target in both Up and Down directions + (scaleUp and scaleDown fields respectively). + properties: + scaleDown: + description: scaleDown is scaling policy for scaling Down. + If not set, the default value is to allow to scale down + to minReplicas pods, with a 300 second stabilization + window (i.e., the highest recommendation for the last + 300sec is used). + properties: + policies: + description: policies is a list of potential scaling + polices which can be used during scaling. At least + one policy must be specified, otherwise the HPAScalingRules + will be discarded as invalid + items: + description: HPAScalingPolicy is a single policy + which must hold true for a specified past interval. + properties: + periodSeconds: + description: PeriodSeconds specifies the window + of time for which the policy should hold true. + PeriodSeconds must be greater than zero and + less than or equal to 1800 (30 min). + format: int32 + type: integer + type: + description: Type is used to specify the scaling + policy. + type: string + value: + description: Value contains the amount of change + which is permitted by the policy. It must + be greater than zero + format: int32 + type: integer + required: + - periodSeconds + - type + - value + type: object + type: array + selectPolicy: + description: selectPolicy is used to specify which + policy should be used. If not set, the default value + MaxPolicySelect is used. + type: string + stabilizationWindowSeconds: + description: 'StabilizationWindowSeconds is the number + of seconds for which past recommendations should + be considered while scaling up or scaling down. + StabilizationWindowSeconds must be greater than + or equal to zero and less than or equal to 3600 + (one hour). If not set, use the default values: + - For scale up: 0 (i.e. no stabilization is done). + - For scale down: 300 (i.e. the stabilization window + is 300 seconds long).' + format: int32 + type: integer + type: object + scaleUp: + description: 'scaleUp is scaling policy for scaling Up. + If not set, the default value is the higher of: * + increase no more than 4 pods per 60 seconds * double + the number of pods per 60 seconds No stabilization is + used.' + properties: + policies: + description: policies is a list of potential scaling + polices which can be used during scaling. At least + one policy must be specified, otherwise the HPAScalingRules + will be discarded as invalid + items: + description: HPAScalingPolicy is a single policy + which must hold true for a specified past interval. + properties: + periodSeconds: + description: PeriodSeconds specifies the window + of time for which the policy should hold true. + PeriodSeconds must be greater than zero and + less than or equal to 1800 (30 min). + format: int32 + type: integer + type: + description: Type is used to specify the scaling + policy. + type: string + value: + description: Value contains the amount of change + which is permitted by the policy. It must + be greater than zero + format: int32 + type: integer + required: + - periodSeconds + - type + - value + type: object + type: array + selectPolicy: + description: selectPolicy is used to specify which + policy should be used. If not set, the default value + MaxPolicySelect is used. + type: string + stabilizationWindowSeconds: + description: 'StabilizationWindowSeconds is the number + of seconds for which past recommendations should + be considered while scaling up or scaling down. + StabilizationWindowSeconds must be greater than + or equal to zero and less than or equal to 3600 + (one hour). If not set, use the default values: + - For scale up: 0 (i.e. no stabilization is done). + - For scale down: 300 (i.e. the stabilization window + is 300 seconds long).' + format: int32 + type: integer + type: object + type: object + type: object + restoreToOriginalReplicaCount: + type: boolean + type: object + cooldownPeriod: + format: int32 + type: integer + fallback: + description: Fallback is the spec for fallback options + properties: + failureThreshold: + format: int32 + type: integer + replicas: + format: int32 + type: integer + required: + - failureThreshold + - replicas + type: object + idleReplicaCount: + format: int32 + type: integer + maxReplicaCount: + format: int32 + type: integer + minReplicaCount: + format: int32 + type: integer + pollingInterval: + format: int32 + type: integer + scaleTargetRef: + description: ScaleTarget holds the a reference to the scale target + Object + properties: + apiVersion: + type: string + envSourceContainerName: + type: string + kind: + type: string + name: + type: string + required: + - name + type: object + triggers: + items: + description: ScaleTriggers reference the scaler that will be used + properties: + authenticationRef: + description: ScaledObjectAuthRef points to the TriggerAuthentication + or ClusterTriggerAuthentication object that is used to authenticate + the scaler with the environment + properties: + kind: + description: Kind of the resource being referred to. Defaults + to TriggerAuthentication. + type: string + name: + type: string + required: + - name + type: object + fallback: + format: int32 + type: integer + metadata: + additionalProperties: + type: string + type: object + name: + type: string + type: + type: string + required: + - metadata + - type + type: object + type: array + required: + - scaleTargetRef + - triggers + type: object + status: + description: ScaledObjectStatus is the status for a ScaledObject resource + properties: + conditions: + description: Conditions an array representation to store multiple + Conditions + items: + description: Condition to store the condition state + properties: + message: + description: A human readable message indicating details about + the transition. + type: string + reason: + description: The reason for the condition's last transition. + type: string + status: + description: Status of the condition, one of True, False, Unknown. + type: string + type: + description: Type of condition + type: string + required: + - status + - type + type: object + type: array + externalMetricNames: + items: + type: string + type: array + health: + additionalProperties: + description: HealthStatus is the status for a ScaledObject's health + properties: + numberOfFailures: + format: int32 + type: integer + status: + description: HealthStatusType is an indication of whether the + health status is happy or failing + type: string + type: object + type: object + lastActiveTime: + format: date-time + type: string + originalReplicaCount: + format: int32 + type: integer + resourceMetricNames: + items: + type: string + type: array + scaleTargetGVKR: + description: GroupVersionKindResource provides unified structure for + schema.GroupVersionKind and Resource + properties: + group: + type: string + kind: + type: string + resource: + type: string + version: + type: string + required: + - group + - kind + - resource + - version + type: object + scaleTargetKind: + type: string + type: object + required: + - spec + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: [] + storedVersions: [] From c973cf3f1a7d7d098e93b876b0a0b5bc87cbda5a Mon Sep 17 00:00:00 2001 From: etamarw Date: Mon, 25 Oct 2021 20:37:46 +0300 Subject: [PATCH 10/12] use ctx in favor of context.TODO() Signed-off-by: etamarw --- controllers/keda/scaledjob_controller.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/controllers/keda/scaledjob_controller.go b/controllers/keda/scaledjob_controller.go index a63bb9d4773..89c58ba2646 100644 --- a/controllers/keda/scaledjob_controller.go +++ b/controllers/keda/scaledjob_controller.go @@ -110,7 +110,7 @@ func (r *ScaledJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( reqLogger.Error(err, "scaledJob.spec.jobTargetRef not found") return ctrl.Result{}, err } - msg, err := r.reconcileScaledJob(reqLogger, scaledJob) + msg, err := r.reconcileScaledJob(ctx, reqLogger, scaledJob) conditions := scaledJob.Status.Conditions.DeepCopy() if err != nil { reqLogger.Error(err, msg) @@ -133,8 +133,8 @@ func (r *ScaledJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( } // reconcileScaledJob implements reconciler logic for K8s Jobs based ScaledJob -func (r *ScaledJobReconciler) reconcileScaledJob(logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) (string, error) { - msg, err := r.deletePreviousVersionScaleJobs(logger, scaledJob) +func (r *ScaledJobReconciler) reconcileScaledJob(ctx context.Context, logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) (string, error) { + msg, err := r.deletePreviousVersionScaleJobs(ctx, logger, scaledJob) if err != nil { return msg, err } @@ -156,7 +156,7 @@ func (r *ScaledJobReconciler) reconcileScaledJob(logger logr.Logger, scaledJob * } // Delete Jobs owned by the previous version of the scaledJob based on the rolloutStrategy given for this scaledJob, if any -func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) (string, error) { +func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(ctx context.Context, logger logr.Logger, scaledJob *kedav1alpha1.ScaledJob) (string, error) { switch scaledJob.Spec.RolloutStrategy { case "gradual": logger.Info("RolloutStrategy: gradual, Not deleting jobs owned by the previous version of the scaleJob") @@ -166,7 +166,7 @@ func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(logger logr.Logger, client.MatchingLabels(map[string]string{"scaledjob.keda.sh/name": scaledJob.GetName()}), } jobs := &batchv1.JobList{} - err := r.Client.List(context.TODO(), jobs, opts...) + err := r.Client.List(ctx, jobs, opts...) if err != nil { return "Cannot get list of Jobs owned by this scaledJob", err } @@ -176,7 +176,7 @@ func (r *ScaledJobReconciler) deletePreviousVersionScaleJobs(logger logr.Logger, } for _, job := range jobs.Items { job := job - err = r.Client.Delete(context.TODO(), &job, client.PropagationPolicy(metav1.DeletePropagationBackground)) + err = r.Client.Delete(ctx, &job, client.PropagationPolicy(metav1.DeletePropagationBackground)) if err != nil { return "Not able to delete job: " + job.Name, err } From 3490e77abe582d9f2e3b14d559e49032e9ba52de Mon Sep 17 00:00:00 2001 From: etamarw <54352064+etamarw@users.noreply.github.com> Date: Tue, 26 Oct 2021 17:42:16 +0300 Subject: [PATCH 11/12] add scaledjob rolloutStrategy to unreleased changelog Signed-off-by: etamarw --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce805db0347..ba90dbffbca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - TODO ([#XXX](https://github.com/kedacore/keda/pull/XXX)) - ScaledJob: introduce MultipleScalersCalculation ([#2016](https://github.com/kedacore/keda/pull/2016)) +- ScaledJob: introduce rolloutStrategy ([#2164](https://github.com/kedacore/keda/pull/2164)) - Add Graphite Scaler ([#1628](https://github.com/kedacore/keda/pull/2092)) ### Improvements From 57b5dc676c378d31284d807d09d2ccc0d7d6c52e Mon Sep 17 00:00:00 2001 From: etamarw <54352064+etamarw@users.noreply.github.com> Date: Sat, 30 Oct 2021 17:28:53 +0300 Subject: [PATCH 12/12] Update CHANGELOG.md Co-authored-by: Zbynek Roubalik <726523+zroubalik@users.noreply.github.com> Signed-off-by: etamarw --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d949a519d..21f6272db28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ ### New - ScaledJob: introduce MultipleScalersCalculation ([#2016](https://github.com/kedacore/keda/pull/2016)) -- ScaledJob: introduce rolloutStrategy ([#2164](https://github.com/kedacore/keda/pull/2164)) +- ScaledJob: introduce `RolloutStrategy` ([#2164](https://github.com/kedacore/keda/pull/2164)) - Add Graphite Scaler ([#1628](https://github.com/kedacore/keda/pull/2092)) - Add Cassandra Scaler ([#2211](https://github.com/kedacore/keda/pull/2211))