mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2026-05-30 08:15:25 +00:00
Compare commits
27 Commits
cc9952d66e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| f2c845aaa7 | |||
| 54e3210e41 | |||
| ee6d8ff265 | |||
| 0eb3d793a8 | |||
| 0ae8f5145e | |||
| 7f8b8d53ef | |||
| 77733fb03d | |||
| ebdf0e2d85 | |||
| 6d6c08e1fc | |||
| b10c0e67d8 | |||
| d0dbe73b55 | |||
| caa6a11ee8 | |||
| 1009ae601e | |||
| 1d35f93162 | |||
| 1d135d4dda | |||
| 35b4365108 | |||
| ad0b98a4a0 | |||
| fbef659df1 | |||
| f77472e8e7 | |||
| 5106e6cfdf | |||
| e1e5a06c9b | |||
| 25bd53a987 | |||
| 58848f0985 | |||
| d28a770825 | |||
| 55bb290076 | |||
| 70641827ce | |||
| 99ca95588e |
@@ -11,12 +11,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6.0.2
|
||||
- uses: actions/setup-go@v6.2.0
|
||||
- uses: actions/setup-go@v6.4.0
|
||||
with:
|
||||
go-version: '^1.25'
|
||||
go-version: '^1.26'
|
||||
- run: go version
|
||||
- run: go install github.com/mattn/goveralls@latest
|
||||
- run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
- run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
|
||||
- run: make build.docker
|
||||
- run: make test
|
||||
- run: make check
|
||||
|
||||
@@ -41,9 +41,9 @@ jobs:
|
||||
uses: actions/checkout@v6.0.2
|
||||
|
||||
- name: setup go
|
||||
uses: actions/setup-go@v6.2.0
|
||||
uses: actions/setup-go@v6.4.0
|
||||
with:
|
||||
go-version: '1.25'
|
||||
go-version: '1.26'
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
|
||||
@@ -27,13 +27,13 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98
|
||||
|
||||
- uses: actions/setup-go@a5f9b05d2d216f63e13859e0d847461041025775
|
||||
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
|
||||
with:
|
||||
# https://www.npmjs.com/package/semver#caret-ranges-123-025-004
|
||||
go-version: '^1.25'
|
||||
go-version: '^1.26'
|
||||
|
||||
- name: Login to Github Container Registry
|
||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9
|
||||
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121
|
||||
with:
|
||||
registry: ${{ env.REGISTRY }}
|
||||
username: ${{ github.actor }}
|
||||
@@ -47,21 +47,21 @@ jobs:
|
||||
make build.linux.amd64 build.linux.arm64
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130
|
||||
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f
|
||||
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9
|
||||
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Docker meta
|
||||
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051
|
||||
uses: docker/metadata-action@030e881283bb7a6894de51c315a6bfe6a94e05cf
|
||||
id: meta
|
||||
with:
|
||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||
@@ -70,10 +70,9 @@ jobs:
|
||||
type=semver,pattern=v{{major}}.{{minor}}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
|
||||
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f
|
||||
with:
|
||||
context: .
|
||||
build-args: BASE_IMAGE=gcr.io/distroless/static-debian12
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: ${{ github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/v') }}
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
@@ -81,10 +80,9 @@ jobs:
|
||||
|
||||
# Build and push latest tag
|
||||
- name: Build and push latest
|
||||
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83
|
||||
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f
|
||||
with:
|
||||
context: .
|
||||
build-args: BASE_IMAGE=gcr.io/distroless/static-debian12
|
||||
platforms: linux/amd64,linux/arm64
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||
|
||||
+25
-9
@@ -1,13 +1,29 @@
|
||||
version: "2"
|
||||
run:
|
||||
concurrency: 4
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
default: none
|
||||
enable:
|
||||
- errcheck
|
||||
- gosimple
|
||||
- govet
|
||||
- ineffassign
|
||||
- staticcheck
|
||||
- typecheck
|
||||
- unused
|
||||
- errcheck
|
||||
- govet
|
||||
- ineffassign
|
||||
- staticcheck
|
||||
- unused
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
- comments
|
||||
- common-false-positives
|
||||
- legacy
|
||||
- std-error-handling
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
formatters:
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
ARG BASE_IMAGE=registry.opensource.zalan.do/library/static:latest
|
||||
ARG BASE_IMAGE=gcr.io/distroless/static-debian12:latest
|
||||
FROM ${BASE_IMAGE}
|
||||
LABEL maintainer="Team Teapot @ Zalando SE <team-teapot@zalando.de>"
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
BINARY ?= kube-metrics-adapter
|
||||
VERSION ?= $(shell git describe --tags --always --dirty)
|
||||
IMAGE ?= registry-write.opensource.zalan.do/teapot/$(BINARY)
|
||||
IMAGE ?= ghcr.io/zalando-incubator/$(BINARY)
|
||||
TAG ?= $(VERSION)
|
||||
SOURCES = $(shell find . -name '*.go')
|
||||
DOCKERFILE ?= Dockerfile
|
||||
|
||||
@@ -15,21 +15,6 @@ pipeline:
|
||||
- desc: test
|
||||
cmd: |
|
||||
make test
|
||||
- desc: build
|
||||
cmd: |
|
||||
make build.docker
|
||||
- desc: push
|
||||
cmd: |
|
||||
if [[ $CDP_TARGET_BRANCH == master && ! $CDP_PULL_REQUEST_NUMBER ]]; then
|
||||
IMAGE=registry-write.opensource.zalan.do/teapot/kube-metrics-adapter
|
||||
VERSION=$(git describe --tags --always)
|
||||
else
|
||||
IMAGE=registry-write.opensource.zalan.do/teapot/kube-metrics-adapter-test
|
||||
VERSION=$CDP_BUILD_VERSION
|
||||
fi
|
||||
IMAGE=$IMAGE VERSION=$VERSION make build.docker
|
||||
git diff --stat --exit-code
|
||||
IMAGE=$IMAGE VERSION=$VERSION make build.push
|
||||
- desc: Build and push image to Zalando's registry
|
||||
cmd: |
|
||||
if [[ $CDP_TARGET_BRANCH == master && ! $CDP_PULL_REQUEST_NUMBER ]]; then
|
||||
|
||||
@@ -20,4 +20,3 @@ spec:
|
||||
groupPriorityMinimum: 100
|
||||
versionPriority: 100
|
||||
{{- end}}
|
||||
""
|
||||
|
||||
+4
-2
@@ -1,7 +1,9 @@
|
||||
FROM registry.opensource.zalan.do/library/alpine-3:latest
|
||||
FROM gcr.io/distroless/static-debian12:latest
|
||||
LABEL maintainer="Team Teapot @ Zalando SE <team-teapot@zalando.de>"
|
||||
|
||||
ARG TARGETARCH
|
||||
|
||||
# add binary
|
||||
ADD build/linux/custom-metrics-consumer /
|
||||
ADD build/linux/${TARGETARCH}/custom-metrics-consumer /
|
||||
|
||||
ENTRYPOINT ["/custom-metrics-consumer"]
|
||||
|
||||
+8
-5
@@ -32,11 +32,14 @@ build/$(BINARY): $(SOURCES)
|
||||
build/linux/$(BINARY): $(SOURCES)
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/linux/$(BINARY) -ldflags "$(LDFLAGS)" .
|
||||
|
||||
build/linux/amd64/$(BINARY): $(SOURCES)
|
||||
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/linux/amd64/$(BINARY) -ldflags "$(LDFLAGS)" .
|
||||
|
||||
build/linux/arm64/$(BINARY): $(SOURCES)
|
||||
GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/linux/arm64/$(BINARY) -ldflags "$(LDFLAGS)" .
|
||||
|
||||
build/osx/$(BINARY): $(SOURCES)
|
||||
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build $(BUILD_FLAGS) -o build/osx/$(BINARY) -ldflags "$(LDFLAGS)" .
|
||||
|
||||
build.docker: build.linux
|
||||
docker build --rm -t "$(IMAGE):$(TAG)" -f $(DOCKERFILE) .
|
||||
|
||||
build.push: build.docker
|
||||
docker push "$(IMAGE):$(TAG)"
|
||||
build.push: build/linux/amd64/$(BINARY) build/linux/arm64/$(BINARY)
|
||||
docker buildx build --rm --build-arg -t "$(IMAGE):$(TAG)" --platform linux/amd64,linux/arm64 --push .
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
func metricsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(200)
|
||||
_, err := w.Write([]byte(fmt.Sprintf(`{"queue": {"length": %d}}`, size)))
|
||||
_, err := fmt.Fprintf(w, `{"queue": {"length": %d}}`, size)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to write: %v", err)
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -35,7 +35,7 @@ type ScalingSchedule struct {
|
||||
// Identifier returns the namespaced scalingScale Identifier in the format
|
||||
// `<namespace>/<name>`.
|
||||
func (s *ScalingSchedule) Identifier() string {
|
||||
return s.ObjectMeta.Namespace + "/" + s.ObjectMeta.Name
|
||||
return s.Namespace + "/" + s.Name
|
||||
}
|
||||
|
||||
// ResourceSpec returns the ScalingScheduleSpec of the ScalingSchedule.
|
||||
@@ -66,7 +66,7 @@ type ClusterScalingSchedule struct {
|
||||
// Identifier returns the cluster scalingScale Identifier in the format
|
||||
// `<name>`.
|
||||
func (s *ClusterScalingSchedule) Identifier() string {
|
||||
return s.ObjectMeta.Name
|
||||
return s.Name
|
||||
}
|
||||
|
||||
// ResourceSpec returns the ScalingScheduleSpec of the ClusterScalingSchedule.
|
||||
|
||||
@@ -34,10 +34,6 @@ import (
|
||||
// It's backed by a very simple object tracker that processes creates, updates and deletions as-is,
|
||||
// without applying any field management, validations and/or defaults. It shouldn't be considered a replacement
|
||||
// for a real clientset and is mostly useful in simple unit tests.
|
||||
//
|
||||
// DEPRECATED: NewClientset replaces this with support for field management, which significantly improves
|
||||
// server side apply testing. NewClientset is only available when apply configurations are generated (e.g.
|
||||
// via --with-applyconfig).
|
||||
func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
||||
o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
|
||||
for _, obj := range objects {
|
||||
@@ -51,8 +47,8 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
||||
cs.AddReactor("*", "*", testing.ObjectReaction(o))
|
||||
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
|
||||
var opts metav1.ListOptions
|
||||
if watchActcion, ok := action.(testing.WatchActionImpl); ok {
|
||||
opts = watchActcion.ListOptions
|
||||
if watchAction, ok := action.(testing.WatchActionImpl); ok {
|
||||
opts = watchAction.ListOptions
|
||||
}
|
||||
gvr := action.GetResource()
|
||||
ns := action.GetNamespace()
|
||||
@@ -83,6 +79,17 @@ func (c *Clientset) Tracker() testing.ObjectTracker {
|
||||
return c.tracker
|
||||
}
|
||||
|
||||
// IsWatchListSemanticsSupported informs the reflector that this client
|
||||
// doesn't support WatchList semantics.
|
||||
//
|
||||
// This is a synthetic method whose sole purpose is to satisfy the optional
|
||||
// interface check performed by the reflector.
|
||||
// Returning true signals that WatchList can NOT be used.
|
||||
// No additional logic is implemented here.
|
||||
func (c *Clientset) IsWatchListSemanticsUnSupported() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
var (
|
||||
_ clientset.Interface = &Clientset{}
|
||||
_ testing.FakeClient = &Clientset{}
|
||||
|
||||
@@ -97,6 +97,7 @@ func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Dur
|
||||
// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory.
|
||||
// Listers obtained via this SharedInformerFactory will be subject to the same filters
|
||||
// as specified here.
|
||||
//
|
||||
// Deprecated: Please use NewSharedInformerFactoryWithOptions instead
|
||||
func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory {
|
||||
return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions))
|
||||
@@ -204,7 +205,7 @@ func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internal
|
||||
//
|
||||
// It is typically used like this:
|
||||
//
|
||||
// ctx, cancel := context.Background()
|
||||
// ctx, cancel := context.WithCancel(context.Background())
|
||||
// defer cancel()
|
||||
// factory := NewSharedInformerFactory(client, resyncPeriod)
|
||||
// defer factory.WaitForStop() // Returns immediately if nothing was started.
|
||||
|
||||
@@ -56,7 +56,7 @@ func NewClusterScalingScheduleInformer(client versioned.Interface, resyncPeriod
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func NewFilteredClusterScalingScheduleInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
|
||||
return cache.NewSharedIndexInformer(
|
||||
&cache.ListWatch{
|
||||
cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
@@ -81,7 +81,7 @@ func NewFilteredClusterScalingScheduleInformer(client versioned.Interface, resyn
|
||||
}
|
||||
return client.ZalandoV1().ClusterScalingSchedules().Watch(ctx, options)
|
||||
},
|
||||
},
|
||||
}, client),
|
||||
&apiszalandoorgv1.ClusterScalingSchedule{},
|
||||
resyncPeriod,
|
||||
indexers,
|
||||
|
||||
@@ -57,7 +57,7 @@ func NewScalingScheduleInformer(client versioned.Interface, namespace string, re
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func NewFilteredScalingScheduleInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
|
||||
return cache.NewSharedIndexInformer(
|
||||
&cache.ListWatch{
|
||||
cache.ToListWatcherWithWatchListSemantics(&cache.ListWatch{
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
@@ -82,7 +82,7 @@ func NewFilteredScalingScheduleInformer(client versioned.Interface, namespace st
|
||||
}
|
||||
return client.ZalandoV1().ScalingSchedules(namespace).Watch(ctx, options)
|
||||
},
|
||||
},
|
||||
}, client),
|
||||
&apiszalandoorgv1.ScalingSchedule{},
|
||||
resyncPeriod,
|
||||
indexers,
|
||||
|
||||
@@ -185,7 +185,7 @@ type MetricTypeName struct {
|
||||
|
||||
func (m MetricTypeName) String() string {
|
||||
str := fmt.Sprintf("%s/%s", m.Type, m.Metric.Name)
|
||||
if len(m.Metric.Selector.MatchLabels) > 0 {
|
||||
if m.Metric.Selector != nil && len(m.Metric.Selector.MatchLabels) > 0 {
|
||||
str += " " + mapToString(m.Metric.Selector.MatchLabels)
|
||||
}
|
||||
return str
|
||||
|
||||
@@ -30,6 +30,88 @@ func (c *mockCollector) Interval() time.Duration {
|
||||
return 0
|
||||
}
|
||||
|
||||
func TestMetricTypeName_String(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
metricType autoscalingv2.MetricSourceType
|
||||
metricName string
|
||||
selector *metav1.LabelSelector
|
||||
expectedStr string
|
||||
shouldContain []string
|
||||
}{
|
||||
{
|
||||
name: "nil selector with PodsMetricSourceType",
|
||||
metricType: autoscalingv2.PodsMetricSourceType,
|
||||
metricName: "metric-name",
|
||||
selector: nil,
|
||||
expectedStr: "Pods/metric-name",
|
||||
},
|
||||
{
|
||||
name: "nil selector with ObjectMetricSourceType",
|
||||
metricType: autoscalingv2.ObjectMetricSourceType,
|
||||
metricName: "metric-name",
|
||||
selector: nil,
|
||||
expectedStr: "Object/metric-name",
|
||||
},
|
||||
{
|
||||
name: "nil selector with ExternalMetricSourceType",
|
||||
metricType: autoscalingv2.ExternalMetricSourceType,
|
||||
metricName: "metric-name",
|
||||
selector: nil,
|
||||
expectedStr: "External/metric-name",
|
||||
},
|
||||
{
|
||||
name: "empty selector (non-nil but empty MatchLabels)",
|
||||
metricType: autoscalingv2.ExternalMetricSourceType,
|
||||
metricName: "metric-name",
|
||||
selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{},
|
||||
},
|
||||
expectedStr: "External/metric-name",
|
||||
},
|
||||
{
|
||||
name: "selector with single MatchLabel",
|
||||
metricType: autoscalingv2.ExternalMetricSourceType,
|
||||
metricName: "metric-name",
|
||||
selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"key": "value"},
|
||||
},
|
||||
shouldContain: []string{"External/metric-name", "key=value"},
|
||||
},
|
||||
{
|
||||
name: "selector with multiple MatchLabels",
|
||||
metricType: autoscalingv2.ExternalMetricSourceType,
|
||||
metricName: "metric-name",
|
||||
selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"key1": "val1", "key2": "val2"},
|
||||
},
|
||||
shouldContain: []string{"External/metric-name", "key1=val1", "key2=val2"},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
mtn := MetricTypeName{
|
||||
Type: tc.metricType,
|
||||
Metric: autoscalingv2.MetricIdentifier{
|
||||
Name: tc.metricName,
|
||||
Selector: tc.selector,
|
||||
},
|
||||
}
|
||||
|
||||
result := mtn.String()
|
||||
|
||||
if tc.expectedStr != "" {
|
||||
require.Equal(t, tc.expectedStr, result)
|
||||
}
|
||||
|
||||
if len(tc.shouldContain) > 0 {
|
||||
for _, substring := range tc.shouldContain {
|
||||
require.Contains(t, result, substring, "result should contain %q", substring)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewCollector(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
msg string
|
||||
|
||||
@@ -63,7 +63,7 @@ func (p *ExternalRPSCollectorPlugin) NewCollector(
|
||||
confCopy := *config
|
||||
|
||||
if _, ok := config.Config["hostnames"]; !ok {
|
||||
return nil, fmt.Errorf("Hostname is not specified, unable to create collector")
|
||||
return nil, fmt.Errorf("hostname is not specified, unable to create collector")
|
||||
}
|
||||
|
||||
hostnames := strings.Split(config.Config["hostnames"], ",")
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
autoscalingv2 "k8s.io/api/autoscaling/v2"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
type testExternalMetricsHandler struct {
|
||||
@@ -84,7 +83,7 @@ func makeTestHTTPCollectorConfig(endpoint, aggregator string) *MetricConfig {
|
||||
Type: autoscalingv2.ExternalMetricSourceType,
|
||||
Metric: autoscalingv2.MetricIdentifier{
|
||||
Name: "test-metric",
|
||||
Selector: &v1.LabelSelector{
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"type": HTTPJSONPathType},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,6 +2,7 @@ package httpmetrics
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -88,7 +89,7 @@ func NewPodMetricsJSONPathGetter(config map[string]string) (*PodMetricsJSONPathG
|
||||
return nil, err
|
||||
}
|
||||
if d < 0 {
|
||||
return nil, fmt.Errorf("Invalid request-timeout config value: %s", v)
|
||||
return nil, fmt.Errorf("invalid request-timeout config value: %s", v)
|
||||
}
|
||||
requestTimeout = d
|
||||
}
|
||||
@@ -99,7 +100,7 @@ func NewPodMetricsJSONPathGetter(config map[string]string) (*PodMetricsJSONPathG
|
||||
return nil, err
|
||||
}
|
||||
if d < 0 {
|
||||
return nil, fmt.Errorf("Invalid connect-timeout config value: %s", v)
|
||||
return nil, fmt.Errorf("invalid connect-timeout config value: %s", v)
|
||||
}
|
||||
connectTimeout = d
|
||||
}
|
||||
@@ -122,7 +123,7 @@ func (g *PodMetricsJSONPathGetter) buildMetricsURL(podIP string) url.URL {
|
||||
|
||||
return url.URL{
|
||||
Scheme: scheme,
|
||||
Host: fmt.Sprintf("%s:%d", podIP, g.port),
|
||||
Host: net.JoinHostPort(podIP, strconv.Itoa(g.port)),
|
||||
Path: g.path,
|
||||
RawQuery: g.rawQuery,
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
autoscalingv2 "k8s.io/api/autoscaling/v2"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
func TestInfluxDBCollector_New(t *testing.T) {
|
||||
@@ -24,7 +23,7 @@ func TestInfluxDBCollector_New(t *testing.T) {
|
||||
Metric: autoscalingv2.MetricIdentifier{
|
||||
Name: "flux-query",
|
||||
// This is actually useless, because the selector should be flattened in Config when parsing.
|
||||
Selector: &v1.LabelSelector{
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"query-name": "range2m",
|
||||
},
|
||||
@@ -62,7 +61,7 @@ func TestInfluxDBCollector_New(t *testing.T) {
|
||||
Type: autoscalingv2.ExternalMetricSourceType,
|
||||
Metric: autoscalingv2.MetricIdentifier{
|
||||
Name: "flux-query",
|
||||
Selector: &v1.LabelSelector{
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"query-name": "range2m",
|
||||
},
|
||||
|
||||
@@ -135,7 +135,7 @@ func (c *PodCollector) Interval() time.Duration {
|
||||
func (c *PodCollector) getPodMetric(pod corev1.Pod, ch chan CollectedMetric, errCh chan error) {
|
||||
value, err := c.Getter.GetMetric(&pod)
|
||||
if err != nil {
|
||||
errCh <- fmt.Errorf("Failed to get metrics from pod '%s/%s': %v", pod.Namespace, pod.Name, err)
|
||||
errCh <- fmt.Errorf("failed to get metrics from pod '%s/%s': %v", pod.Namespace, pod.Name, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -289,9 +289,9 @@ func makeTestPods(t *testing.T, testServer string, metricName string, port strin
|
||||
}
|
||||
|
||||
if podDeletionTimestamp.IsZero() {
|
||||
testPod.ObjectMeta.DeletionTimestamp = nil
|
||||
testPod.DeletionTimestamp = nil
|
||||
} else {
|
||||
testPod.ObjectMeta.DeletionTimestamp = &v1.Time{Time: podDeletionTimestamp}
|
||||
testPod.DeletionTimestamp = &v1.Time{Time: podDeletionTimestamp}
|
||||
}
|
||||
_, err := client.CoreV1().Pods(testNamespace).Create(context.Background(), testPod, v1.CreateOptions{})
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -654,7 +654,7 @@ func TestScalingScheduleCollector(t *testing.T) {
|
||||
require.EqualValues(t, namespace, collected[0].Custom.DescribedObject.Namespace)
|
||||
require.EqualValues(t, "zalando.org/v1", collected[0].Custom.DescribedObject.APIVersion)
|
||||
require.EqualValues(t, resourceType, collected[0].Custom.DescribedObject.Kind)
|
||||
require.EqualValues(t, uTCNowRFC3339, collected[0].Custom.Timestamp.Time.Format(time.RFC3339))
|
||||
require.EqualValues(t, uTCNowRFC3339, collected[0].Custom.Timestamp.Format(time.RFC3339))
|
||||
require.EqualValues(t, collected[0].Custom.Metric.Name, scalingScheduleName)
|
||||
require.EqualValues(t, namespace, collected[0].Namespace)
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ func (c *SkipperCollector) getCollector(ctx context.Context) (Collector, error)
|
||||
}
|
||||
|
||||
for _, rule := range ingress.Spec.Rules {
|
||||
escapedHostnames = append(escapedHostnames, regexp.QuoteMeta(strings.Replace(rule.Host, ".", "_", -1)))
|
||||
escapedHostnames = append(escapedHostnames, regexp.QuoteMeta(strings.ReplaceAll(rule.Host, ".", "_")))
|
||||
}
|
||||
case "RouteGroup":
|
||||
routegroup, err := c.rgClient.ZalandoV1().RouteGroups(c.objectReference.Namespace).Get(ctx, c.objectReference.Name, metav1.GetOptions{})
|
||||
@@ -187,7 +187,7 @@ func (c *SkipperCollector) getCollector(ctx context.Context) (Collector, error)
|
||||
}
|
||||
|
||||
for _, host := range routegroup.Spec.Hosts {
|
||||
escapedHostnames = append(escapedHostnames, regexp.QuoteMeta(strings.Replace(host, ".", "_", -1)))
|
||||
escapedHostnames = append(escapedHostnames, regexp.QuoteMeta(strings.ReplaceAll(host, ".", "_")))
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown skipper resource kind %s for resource %s/%s", c.objectReference.Kind, c.objectReference.Namespace, c.objectReference.Name)
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/restmapper"
|
||||
"k8s.io/client-go/scale"
|
||||
scaleclient "k8s.io/client-go/scale"
|
||||
)
|
||||
|
||||
@@ -41,8 +40,8 @@ func NewHPATargetScaler(ctx context.Context, kubeClient kubernetes.Interface, cf
|
||||
restMapper.Reset()
|
||||
}, 30*time.Second, ctx.Done())
|
||||
|
||||
scaleKindResolver := scale.NewDiscoveryScaleKindResolver(kubeClient.Discovery())
|
||||
scaleClient, err := scale.NewForConfig(cfg, restMapper, dynamic.LegacyAPIPathResolverFunc, scaleKindResolver)
|
||||
scaleKindResolver := scaleclient.NewDiscoveryScaleKindResolver(kubeClient.Discovery())
|
||||
scaleClient, err := scaleclient.NewForConfig(cfg, restMapper, dynamic.LegacyAPIPathResolverFunc, scaleKindResolver)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create scale client: %w", err)
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user