Compare commits

...

6 Commits

Author SHA1 Message Date
Katyanna Moura
7b592c6832 Merge pull request #447 from zalando-incubator/ingress-upgrade-v1
Limit ingress support to only networking.k8s.io/v1
2022-06-22 11:12:21 +02:00
Katyanna Moura
203aaeafb9 Update supported K8s version for skipper-collector
Signed-off-by: Katyanna Moura <amelie.kn@gmail.com>
2022-06-22 10:27:35 +02:00
Katyanna Moura
5926f1aea1 Limit ingress support to only networking.k8s.io/v1
Given the deprecation of extensions/v1beta1, remove it from Ingress possibilities.

Signed-off-by: Katyanna Moura <amelie.kn@gmail.com>
2022-06-21 12:46:08 +02:00
Sandor Szücs
be1e1c635d Create codeql-analysis.yml (#446)
Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
2022-06-09 11:52:46 +02:00
Mikkel Oscar Lyderik Larsen
094a9f9b9d Merge pull request #443 from zalando-incubator/update-deps-2022-06
Update dependencies + fix CI build
2022-06-01 16:03:37 +02:00
Mikkel Oscar Lyderik Larsen
47d34b328c Update dependencies + fix CI build
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
2022-06-01 12:16:11 +02:00
13 changed files with 118 additions and 49 deletions

View File

@ -1,7 +1,5 @@
name: ci
on: [push, pull_request]
env:
GO111MODULE: on
jobs:
tests:
runs-on: ubuntu-latest
@ -11,12 +9,10 @@ jobs:
with:
go-version: '^1.18'
- run: go version
- run: go get github.com/mattn/goveralls
- run: go install github.com/mattn/goveralls@latest
- run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_RELEASE}
env:
GO111MODULE: off
- run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_RELEASE}
env:
GOLANGCI_RELEASE: v1.45.2
GOLANGCI_RELEASE: v1.46.2
- run: make build.docker
- run: make test
- run: make check

72
.github/workflows/codeql-analysis.yml vendored Normal file
View File

@ -0,0 +1,72 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ "master" ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ "master" ]
schedule:
- cron: '29 17 * * 1'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

View File

@ -320,7 +320,7 @@ box so users don't have to define those manually.
| Metric | Description | Type | Kind | K8s Versions |
| ----------- | -------------- | ------ | ---- | ---- |
| `requests-per-second` | Scale based on requests per second for a certain ingress or routegroup. | Object | `Ingress`, `RouteGroup` | `>=1.14` |
| `requests-per-second` | Scale based on requests per second for a certain ingress or routegroup. | Object | `Ingress`, `RouteGroup` | `>=1.19` |
### Example

View File

@ -60,7 +60,7 @@ rules:
verbs:
- get
- apiGroups:
- extensions
- networking.k8s.io
resources:
- ingresses
verbs:

View File

@ -67,7 +67,6 @@ rules:
# only relevant if running with the flag:
# --skipper-ingress-metrics
- apiGroups:
- extensions
- networking.k8s.io
resources:
- ingresses

View File

@ -39,7 +39,7 @@ spec:
- type: Object
object:
describedObject:
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
name: custom-metrics-consumer
metric:

View File

@ -1,4 +1,4 @@
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: custom-metrics-consumer

6
go.mod
View File

@ -1,11 +1,11 @@
module github.com/zalando-incubator/kube-metrics-adapter
require (
github.com/aws/aws-sdk-go v1.43.31
github.com/aws/aws-sdk-go v1.44.25
github.com/influxdata/influxdb-client-go v0.2.0
github.com/kubernetes-sigs/custom-metrics-apiserver v0.0.0-20201216091021-1b9fa998bbaa
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/common v0.33.0
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/common v0.34.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.4.0
github.com/spyzhov/ajson v0.7.1

11
go.sum
View File

@ -106,8 +106,8 @@ github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/aws/aws-sdk-go v1.15.64/go.mod h1:E3/ieXAlvM0XWO57iftYVDLLvQ824smPP3ATZkfNZeM=
github.com/aws/aws-sdk-go v1.43.31 h1:yJZIr8nMV1hXjAvvOLUFqZRJcHV7udPQBfhJqawDzI0=
github.com/aws/aws-sdk-go v1.43.31/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/aws/aws-sdk-go v1.44.25 h1:cJZ4gtEpWAD/StO9GGOAyv6AaAoZ9OJUhu96gF9qaio=
github.com/aws/aws-sdk-go v1.44.25/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/benbjohnson/clock v1.0.3/go.mod h1:bGMdMPoPVvcYyt1gHDf4J2KE153Yf9BuiUKYMaxlTDM=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
@ -616,8 +616,9 @@ github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDf
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.12.1 h1:ZiaPsmm9uiBeaSMRznKsCDNtPCS0T3JVDGF+06gjBzk=
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
github.com/prometheus/client_golang v1.12.2 h1:51L9cDoUHVrXx4zWYlcLQIZ+d+VXHgqnYKkIuq4g/34=
github.com/prometheus/client_golang v1.12.2/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
@ -630,8 +631,8 @@ github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB8
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=
github.com/prometheus/common v0.28.0/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls=
github.com/prometheus/common v0.33.0 h1:rHgav/0a6+uYgGdNt3jwz8FNSesO/Hsang3O0T9A5SE=
github.com/prometheus/common v0.33.0/go.mod h1:gB3sOl7P0TvJabZpLY5uQMpUqRCPPCyRLCZYc7JZTNE=
github.com/prometheus/common v0.34.0 h1:RBmGO9d/FVjqHT0yUGQwBJhkwKV+wPCn7KGpvfab0uE=
github.com/prometheus/common v0.34.0/go.mod h1:gB3sOl7P0TvJabZpLY5uQMpUqRCPPCyRLCZYc7JZTNE=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=

View File

@ -162,7 +162,7 @@ func (c *SkipperCollector) getCollector(ctx context.Context) (Collector, error)
var backendWeight float64
switch c.objectReference.Kind {
case "Ingress":
ingress, err := c.client.NetworkingV1beta1().Ingresses(c.objectReference.Namespace).Get(ctx, c.objectReference.Name, metav1.GetOptions{})
ingress, err := c.client.NetworkingV1().Ingresses(c.objectReference.Namespace).Get(ctx, c.objectReference.Name, metav1.GetOptions{})
if err != nil {
return nil, err
}

View File

@ -14,7 +14,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
corev1 "k8s.io/api/core/v1"
v1beta1 "k8s.io/api/networking/v1beta1"
netv1 "k8s.io/api/networking/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
@ -547,29 +547,31 @@ func makeIngress(client kubernetes.Interface, namespace, resourceName, backend s
}
annotations[anno] = string(sWeights)
}
ingress := &v1beta1.Ingress{
ingress := &netv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: resourceName,
Annotations: annotations,
},
Spec: v1beta1.IngressSpec{
Backend: &v1beta1.IngressBackend{
ServiceName: backend,
Spec: netv1.IngressSpec{
DefaultBackend: &netv1.IngressBackend{
Service: &netv1.IngressServiceBackend{
Name: backend,
},
},
TLS: nil,
},
Status: v1beta1.IngressStatus{
Status: netv1.IngressStatus{
LoadBalancer: corev1.LoadBalancerStatus{
Ingress: nil,
},
},
}
for _, hostname := range hostnames {
ingress.Spec.Rules = append(ingress.Spec.Rules, v1beta1.IngressRule{
ingress.Spec.Rules = append(ingress.Spec.Rules, netv1.IngressRule{
Host: hostname,
})
}
_, err := client.NetworkingV1beta1().Ingresses(namespace).Create(context.TODO(), ingress, metav1.CreateOptions{})
_, err := client.NetworkingV1().Ingresses(namespace).Create(context.TODO(), ingress, metav1.CreateOptions{})
return err
}

View File

@ -87,8 +87,7 @@ func (s *MetricStore) insertCustomMetric(value custom_metrics.MetricValue) {
Resource: "pods",
}
case "Ingress":
// group can be either `extensions` or `networking.k8s.io`
group := "extensions"
group := "networking.k8s.io"
gv, err := schema.ParseGroupVersion(value.DescribedObject.APIVersion)
if err == nil {
group = gv.Group

View File

@ -320,7 +320,7 @@ func TestInternalMetricStorage(t *testing.T) {
DescribedObject: custom_metrics.ObjectReference{
Name: "metricObject",
Kind: "Ingress",
APIVersion: "extensions/v1beta1",
APIVersion: "networking.k8s.io/v1",
},
},
},
@ -328,7 +328,7 @@ func TestInternalMetricStorage(t *testing.T) {
list: []provider.CustomMetricInfo{
{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: false,
@ -342,7 +342,7 @@ func TestInternalMetricStorage(t *testing.T) {
name: types.NamespacedName{Name: "metricObject", Namespace: ""},
info: provider.CustomMetricInfo{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: false,
@ -358,7 +358,7 @@ func TestInternalMetricStorage(t *testing.T) {
selector: labels.SelectorFromSet(labels.Set{"select_key": "select_value"}),
info: provider.CustomMetricInfo{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: false,
@ -376,7 +376,7 @@ func TestInternalMetricStorage(t *testing.T) {
DescribedObject: custom_metrics.ObjectReference{
Name: "metricObject",
Kind: "Ingress",
APIVersion: "extensions/v1beta1",
APIVersion: "networking.k8s.io/v1",
},
},
},
@ -384,7 +384,7 @@ func TestInternalMetricStorage(t *testing.T) {
list: []provider.CustomMetricInfo{
{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: false,
@ -398,7 +398,7 @@ func TestInternalMetricStorage(t *testing.T) {
name: types.NamespacedName{Name: "metricObject", Namespace: ""},
info: provider.CustomMetricInfo{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: false,
@ -414,7 +414,7 @@ func TestInternalMetricStorage(t *testing.T) {
selector: labels.Everything(),
info: provider.CustomMetricInfo{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: false,
@ -433,7 +433,7 @@ func TestInternalMetricStorage(t *testing.T) {
Name: "metricObject",
Namespace: "right",
Kind: "Ingress",
APIVersion: "extensions/v1beta1",
APIVersion: "networking.k8s.io/v1",
},
},
},
@ -441,7 +441,7 @@ func TestInternalMetricStorage(t *testing.T) {
list: []provider.CustomMetricInfo{
{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: true,
@ -455,7 +455,7 @@ func TestInternalMetricStorage(t *testing.T) {
name: types.NamespacedName{Name: "metricObject", Namespace: "wrong"},
info: provider.CustomMetricInfo{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: true,
@ -471,7 +471,7 @@ func TestInternalMetricStorage(t *testing.T) {
selector: labels.Everything(),
info: provider.CustomMetricInfo{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: true,
@ -535,7 +535,7 @@ func TestMultipleMetricValues(t *testing.T) {
DescribedObject: custom_metrics.ObjectReference{
Name: "metricObject",
Kind: "Ingress",
APIVersion: "extensions/v1beta1",
APIVersion: "networking.k8s.io/v1",
},
},
},
@ -547,7 +547,7 @@ func TestMultipleMetricValues(t *testing.T) {
DescribedObject: custom_metrics.ObjectReference{
Name: "metricObject",
Kind: "Ingress",
APIVersion: "extensions/v1beta1",
APIVersion: "networking.k8s.io/v1",
},
},
},
@ -555,7 +555,7 @@ func TestMultipleMetricValues(t *testing.T) {
list: []provider.CustomMetricInfo{
{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: false,
@ -569,7 +569,7 @@ func TestMultipleMetricValues(t *testing.T) {
name: types.NamespacedName{Name: "metricObject", Namespace: ""},
info: provider.CustomMetricInfo{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: false,
@ -585,7 +585,7 @@ func TestMultipleMetricValues(t *testing.T) {
selector: labels.Everything(),
info: provider.CustomMetricInfo{
GroupResource: schema.GroupResource{
Group: "extensions",
Group: "networking.k8s.io",
Resource: "ingresses",
},
Namespaced: false,
@ -831,7 +831,7 @@ func TestCustomMetricsStorageErrors(t *testing.T) {
Name: "metricObject",
Namespace: "default",
Kind: "Ingress",
APIVersion: "extensions/vbeta1",
APIVersion: "networking.k8s.io/v1",
},
},
},