From 5926f1aea16f2449319ffd29653515d879c2400f Mon Sep 17 00:00:00 2001 From: Katyanna Moura Date: Wed, 5 Jan 2022 17:53:06 +0100 Subject: [PATCH 1/2] 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 --- docs/helm/templates/rbac.yaml | 2 +- docs/rbac.yaml | 1 - example/deploy/hpa.yaml | 2 +- example/deploy/ingress.yaml | 2 +- pkg/collector/skipper_collector.go | 2 +- pkg/collector/skipper_collector_test.go | 18 +++++++------ pkg/provider/metric_store.go | 3 +-- pkg/provider/metric_store_test.go | 36 ++++++++++++------------- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/docs/helm/templates/rbac.yaml b/docs/helm/templates/rbac.yaml index cb521c8..1f9d250 100644 --- a/docs/helm/templates/rbac.yaml +++ b/docs/helm/templates/rbac.yaml @@ -60,7 +60,7 @@ rules: verbs: - get - apiGroups: - - extensions + - networking.k8s.io resources: - ingresses verbs: diff --git a/docs/rbac.yaml b/docs/rbac.yaml index 67eab2b..9e6d765 100644 --- a/docs/rbac.yaml +++ b/docs/rbac.yaml @@ -67,7 +67,6 @@ rules: # only relevant if running with the flag: # --skipper-ingress-metrics - apiGroups: - - extensions - networking.k8s.io resources: - ingresses diff --git a/example/deploy/hpa.yaml b/example/deploy/hpa.yaml index afa4087..550e463 100644 --- a/example/deploy/hpa.yaml +++ b/example/deploy/hpa.yaml @@ -39,7 +39,7 @@ spec: - type: Object object: describedObject: - apiVersion: extensions/v1beta1 + apiVersion: networking.k8s.io/v1 kind: Ingress name: custom-metrics-consumer metric: diff --git a/example/deploy/ingress.yaml b/example/deploy/ingress.yaml index 8a95f81..5a95697 100644 --- a/example/deploy/ingress.yaml +++ b/example/deploy/ingress.yaml @@ -1,4 +1,4 @@ -apiVersion: extensions/v1beta1 +apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: custom-metrics-consumer diff --git a/pkg/collector/skipper_collector.go b/pkg/collector/skipper_collector.go index 47af0de..06e1daf 100644 --- a/pkg/collector/skipper_collector.go +++ b/pkg/collector/skipper_collector.go @@ -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 } diff --git a/pkg/collector/skipper_collector_test.go b/pkg/collector/skipper_collector_test.go index 8f610a0..cbe3146 100644 --- a/pkg/collector/skipper_collector_test.go +++ b/pkg/collector/skipper_collector_test.go @@ -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 } diff --git a/pkg/provider/metric_store.go b/pkg/provider/metric_store.go index 6614e8f..e17b836 100644 --- a/pkg/provider/metric_store.go +++ b/pkg/provider/metric_store.go @@ -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 diff --git a/pkg/provider/metric_store_test.go b/pkg/provider/metric_store_test.go index 3a0e4dd..468770e 100644 --- a/pkg/provider/metric_store_test.go +++ b/pkg/provider/metric_store_test.go @@ -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", }, }, }, From 203aaeafb9d517b948964235228ba60307dab84c Mon Sep 17 00:00:00 2001 From: Katyanna Moura Date: Wed, 22 Jun 2022 10:27:35 +0200 Subject: [PATCH 2/2] Update supported K8s version for skipper-collector Signed-off-by: Katyanna Moura --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a4afe8..874eebb 100644 --- a/README.md +++ b/README.md @@ -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