Skip to content

Commit

Permalink
use operator-sdk framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Zbynek Roubalik committed Oct 18, 2019
1 parent e5594a7 commit 8b62b50
Show file tree
Hide file tree
Showing 91 changed files with 7,367 additions and 3,745 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,6 @@ apiserver.local.config/
config
*.cert
*.key

# VSCode specific files
.vscode
20 changes: 0 additions & 20 deletions .vscode/launch.json

This file was deleted.

21 changes: 0 additions & 21 deletions Dockerfile

This file was deleted.

57 changes: 38 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
##################################################
# Variables #
##################################################
ARCH?=amd64
CGO?=0
TARGET_OS?=linux
IMAGE_TAG ?= 0.0.4
IMAGE_REGISTRY ?= docker.io
IMAGE_REPO ?= kedacore

##################################################
# Variables #
##################################################
IMAGE_CONTROLLER = $(IMAGE_REGISTRY)/$(IMAGE_REPO)/keda:$(IMAGE_TAG)
IMAGE_ADAPTER = $(IMAGE_REGISTRY)/$(IMAGE_REPO)/keda-metrics-adapter:$(IMAGE_TAG)


ARCH ?=amd64
CGO ?=0
TARGET_OS ?=linux

GIT_VERSION = $(shell git describe --always --abbrev=7)
GIT_COMMIT = $(shell git rev-list -1 HEAD)
Expand Down Expand Up @@ -38,31 +42,46 @@ e2e-test:
npm install --prefix tests
npm test --verbose --prefix tests

##################################################
# PUBLISH #
##################################################
.PHONY: publish
publish: build
docker push $(IMAGE_ADAPTER)
docker push $(IMAGE_CONTROLLER)

##################################################
# Build #
##################################################
GENERATED = $(shell find pkg/client -type f)
GO_BUILD_VARS= GO111MODULE=on CGO_ENABLED=$(CGO) GOOS=$(TARGET_OS) GOARCH=$(ARCH)

.PHONY: build
build: pkg/scalers/liiklus/LiiklusService.pb.go
GO111MODULE=on CGO_ENABLED=$(CGO) GOOS=$(TARGET_OS) GOARCH=$(ARCH) go build \
-ldflags "-X main.GitCommit=$(GIT_COMMIT)" \
-o dist/keda \
cmd/main.go
build: build-adapter build-controller

.PHONY: build-controller
build-controller: generate-api pkg/scalers/liiklus/LiiklusService.pb.go
$(GO_BUILD_VARS) operator-sdk build $(IMAGE_CONTROLLER) \
--go-build-args "-ldflags -X=main.GitCommit=$(GIT_COMMIT)"

.PHONY: build-adapter
build-adapter: generate-api pkg/scalers/liiklus/LiiklusService.pb.go
$(GO_BUILD_VARS) go build \
-ldflags "-X=main.GitCommit=$(GIT_COMMIT)" \
-o build/_output/bin/keda-adapter \
cmd/adapter/main.go
docker build -f build/Dockerfile.adapter -t $(IMAGE_ADAPTER) .

.PHONY: generate-api
generate-api:
$(GO_BUILD_VARS) operator-sdk generate k8s
$(GO_BUILD_VARS) operator-sdk generate openapi

pkg/scalers/liiklus/LiiklusService.pb.go: hack/LiiklusService.proto
protoc -I hack/ hack/LiiklusService.proto --go_out=plugins=grpc:pkg/scalers/liiklus

pkg/scalers/liiklus/mocks/mock_liiklus.go: pkg/scalers/liiklus/LiiklusService.pb.go
mockgen github.com/kedacore/keda/pkg/scalers/liiklus LiiklusServiceClient > pkg/scalers/liiklus/mocks/mock_liiklus.go

APIS_FILES = $(shell find pkg/apis -type f)
GEN_SCRIPT = $(shell find hack/ -type f)

.PHONY: codegen
$(GENERATED) codegen: $(APIS_FILES) $(GEN_SCRIPT)
hack/generate-groups.sh

##################################################
# Helm Chart tasks #
##################################################
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ func kubernetes install --namespace keda
```

### Deploying using the deploy yaml
If you want to try KEDA on minikube or a different Kubernetes deployment without using Helm, you can deploy the yaml under the `/deploy` directory.
If you want to try KEDA on minikube or a different Kubernetes deployment without using Helm, you can deploy CRD and yamls under the `/deploy` directory.
```
kubectl apply -f KedaScaleController.yaml
kubectl apply -f deploy/crds/keda.k8s.io_scaledobjects_crd.yaml
kubectl apply -f deploy/crds/keda.k8s.io_triggerauthentications_crd.yaml
kubectl apply -f deploy/
```

## How KEDA works
Expand Down Expand Up @@ -130,12 +132,12 @@ Zoom link: [https://zoom.us/j/150360492 ](https://zoom.us/j/150360492 )
Meeting agenda: [https://hackmd.io/s/r127ErYiN](https://hackmd.io/s/r127ErYiN)

## Building
This project is using [Operator SDK framework](https://github.com/operator-framework/operator-sdk) v0.11.0.

```bash
git clone git@github.com:kedacore/keda.git
cd keda
make build
./dist/keda
```

# Contributing
Expand Down
15 changes: 15 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest

ENV OPERATOR=/usr/local/bin/keda \
USER_UID=1001 \
USER_NAME=keda

# install operator binary
COPY build/_output/bin/keda ${OPERATOR}

COPY build/bin /usr/local/bin
RUN /usr/local/bin/user_setup

ENTRYPOINT ["/usr/local/bin/entrypoint"]

USER ${USER_UID}
19 changes: 19 additions & 0 deletions build/Dockerfile.adapter
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest

ENV OPERATOR=/usr/local/bin/keda-adapter \
USER_UID=1001 \
USER_NAME=keda

COPY build/_output/bin/keda-adapter ${OPERATOR}

COPY build/bin /usr/local/bin
RUN /usr/local/bin/user_setup && \
mkdir /adapter && \
chmod 777 /adapter && \
chmod +x ${OPERATOR}

WORKDIR /adapter

ENTRYPOINT ["/usr/local/bin/entrypoint", "--secure-port=6443", "--logtostderr=true", "--v=2"]

USER ${USER_UID}
82 changes: 82 additions & 0 deletions cmd/adapter/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package main

import (
"flag"
"os"

"github.com/kedacore/keda/pkg/handler"
kedaprovider "github.com/kedacore/keda/pkg/provider"

"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/component-base/logs"
"k8s.io/klog"

kedav1alpha1 "github.com/kedacore/keda/pkg/apis/keda/v1alpha1"
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"

basecmd "github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/cmd"
"github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider"
)

// Adapter creates External Metrics Provider
type Adapter struct {
basecmd.AdapterBase

// Message is printed on succesful startup
Message string
}

func (a *Adapter) makeProviderOrDie() provider.MetricsProvider {

// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
klog.Fatalf("failed to get the config: %v", err)
}

scheme := scheme.Scheme
if err := appsv1.SchemeBuilder.AddToScheme(scheme); err != nil {
klog.Fatalf("failed to add apps/v1 scheme to runtime scheme: (%v)", err)
}
if err := kedav1alpha1.SchemeBuilder.AddToScheme(scheme); err != nil {
klog.Fatalf("failed to add keda scheme to runtime scheme: (%v)", err)
}

kubeclient, err := client.New(cfg, client.Options{
Scheme: scheme,
})
if err != nil {
klog.Fatalf("unable to construct new client: %v", err)
}

handler := handler.NewScaleHandler(kubeclient, scheme)

namespace, err := k8sutil.GetWatchNamespace()
if err != nil {
klog.Fatalf("failed to get watch namespace: %v", err)
}

return kedaprovider.NewProvider(handler, kubeclient, namespace)
}

func main() {
logs.InitLogs()
defer logs.FlushLogs()

cmd := &Adapter{}
cmd.Flags().StringVar(&cmd.Message, "msg", "starting adapter...", "startup message")
cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure we get the klog flags
cmd.Flags().Parse(os.Args)

kedaProvider := cmd.makeProviderOrDie()
cmd.WithExternalMetrics(kedaProvider)

klog.Infof(cmd.Message)
if err := cmd.Run(wait.NeverStop); err != nil {
klog.Fatalf("unable to run external metrics adapter: %v", err)
}
}
66 changes: 0 additions & 66 deletions cmd/main.go

This file was deleted.

Loading

0 comments on commit 8b62b50

Please sign in to comment.