-
Notifications
You must be signed in to change notification settings - Fork 130
Add control and data plane HPA #3492
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
Open
nowjean
wants to merge
13
commits into
nginx:main
Choose a base branch
from
nowjean:hpa
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
744fe00
Add control/data plane HPA
nowjean e351ae3
Fix Pipeline err
nowjean 59510a1
Update generated files
nowjean 853188a
Add Test case
nowjean 81f5d6a
Refactoring
nowjean f686a2d
Code Review
nowjean 1e1a296
Code Review & HPA event handler
nowjean 1ad0f63
Code Review & HPA event handler
nowjean be4952c
Code Review
nowjean 444740c
Resolve Conflict files & rebase & make generate-all
nowjean 29d48e3
Code Review
nowjean aff80d8
Code Review
nowjean ca0383c
Code Review
nowjean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package v1alpha2 | ||
|
||
import ( | ||
autoscalingv2 "k8s.io/api/autoscaling/v2" | ||
corev1 "k8s.io/api/core/v1" | ||
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
@@ -431,6 +432,11 @@ type DeploymentSpec struct { | |
// +optional | ||
Replicas *int32 `json:"replicas,omitempty"` | ||
|
||
// Autoscaling defines the configuration for Horizontal Pod Autoscaling. | ||
// | ||
// +optional | ||
Autoscaling HPASpec `json:"autoscaling"` | ||
|
||
// Pod defines Pod-specific fields. | ||
// | ||
// +optional | ||
|
@@ -460,6 +466,49 @@ type DaemonSetSpec struct { | |
Patches []Patch `json:"patches,omitempty"` | ||
} | ||
|
||
// +kubebuilder:validation:XValidation:message="at least one metric must be specified when autoscaling is enabled",rule="!self.enabled || (has(self.targetCPUUtilizationPercentage) || has(self.targetMemoryUtilizationPercentage) || (has(self.autoscalingTemplate) && size(self.autoscalingTemplate) > 0))" | ||
// +kubebuilder:validation:XValidation:message="minReplicas must be less than or equal to maxReplicas",rule="self.minReplicas <= self.maxReplicas" | ||
// +kubebuilder:validation:XValidation:message="CPU utilization must be between 1 and 100",rule="!has(self.targetCPUUtilizationPercentage) || (self.targetCPUUtilizationPercentage >= 1 && self.targetCPUUtilizationPercentage <= 100)" | ||
// +kubebuilder:validation:XValidation:message="memory utilization must be between 1 and 100",rule="!has(self.targetMemoryUtilizationPercentage) || (self.targetMemoryUtilizationPercentage >= 1 && self.targetMemoryUtilizationPercentage <= 100)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment |
||
// | ||
// HPASpec is the configuration for the Horizontal Pod Autoscaling. | ||
sjberman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
//nolint:lll | ||
type HPASpec struct { | ||
ciarams87 marked this conversation as resolved.
Show resolved
Hide resolved
sjberman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Behavior configures the scaling behavior of the target | ||
// in both Up and Down directions (scaleUp and scaleDown fields respectively). | ||
// If not set, the default HPAScalingRules for scale up and scale down are used. | ||
// | ||
// +optional | ||
Behavior *autoscalingv2.HorizontalPodAutoscalerBehavior `json:"behavior,omitempty"` | ||
|
||
// AutoscalingTemplate configures the additional scaling option. | ||
// | ||
// +optional | ||
AutoscalingTemplate *[]autoscalingv2.MetricSpec `json:"autoscalingTemplate,omitempty"` | ||
sjberman marked this conversation as resolved.
Show resolved
Hide resolved
sjberman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Target cpu utilization percentage of HPA. | ||
// | ||
// +optional | ||
TargetCPUUtilizationPercentage *int32 `json:"targetCPUUtilizationPercentage,omitempty"` | ||
|
||
// Target memory utilization percentage of HPA. | ||
// | ||
// +optional | ||
TargetMemoryUtilizationPercentage *int32 `json:"targetMemoryUtilizationPercentage,omitempty"` | ||
|
||
// Minimum number of replicas. | ||
// | ||
// +optional | ||
ciarams87 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
MinReplicas *int32 `json:"minReplicas,omitempty"` | ||
|
||
// Maximum number of replicas. | ||
MaxReplicas int32 `json:"maxReplicas"` | ||
|
||
// Enable or disable Horizontal Pod Autoscaler | ||
Enabled bool `json:"enabled"` | ||
} | ||
|
||
// PodSpec defines Pod-specific fields. | ||
type PodSpec struct { | ||
// TerminationGracePeriodSeconds is the optional duration in seconds the pod needs to terminate gracefully. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{{- if and (eq .Values.nginxGateway.kind "deployment") .Values.nginxGateway.autoscaling.enabled (.Capabilities.APIVersions.Has "autoscaling/v2") -}} | ||
apiVersion: autoscaling/v2 | ||
kind: HorizontalPodAutoscaler | ||
metadata: | ||
{{- with .Values.nginxGateway.autoscaling.annotations }} | ||
annotations: {{ toYaml . | nindent 4 }} | ||
{{- end }} | ||
labels: | ||
{{- include "nginx-gateway.labels" . | nindent 4 }} | ||
{{- with .Values.nginxGateway.labels }} | ||
{{- toYaml . | nindent 4 }} | ||
{{- end }} | ||
name: {{ include "nginx-gateway.fullname" . }} | ||
namespace: {{ .Release.Namespace }} | ||
spec: | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: {{ include "nginx-gateway.fullname" . }} | ||
minReplicas: {{ .Values.nginxGateway.autoscaling.minReplicas }} | ||
sjberman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
maxReplicas: {{ .Values.nginxGateway.autoscaling.maxReplicas }} | ||
metrics: | ||
{{- with .Values.nginxGateway.autoscaling.targetMemoryUtilizationPercentage }} | ||
- type: Resource | ||
resource: | ||
name: memory | ||
target: | ||
type: Utilization | ||
averageUtilization: {{ . }} | ||
{{- end }} | ||
{{- with .Values.nginxGateway.autoscaling.targetCPUUtilizationPercentage }} | ||
- type: Resource | ||
resource: | ||
name: cpu | ||
target: | ||
type: Utilization | ||
averageUtilization: {{ . }} | ||
{{- end }} | ||
{{- with .Values.autoscalingTemplate }} | ||
{{- toYaml . | nindent 2 }} | ||
{{- end }} | ||
{{- with .Values.nginxGateway.autoscaling.behavior }} | ||
behavior: | ||
{{- toYaml . | nindent 4 }} | ||
{{- end }} | ||
{{- end }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't need to use CEL validation. You can just set minimum and maximum directly on the field. See other int values as examples in here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still needs to be fixed (and the comment below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be specific, we just need to remove the validation for the values that specify max/min, and convert those to max/min kubebuilder tags. The other validation for "at least one metric" can stay.