Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] Adding Standard Resource metrics to KEDA #874

Merged
merged 6 commits into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12,005 changes: 5,922 additions & 6,083 deletions deploy/crds/keda.sh_scaledjobs_crd.yaml

Large diffs are not rendered by default.

560 changes: 312 additions & 248 deletions deploy/crds/keda.sh_scaledobjects_crd.yaml

Large diffs are not rendered by default.

153 changes: 77 additions & 76 deletions deploy/crds/keda.sh_triggerauthentications_crd.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
apiVersion: apiextensions.k8s.io/v1
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: triggerauthentications.keda.sh
spec:
additionalPrinterColumns:
zroubalik marked this conversation as resolved.
Show resolved Hide resolved
- JSONPath: .spec.podIdentity.provider
name: PodIdentity
type: string
- JSONPath: .spec.secretTargetRef[*].name
name: Secret
type: string
- JSONPath: .spec.env[*].name
name: Env
type: string
group: keda.sh
names:
kind: TriggerAuthentication
Expand All @@ -13,84 +23,75 @@ spec:
- triggerauth
singular: triggerauthentication
scope: Namespaced
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
name: v1alpha1
schema:
openAPIV3Schema:
description: TriggerAuthentication defines how a trigger can authenticate
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
podIdentity:
description: AuthPodIdentity allows users to select the platform native
identity mechanism
subresources: {}
validation:
openAPIV3Schema:
description: TriggerAuthentication defines how a trigger can authenticate
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
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:
provider:
description: PodIdentityProvider contains the list of providers
key:
type: string
name:
type: string
parameter:
type: string
required:
- provider
- key
- name
- parameter
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
type: array
type: object
required:
- spec
type: object
version: v1alpha1
versions:
- name: v1alpha1
served: true
storage: true
subresources: {}
12 changes: 11 additions & 1 deletion pkg/apis/keda/v1alpha1/scaledobject_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,21 @@ type ScaledObjectSpec struct {
// +optional
MaxReplicaCount *int32 `json:"maxReplicaCount,omitempty"`
// +optional
Behavior *autoscalingv2beta2.HorizontalPodAutoscalerBehavior `json:"behavior,omitempty"`
Advanced *AdvancedConfig `json:"advanced,omitempty"`

Triggers []ScaleTriggers `json:"triggers"`
}

type AdvancedConfig struct {
HorizontalPodAutoscalerConfig *HorizontalPodAutoscalerConfig `json:"horizontalPodAutoscalerConfig,omitempty"`
}

type HorizontalPodAutoscalerConfig struct {
ResourceMetrics []*autoscalingv2beta2.ResourceMetricSource `json:"resourceMetrics,omitempty"`
// +optional
Behavior *autoscalingv2beta2.HorizontalPodAutoscalerBehavior `json:"behavior,omitempty"`
}

//ScaleTarget holds the a reference to the scale target Object
// +k8s:openapi-gen=true
type ScaleTarget struct {
Expand Down
59 changes: 56 additions & 3 deletions pkg/apis/keda/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions pkg/controller/scaledobject/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func (r *ReconcileScaledObject) newHPAForScaledObject(logger logr.Logger, scaled
}

var behavior *autoscalingv2beta2.HorizontalPodAutoscalerBehavior
if r.kubeVersion.MinorVersion >= 18 {
behavior = scaledObject.Spec.Behavior
if r.kubeVersion.MinorVersion >= 18 && scaledObject.Spec.Advanced != nil && scaledObject.Spec.Advanced.HorizontalPodAutoscalerConfig != nil {
behavior = scaledObject.Spec.Advanced.HorizontalPodAutoscalerConfig.Behavior
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Advanced and HorizontalPodAutoscalerConfig could be nil, right? should the condition be updated to && scaledObject.Spec.Advanced != nil && scaledObject.Spec.Advanced.HorizontalPodAutoscalerConfig != nil?

Also in other places

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid point. Have made the change

} else {
behavior = nil
}
Expand Down Expand Up @@ -128,6 +128,12 @@ func (r *ReconcileScaledObject) getScaledObjectMetricSpecs(logger logr.Logger, s
return nil, err
}

// Handling the Resource metrics through KEDA
if scaledObject.Spec.Advanced != nil && scaledObject.Spec.Advanced.HorizontalPodAutoscalerConfig != nil {
metrics := getResourceMetrics(scaledObject.Spec.Advanced.HorizontalPodAutoscalerConfig.ResourceMetrics)
scaledObjectMetricSpecs = append(scaledObjectMetricSpecs, metrics...)
}

for _, scaler := range scalers {
metricSpecs := scaler.GetMetricSpecForScaling()

Expand All @@ -153,10 +159,22 @@ func (r *ReconcileScaledObject) getScaledObjectMetricSpecs(logger logr.Logger, s
return scaledObjectMetricSpecs, nil
}

func getResourceMetrics(resourceMetrics []*autoscalingv2beta2.ResourceMetricSource) []autoscalingv2beta2.MetricSpec {
metrics := make ([]autoscalingv2beta2.MetricSpec, 0, len(resourceMetrics))
for _, resourceMetric := range resourceMetrics {
metrics = append(metrics, autoscalingv2beta2.MetricSpec{
Type: "Resource",
Resource: resourceMetric,
})
}

return metrics
}

// checkMinK8sVersionforHPABehavior min version (k8s v1.18) for HPA Behavior
func (r *ReconcileScaledObject) checkMinK8sVersionforHPABehavior(logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject) {
if r.kubeVersion.MinorVersion < 18 {
if scaledObject.Spec.Behavior != nil {
if scaledObject.Spec.Advanced != nil && scaledObject.Spec.Advanced.HorizontalPodAutoscalerConfig != nil && scaledObject.Spec.Advanced.HorizontalPodAutoscalerConfig.Behavior != nil {
logger.Info("Warning: Ignoring scaledObject.spec.behavior, it is only supported on kubernetes version >= 1.18", "kubernetes.version", r.kubeVersion.PrettyVersion)
}
}
Expand Down