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

fix: HPA apiVersion support for Kubernetes 1.24+ versions #172

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ishuar
Copy link

@ishuar ishuar commented Oct 2, 2024

Purpose

As the autoscaling/v2beta1 API version of HorizontalPodAutoscaler is no longer served as of kubernetes version v1.25.
Fixed the apiVersion selection on the basis of kubernetes capabilities to main backward compatibility.

Reference: https://kubernetes.io/docs/reference/using-api/deprecation-guide/#horizontalpodautoscaler-v125

Changes

  • Added a ternary operation for httpbin HPA api version selection.

Issue Visuals

Click to view K8s version
╰─$ kubectl version                                                                                                                                                          130 ↵
Client Version: v1.31.0
Kustomize Version: v5.4.2
Server Version: v1.29.7-eks-a18cd3a
Click to view Usage of httpbin chart in our context
resource "helm_release" "httpbin" {
  name             = "httpbin"
  repository       = "https://estahn.github.io/charts"
  chart            = "httpbingo"
  version          = "0.1.1"
  atomic           = true
  namespace        = "httpbin"
  create_namespace = true
  values = [
    file("${path.module}/values.yaml")
  ]
}
Click to view values file
# top REDACTED

autoscaling:
  enabled: true
  minReplicas: 1
  maxReplicas: 50
  targetCPUUtilizationPercentage: 75
  targetMemoryUtilizationPercentage: 75
Click to view Error message
│ Error: resource mapping not found for name: "httpbin-httpbingo" namespace: "" from "": no matches for kind "HorizontalPodAutoscaler" in version "autoscaling/v2beta1"
│ ensure CRDs are installed first
│ 
│   with helm_release.httpbin,
│   on main.tf line 1, in resource "helm_release" "httpbin":
│    1: resource "helm_release" "httpbin" {

Testing

  1. I enabled autoscaling to true in values file

  2. Use helm template to rendered manifest files with cmd helm template ./ --values values.yaml

Click to Values and Helm rendered manifests
autoscaling:
  enabled: true
  minReplicas: 1
  maxReplicas: 100
  targetCPUUtilizationPercentage: 80
  # targetMemoryUtilizationPercentage: 80
---
# Source: httpbingo/templates/hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: release-name-httpbingo
  labels:
    helm.sh/chart: httpbingo-0.1.2
    app.kubernetes.io/name: httpbingo
    app.kubernetes.io/instance: release-name
    app.kubernetes.io/version: "v2.2.2"
    app.kubernetes.io/managed-by: Helm
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: release-name-httpbingo
  minReplicas: 1
  maxReplicas: 100
  metrics:
    - type: Resource
      resource:
        name: cpu
        targetAverageUtilization: 80
---

Code Author Checklist

  • Bump the chart version (Chart.yaml -> version)
  • JSON Schema updated (values.schema.json)
  • Update README.md via helm-docs (or make prep)
  • Run pre-commit run --all-files via pre-commit (or make prep)
  • Update Artifacthub annotation (Chart.yaml -> artifacthub.io/changes, artifacthub.io/images)

@github-actions github-actions bot added bugfix and removed bugfix labels Oct 2, 2024
@ishuar
Copy link
Author

ishuar commented Oct 25, 2024

@estahn could you please take a look ? 😇 thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant