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

Bump k8s go sdk client #41

Merged
merged 10 commits into from
Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

!cmd/
!pkg/
!vendor/
!test/

**/Dockerfile
67 changes: 67 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: CI

on:
pull_request:
branches:
- development

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-go@v2
with:
go-version: "^1.14.0"

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Lint
run: make lint

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-go@v2
with:
go-version: "^1.14.0"

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Run test
run: make test

build:
name: Build docker images
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-go@v2
with:
go-version: "^1.14.0"

- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Build docker images
run: make docker-images
16 changes: 10 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,26 @@ linters:
- vet
- vetshadow
- errcheck
- govet
- structcheck
- typecheck

run:

# timeout for analysis
timeout: 5m

# include test files or not, default is true
tests: false

skip-dirs:
- test

issues:

# List of regexps of issue texts to exclude
exclude:
- "comment on"
- "error should be the last"
- "should have comment"

exclude-rules:

# list of excluded linters applied on test files
- path: _test\.go
linters:
- goconst
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ lint: modules
$(GOPATH)/bin/golangci-lint run -v
@echo Done.

.PHONY: fmt
fmt:
gofmt -s -w .

.PHONY: test-undockerized
test-undockerized: modules
go test -v ./pkg/... -p 1
Expand Down
25 changes: 18 additions & 7 deletions cmd/autoscaler/app/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ import (
"github.com/nuclio/errors"
"github.com/nuclio/zap"
"github.com/v3io/scaler-types"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/client-go/discovery/cached/memory"
"k8s.io/client-go/rest"
"k8s.io/client-go/restmapper"
"k8s.io/client-go/tools/clientcmd"
custommetricsv1 "k8s.io/metrics/pkg/client/custom_metrics"
"k8s.io/metrics/pkg/client/custom_metrics"
)

func Run(kubeconfigPath string,
namespace string,
scaleInterval time.Duration,
metricsGroupKind string) error {
metricsGroupKind string,
metricsGroupName string) error {
autoScalerOptions := scaler_types.AutoScalerOptions{
Namespace: namespace,
ScaleInterval: scaler_types.Duration{Duration: scaleInterval},
GroupKind: metricsGroupKind,
GroupKind: schema.GroupKind{
Group: metricsGroupName,
Kind: metricsGroupKind,
},
}

pluginLoader, err := pluginloader.New()
Expand Down Expand Up @@ -75,15 +83,18 @@ func createAutoScaler(restConfig *rest.Config,
return nil, errors.Wrap(err, "Failed to initialize root logger")
}

customMetricsClient, err := custommetricsv1.NewForConfig(restConfig)
dc, err := discovery.NewDiscoveryClientForConfig(restConfig)
liranbg marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, errors.Wrap(err, "Failed create custom metrics client set")
return nil, err
liranbg marked this conversation as resolved.
Show resolved Hide resolved
}
availableAPIsGetter := custom_metrics.NewAvailableAPIsGetter(dc)
mapper := restmapper.NewDeferredDiscoveryRESTMapper(memory.NewMemCacheClient(dc))
customMetricsClient := custom_metrics.NewForConfig(restConfig, mapper, availableAPIsGetter)
liranbg marked this conversation as resolved.
Show resolved Hide resolved

// create auto scaler
newScaler, err := autoscaler.NewAutoScaler(rootLogger, resourceScaler, customMetricsClient, options)

if err != nil {
return nil, err
return nil, errors.Wrap(err, "Failed to create auto scaler")
}

return newScaler, nil
Expand Down
6 changes: 4 additions & 2 deletions cmd/autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ func main() {
kubeconfigPath := flag.String("kubeconfig-path", os.Getenv("KUBECONFIG"), "Path of kubeconfig file")
namespace := flag.String("namespace", "", "Namespace to listen on, or * for all")
scaleInterval := flag.Duration("scale-interval", time.Minute, "Interval to call check scale function")
metricsGroupKind := flag.String("metrics-group-kind", "", "Metrics resource kind")
metricsGroupName := flag.String("metrics-group-name", "", "Metrics resource group name")
metricsGroupKind := flag.String("metrics-group-kind", "", "Metrics resource group kind")
flag.Parse()

*namespace = common.GetNamespace(*namespace)

if err := app.Run(*kubeconfigPath,
*namespace,
*scaleInterval,
*metricsGroupKind); err != nil {
*metricsGroupKind,
*metricsGroupName); err != nil {
errors.PrintErrorStack(os.Stderr, err, 5)

os.Exit(1)
Expand Down
33 changes: 14 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ module github.com/v3io/scaler
go 1.14

require (
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/howeyc/gopass v0.0.0-20170109162249-bf9dde6d0d2c // indirect
github.com/gogo/protobuf v1.1.1 // indirect
github.com/golang/protobuf v1.3.3 // indirect
github.com/google/go-cmp v0.4.0 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/json-iterator/go v1.1.7 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.2 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/nuclio/errors v0.0.3
github.com/nuclio/logger v0.0.1
github.com/nuclio/zap v0.0.3
Expand All @@ -22,18 +19,16 @@ require (
github.com/spf13/pflag v1.0.3 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.5.1
github.com/v3io/scaler-types v1.6.0
go.uber.org/atomic v1.4.0 // indirect
github.com/v3io/scaler-types v1.7.0
go.uber.org/atomic v1.3.2 // indirect
go.uber.org/multierr v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 // indirect
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
k8s.io/api v0.0.0-20180713172427-0f11257a8a25 // indirect
k8s.io/apimachinery v0.0.0-20180619225948-e386b2658ed2
k8s.io/client-go v7.0.0+incompatible
k8s.io/metrics v0.0.0-20190116212108-c656f2547d11
google.golang.org/appengine v1.6.5 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
k8s.io/apimachinery v0.15.12
k8s.io/client-go v0.15.12
k8s.io/metrics v0.15.12
)
Loading