mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2025-05-13 08:51:58 +00:00
Compare commits
3 Commits
scheduled-
...
feature/k8
Author | SHA1 | Date | |
---|---|---|---|
417f650caa | |||
37003d6513 | |||
b685c7db1c |
@ -1,19 +0,0 @@
|
|||||||
run:
|
|
||||||
linters-settings:
|
|
||||||
golint:
|
|
||||||
min-confidence: 0.9
|
|
||||||
|
|
||||||
linters:
|
|
||||||
disable-all: true
|
|
||||||
enable:
|
|
||||||
- staticcheck
|
|
||||||
- ineffassign
|
|
||||||
- golint
|
|
||||||
- goimports
|
|
||||||
- errcheck
|
|
||||||
issues:
|
|
||||||
exclude-rules:
|
|
||||||
# Exclude some staticcheck messages
|
|
||||||
- linters:
|
|
||||||
- staticcheck
|
|
||||||
text: "SA9003:"
|
|
10
.travis.yml
10
.travis.yml
@ -2,19 +2,17 @@ language: go
|
|||||||
dist: xenial
|
dist: xenial
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- "1.13.x"
|
- "1.11.x"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
- GO111MODULE=on GOLANGCI_RELEASE="v1.21.0"
|
- GO111MODULE=on
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- GO111MODULE=off go get github.com/mattn/goveralls
|
- go get github.com/mattn/goveralls
|
||||||
- GO111MODULE=off go get github.com/lawrencewoodman/roveralls
|
- go get github.com/lawrencewoodman/roveralls
|
||||||
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_RELEASE}
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- make test
|
- make test
|
||||||
- make build.docker
|
- make build.docker
|
||||||
- make check
|
|
||||||
- roveralls
|
- roveralls
|
||||||
- goveralls -v -coverprofile=roveralls.coverprofile -service=travis-ci
|
- goveralls -v -coverprofile=roveralls.coverprofile -service=travis-ci
|
||||||
|
4
Makefile
4
Makefile
@ -19,8 +19,8 @@ test:
|
|||||||
go test -v $(GOPKGS)
|
go test -v $(GOPKGS)
|
||||||
|
|
||||||
check:
|
check:
|
||||||
go mod download
|
golint $(GOPKGS)
|
||||||
golangci-lint run --timeout=2m ./...
|
go vet -v $(GOPKGS)
|
||||||
|
|
||||||
build.local: build/$(BINARY)
|
build.local: build/$(BINARY)
|
||||||
build.linux: build/linux/$(BINARY)
|
build.linux: build/linux/$(BINARY)
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
We acknowledge that every line of code that we write may potentially contain security issues.
|
We acknowledge that every line of code that we write may potentially contain security issues.
|
||||||
We are trying to deal with it responsibly and provide patches as quickly as possible.
|
|
||||||
|
|
||||||
We host our bug bounty program on HackerOne, it is currently private, therefore if you would like to report a vulnerability and get rewarded for it, please ask to join our program by filling this form:
|
We are trying to deal with it responsibly and provide patches as quickly as possible. If you have anything to report to us please use the following channels:
|
||||||
|
|
||||||
https://corporate.zalando.com/en/services-and-contact#security-form
|
Email: Tech-Security@zalando.de
|
||||||
|
OR
|
||||||
You can also send you report via this form if you do not want to join our bug bounty program and just want to report a vulnerability or security issue.
|
Submit your vulnerability report through our bug bounty program at: https://hackerone.com/zalando
|
||||||
|
@ -2,13 +2,7 @@ version: "2017-09-20"
|
|||||||
pipeline:
|
pipeline:
|
||||||
- id: build
|
- id: build
|
||||||
overlay: ci/golang
|
overlay: ci/golang
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- /go/pkg/mod # pkg cache for Go modules
|
|
||||||
- ~/.cache/go-build # Go build cache
|
|
||||||
type: script
|
type: script
|
||||||
env:
|
|
||||||
GOFLAGS: "-mod=readonly"
|
|
||||||
commands:
|
commands:
|
||||||
- desc: test
|
- desc: test
|
||||||
cmd: |
|
cmd: |
|
||||||
@ -20,11 +14,7 @@ pipeline:
|
|||||||
cmd: |
|
cmd: |
|
||||||
if [[ $CDP_TARGET_BRANCH == master && ! $CDP_PULL_REQUEST_NUMBER ]]; then
|
if [[ $CDP_TARGET_BRANCH == master && ! $CDP_PULL_REQUEST_NUMBER ]]; then
|
||||||
IMAGE=registry-write.opensource.zalan.do/teapot/kube-metrics-adapter
|
IMAGE=registry-write.opensource.zalan.do/teapot/kube-metrics-adapter
|
||||||
VERSION=$(git describe --tags --always)
|
|
||||||
else
|
else
|
||||||
IMAGE=registry-write.opensource.zalan.do/teapot/kube-metrics-adapter-test
|
IMAGE=registry-write.opensource.zalan.do/teapot/kube-metrics-adapter-test
|
||||||
VERSION=$CDP_BUILD_VERSION
|
|
||||||
fi
|
fi
|
||||||
IMAGE=$IMAGE VERSION=$VERSION make build.docker
|
IMAGE=$IMAGE VERSION=$CDP_BUILD_VERSION make build.push
|
||||||
git diff --stat --exit-code
|
|
||||||
IMAGE=$IMAGE VERSION=$VERSION make build.push
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
apiVersion: autoscaling/v2beta2
|
apiVersion: autoscaling/v2beta1
|
||||||
kind: HorizontalPodAutoscaler
|
kind: HorizontalPodAutoscaler
|
||||||
metadata:
|
metadata:
|
||||||
name: custom-metrics-consumer
|
name: custom-metrics-consumer
|
||||||
@ -25,36 +25,24 @@ spec:
|
|||||||
# - type: Resource
|
# - type: Resource
|
||||||
# resource:
|
# resource:
|
||||||
# name: cpu
|
# name: cpu
|
||||||
# current:
|
# targetAverageUtilization: 50
|
||||||
# averageUtilization: 50
|
|
||||||
|
|
||||||
- type: Pods
|
- type: Pods
|
||||||
pods:
|
pods:
|
||||||
metric:
|
metricName: queue-length
|
||||||
name: queue-length
|
targetAverageValue: 1k
|
||||||
target:
|
|
||||||
averageValue: 1k
|
|
||||||
type: AverageValue
|
|
||||||
|
|
||||||
- type: Object
|
- type: Object
|
||||||
object:
|
object:
|
||||||
describedObject:
|
metricName: requests-per-second
|
||||||
|
target:
|
||||||
apiVersion: extensions/v1beta1
|
apiVersion: extensions/v1beta1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
name: custom-metrics-consumer
|
name: custom-metrics-consumer
|
||||||
metric:
|
targetValue: 10 # this will be treated as targetAverageValue
|
||||||
name: requests-per-second
|
|
||||||
target:
|
|
||||||
averageValue: "10"
|
|
||||||
type: AverageValue
|
|
||||||
- type: External
|
- type: External
|
||||||
external:
|
external:
|
||||||
metric:
|
metricName: sqs-queue-length
|
||||||
name: sqs-queue-length
|
metricSelector:
|
||||||
selector:
|
matchLabels:
|
||||||
matchLabels:
|
queue-name: foobar
|
||||||
queue-name: foobar
|
region: eu-central-1
|
||||||
region: eu-central-1
|
targetAverageValue: 30
|
||||||
target:
|
|
||||||
averageValue: "30"
|
|
||||||
type: AverageValue
|
|
||||||
|
@ -3,15 +3,13 @@ package main
|
|||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func metricsHandler(w http.ResponseWriter, r *http.Request) {
|
func metricsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(200)
|
w.WriteHeader(200)
|
||||||
_, err := w.Write([]byte(fmt.Sprintf(`{"queue": {"length": %d}}`, size)))
|
w.Write([]byte(fmt.Sprintf(`{"queue": {"length": %d}}`, size)))
|
||||||
log.Fatalf("failed to write: %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -31,5 +29,5 @@ func main() {
|
|||||||
ReadTimeout: 5 * time.Second,
|
ReadTimeout: 5 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Fatal(server.ListenAndServe())
|
server.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
96
go.mod
96
go.mod
@ -1,33 +1,93 @@
|
|||||||
module github.com/zalando-incubator/kube-metrics-adapter
|
module github.com/zalando-incubator/kube-metrics-adapter
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
bitbucket.org/ww/goautoneg v0.0.0-20120707110453-75cd24fc2f2c // indirect
|
||||||
|
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
|
||||||
|
github.com/BurntSushi/toml v0.3.0 // indirect
|
||||||
github.com/NYTimes/gziphandler v1.0.1 // indirect
|
github.com/NYTimes/gziphandler v1.0.1 // indirect
|
||||||
github.com/aws/aws-sdk-go v1.29.4
|
github.com/PuerkitoBio/purell v1.1.0 // indirect
|
||||||
|
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
|
||||||
|
github.com/Sirupsen/logrus v1.0.6 // indirect
|
||||||
|
github.com/aws/aws-sdk-go v1.16.6
|
||||||
|
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
|
||||||
|
github.com/boltdb/bolt v1.3.1 // indirect
|
||||||
|
github.com/coreos/bbolt v1.3.0 // indirect
|
||||||
|
github.com/coreos/etcd v3.3.9+incompatible // indirect
|
||||||
|
github.com/coreos/go-semver v0.2.0 // indirect
|
||||||
github.com/coreos/go-systemd v0.0.0-20180705093442-88bfeed483d3 // indirect
|
github.com/coreos/go-systemd v0.0.0-20180705093442-88bfeed483d3 // indirect
|
||||||
|
github.com/coreos/pkg v0.0.0-20180108230652-97fdf19511ea // indirect
|
||||||
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
|
||||||
|
github.com/docker/docker v1.13.1 // indirect
|
||||||
|
github.com/elazarl/go-bindata-assetfs v1.0.0 // indirect
|
||||||
|
github.com/emicklei/go-restful v2.8.0+incompatible // indirect
|
||||||
|
github.com/emicklei/go-restful-swagger12 v0.0.0-20170926063155-7524189396c6 // indirect
|
||||||
|
github.com/evanphx/json-patch v3.0.0+incompatible // indirect
|
||||||
|
github.com/fsnotify/fsnotify v1.4.7 // indirect
|
||||||
|
github.com/ghodss/yaml v1.0.0 // indirect
|
||||||
|
github.com/go-openapi/jsonpointer v0.0.0-20180322222829-3a0015ad55fa // indirect
|
||||||
|
github.com/go-openapi/jsonreference v0.0.0-20180322222742-3fb327e6747d // indirect
|
||||||
|
github.com/go-openapi/spec v0.0.0-20180801175345-384415f06ee2 // indirect
|
||||||
|
github.com/go-openapi/swag v0.0.0-20180715190254-becd2f08beaf // indirect
|
||||||
|
github.com/gogo/protobuf v1.1.1 // indirect
|
||||||
|
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
|
||||||
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 // indirect
|
github.com/golang/groupcache v0.0.0-20180513044358-24b0969c4cb7 // indirect
|
||||||
|
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c // indirect
|
||||||
|
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
|
||||||
github.com/googleapis/gnostic v0.2.0 // indirect
|
github.com/googleapis/gnostic v0.2.0 // indirect
|
||||||
|
github.com/gorilla/websocket v1.3.0 // indirect
|
||||||
|
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
|
||||||
|
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.4.1 // indirect
|
github.com/grpc-ecosystem/grpc-gateway v1.4.1 // indirect
|
||||||
github.com/influxdata/influxdb-client-go v0.1.4
|
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47 // indirect
|
||||||
github.com/kubernetes-incubator/custom-metrics-apiserver v0.0.0-20190918110929-3d9be26a50eb
|
github.com/hpcloud/tail v1.0.0 // indirect
|
||||||
|
github.com/imdario/mergo v0.3.6 // indirect
|
||||||
|
github.com/inconshreveable/mousetrap v1.0.0 // indirect
|
||||||
|
github.com/jonboulle/clockwork v0.1.0 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.5 // indirect
|
||||||
|
github.com/kubernetes-incubator/custom-metrics-apiserver v0.0.0-20190103205038-2655ce32a120
|
||||||
|
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 // indirect
|
||||||
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||||
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852
|
github.com/oliveagle/jsonpath v0.0.0-20180606110733-2e52cf6e6852
|
||||||
github.com/prometheus/client_golang v0.9.2
|
github.com/onsi/ginkgo v1.6.0 // indirect
|
||||||
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275
|
github.com/onsi/gomega v1.4.1 // indirect
|
||||||
github.com/sirupsen/logrus v1.4.2
|
github.com/pborman/uuid v0.0.0-20180122190007-c65b2f87fee3 // indirect
|
||||||
|
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
|
||||||
|
github.com/prometheus/client_golang v0.9.0-pre1.0.20180824101016-4eb539fa85a2
|
||||||
|
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 // indirect
|
||||||
|
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e
|
||||||
|
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273 // indirect
|
||||||
|
github.com/sirupsen/logrus v1.3.0
|
||||||
github.com/soheilhy/cmux v0.1.4 // indirect
|
github.com/soheilhy/cmux v0.1.4 // indirect
|
||||||
github.com/spf13/cobra v0.0.3
|
github.com/spf13/cobra v0.0.3
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/spf13/pflag v1.0.2 // indirect
|
||||||
|
github.com/stretchr/testify v1.2.2
|
||||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6 // indirect
|
github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6 // indirect
|
||||||
|
github.com/ugorji/go v1.1.1 // indirect
|
||||||
|
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 // indirect
|
||||||
github.com/zalando-incubator/cluster-lifecycle-manager v0.0.0-20180921141935-824b77fb1f84
|
github.com/zalando-incubator/cluster-lifecycle-manager v0.0.0-20180921141935-824b77fb1f84
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
|
golang.org/x/crypto v0.0.0-20181015023909-0c41d7ab0a0e // indirect
|
||||||
|
golang.org/x/net v0.0.0-20180824152047-4bcd98cce591 // indirect
|
||||||
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect
|
||||||
|
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
|
||||||
|
google.golang.org/appengine v1.2.0 // indirect
|
||||||
|
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 // indirect
|
||||||
|
google.golang.org/grpc v1.14.0 // indirect
|
||||||
|
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
|
||||||
|
gopkg.in/fsnotify.v1 v1.4.7 // indirect
|
||||||
|
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
|
||||||
gopkg.in/inf.v0 v0.9.1 // indirect
|
gopkg.in/inf.v0 v0.9.1 // indirect
|
||||||
k8s.io/api v0.0.0-20190918155943-95b840bb6a1f
|
gopkg.in/natefinch/lumberjack.v2 v2.0.0-20170531160350-a96e63847dc3 // indirect
|
||||||
k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655
|
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||||
k8s.io/apiserver v0.0.0-20190918160949-bfa5e2e684ad // indirect
|
gopkg.in/yaml.v2 v2.2.1 // indirect
|
||||||
k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90
|
k8s.io/api v0.0.0-20181128191700-6db15a15d2d3
|
||||||
k8s.io/code-generator v0.17.4
|
k8s.io/apimachinery v0.0.0-20190104073114-849b284f3b75
|
||||||
k8s.io/component-base v0.0.0-20190918160511-547f6c5d7090
|
k8s.io/apiserver v0.0.0-20181207191401-9601a7bf41ef
|
||||||
k8s.io/klog v1.0.0
|
k8s.io/client-go v2.0.0-alpha.0.0.20181126152608-d082d5923d3c+incompatible
|
||||||
k8s.io/metrics v0.0.0-20190226180357-f3f09b9076d1
|
k8s.io/klog v0.1.0 // indirect
|
||||||
|
k8s.io/kube-openapi v0.0.0-20180731170545-e3762e86a74c // indirect
|
||||||
|
k8s.io/metrics v0.0.0-20181217194040-83acca0c921f
|
||||||
|
sigs.k8s.io/yaml v1.1.0 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
go 1.13
|
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright YEAR The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
@ -1,5 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
_ "k8s.io/code-generator"
|
|
||||||
)
|
|
@ -1,48 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Copyright 2017 The Kubernetes Authors.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
set -x
|
|
||||||
SRC="github.com"
|
|
||||||
GOPKG="$SRC/zalando-incubator/kube-metrics-adapter"
|
|
||||||
CUSTOM_RESOURCE_NAME="zalando.org"
|
|
||||||
CUSTOM_RESOURCE_VERSION="v1"
|
|
||||||
|
|
||||||
SCRIPT_ROOT="$(dirname ${BASH_SOURCE[0]})/.."
|
|
||||||
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
|
|
||||||
OUTPUT_BASE="$(dirname ${BASH_SOURCE})/"
|
|
||||||
|
|
||||||
go mod vendor
|
|
||||||
|
|
||||||
# generate the code with:
|
|
||||||
# --output-base because this script should also be able to run inside the vendor dir of
|
|
||||||
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
|
|
||||||
# instead of the $GOPATH directly. For normal projects this can be dropped.
|
|
||||||
bash "${CODEGEN_PKG}"/generate-groups.sh all \
|
|
||||||
"${GOPKG}/pkg/client" "${GOPKG}/pkg/apis" \
|
|
||||||
"${CUSTOM_RESOURCE_NAME}:${CUSTOM_RESOURCE_VERSION}" \
|
|
||||||
--go-header-file hack/boilerplate.go.txt \
|
|
||||||
--output-base "$OUTPUT_BASE"
|
|
||||||
|
|
||||||
# To use your own boilerplate text append:
|
|
||||||
# --go-header-file ${SCRIPT_ROOT}/hack/custom-boilerplate.go.txt
|
|
||||||
|
|
||||||
# hack to make the generated code work with Go module based projects
|
|
||||||
cp -r "$OUTPUT_BASE/$GOPKG/pkg/apis" ./pkg
|
|
||||||
cp -r "$OUTPUT_BASE/$GOPKG/pkg/client" ./pkg
|
|
||||||
rm -rf "${OUTPUT_BASE:?}${SRC}"
|
|
@ -1,40 +0,0 @@
|
|||||||
# Skipper Prometheus Metrics Collection
|
|
||||||
|
|
||||||
The skipper-ingress pods should be configured to be scraped by Prometheus. This
|
|
||||||
can be done by Prometheus service discovery using discovery of Kubernetes services
|
|
||||||
or Kubernetes pods:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
annotations:
|
|
||||||
prometheus.io/path: /metrics
|
|
||||||
prometheus.io/port: "9911"
|
|
||||||
prometheus.io/scrape: "true"
|
|
||||||
labels:
|
|
||||||
application: skipper-ingress
|
|
||||||
name: skipper-ingress
|
|
||||||
spec:
|
|
||||||
ports:
|
|
||||||
- port: 80
|
|
||||||
protocol: TCP
|
|
||||||
targetPort: 9999
|
|
||||||
selector:
|
|
||||||
application: skipper-ingress
|
|
||||||
type: ClusterIP
|
|
||||||
```
|
|
||||||
This [configuration](https://github.com/zalando-incubator/kubernetes-on-aws/blob/dev/cluster/manifests/prometheus/configmap.yaml#L69)
|
|
||||||
shows how prometheus is configured in our clusters to scrape service endpoints.
|
|
||||||
The annotations `prometheus.io/path`, `prometheus.io/port` and `prometheus.io/scrape`
|
|
||||||
instruct Prometheus to scrape all pods of this service on the port _9911_ and
|
|
||||||
the path `/metrics`.
|
|
||||||
|
|
||||||
When the `kube-metrics-adapter` is started the flag `--prometheus-server` should be set so that
|
|
||||||
the adapter can query prometheus to get aggregated metrics. When running in kubernetes it can
|
|
||||||
be the service address of the prometheus service like `http://prometheus.kube-system`.
|
|
||||||
|
|
||||||
With these settings the `kube-metrics-adapter` can provide `request-per-second` metrics for ingress
|
|
||||||
objects which are present in the cluster. The prometheus instances scrape the metrics from
|
|
||||||
the `skipper-ingress` pods. The adapter then queries prometheus to get the metric and then
|
|
||||||
provides them to the API server when requested.
|
|
3
main.go
3
main.go
@ -18,13 +18,12 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
_ "net/http/pprof"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"github.com/zalando-incubator/kube-metrics-adapter/pkg/server"
|
"github.com/zalando-incubator/kube-metrics-adapter/pkg/server"
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/component-base/logs"
|
"k8s.io/apiserver/pkg/util/logs"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -1,101 +0,0 @@
|
|||||||
package annotations
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
customMetricsPrefix = "metric-config."
|
|
||||||
perReplicaMetricsConfKey = "per-replica"
|
|
||||||
intervalMetricsConfKey = "interval"
|
|
||||||
)
|
|
||||||
|
|
||||||
type AnnotationConfigs struct {
|
|
||||||
CollectorName string
|
|
||||||
Configs map[string]string
|
|
||||||
PerReplica bool
|
|
||||||
Interval time.Duration
|
|
||||||
}
|
|
||||||
|
|
||||||
type MetricConfigKey struct {
|
|
||||||
Type autoscalingv2.MetricSourceType
|
|
||||||
MetricName string
|
|
||||||
}
|
|
||||||
|
|
||||||
type AnnotationConfigMap map[MetricConfigKey]*AnnotationConfigs
|
|
||||||
|
|
||||||
func (m AnnotationConfigMap) Parse(annotations map[string]string) error {
|
|
||||||
for key, val := range annotations {
|
|
||||||
if !strings.HasPrefix(key, customMetricsPrefix) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
parts := strings.Split(key, "/")
|
|
||||||
if len(parts) != 2 {
|
|
||||||
// TODO: error?
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
configs := strings.Split(parts[0], ".")
|
|
||||||
if len(configs) != 4 {
|
|
||||||
// TODO: error?
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
key := MetricConfigKey{
|
|
||||||
MetricName: configs[2],
|
|
||||||
}
|
|
||||||
|
|
||||||
switch configs[1] {
|
|
||||||
case "pods":
|
|
||||||
key.Type = autoscalingv2.PodsMetricSourceType
|
|
||||||
case "object":
|
|
||||||
key.Type = autoscalingv2.ObjectMetricSourceType
|
|
||||||
default:
|
|
||||||
key.Type = autoscalingv2.ExternalMetricSourceType
|
|
||||||
}
|
|
||||||
|
|
||||||
metricCollector := configs[3]
|
|
||||||
|
|
||||||
config, ok := m[key]
|
|
||||||
if !ok {
|
|
||||||
config = &AnnotationConfigs{
|
|
||||||
CollectorName: metricCollector,
|
|
||||||
Configs: map[string]string{},
|
|
||||||
}
|
|
||||||
m[key] = config
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: fail if collector name doesn't match
|
|
||||||
if config.CollectorName != metricCollector {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if parts[1] == perReplicaMetricsConfKey {
|
|
||||||
config.PerReplica = true
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if parts[1] == intervalMetricsConfKey {
|
|
||||||
interval, err := time.ParseDuration(val)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to parse interval value %s for %s: %v", val, key, err)
|
|
||||||
}
|
|
||||||
config.Interval = interval
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
config.Configs[parts[1]] = val
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m AnnotationConfigMap) GetAnnotationConfig(metricName string, metricType autoscalingv2.MetricSourceType) (*AnnotationConfigs, bool) {
|
|
||||||
key := MetricConfigKey{MetricName: metricName, Type: metricType}
|
|
||||||
config, ok := m[key]
|
|
||||||
return config, ok
|
|
||||||
}
|
|
@ -1,106 +0,0 @@
|
|||||||
package annotations
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestParser(t *testing.T) {
|
|
||||||
for _, tc := range []struct {
|
|
||||||
Name string
|
|
||||||
Annotations map[string]string
|
|
||||||
MetricName string
|
|
||||||
MetricType autoscalingv2.MetricSourceType
|
|
||||||
ExpectedConfig map[string]string
|
|
||||||
PerReplica bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
Name: "no annotations",
|
|
||||||
Annotations: map[string]string{},
|
|
||||||
ExpectedConfig: map[string]string{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "pod metrics",
|
|
||||||
Annotations: map[string]string{
|
|
||||||
"metric-config.pods.requests-per-second.json-path/json-key": "$.http_server.rps",
|
|
||||||
"metric-config.pods.requests-per-second.json-path/path": "/metrics",
|
|
||||||
"metric-config.pods.requests-per-second.json-path/port": "9090",
|
|
||||||
"metric-config.pods.requests-per-second.json-path/scheme": "https",
|
|
||||||
},
|
|
||||||
MetricName: "requests-per-second",
|
|
||||||
MetricType: autoscalingv2.PodsMetricSourceType,
|
|
||||||
ExpectedConfig: map[string]string{
|
|
||||||
"json-key": "$.http_server.rps",
|
|
||||||
"path": "/metrics",
|
|
||||||
"port": "9090",
|
|
||||||
"scheme": "https",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "prometheus metrics",
|
|
||||||
Annotations: map[string]string{
|
|
||||||
"metric-config.object.processed-events-per-second.prometheus/query": "scalar(sum(rate(event-service_events_count{application=\"event-service\",processed=\"true\"}[1m])))",
|
|
||||||
"metric-config.object.processed-events-per-second.prometheus/per-replica": "true",
|
|
||||||
},
|
|
||||||
MetricName: "processed-events-per-second",
|
|
||||||
MetricType: autoscalingv2.ObjectMetricSourceType,
|
|
||||||
ExpectedConfig: map[string]string{
|
|
||||||
"query": "scalar(sum(rate(event-service_events_count{application=\"event-service\",processed=\"true\"}[1m])))",
|
|
||||||
},
|
|
||||||
PerReplica: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "zmon collector",
|
|
||||||
Annotations: map[string]string{
|
|
||||||
"metric-config.external.zmon-check.zmon/key": "custom.*",
|
|
||||||
"metric-config.external.zmon-check.zmon/tag-application": "my-custom-app-*",
|
|
||||||
},
|
|
||||||
MetricName: "zmon-check",
|
|
||||||
MetricType: autoscalingv2.ExternalMetricSourceType,
|
|
||||||
ExpectedConfig: map[string]string{
|
|
||||||
"key": "custom.*",
|
|
||||||
"tag-application": "my-custom-app-*",
|
|
||||||
},
|
|
||||||
PerReplica: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "influxdb metrics",
|
|
||||||
Annotations: map[string]string{
|
|
||||||
"metric-config.external.flux-query.influxdb/range1m": `from(bucket: "?") |> range(start: -1m)`,
|
|
||||||
"metric-config.external.flux-query.influxdb/range2m": `from(bucket: "?") |> range(start: -2m)`,
|
|
||||||
"metric-config.external.flux-query.influxdb/range3m": `from(bucket: "?") |> range(start: -3m)`,
|
|
||||||
"metric-config.external.flux-query.influxdb/address": "http://localhost:9999",
|
|
||||||
"metric-config.external.flux-query.influxdb/token": "sEcr3TT0ken",
|
|
||||||
"metric-config.external.flux-query.influxdb/org-id": "deadbeef",
|
|
||||||
},
|
|
||||||
MetricName: "flux-query",
|
|
||||||
MetricType: autoscalingv2.ExternalMetricSourceType,
|
|
||||||
ExpectedConfig: map[string]string{
|
|
||||||
"range1m": `from(bucket: "?") |> range(start: -1m)`,
|
|
||||||
"range2m": `from(bucket: "?") |> range(start: -2m)`,
|
|
||||||
"range3m": `from(bucket: "?") |> range(start: -3m)`,
|
|
||||||
"address": "http://localhost:9999",
|
|
||||||
"token": "sEcr3TT0ken",
|
|
||||||
"org-id": "deadbeef",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
} {
|
|
||||||
t.Run(tc.Name, func(t *testing.T) {
|
|
||||||
hpaMap := make(AnnotationConfigMap)
|
|
||||||
err := hpaMap.Parse(tc.Annotations)
|
|
||||||
require.NoError(t, err)
|
|
||||||
config, present := hpaMap.GetAnnotationConfig(tc.MetricName, tc.MetricType)
|
|
||||||
if len(tc.ExpectedConfig) == 0 {
|
|
||||||
require.False(t, present)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
require.True(t, present)
|
|
||||||
for k, v := range tc.ExpectedConfig {
|
|
||||||
require.Equal(t, v, config.Configs[k])
|
|
||||||
}
|
|
||||||
require.Equal(t, tc.PerReplica, config.PerReplica)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package zalando
|
|
||||||
|
|
||||||
const (
|
|
||||||
// GroupName is the group name used in this package.
|
|
||||||
GroupName = "zalando.org"
|
|
||||||
)
|
|
@ -1,17 +0,0 @@
|
|||||||
package v1
|
|
||||||
|
|
||||||
import (
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
// +genclient
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
|
||||||
// +kubebuilder:object:root=true
|
|
||||||
|
|
||||||
// ScheduledScaling describes an application resource.
|
|
||||||
// +k8s:deepcopy-gen=true
|
|
||||||
type ScheduledScaling struct {
|
|
||||||
metav1.TypeMeta `json:",inline"`
|
|
||||||
metav1.ObjectMeta `json:"metadata,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
|||||||
// +build !ignore_autogenerated
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by deepcopy-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package v1
|
|
||||||
|
|
||||||
import (
|
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
|
||||||
func (in *ScheduledScaling) DeepCopyInto(out *ScheduledScaling) {
|
|
||||||
*out = *in
|
|
||||||
out.TypeMeta = in.TypeMeta
|
|
||||||
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScheduledScaling.
|
|
||||||
func (in *ScheduledScaling) DeepCopy() *ScheduledScaling {
|
|
||||||
if in == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
out := new(ScheduledScaling)
|
|
||||||
in.DeepCopyInto(out)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object.
|
|
||||||
func (in *ScheduledScaling) DeepCopyObject() runtime.Object {
|
|
||||||
if c := in.DeepCopy(); c != nil {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package versioned
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
zalandov1 "github.com/zalando-incubator/kube-metrics-adapter/pkg/client/clientset/versioned/typed/zalando.org/v1"
|
|
||||||
discovery "k8s.io/client-go/discovery"
|
|
||||||
rest "k8s.io/client-go/rest"
|
|
||||||
flowcontrol "k8s.io/client-go/util/flowcontrol"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Interface interface {
|
|
||||||
Discovery() discovery.DiscoveryInterface
|
|
||||||
ZalandoV1() zalandov1.ZalandoV1Interface
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clientset contains the clients for groups. Each group has exactly one
|
|
||||||
// version included in a Clientset.
|
|
||||||
type Clientset struct {
|
|
||||||
*discovery.DiscoveryClient
|
|
||||||
zalandoV1 *zalandov1.ZalandoV1Client
|
|
||||||
}
|
|
||||||
|
|
||||||
// ZalandoV1 retrieves the ZalandoV1Client
|
|
||||||
func (c *Clientset) ZalandoV1() zalandov1.ZalandoV1Interface {
|
|
||||||
return c.zalandoV1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Discovery retrieves the DiscoveryClient
|
|
||||||
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
|
|
||||||
if c == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return c.DiscoveryClient
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewForConfig creates a new Clientset for the given config.
|
|
||||||
// If config's RateLimiter is not set and QPS and Burst are acceptable,
|
|
||||||
// NewForConfig will generate a rate-limiter in configShallowCopy.
|
|
||||||
func NewForConfig(c *rest.Config) (*Clientset, error) {
|
|
||||||
configShallowCopy := *c
|
|
||||||
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
|
|
||||||
if configShallowCopy.Burst <= 0 {
|
|
||||||
return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0")
|
|
||||||
}
|
|
||||||
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
|
|
||||||
}
|
|
||||||
var cs Clientset
|
|
||||||
var err error
|
|
||||||
cs.zalandoV1, err = zalandov1.NewForConfig(&configShallowCopy)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &cs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewForConfigOrDie creates a new Clientset for the given config and
|
|
||||||
// panics if there is an error in the config.
|
|
||||||
func NewForConfigOrDie(c *rest.Config) *Clientset {
|
|
||||||
var cs Clientset
|
|
||||||
cs.zalandoV1 = zalandov1.NewForConfigOrDie(c)
|
|
||||||
|
|
||||||
cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c)
|
|
||||||
return &cs
|
|
||||||
}
|
|
||||||
|
|
||||||
// New creates a new Clientset for the given RESTClient.
|
|
||||||
func New(c rest.Interface) *Clientset {
|
|
||||||
var cs Clientset
|
|
||||||
cs.zalandoV1 = zalandov1.New(c)
|
|
||||||
|
|
||||||
cs.DiscoveryClient = discovery.NewDiscoveryClient(c)
|
|
||||||
return &cs
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
// This package has the automatically generated clientset.
|
|
||||||
package versioned
|
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package fake
|
|
||||||
|
|
||||||
import (
|
|
||||||
clientset "github.com/zalando-incubator/kube-metrics-adapter/pkg/client/clientset/versioned"
|
|
||||||
zalandov1 "github.com/zalando-incubator/kube-metrics-adapter/pkg/client/clientset/versioned/typed/zalando.org/v1"
|
|
||||||
fakezalandov1 "github.com/zalando-incubator/kube-metrics-adapter/pkg/client/clientset/versioned/typed/zalando.org/v1/fake"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
|
||||||
"k8s.io/client-go/discovery"
|
|
||||||
fakediscovery "k8s.io/client-go/discovery/fake"
|
|
||||||
"k8s.io/client-go/testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewSimpleClientset returns a clientset that will respond with the provided objects.
|
|
||||||
// It's backed by a very simple object tracker that processes creates, updates and deletions as-is,
|
|
||||||
// without applying any validations and/or defaults. It shouldn't be considered a replacement
|
|
||||||
// for a real clientset and is mostly useful in simple unit tests.
|
|
||||||
func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
|
||||||
o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
|
|
||||||
for _, obj := range objects {
|
|
||||||
if err := o.Add(obj); err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cs := &Clientset{tracker: o}
|
|
||||||
cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
|
|
||||||
cs.AddReactor("*", "*", testing.ObjectReaction(o))
|
|
||||||
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
|
|
||||||
gvr := action.GetResource()
|
|
||||||
ns := action.GetNamespace()
|
|
||||||
watch, err := o.Watch(gvr, ns)
|
|
||||||
if err != nil {
|
|
||||||
return false, nil, err
|
|
||||||
}
|
|
||||||
return true, watch, nil
|
|
||||||
})
|
|
||||||
|
|
||||||
return cs
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clientset implements clientset.Interface. Meant to be embedded into a
|
|
||||||
// struct to get a default implementation. This makes faking out just the method
|
|
||||||
// you want to test easier.
|
|
||||||
type Clientset struct {
|
|
||||||
testing.Fake
|
|
||||||
discovery *fakediscovery.FakeDiscovery
|
|
||||||
tracker testing.ObjectTracker
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
|
|
||||||
return c.discovery
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Clientset) Tracker() testing.ObjectTracker {
|
|
||||||
return c.tracker
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ clientset.Interface = &Clientset{}
|
|
||||||
|
|
||||||
// ZalandoV1 retrieves the ZalandoV1Client
|
|
||||||
func (c *Clientset) ZalandoV1() zalandov1.ZalandoV1Interface {
|
|
||||||
return &fakezalandov1.FakeZalandoV1{Fake: &c.Fake}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
// This package has the automatically generated fake clientset.
|
|
||||||
package fake
|
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package fake
|
|
||||||
|
|
||||||
import (
|
|
||||||
zalandov1 "github.com/zalando-incubator/kube-metrics-adapter/pkg/apis/zalando.org/v1"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
var scheme = runtime.NewScheme()
|
|
||||||
var codecs = serializer.NewCodecFactory(scheme)
|
|
||||||
var parameterCodec = runtime.NewParameterCodec(scheme)
|
|
||||||
var localSchemeBuilder = runtime.SchemeBuilder{
|
|
||||||
zalandov1.AddToScheme,
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
|
|
||||||
// of clientsets, like in:
|
|
||||||
//
|
|
||||||
// import (
|
|
||||||
// "k8s.io/client-go/kubernetes"
|
|
||||||
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
|
|
||||||
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
|
|
||||||
// )
|
|
||||||
//
|
|
||||||
// kclientset, _ := kubernetes.NewForConfig(c)
|
|
||||||
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
|
|
||||||
//
|
|
||||||
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
|
|
||||||
// correctly.
|
|
||||||
var AddToScheme = localSchemeBuilder.AddToScheme
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"})
|
|
||||||
utilruntime.Must(AddToScheme(scheme))
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
// This package contains the scheme of the automatically generated clientset.
|
|
||||||
package scheme
|
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package scheme
|
|
||||||
|
|
||||||
import (
|
|
||||||
zalandov1 "github.com/zalando-incubator/kube-metrics-adapter/pkg/apis/zalando.org/v1"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
runtime "k8s.io/apimachinery/pkg/runtime"
|
|
||||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
|
||||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Scheme = runtime.NewScheme()
|
|
||||||
var Codecs = serializer.NewCodecFactory(Scheme)
|
|
||||||
var ParameterCodec = runtime.NewParameterCodec(Scheme)
|
|
||||||
var localSchemeBuilder = runtime.SchemeBuilder{
|
|
||||||
zalandov1.AddToScheme,
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
|
|
||||||
// of clientsets, like in:
|
|
||||||
//
|
|
||||||
// import (
|
|
||||||
// "k8s.io/client-go/kubernetes"
|
|
||||||
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
|
|
||||||
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
|
|
||||||
// )
|
|
||||||
//
|
|
||||||
// kclientset, _ := kubernetes.NewForConfig(c)
|
|
||||||
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
|
|
||||||
//
|
|
||||||
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
|
|
||||||
// correctly.
|
|
||||||
var AddToScheme = localSchemeBuilder.AddToScheme
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
|
|
||||||
utilruntime.Must(AddToScheme(Scheme))
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
// This package has the automatically generated typed clients.
|
|
||||||
package v1
|
|
@ -1,20 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
// Package fake has the automatically generated clients.
|
|
||||||
package fake
|
|
@ -1,128 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2020 The Kubernetes Authors.
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Code generated by client-gen. DO NOT EDIT.
|
|
||||||
|
|
||||||
package fake
|
|
||||||
|
|
||||||
import (
|
|
||||||
zalandoorgv1 "github.com/zalando-incubator/kube-metrics-adapter/pkg/apis/zalando.org/v1"
|
|
||||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
labels "k8s.io/apimachinery/pkg/labels"
|
|
||||||
schema "k8s.io/apimachinery/pkg/runtime/schema"
|
|
||||||
types "k8s.io/apimachinery/pkg/types"
|
|
||||||
watch "k8s.io/apimachinery/pkg/watch"
|
|
||||||
testing "k8s.io/client-go/testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// FakeScheduledScalings implements ScheduledScalingInterface
|
|
||||||
type FakeScheduledScalings struct {
|
|
||||||
Fake *FakeZalandoV1
|
|
||||||
ns string
|
|
||||||
}
|
|
||||||
|
|
||||||
var scheduledscalingsResource = schema.GroupVersionResource{Group: "zalando.org", Version: "v1", Resource: "scheduledscalings"}
|
|
||||||
|
|
||||||
var scheduledscalingsKind = schema.GroupVersionKind{Group: "zalando.org", Version: "v1", Kind: "ScheduledScaling"}
|
|
||||||
|
|
||||||
// Get takes name of the scheduledScaling, and returns the corresponding scheduledScaling object, and an error if there is any.
|
|
||||||
func (c *FakeScheduledScalings) Get(name string, options v1.GetOptions) (result *zalandoorgv1.ScheduledScaling, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewGetAction(scheduledscalingsResource, c.ns, name), &zalandoorgv1.ScheduledScaling{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*zalandoorgv1.ScheduledScaling), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// List takes label and field selectors, and returns the list of ScheduledScalings that match those selectors.
|
|
||||||
func (c *FakeScheduledScalings) List(opts v1.ListOptions) (result *zalandoorgv1.ScheduledScalingList, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewListAction(scheduledscalingsResource, scheduledscalingsKind, c.ns, opts), &zalandoorgv1.ScheduledScalingList{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
label, _, _ := testing.ExtractFromListOptions(opts)
|
|
||||||
if label == nil {
|
|
||||||
label = labels.Everything()
|
|
||||||
}
|
|
||||||
list := &zalandoorgv1.ScheduledScalingList{ListMeta: obj.(*zalandoorgv1.ScheduledScalingList).ListMeta}
|
|
||||||
for _, item := range obj.(*zalandoorgv1.ScheduledScalingList).Items {
|
|
||||||
if label.Matches(labels.Set(item.Labels)) {
|
|
||||||
list.Items = append(list.Items, item)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Watch returns a watch.Interface that watches the requested scheduledScalings.
|
|
||||||
func (c *FakeScheduledScalings) Watch(opts v1.ListOptions) (watch.Interface, error) {
|
|
||||||
return c.Fake.
|
|
||||||
InvokesWatch(testing.NewWatchAction(scheduledscalingsResource, c.ns, opts))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create takes the representation of a scheduledScaling and creates it. Returns the server's representation of the scheduledScaling, and an error, if there is any.
|
|
||||||
func (c *FakeScheduledScalings) Create(scheduledScaling *zalandoorgv1.ScheduledScaling) (result *zalandoorgv1.ScheduledScaling, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewCreateAction(scheduledscalingsResource, c.ns, scheduledScaling), &zalandoorgv1.ScheduledScaling{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*zalandoorgv1.ScheduledScaling), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update takes the representation of a scheduledScaling and updates it. Returns the server's representation of the scheduledScaling, and an error, if there is any.
|
|
||||||
func (c *FakeScheduledScalings) Update(scheduledScaling *zalandoorgv1.ScheduledScaling) (result *zalandoorgv1.ScheduledScaling, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewUpdateAction(scheduledscalingsResource, c.ns, scheduledScaling), &zalandoorgv1.ScheduledScaling{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*zalandoorgv1.ScheduledScaling), err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete takes name of the scheduledScaling and deletes it. Returns an error if one occurs.
|
|
||||||
func (c *FakeScheduledScalings) Delete(name string, options *v1.DeleteOptions) error {
|
|
||||||
_, err := c.Fake.
|
|
||||||
Invokes(testing.NewDeleteAction(scheduledscalingsResource, c.ns, name), &zalandoorgv1.ScheduledScaling{})
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeleteCollection deletes a collection of objects.
|
|
||||||
func (c *FakeScheduledScalings) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error {
|
|
||||||
action := testing.NewDeleteCollectionAction(scheduledscalingsResource, c.ns, listOptions)
|
|
||||||
|
|
||||||
_, err := c.Fake.Invokes(action, &zalandoorgv1.ScheduledScalingList{})
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Patch applies the patch and returns the patched scheduledScaling.
|
|
||||||
func (c *FakeScheduledScalings) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *zalandoorgv1.ScheduledScaling, err error) {
|
|
||||||
obj, err := c.Fake.
|
|
||||||
Invokes(testing.NewPatchSubresourceAction(scheduledscalingsResource, c.ns, name, pt, data, subresources...), &zalandoorgv1.ScheduledScaling{})
|
|
||||||
|
|
||||||
if obj == nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return obj.(*zalandoorgv1.ScheduledScaling), err
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user