Skip to content

Commit

Permalink
Merge pull request #85 from amshuman-kr/create-separate-api-module
Browse files Browse the repository at this point in the history
Create separate api module
  • Loading branch information
Amshuman K R authored Mar 29, 2021
2 parents 26a2970 + f144806 commit 531ed42
Show file tree
Hide file tree
Showing 1,130 changed files with 185,898 additions and 63,110 deletions.
4 changes: 2 additions & 2 deletions .ci/check
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ fi

cd ${SOURCE_PATH}

echo "Install Golint (linting tool) using $(go version) at ${PWD}"
go install -mod=vendor golang.org/x/lint/golint
echo "Install Golint (linting tool)."
go install golang.org/x/lint/golint

###############################################################################

Expand Down
3 changes: 3 additions & 0 deletions .ci/pipeline_definitions
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ hvpa-controller:
preprocess: 'finalize'
release:
nextversion: 'bump_minor'
git_tags:
- ref_template: 'refs/tags/{VERSION}'
- ref_template: 'refs/tags/api/{VERSION}'
slack:
default_channel: 'internal_scp_workspace'
channel_cfgs:
Expand Down
25 changes: 14 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

VERSION := $(shell cat VERSION)
REGISTRY := eu.gcr.io/gardener-project/gardener
REPO_ROOT := $(shell dirname "$(realpath $(lastword $(MAKEFILE_LIST)))")

IMAGE_REPOSITORY := $(REGISTRY)/hvpa-controller
IMAGE_TAG := $(VERSION)
Expand All @@ -34,16 +35,16 @@ endif
all: manager

# Run tests
test: generate fmt vet manifests
go test ./api/... ./controllers/... ./utils/... -coverprofile cover.out
test: generate fmt vet
@env GO111MODULE=on GOFLAGS=-mod=vendor go test ./internal/... ./controllers/... ./utils/... -coverprofile cover.out

# Build manager binary
manager: generate fmt vet
go build -o bin/manager main.go
@env GO111MODULE=on GOFLAGS=-mod=vendor go build -o bin/manager main.go

# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet
go run ./main.go --enable-detailed-metrics --logtostderr=true --v=2
@env GO111MODULE=on GOFLAGS=-mod=vendor go run ./main.go --enable-detailed-metrics --logtostderr=true --v=2

# Install CRDs into a cluster
install: manifests
Expand All @@ -56,19 +57,20 @@ deploy: manifests

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
"$(CONTROLLER_GEN)" $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./api/..." output:crd:artifacts:config=config/crd/bases
cd "$(REPO_ROOT)/api" && $(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." output:crd:artifacts:config=../config/crd/bases
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./controllers/..."

# Run go fmt against code
fmt:
go fmt ./...
@env GO111MODULE=on GOFLAGS=-mod=vendor go fmt ./...

# Run go vet against code
vet:
go vet ./...
@env GO111MODULE=on GOFLAGS=-mod=vendor go vet ./...

# Generate code
generate: controller-gen
"$(CONTROLLER_GEN)" object:headerFile=./hack/boilerplate.go.txt paths=./api/...
cd "$(REPO_ROOT)/api" && $(CONTROLLER_GEN) object:headerFile=../hack/boilerplate.go.txt paths=./...

# Build the docker image
docker-build: test
Expand All @@ -82,14 +84,15 @@ docker-push:

# Revendor
revendor:
@GO111MODULE=on go mod vendor
@GO111MODULE=on go mod tidy
@cd "$(REPO_ROOT)/api" && go mod tidy
@env GO111MODULE=on go mod tidy
@env GO111MODULE=on go mod vendor

# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.0-beta.4
go install sigs.k8s.io/controller-tools/cmd/controller-gen
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
Expand Down
9 changes: 9 additions & 0 deletions api/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/gardener/hvpa-controller/api

go 1.15

require (
k8s.io/api v0.18.8
k8s.io/apimachinery v0.18.8
k8s.io/autoscaler/vertical-pod-autoscaler v0.9.0
)
252 changes: 252 additions & 0 deletions api/go.sum

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions api/v1alpha1/zz_generated.deepcopy.go

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

11 changes: 5 additions & 6 deletions controllers/hvpa_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"time"

autoscalingv1alpha1 "github.com/gardener/hvpa-controller/api/v1alpha1"
validation "github.com/gardener/hvpa-controller/api/validation"
validation "github.com/gardener/hvpa-controller/internal/api/validation"
"github.com/gardener/hvpa-controller/utils"
appsv1 "k8s.io/api/apps/v1"
autoscaling "k8s.io/api/autoscaling/v2beta1"
Expand Down Expand Up @@ -145,8 +145,10 @@ type hvpaObj struct {
Selector labels.Selector
}

var cachedNames map[string][]*hvpaObj
var cacheMux sync.Mutex
var (
cachedNames map[string][]*hvpaObj
cacheMux sync.Mutex
)

func (r *HvpaReconciler) getSelectorFromHvpa(instance *autoscalingv1alpha1.Hvpa) (labels.Selector, error) {
targetRef := instance.Spec.TargetRef
Expand Down Expand Up @@ -469,7 +471,6 @@ func (r *HvpaReconciler) scaleIfRequired(hpaStatus *autoscaling.HorizontalPodAut
autoscalingv1alpha1.VpaWeight,
*[]*autoscalingv1alpha1.BlockedScaling,
error) {

var newObj runtime.Object
var deploy *appsv1.Deployment
var ss *appsv1.StatefulSet
Expand Down Expand Up @@ -733,7 +734,6 @@ func getWeightedReplicas(hpaStatus *autoscaling.HorizontalPodAutoscalerStatus, h

if hpaWeight == 0 {
blockReason = autoscalingv1alpha1.BlockingReasonWeight

} else if weightedReplicas > currentReplicas {
if scaleUpUpdateMode == autoscalingv1alpha1.UpdateModeOff {
blockReason = autoscalingv1alpha1.BlockingReasonUpdatePolicy
Expand All @@ -746,7 +746,6 @@ func getWeightedReplicas(hpaStatus *autoscaling.HorizontalPodAutoscalerStatus, h
outHpaStatus.DesiredReplicas = weightedReplicas
return outHpaStatus, err
}

} else if weightedReplicas < currentReplicas {
if scaleDownUpdateMode == autoscalingv1alpha1.UpdateModeOff {
blockReason = autoscalingv1alpha1.BlockingReasonUpdatePolicy
Expand Down
18 changes: 10 additions & 8 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand All @@ -46,19 +47,21 @@ import (
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.

var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment
var mgr manager.Manager
var stopMgr chan struct{}
var mgrStopped *sync.WaitGroup
var (
cfg *rest.Config
k8sClient client.Client
testEnv *envtest.Environment
mgr manager.Manager
stopMgr chan struct{}
mgrStopped *sync.WaitGroup
)

func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)

RunSpecsWithDefaultAndCustomReporters(t,
"Controller Suite",
[]Reporter{envtest.NewlineReporter{}})
[]Reporter{printer.NewlineReporter{}})
}

var _ = BeforeSuite(func(done Done) {
Expand Down Expand Up @@ -252,7 +255,6 @@ func newHpaStatus(currentReplicas, desiredReplicas int32, conditions []autoscali
}

func newVpaStatus(containerName, mem, cpu string) *vpa_api.VerticalPodAutoscalerStatus {

return &vpa_api.VerticalPodAutoscalerStatus{
Recommendation: &vpa_api.RecommendedPodResources{
ContainerRecommendations: []vpa_api.RecommendedContainerResources{
Expand Down
20 changes: 11 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ module github.com/gardener/hvpa-controller
go 1.15

require (
github.com/gardener/hvpa-controller/api v0.0.0
github.com/nxadm/tail v1.4.5 // indirect
github.com/onsi/ginkgo v1.14.2
github.com/onsi/gomega v1.10.1
github.com/prometheus/client_golang v0.9.0
github.com/prometheus/client_golang v1.0.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
golang.org/x/net v0.0.0-20201021035429-f5854403a974
golang.org/x/sys v0.0.0-20201107080550-4d91cf3a1aaf // indirect
golang.org/x/tools v0.0.0-20201105220310-78b158585360 // indirect
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
k8s.io/apimachinery v0.0.0-20190404173353-6a84e37a896d
k8s.io/autoscaler v0.0.0-20190805135949-100e91ba756e
k8s.io/client-go v11.0.1-0.20190409021438-1a26190bd76a+incompatible
k8s.io/klog v0.3.0
sigs.k8s.io/controller-runtime v0.2.0-beta.5
sigs.k8s.io/controller-tools v0.2.0-beta.4
k8s.io/api v0.18.8
k8s.io/apimachinery v0.18.8
k8s.io/autoscaler/vertical-pod-autoscaler v0.9.0
k8s.io/client-go v0.18.8
k8s.io/klog v1.0.0
sigs.k8s.io/controller-runtime v0.6.3
sigs.k8s.io/controller-tools v0.4.0
)

replace github.com/gardener/hvpa-controller/api => ./api
Loading

0 comments on commit 531ed42

Please sign in to comment.