Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
levrado committed Jan 14, 2019
1 parent 0eef292 commit 21bd1ae
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea/

# Binaries for programs and plugins
*.exe
*.exe~
Expand Down
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
sudo: required

services:
- docker

addons:
apt:
packages:
- docker-ce

language: go
go_import_path: github.com/v3io/scaler
go: "1.10"

script:
- make lint test

after_success:
- bash <(curl -s https://codecov.io/bash)
- echo $TRAVIS_PULL_REQUEST
- echo $TRAVIS_BRANCH
- echo "$DOCKER_PASSWORD" | docker login -u="$DOCKER_USERNAME" --password-stdin &&
make docker-images push-docker-images
- echo "Done."
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,19 @@ DLX_DOCKER_REPO = levrado1/dlx-onbuild

.PHONY: autoscaler-onbuild
autoscaler-onbuild:
@echo Building autoscaler
@echo Building autoscaler-onbuild
docker build -f cmd/autoscaler/Dockerfile -t $(AUTOSCALER_DOCKER_REPO) .

.PHONY: dlx-onbuild
dlx-onbuild:
@echo Building dlx
@echo Building dlx-onbuild
docker build -f cmd/dlx/Dockerfile -t $(DLX_DOCKER_REPO) .

.PHONY: docker-push
docker-push:
.PHONY: docker-images
docker-images: autoscaler-onbuild dlx-onbuild

.PHONY: push-docker-images
push-docker-images:
@echo Pushing images
docker push $(DLX_DOCKER_REPO)
docker push $(AUTOSCALER_DOCKER_REPO)
Expand Down
32 changes: 16 additions & 16 deletions cmd/autoscaler/app/autoscaler.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package app

import (
"github.com/v3io/scaler/pkg"
"os"
"time"

"github.com/nuclio/errors"
"github.com/nuclio/zap"
"github.com/v3io/scaler/pkg"
"github.com/v3io/scaler/pkg/autoscaler"
"github.com/v3io/scaler/pkg/resourcescaler"

"github.com/nuclio/errors"
"github.com/nuclio/zap"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -24,16 +24,16 @@ func Run(kubeconfigPath string,
scaleThreshold int64,
metricsInterval time.Duration) error {
autoScalerOptions := scaler.AutoScalerOptions{
Namespace: namespace,
Namespace: namespace,
ScaleInterval: scaleInterval,
ScaleWindow: scaleWindow,
Threshold: scaleThreshold,
MetricName: metricName,
ScaleWindow: scaleWindow,
Threshold: scaleThreshold,
MetricName: metricName,
}

pollerOptions := scaler.PollerOptions{
Namespace: namespace,
MetricName: metricName,
Namespace: namespace,
MetricName: metricName,
MetricInterval: metricsInterval,
}

Expand All @@ -50,8 +50,8 @@ func Run(kubeconfigPath string,
pollerOptions = resourceScalerConfig.PollerOptions
}

autoScalerOptions.resourceScaler = resourceScaler
pollerOptions.resourceScaler = resourceScaler
autoScalerOptions.ResourceScaler = resourceScaler
pollerOptions.ResourceScaler = resourceScaler

restConfig, err := getClientConfig(kubeconfigPath)
if err != nil {
Expand All @@ -63,7 +63,7 @@ func Run(kubeconfigPath string,
return errors.Wrap(err, "Failed to create scaler")
}

if err := newScaler.Start(); err != nil {
if err = newScaler.Start(); err != nil {
return errors.Wrap(err, "Failed to start scaler")
}

Expand All @@ -72,7 +72,7 @@ func Run(kubeconfigPath string,
return errors.Wrap(err, "Failed to create poller")
}

if err := newScaler.Start(); err != nil {
if err = newScaler.Start(); err != nil {
return errors.Wrap(err, "Failed to start scaler")
}

Expand All @@ -94,7 +94,7 @@ func createAutoScaler(restConfig *rest.Config, options scaler.AutoScalerOptions)
return nil, errors.Wrap(err, "Failed to create k8s client set")
}

options.kubeClientSet = kubeClientSet
options.KubeClientSet = kubeClientSet

newScaler, err := autoscaler.NewAutoScaler(rootLogger, options)

Expand All @@ -116,7 +116,7 @@ func createPoller(restConfig *rest.Config, reporter autoscaler.MetricReporter, o
return nil, errors.Wrap(err, "Failed create custom metrics client set")
}

options.customMetricsClientSet = customMetricsClient
options.CustomMetricsClientSet = customMetricsClient

newPoller, err := autoscaler.NewMetricsPoller(rootLogger, reporter, options)
if err != nil {
Expand All @@ -132,4 +132,4 @@ func getClientConfig(kubeconfigPath string) (*rest.Config, error) {
}

return rest.InClusterConfig()
}
}
3 changes: 2 additions & 1 deletion cmd/autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import (
"os"
"time"

"github.com/nuclio/errors"
"github.com/v3io/scaler/cmd/autoscaler/app"

"github.com/nuclio/errors"
)

func main() {
Expand Down
9 changes: 4 additions & 5 deletions cmd/dlx/app/dlx.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"github.com/nuclio/errors"
"github.com/nuclio/zap"

)

func Run(namespace string, targetNameHeader string, targetPathHeader string, targetPort int, listenAddress string) error {
Expand All @@ -18,10 +17,10 @@ func Run(namespace string, targetNameHeader string, targetPathHeader string, tar
dlxOptions := scaler.DLXOptions{
TargetNameHeader: targetNameHeader,
TargetPathHeader: targetPathHeader,
TargetPort: targetPort,
ListenAddress: listenAddress,
Namespace: namespace,
ResourceScaler: resourceScaler,
TargetPort: targetPort,
ListenAddress: listenAddress,
Namespace: namespace,
ResourceScaler: resourceScaler,
}

// see if resource scaler wants to override the arguments
Expand Down
3 changes: 2 additions & 1 deletion pkg/autoscaler/autoscaler.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package autoscaler

import (
"github.com/v3io/scaler/pkg"
"time"

"github.com/v3io/scaler/pkg"

"github.com/nuclio/logger"
)

Expand Down
3 changes: 2 additions & 1 deletion pkg/autoscaler/autoscaler_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package autoscaler

import (
"github.com/v3io/scaler/pkg"
"testing"
"time"

"github.com/v3io/scaler/pkg"

"github.com/nuclio/logger"
"github.com/nuclio/zap"
"github.com/stretchr/testify/mock"
Expand Down
16 changes: 9 additions & 7 deletions pkg/dlx/dlx.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package dlx

import (
"net/http"

"github.com/v3io/scaler/pkg"

"github.com/nuclio/errors"
"github.com/nuclio/logger"
"github.com/v3io/scaler/pkg"
"net/http"
)

type DLX struct {
logger logger.Logger
listenAddress string
handler Handler
logger logger.Logger
listenAddress string
handler Handler
}

func NewDLX(logger logger.Logger,
Expand All @@ -30,9 +32,9 @@ func NewDLX(logger logger.Logger,
}

return &DLX{
logger: logger,
logger: logger,
listenAddress: options.ListenAddress,
handler: handler,
handler: handler,
}, nil
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/dlx/resourcestarter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package dlx

import (
"github.com/v3io/scaler/pkg"
"net/http"
"sync"
"time"

"github.com/v3io/scaler/pkg"

"github.com/nuclio/errors"
"github.com/nuclio/logger"
)
Expand Down Expand Up @@ -36,7 +37,7 @@ func NewResourceStarter(parentLogger logger.Logger,
resourceSinksMap: make(resourceSinksMap),
namespace: namespace,
resourceReadinnesTimeout: time.Minute,
scaler: scaler,
scaler: scaler,
}
return fs, nil
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/dlx/resourcestarter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package dlx

import (
"fmt"
"github.com/v3io/scaler/pkg"
"net/http"
"sync"
"testing"
"time"

"github.com/v3io/scaler/pkg"

"github.com/nuclio/logger"
"github.com/nuclio/zap"
"github.com/stretchr/testify/mock"
Expand Down
13 changes: 6 additions & 7 deletions pkg/resourcescaler/resourcescaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@ package resourcescaler

import "github.com/v3io/scaler/pkg"

type resourceScaler struct {}
type ResourceScaler struct{}


func New() *resourceScaler {
return &resourceScaler{}
func New() *ResourceScaler {
return &ResourceScaler{}
}

func (r *resourceScaler) SetScale(string, scaler.Resource, int) error {
func (r *ResourceScaler) SetScale(string, scaler.Resource, int) error {
return nil
}

func (r *resourceScaler) GetResources() ([]scaler.Resource, error) {
func (r *ResourceScaler) GetResources() ([]scaler.Resource, error) {
return []scaler.Resource{}, nil
}

func (r *resourceScaler) GetConfig() (*scaler.ResourceScalerConfig, error) {
func (r *ResourceScaler) GetConfig() (*scaler.ResourceScalerConfig, error) {
return nil, nil
}
18 changes: 9 additions & 9 deletions pkg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ type AutoScalerOptions struct {
KubeClientSet kubernetes.Interface
ResourceScaler ResourceScaler

Namespace string
ScaleInterval time.Duration
ScaleWindow time.Duration
MetricName string
Threshold int64
Namespace string
ScaleInterval time.Duration
ScaleWindow time.Duration
MetricName string
Threshold int64
}

type PollerOptions struct {
// not needed to be provided by ResourceScalerConfig
CustomMetricsClientSet custommetricsv1.CustomMetricsClient
ResourceScaler ResourceScaler

MetricInterval time.Duration
MetricName string
Namespace string
MetricInterval time.Duration
MetricName string
Namespace string
}

type ResourceScalerConfig struct {
Expand All @@ -38,7 +38,7 @@ type ResourceScalerConfig struct {

type DLXOptions struct {
// not needed to be provided by ResourceScalerConfig
ResourceScaler ResourceScaler
ResourceScaler ResourceScaler

Namespace string
TargetNameHeader string
Expand Down

0 comments on commit 21bd1ae

Please sign in to comment.