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

Add openapi spec #1512

Merged
merged 12 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
restore-keys: |
${{ runner.os }}-go-

- name: Go modules sync
run: go mod tidy

- name: Verify Generated clientset is up to date
run: make clientset-verify

Expand Down
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ issues:
- path: _finalizer.go
linters:
- interfacer

# Excluding the stackdriver_client scaler until it is fixed: https://github.com/kedacore/keda/pull/1512#issuecomment-763454243
- path: pkg/scalers/stackdriver_client.go
linters:
- staticcheck
# https://github.com/go-critic/go-critic/issues/926
- linters:
- gocritic
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
- Improve performance when fetching current scaling information on Deployments ([#1458](https://github.com/kedacore/keda/pull/1458))
- Improve error reporting in prometheus scaler ([#1497](https://github.com/kedacore/keda/pull/1497))
- Check that metricNames are unique in ScaledObject ([#1390](https://github.com/kedacore/keda/pull/1390))
- Serve OpenAPI spec from KEDA Metrics Apiserver ([#1512](https://github.com/kedacore/keda/pull/1512))

### Breaking Changes

Expand Down
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,20 @@ manifests: controller-gen

# Generate code (API)
.PHONY: generate
generate: controller-gen
generate: controller-gen adapter/generated/openapi/zz_generated.openapi.go
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

adapter/generated/openapi/zz_generated.openapi.go: go.mod go.sum
@OPENAPI_PATH=`go list -mod=readonly -m -f '{{.Dir}}' k8s.io/kube-openapi`; \
go run $${OPENAPI_PATH}/cmd/openapi-gen/openapi-gen.go --logtostderr \
zroubalik marked this conversation as resolved.
Show resolved Hide resolved
-i k8s.io/metrics/pkg/apis/custom_metrics,k8s.io/metrics/pkg/apis/custom_metrics/v1beta1,k8s.io/metrics/pkg/apis/custom_metrics/v1beta2,k8s.io/metrics/pkg/apis/external_metrics,k8s.io/metrics/pkg/apis/external_metrics/v1beta1,k8s.io/metrics/pkg/apis/metrics,k8s.io/metrics/pkg/apis/metrics/v1beta1,k8s.io/apimachinery/pkg/apis/meta/v1,k8s.io/apimachinery/pkg/api/resource,k8s.io/apimachinery/pkg/version,k8s.io/api/core/v1 \
--build-tag autogenerated \
-h ./hack/boilerplate.go.txt \
-p ./adapter/generated/openapi \
-O zz_generated.openapi \
-o ./ \
-r /dev/null

# find or download controller-gen
# download controller-gen if necessary
.PHONY: controller-gen
Expand Down
14,631 changes: 14,631 additions & 0 deletions adapter/generated/openapi/zz_generated.openapi.go

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions adapter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ import (

appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/util/wait"
openapinamer "k8s.io/apiserver/pkg/endpoints/openapi"
genericapiserver "k8s.io/apiserver/pkg/server"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog"
"k8s.io/klog/klogr"
"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"
basecmd "github.com/kubernetes-sigs/custom-metrics-apiserver/pkg/cmd"
"github.com/kubernetes-sigs/custom-metrics-apiserver/pkg/provider"

generatedopenapi "github.com/kedacore/keda/v2/adapter/generated/openapi"
kedav1alpha1 "github.com/kedacore/keda/v2/api/v1alpha1"
prommetrics "github.com/kedacore/keda/v2/pkg/metrics"
kedaprovider "github.com/kedacore/keda/v2/pkg/provider"
Expand Down Expand Up @@ -111,6 +114,11 @@ func main() {
printVersion()

cmd := &Adapter{}

cmd.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(generatedopenapi.GetOpenAPIDefinitions, openapinamer.NewDefinitionNamer(scheme.Scheme))
cmd.OpenAPIConfig.Info.Title = "keda-adapter"
cmd.OpenAPIConfig.Info.Version = "1.0.0"
zroubalik marked this conversation as resolved.
Show resolved Hide resolved

cmd.Flags().StringVar(&cmd.Message, "msg", "starting adapter...", "startup message")
cmd.Flags().AddGoFlagSet(flag.CommandLine) // make sure we get the klog flags
cmd.Flags().IntVar(&prometheusMetricsPort, "metrics-port", 9022, "Set the port to expose prometheus metrics")
Expand Down
40 changes: 17 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ require (
github.com/Huawei/gophercloud v1.0.21
github.com/Shopify/sarama v1.27.2
github.com/aws/aws-sdk-go v1.36.19
github.com/go-logr/logr v0.1.0
github.com/go-logr/logr v0.3.0
github.com/go-logr/zapr v0.3.0 // indirect
github.com/go-openapi/spec v0.20.0
github.com/go-redis/redis v6.15.9+incompatible
github.com/go-sql-driver/mysql v1.5.0
github.com/golang/mock v1.4.4
Expand All @@ -24,7 +26,7 @@ require (
github.com/hashicorp/vault/api v1.0.4
github.com/imdario/mergo v0.3.11
github.com/influxdata/influxdb-client-go/v2 v2.2.1
github.com/kubernetes-incubator/custom-metrics-apiserver v0.0.0-20200618121405-54026617ec44
github.com/kubernetes-sigs/custom-metrics-apiserver v0.0.0-20201216091021-1b9fa998bbaa
github.com/lib/pq v1.9.0
github.com/mitchellh/hashstructure v1.1.0
github.com/onsi/ginkgo v1.14.2
Expand All @@ -39,31 +41,23 @@ require (
go.mongodb.org/mongo-driver v1.1.2
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 // indirect
google.golang.org/api v0.36.0
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d
google.golang.org/genproto v0.0.0-20201203001206-6486ece9c497
google.golang.org/grpc v1.34.0
k8s.io/api v0.18.8
k8s.io/apimachinery v0.18.8
k8s.io/client-go v12.0.0+incompatible
k8s.io/code-generator v0.18.8
k8s.io/api v0.20.2
k8s.io/apimachinery v0.20.2
k8s.io/apiserver v0.20.2
k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible
k8s.io/code-generator v0.20.0
k8s.io/klog v1.0.0
k8s.io/metrics v0.18.8
k8s.io/kube-openapi v0.0.0-20201113171705-d219536bb9fd
k8s.io/metrics v0.20.0
knative.dev/pkg v0.0.0-20201019114258-95e9532f0457
sigs.k8s.io/controller-runtime v0.6.4
)

replace (
k8s.io/apiserver => k8s.io/apiserver v0.18.8 // Required by kubernetes-incubator/custom-metrics-apiserver
k8s.io/client-go => k8s.io/client-go v0.18.8
)

// Required to resolve go/grpc issues
// (grpc version needed by k8s.io/apiserver vs kubernetes-incubator/custom-metrics-apiserver)
replace (
cloud.google.com/go => cloud.google.com/go v0.48.0
google.golang.org/api => google.golang.org/api v0.15.1
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20191002211648-c459b9ce5143
google.golang.org/grpc => google.golang.org/grpc v1.26.0
)
replace k8s.io/client-go => k8s.io/client-go v0.20.2

// Required for k8s.io/apiserver, using k8s.io/kube-openapi branch release-1.18
replace k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6
// adapter uses k8s.io/apiserver/pkg/server, which indirectly uses go.etcd.io/etcd/proxy/grpcproxy.
// etcd is not compatible with newer grpc version, see here https://github.com/etcd-io/etcd/issues/12124
// so until that is fixed, we will pin the grpc version to v1.29.1
replace google.golang.org/grpc => google.golang.org/grpc v1.29.1
Loading