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

migrate to autoscaling/v2 #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
49 changes: 20 additions & 29 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,45 @@
name: Test
on: [push]
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: set up
uses: actions/setup-go@v2
with:
go-version: ^1.16
- name: check out
uses: actions/checkout@v2
- name: before cache
run: |
mkdir -p ~/go/pkg/mod
- name: Cache
uses: actions/cache@v2.1.0
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
build:
needs: setup
runs-on: ubuntu-latest
steps:
- name: check out
uses: actions/checkout@v3
- name: set up
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ^1.16
- uses: actions/checkout@v2
go-version: '1.20'
check-latest: true
cache-dependency-path: go.sum
- name: build
run: make build
lint:
needs: setup
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: check out
uses: actions/checkout@v3
- name: set up
uses: actions/setup-go@v4
with:
go-version: '1.20'
check-latest: true
cache-dependency-path: go.sum
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.42.1
test:
needs: setup
runs-on: ubuntu-latest
steps:
- name: check out
uses: actions/checkout@v3
- name: set up
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ^1.16
- uses: actions/checkout@v2
go-version: '1.20'
check-latest: true
cache-dependency-path: go.sum
- name: test
run: make test
- uses: shogo82148/actions-goveralls@v1
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.16 as builder
FROM golang:1.20 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand Down
23 changes: 13 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Image URL to use all building/pushing image targets
IMG ?= docker.pkg.github.com/dtaniwaki/cron-hpa/cron-hpa-controller:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
CRD_OPTIONS ?= "crd"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -56,10 +56,9 @@ lint: ## Run golangci-lint.
golangci-lint run

ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: manifests generate fmt vet ## Run tests.
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
ENVTEST_K8S_VERSION = 1.26.1
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out

##@ Build

Expand Down Expand Up @@ -101,22 +100,26 @@ undeploy-samples:

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.12.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)

# go-get-tool will 'go get' any package $2 and install it to $1.
ENVTEST = $(shell pwd)/bin/setup-envtest
envtest: ## Download setup-envtest locally if necessary.
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

# go-install-tool will 'go install' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
define go-install-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ spec:
Mark the target HPA resource as below to temporarily skip getting CronHPA's update.

```yaml
apiVersion: autoscaling/v2beta2
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
annotations:
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/cronhorizontalpodautoscaler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package v1alpha1

import (
autoscalingv2beta2 "k8s.io/api/autoscaling/v2beta2"
autoscalingv2 "k8s.io/api/autoscaling/v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -39,8 +39,8 @@ type TemplateMetadata struct {

// HPATemplate is the template of HPA to create.
type HPATemplate struct {
Metadata *TemplateMetadata `json:"metadata,omitempty"`
Spec autoscalingv2beta2.HorizontalPodAutoscalerSpec `json:"spec"`
Metadata *TemplateMetadata `json:"metadata,omitempty"`
Spec autoscalingv2.HorizontalPodAutoscalerSpec `json:"spec"`
}

// HPAPatch is a patch applied to the template.
Expand All @@ -64,7 +64,7 @@ type HPAPatch struct {
// increased, and vice-versa. See the individual metric source types for
// more information about how each type of metric must respond.
// +optional
Metrics []autoscalingv2beta2.MetricSpec `json:"metrics,omitempty"`
Metrics []autoscalingv2.MetricSpec `json:"metrics,omitempty"`
}

// CronHorizontalPodAutoscalerScheduledPatch is a patch w/ schedule to apply.
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the cronhpa v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=cron-hpa.dtaniwaki.github.com
// +kubebuilder:object:generate=true
// +groupName=cron-hpa.dtaniwaki.github.com
package v1alpha1

import (
Expand Down
5 changes: 3 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.12.0
name: cronhorizontalpodautoscalers.cron-hpa.dtaniwaki.github.com
spec:
group: cron-hpa.dtaniwaki.github.com
Expand Down Expand Up @@ -78,7 +76,7 @@ spec:
field should be set at once).
properties:
containerResource:
description: container resource refers to a resource
description: containerResource refers to a resource
metric (such as those specified in requests and
limits) known to Kubernetes describing a single
container in each pod of the current scale target
Expand Down Expand Up @@ -212,6 +210,7 @@ spec:
only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
required:
- name
type: object
Expand Down Expand Up @@ -262,16 +261,15 @@ spec:
on an Ingress object).
properties:
describedObject:
description: CrossVersionObjectReference contains
enough information to let you identify the referred
resource.
description: describedObject specifies the descriptions
of a object,such as kind,name apiVersion
properties:
apiVersion:
description: API version of the referent
type: string
kind:
description: 'Kind of the referent; More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"'
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent; More info:
Expand Down Expand Up @@ -346,6 +344,7 @@ spec:
only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
required:
- name
type: object
Expand Down Expand Up @@ -462,6 +461,7 @@ spec:
only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
required:
- name
type: object
Expand Down Expand Up @@ -669,10 +669,11 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
description: selectPolicy is used to specify which
policy should be used. If not set, the default value
MaxPolicySelect is used.
Max is used.
type: string
stabilizationWindowSeconds:
description: 'StabilizationWindowSeconds is the number
Expand All @@ -689,10 +690,9 @@ spec:
type: object
scaleUp:
description: 'scaleUp is scaling policy for scaling Up.
If not set, the default value is the higher of: *
increase no more than 4 pods per 60 seconds * double
the number of pods per 60 seconds No stabilization is
used.'
If not set, the default value is the higher of: * increase
no more than 4 pods per 60 seconds * double the number
of pods per 60 seconds No stabilization is used.'
properties:
policies:
description: policies is a list of potential scaling
Expand Down Expand Up @@ -726,10 +726,11 @@ spec:
- value
type: object
type: array
x-kubernetes-list-type: atomic
selectPolicy:
description: selectPolicy is used to specify which
policy should be used. If not set, the default value
MaxPolicySelect is used.
Max is used.
type: string
stabilizationWindowSeconds:
description: 'StabilizationWindowSeconds is the number
Expand Down Expand Up @@ -768,7 +769,7 @@ spec:
should be set at once).
properties:
containerResource:
description: container resource refers to a resource
description: containerResource refers to a resource
metric (such as those specified in requests and limits)
known to Kubernetes describing a single container
in each pod of the current scale target (e.g. CPU
Expand Down Expand Up @@ -900,6 +901,7 @@ spec:
only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
required:
- name
type: object
Expand Down Expand Up @@ -950,16 +952,15 @@ spec:
on an Ingress object).
properties:
describedObject:
description: CrossVersionObjectReference contains
enough information to let you identify the referred
resource.
description: describedObject specifies the descriptions
of a object,such as kind,name apiVersion
properties:
apiVersion:
description: API version of the referent
type: string
kind:
description: 'Kind of the referent; More info:
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"'
https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent; More info:
Expand Down Expand Up @@ -1033,6 +1034,7 @@ spec:
only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
required:
- name
type: object
Expand Down Expand Up @@ -1148,6 +1150,7 @@ spec:
only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
required:
- name
type: object
Expand Down Expand Up @@ -1258,6 +1261,7 @@ spec:
- type
type: object
type: array
x-kubernetes-list-type: atomic
minReplicas:
description: minReplicas is the lower limit for the number
of replicas to which the autoscaler can scale down. It
Expand All @@ -1277,7 +1281,7 @@ spec:
description: API version of the referent
type: string
kind:
description: 'Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"'
description: 'Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names'
Expand Down Expand Up @@ -1315,9 +1319,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Loading