diff --git a/README.md b/README.md index 7e7c95394..1c41e0261 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ spec: progressDeadlineSeconds: 60 # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/artifacts/examples/appmesh-abtest.yaml b/artifacts/examples/appmesh-abtest.yaml index 6fddb07ec..726fcab64 100644 --- a/artifacts/examples/appmesh-abtest.yaml +++ b/artifacts/examples/appmesh-abtest.yaml @@ -11,7 +11,7 @@ spec: kind: Deployment name: podinfo autoscalerRef: - apiVersion: autoscaling/v2beta1 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/artifacts/examples/appmesh-canary.yaml b/artifacts/examples/appmesh-canary.yaml index dcf40c437..16741963d 100644 --- a/artifacts/examples/appmesh-canary.yaml +++ b/artifacts/examples/appmesh-canary.yaml @@ -11,7 +11,7 @@ spec: kind: Deployment name: podinfo autoscalerRef: - apiVersion: autoscaling/v2beta1 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/artifacts/examples/istio-abtest.yaml b/artifacts/examples/istio-abtest.yaml index 1586eac2b..abf7c14d7 100644 --- a/artifacts/examples/istio-abtest.yaml +++ b/artifacts/examples/istio-abtest.yaml @@ -10,7 +10,7 @@ spec: kind: Deployment name: podinfo autoscalerRef: - apiVersion: autoscaling/v2beta1 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/artifacts/examples/istio-canary.yaml b/artifacts/examples/istio-canary.yaml index f8d417040..da5870a87 100644 --- a/artifacts/examples/istio-canary.yaml +++ b/artifacts/examples/istio-canary.yaml @@ -11,7 +11,7 @@ spec: kind: Deployment name: podinfo autoscalerRef: - apiVersion: autoscaling/v2beta1 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/artifacts/examples/linkerd-canary-steps.yaml b/artifacts/examples/linkerd-canary-steps.yaml index 1e1a09afa..9110271c1 100644 --- a/artifacts/examples/linkerd-canary-steps.yaml +++ b/artifacts/examples/linkerd-canary-steps.yaml @@ -11,7 +11,7 @@ spec: kind: Deployment name: podinfo autoscalerRef: - apiVersion: autoscaling/v2beta1 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/artifacts/examples/linkerd-canary.yaml b/artifacts/examples/linkerd-canary.yaml index 63884b9f1..7c85e7bc5 100644 --- a/artifacts/examples/linkerd-canary.yaml +++ b/artifacts/examples/linkerd-canary.yaml @@ -11,7 +11,7 @@ spec: kind: Deployment name: podinfo autoscalerRef: - apiVersion: autoscaling/v2beta1 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/charts/podinfo/templates/canary.yaml b/charts/podinfo/templates/canary.yaml index bb6441427..bb006154f 100644 --- a/charts/podinfo/templates/canary.yaml +++ b/charts/podinfo/templates/canary.yaml @@ -14,7 +14,7 @@ spec: kind: Deployment name: {{ template "podinfo.fullname" . }} autoscalerRef: - apiVersion: autoscaling/v2beta1 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: {{ template "podinfo.fullname" . }} service: @@ -57,4 +57,4 @@ spec: metadata: cmd: "hey -z 1m -q 5 -c 2 http://{{ template "podinfo.fullname" . }}.{{ .Release.Namespace }}:{{ .Values.service.port }}" {{- end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/charts/podinfo/templates/hpa.yaml b/charts/podinfo/templates/hpa.yaml index 8526f1622..224fb344c 100644 --- a/charts/podinfo/templates/hpa.yaml +++ b/charts/podinfo/templates/hpa.yaml @@ -1,5 +1,5 @@ {{- if .Values.hpa.enabled -}} -apiVersion: autoscaling/v2beta1 +apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: {{ template "podinfo.fullname" . }} diff --git a/docs/gitbook/tutorials/appmesh-progressive-delivery.md b/docs/gitbook/tutorials/appmesh-progressive-delivery.md index 1188a8b22..a7013d899 100644 --- a/docs/gitbook/tutorials/appmesh-progressive-delivery.md +++ b/docs/gitbook/tutorials/appmesh-progressive-delivery.md @@ -80,7 +80,7 @@ spec: progressDeadlineSeconds: 60 # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/docs/gitbook/tutorials/contour-progressive-delivery.md b/docs/gitbook/tutorials/contour-progressive-delivery.md index 29abec2d2..de7afad6c 100644 --- a/docs/gitbook/tutorials/contour-progressive-delivery.md +++ b/docs/gitbook/tutorials/contour-progressive-delivery.md @@ -76,7 +76,7 @@ spec: name: podinfo # HPA reference autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/docs/gitbook/tutorials/gatewayapi-progressive-delivery.md b/docs/gitbook/tutorials/gatewayapi-progressive-delivery.md index aa0cfa453..617f4a7e6 100644 --- a/docs/gitbook/tutorials/gatewayapi-progressive-delivery.md +++ b/docs/gitbook/tutorials/gatewayapi-progressive-delivery.md @@ -156,7 +156,7 @@ spec: progressDeadlineSeconds: 60 # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: @@ -406,7 +406,7 @@ spec: progressDeadlineSeconds: 60 # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: @@ -515,7 +515,7 @@ spec: progressDeadlineSeconds: 60 # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/docs/gitbook/tutorials/gloo-progressive-delivery.md b/docs/gitbook/tutorials/gloo-progressive-delivery.md index ccccb3319..fcc1f0627 100644 --- a/docs/gitbook/tutorials/gloo-progressive-delivery.md +++ b/docs/gitbook/tutorials/gloo-progressive-delivery.md @@ -110,7 +110,7 @@ spec: name: podinfo # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/docs/gitbook/tutorials/istio-ab-testing.md b/docs/gitbook/tutorials/istio-ab-testing.md index 2e1241b8e..d4b276fcb 100644 --- a/docs/gitbook/tutorials/istio-ab-testing.md +++ b/docs/gitbook/tutorials/istio-ab-testing.md @@ -84,7 +84,7 @@ spec: progressDeadlineSeconds: 60 # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/docs/gitbook/tutorials/istio-progressive-delivery.md b/docs/gitbook/tutorials/istio-progressive-delivery.md index 49aa55bc4..cefbf3fb3 100644 --- a/docs/gitbook/tutorials/istio-progressive-delivery.md +++ b/docs/gitbook/tutorials/istio-progressive-delivery.md @@ -85,7 +85,7 @@ spec: progressDeadlineSeconds: 60 # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: @@ -316,7 +316,7 @@ spec: progressDeadlineSeconds: 60 # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/docs/gitbook/tutorials/kubernetes-blue-green.md b/docs/gitbook/tutorials/kubernetes-blue-green.md index 9a3cf3d7c..ad8db524e 100644 --- a/docs/gitbook/tutorials/kubernetes-blue-green.md +++ b/docs/gitbook/tutorials/kubernetes-blue-green.md @@ -84,7 +84,7 @@ spec: progressDeadlineSeconds: 60 # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/docs/gitbook/tutorials/linkerd-progressive-delivery.md b/docs/gitbook/tutorials/linkerd-progressive-delivery.md index 69bfae57a..a3b11748b 100644 --- a/docs/gitbook/tutorials/linkerd-progressive-delivery.md +++ b/docs/gitbook/tutorials/linkerd-progressive-delivery.md @@ -98,7 +98,7 @@ spec: name: podinfo # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo # the maximum time in seconds for the canary deployment @@ -426,7 +426,7 @@ spec: kind: Deployment name: podinfo autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo service: diff --git a/docs/gitbook/tutorials/nginx-progressive-delivery.md b/docs/gitbook/tutorials/nginx-progressive-delivery.md index 384b15513..b61c5c8c2 100644 --- a/docs/gitbook/tutorials/nginx-progressive-delivery.md +++ b/docs/gitbook/tutorials/nginx-progressive-delivery.md @@ -110,7 +110,7 @@ spec: name: podinfo # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo # the maximum time in seconds for the canary deployment diff --git a/docs/gitbook/tutorials/osm-progressive-delivery.md b/docs/gitbook/tutorials/osm-progressive-delivery.md index 36292f207..9f1edbe1d 100644 --- a/docs/gitbook/tutorials/osm-progressive-delivery.md +++ b/docs/gitbook/tutorials/osm-progressive-delivery.md @@ -86,7 +86,7 @@ spec: name: podinfo # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo # the maximum time in seconds for the canary deployment diff --git a/docs/gitbook/tutorials/skipper-progressive-delivery.md b/docs/gitbook/tutorials/skipper-progressive-delivery.md index dc1a9c997..38380f098 100644 --- a/docs/gitbook/tutorials/skipper-progressive-delivery.md +++ b/docs/gitbook/tutorials/skipper-progressive-delivery.md @@ -113,7 +113,7 @@ spec: name: podinfo # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo # the maximum time in seconds for the canary deployment diff --git a/docs/gitbook/tutorials/traefik-progressive-delivery.md b/docs/gitbook/tutorials/traefik-progressive-delivery.md index 7a4be213b..410333a3c 100644 --- a/docs/gitbook/tutorials/traefik-progressive-delivery.md +++ b/docs/gitbook/tutorials/traefik-progressive-delivery.md @@ -103,7 +103,7 @@ spec: name: podinfo # HPA reference (optional) autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo # the maximum time in seconds for the canary deployment diff --git a/docs/gitbook/tutorials/zero-downtime-deployments.md b/docs/gitbook/tutorials/zero-downtime-deployments.md index 432ab38c3..f99b205a3 100644 --- a/docs/gitbook/tutorials/zero-downtime-deployments.md +++ b/docs/gitbook/tutorials/zero-downtime-deployments.md @@ -139,7 +139,7 @@ Note that without resource requests the horizontal pod autoscaler can't determin A production environment should be able to handle traffic bursts without impacting the quality of service. This can be achieved with Kubernetes autoscaling capabilities. Autoscaling in Kubernetes has two dimensions: the Cluster Autoscaler that deals with node scaling operations and the Horizontal Pod Autoscaler that automatically scales the number of pods in a deployment. ```yaml -apiVersion: autoscaling/v2beta2 +apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler spec: scaleTargetRef: diff --git a/docs/gitbook/usage/how-it-works.md b/docs/gitbook/usage/how-it-works.md index 2a586504b..e418cf881 100644 --- a/docs/gitbook/usage/how-it-works.md +++ b/docs/gitbook/usage/how-it-works.md @@ -65,7 +65,7 @@ spec: kind: Deployment name: podinfo autoscalerRef: - apiVersion: autoscaling/v2beta2 + apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler name: podinfo primaryScalerReplicas: diff --git a/pkg/canary/deployment_controller.go b/pkg/canary/deployment_controller.go index ad95426a9..3d605bad1 100644 --- a/pkg/canary/deployment_controller.go +++ b/pkg/canary/deployment_controller.go @@ -20,10 +20,8 @@ import ( "context" "fmt" - "github.com/google/go-cmp/cmp" "go.uber.org/zap" appsv1 "k8s.io/api/apps/v1" - hpav2 "k8s.io/api/autoscaling/v2beta2" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -330,105 +328,6 @@ func (c *DeploymentController) createPrimaryDeployment(cd *flaggerv1.Canary, inc return nil } -func (c *DeploymentController) reconcilePrimaryHpa(cd *flaggerv1.Canary, init bool) error { - primaryName := fmt.Sprintf("%s-primary", cd.Spec.TargetRef.Name) - hpa, err := c.kubeClient.AutoscalingV2beta2().HorizontalPodAutoscalers(cd.Namespace).Get(context.TODO(), cd.Spec.AutoscalerRef.Name, metav1.GetOptions{}) - if err != nil { - return fmt.Errorf("HorizontalPodAutoscaler %s.%s get query error: %w", - cd.Spec.AutoscalerRef.Name, cd.Namespace, err) - } - - hpaSpec := hpav2.HorizontalPodAutoscalerSpec{ - ScaleTargetRef: hpav2.CrossVersionObjectReference{ - Name: primaryName, - Kind: hpa.Spec.ScaleTargetRef.Kind, - APIVersion: hpa.Spec.ScaleTargetRef.APIVersion, - }, - MinReplicas: hpa.Spec.MinReplicas, - MaxReplicas: hpa.Spec.MaxReplicas, - Metrics: hpa.Spec.Metrics, - Behavior: hpa.Spec.Behavior, - } - - primaryHpaName := fmt.Sprintf("%s-primary", cd.Spec.AutoscalerRef.Name) - primaryHpa, err := c.kubeClient.AutoscalingV2beta2().HorizontalPodAutoscalers(cd.Namespace).Get(context.TODO(), primaryHpaName, metav1.GetOptions{}) - - // create HPA - if errors.IsNotFound(err) { - primaryHpa = &hpav2.HorizontalPodAutoscaler{ - ObjectMeta: metav1.ObjectMeta{ - Name: primaryHpaName, - Namespace: cd.Namespace, - Labels: filterMetadata(hpa.Labels), - OwnerReferences: []metav1.OwnerReference{ - *metav1.NewControllerRef(cd, schema.GroupVersionKind{ - Group: flaggerv1.SchemeGroupVersion.Group, - Version: flaggerv1.SchemeGroupVersion.Version, - Kind: flaggerv1.CanaryKind, - }), - }, - }, - Spec: hpaSpec, - } - - _, err = c.kubeClient.AutoscalingV2beta2().HorizontalPodAutoscalers(cd.Namespace).Create(context.TODO(), primaryHpa, metav1.CreateOptions{}) - if err != nil { - return fmt.Errorf("creating HorizontalPodAutoscaler %s.%s failed: %w", - primaryHpa.Name, primaryHpa.Namespace, err) - } - c.logger.With("canary", fmt.Sprintf("%s.%s", cd.Name, cd.Namespace)).Infof( - "HorizontalPodAutoscaler %s.%s created", primaryHpa.GetName(), cd.Namespace) - return nil - } else if err != nil { - return fmt.Errorf("HorizontalPodAutoscaler %s.%s get query failed: %w", - primaryHpa.Name, primaryHpa.Namespace, err) - } - - // update HPA - if !init && primaryHpa != nil { - diffMetrics := cmp.Diff(hpaSpec.Metrics, primaryHpa.Spec.Metrics) - diffBehavior := cmp.Diff(hpaSpec.Behavior, primaryHpa.Spec.Behavior) - diffLabels := cmp.Diff(hpa.ObjectMeta.Labels, primaryHpa.ObjectMeta.Labels) - diffAnnotations := cmp.Diff(hpa.ObjectMeta.Annotations, primaryHpa.ObjectMeta.Annotations) - if diffMetrics != "" || diffBehavior != "" || diffLabels != "" || diffAnnotations != "" || int32Default(hpaSpec.MinReplicas) != int32Default(primaryHpa.Spec.MinReplicas) || hpaSpec.MaxReplicas != primaryHpa.Spec.MaxReplicas { - err = retry.RetryOnConflict(retry.DefaultRetry, func() error { - primaryHpa, err := c.kubeClient.AutoscalingV2beta2().HorizontalPodAutoscalers(cd.Namespace).Get(context.TODO(), primaryHpaName, metav1.GetOptions{}) - if err != nil { - return err - } - hpaClone := primaryHpa.DeepCopy() - hpaClone.Spec.MaxReplicas = hpaSpec.MaxReplicas - hpaClone.Spec.MinReplicas = hpaSpec.MinReplicas - hpaClone.Spec.Metrics = hpaSpec.Metrics - hpaClone.Spec.Behavior = hpaSpec.Behavior - - // update hpa annotations - hpaClone.ObjectMeta.Annotations = make(map[string]string) - filteredAnnotations := includeLabelsByPrefix(hpa.ObjectMeta.Annotations, c.includeLabelPrefix) - for k, v := range filteredAnnotations { - hpaClone.ObjectMeta.Annotations[k] = v - } - // update hpa labels - hpaClone.ObjectMeta.Labels = make(map[string]string) - filteredLabels := includeLabelsByPrefix(hpa.ObjectMeta.Labels, c.includeLabelPrefix) - for k, v := range filteredLabels { - hpaClone.ObjectMeta.Labels[k] = v - } - - _, err = c.kubeClient.AutoscalingV2beta2().HorizontalPodAutoscalers(cd.Namespace).Update(context.TODO(), hpaClone, metav1.UpdateOptions{}) - return err - }) - if err != nil { - return fmt.Errorf("updating HorizontalPodAutoscaler %s.%s failed: %w", - primaryHpa.Name, primaryHpa.Namespace, err) - } - c.logger.With("canary", fmt.Sprintf("%s.%s", cd.Name, cd.Namespace)). - Infof("HorizontalPodAutoscaler %s.%s updated", primaryHpa.GetName(), cd.Namespace) - } - } - return nil -} - // getSelectorLabel returns the selector match label func (c *DeploymentController) getSelectorLabel(deployment *appsv1.Deployment) (string, string, error) { for _, l := range c.labels {