Skip to content

Commit

Permalink
Add version compatibility to the HPA API for k8s >= 1.23 (#151)
Browse files Browse the repository at this point in the history
* Upgrade Go to 1.18

* Ignore goenv file

* Test with k8s 1.21 and 1.24

* Fix setup

* Work around CRI issues

* Different CI version per k8s version

* Fix pre-commit

* Add support for HPA in k8s =>1.23
  • Loading branch information
autero1 authored Jan 24, 2023
1 parent cd1f8a3 commit 8dd41b9
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 630 deletions.
23 changes: 14 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ base_env: &base_env
GRUNTWORK_INSTALLER_VERSION: v0.0.38
TERRATEST_LOG_PARSER_VERSION: v0.40.6
HELM_VERSION: v3.8.0
# Newer versions of minikube has bugs in the nginx ingress setup for k8s <1.19
MINIKUBE_VERSION: v1.22.0
MODULE_CI_VERSION: v0.46.1
MODULE_CI_VERSION: v0.51.0
MINIKUBE_VERSION: v1.28.0
TERRAFORM_VERSION: NONE
TERRAGRUNT_VERSION: NONE
PACKER_VERSION: NONE
GOLANG_VERSION: 1.16
GOLANG_VERSION: 1.18
GO111MODULE: auto
KUBECONFIG: /home/circleci/.kube/config

Expand Down Expand Up @@ -52,7 +51,7 @@ integration_test_steps: &integration_test_steps
command: |
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y conntrack
setup-minikube --minikube-version "${MINIKUBE_VERSION}" --k8s-version "${KUBERNETES_VERSION}"
setup-minikube --minikube-version "${MINIKUBE_VERSION}" --k8s-version "${KUBERNETES_VERSION}" ${CRI_DOCKERD_ARG}
- run:
<<: *install_helm_client
- run:
Expand Down Expand Up @@ -129,17 +128,23 @@ jobs:
- store_test_results:
path: /tmp/logs

test_k8s117:
test_k8s124:
<<: [*defaults, *integration_test_steps]
environment:
<<: *base_env
KUBERNETES_VERSION: v1.17.12
KUBERNETES_VERSION: v1.24.8
CRI_DOCKERD_ARG: "--cri-dockerd-version 0.3.0"
MINIKUBE_VERSION: v1.28.0
MODULE_CI_VERSION: v0.51.0

test_k8s121:
<<: [*defaults, *integration_test_steps]
environment:
<<: *base_env
KUBERNETES_VERSION: v1.21.7
CRI_DOCKERD_ARG: ""
MINIKUBE_VERSION: v1.22.0
MODULE_CI_VERSION: v0.50.0

deploy:
<<: *defaults
Expand Down Expand Up @@ -193,7 +198,7 @@ workflows:
context:
- Gruntwork Admin

- test_k8s117:
- test_k8s124:
requires:
- setup
filters:
Expand All @@ -214,7 +219,7 @@ workflows:
- deploy:
requires:
- tpl_tests
- test_k8s117
- test_k8s124
- test_k8s121
filters:
tags:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ __pycache__

# Generic temporary files
/tmp

# goenv file
.go-version
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/gruntwork-io/pre-commit
sha: v0.0.7
sha: v0.1.17
hooks:
- id: helmlint
9 changes: 9 additions & 0 deletions charts/k8s-service/templates/_capabilities_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@
{{- print "policy/v1beta1" -}}
{{- end -}}
{{- end -}}

{{/* Get HorizontalPodAutoscaler API Version */}}
{{- define "gruntwork.horizontalPodAutoscaler.apiVersion" -}}
{{- if and (.Capabilities.APIVersions.Has "autoscaling/v2") (semverCompare ">= 1.23-0" (include "gruntwork.kubeVersion" .)) -}}
{{- print "autoscaling/v2" -}}
{{- else -}}
{{- print "autoscaling/v2beta2" -}}
{{- end -}}
{{- end -}}
2 changes: 1 addition & 1 deletion charts/k8s-service/templates/horizontalpodautoscaler.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.horizontalPodAutoscaler.enabled }}
apiVersion: autoscaling/v2beta2
apiVersion: {{ include "gruntwork.horizontalPodAutoscaler.apiVersion" . }}
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "k8s-service.fullname" . }}
Expand Down
101 changes: 94 additions & 7 deletions test/go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,101 @@
module github.com/gruntwork-io/helm-kubernetes-services/test

go 1.16
go 1.18

require (
github.com/GoogleCloudPlatform/gke-managed-certs v1.0.5
github.com/ghodss/yaml v1.0.0
github.com/gruntwork-io/terratest v0.40.6
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.52.1
github.com/stretchr/testify v1.7.0
golang.org/x/mod v0.4.2
k8s.io/api v0.22.3
k8s.io/apimachinery v0.22.3
github.com/gruntwork-io/terratest v0.41.9
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.51.2
github.com/stretchr/testify v1.8.0
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
k8s.io/api v0.24.9
k8s.io/apimachinery v0.24.9
)

require (
cloud.google.com/go v0.83.0 // indirect
cloud.google.com/go/storage v1.10.0 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/aws/aws-sdk-go v1.40.56 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-sql-driver/mysql v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/gruntwork-io/go-commons v0.8.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.6.1 // indirect
github.com/hashicorp/go-multierror v1.1.0 // indirect
github.com/hashicorp/go-safetemp v1.0.0 // indirect
github.com/hashicorp/go-version v1.3.0 // indirect
github.com/hashicorp/hcl/v2 v2.9.1 // indirect
github.com/hashicorp/terraform-json v0.13.0 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/klauspost/compress v1.13.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pquerna/otp v1.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tmccombs/hcl2json v0.3.3 // indirect
github.com/ulikunitz/xz v0.5.8 // indirect
github.com/urfave/cli v1.22.2 // indirect
github.com/zclconf/go-cty v1.9.1 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/api v0.47.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c // indirect
google.golang.org/grpc v1.38.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/client-go v0.24.9 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
Loading

0 comments on commit 8dd41b9

Please sign in to comment.