Skip to content

Commit

Permalink
Upgrade to Go 1.20 and update dependencies (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
jthomperoo authored Mar 7, 2023
1 parent f8c380b commit be8c6d8
Show file tree
Hide file tree
Showing 34 changed files with 384 additions and 203 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.19
- name: Set up Go 1.20
uses: actions/setup-go@v1
with:
go-version: 1.19
go-version: 1.20
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Lint, format, and test
run: |
# Get staticcheck
export PATH=$PATH:$(go env GOPATH)/bin
go install honnef.co/go/tools/cmd/staticcheck@v0.3.3
make lint
make format
# Exit if after formatting there are any code differences
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Upgraded to Go `v1.20`.
- Upgraded package dependencies.

## [v2.0.0] - 2022-12-02
### Changed
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ the other projects that solved it better and which could serve as inspiration.

Developing this project requires these dependencies:

* [Go v1.19+](https://go.dev/doc/install)
* [staticcheck v0.3.3 (2022.1.3)](https://staticcheck.io/docs/getting-started/)
* [Go v1.20+](https://go.dev/doc/install)
* [Docker](https://docs.docker.com/install/)

To view the docs, you need Python 3 installed:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test:

lint:
@echo "=============Linting============="
staticcheck ./...
go run honnef.co/go/tools/cmd/staticcheck@v0.4.2 ./...

format:
@echo "=============Formatting============="
Expand Down
21 changes: 21 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2023 The K8sHorizMetrics Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package k8shorizmetrics provides a simplified interface for gathering metrics and calculating replicas in the same
// way that the Horizontal Pod Autoscaler (HPA) does.
// This is split into two parts, gathering metrics, and evaluating metrics (calculating replicas).
// You can use these parts separately, or together to create a full evaluation process in the same way the HPA does.
package k8shorizmetrics
6 changes: 4 additions & 2 deletions evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ func NewEvaluator(tolerance float64) *Evaluator {
}
}

// Evaluate returns the target replica count for an array of multiple metrics
func (e *Evaluator) Evaluate(gatheredMetrics []*metrics.Metric, currentReplicas int32) (int32, error) {
return e.EvaluateWithOptions(gatheredMetrics, currentReplicas, e.Tolerance)
}

// Evaluate returns the target replica count for an array of multiple metrics
// EvaluateWithOptions returns the target replica count for an array of multiple metrics with provided options
func (e *Evaluator) EvaluateWithOptions(gatheredMetrics []*metrics.Metric, currentReplicas int32, tolerance float64) (int32, error) {
var evaluation int32
var invalidEvaluationError error
Expand Down Expand Up @@ -124,11 +125,12 @@ func (e *Evaluator) EvaluateWithOptions(gatheredMetrics []*metrics.Metric, curre
return evaluation, nil
}

// EvaluateSingleMetric returns the target replica count for a single metrics
func (e *Evaluator) EvaluateSingleMetric(gatheredMetric *metrics.Metric, currentReplicas int32) (int32, error) {
return e.EvaluateSingleMetricWithOptions(gatheredMetric, currentReplicas, e.Tolerance)
}

// EvaluateSingleMetric returns the target replica count for a single metrics
// EvaluateSingleMetricWithOptions returns the target replica count for a single metrics with provided options
func (e *Evaluator) EvaluateSingleMetricWithOptions(gatheredMetric *metrics.Metric, currentReplicas int32, tolerance float64) (int32, error) {
switch gatheredMetric.Spec.Type {
case autoscalingv2.ObjectMetricSourceType:
Expand Down
43 changes: 23 additions & 20 deletions examples/cpuprint/go.mod
Original file line number Diff line number Diff line change
@@ -1,52 +1,55 @@
module github.com/jthomperoo/k8shorizmetrics/examples/cpuprint

go 1.19
go 1.20

require (
github.com/jthomperoo/k8shorizmetrics/v2 v2.0.0
k8s.io/api v0.25.4
k8s.io/apimachinery v0.25.4
k8s.io/client-go v0.25.4
k8s.io/api v0.26.2
k8s.io/apimachinery v0.26.2
k8s.io/client-go v0.26.2
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // 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
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/tools v0.4.1-0.20221208213631-3f74d914ae6d // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
google.golang.org/protobuf v1.28.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/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/metrics v0.25.4 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
honnef.co/go/tools v0.4.2 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/metrics v0.26.2 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

replace github.com/jthomperoo/k8shorizmetrics/v2 => ../../
Loading

0 comments on commit be8c6d8

Please sign in to comment.