From 5f8386c82d6a44fee0e3799142eb92c5b52185e1 Mon Sep 17 00:00:00 2001 From: Lucie Dubrunfaut <123162035+lucie-dubrunfaut@users.noreply.github.com> Date: Tue, 16 Jul 2024 10:51:34 +0200 Subject: [PATCH] Ctor 713 custom cloud kuberneted custom change kubenetes api path v1beta in v1 (#5109) Co-authored-by: Tpo76 Fixed unrelevant path on latest k8s version for cronjob api and ingress api Co-authored-by: Lucie Dubrunfaut Added an option --legacy-api-beta if old path should be use. --- src/cloud/kubernetes/custom/api.pm | 39 ++++++++++++++++++-------- tests/resources/spellcheck/stopwords.t | 5 ++++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/cloud/kubernetes/custom/api.pm b/src/cloud/kubernetes/custom/api.pm index 420a30b41a..b5411171b5 100644 --- a/src/cloud/kubernetes/custom/api.pm +++ b/src/cloud/kubernetes/custom/api.pm @@ -43,14 +43,15 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - 'hostname:s' => { name => 'hostname' }, - 'port:s' => { name => 'port' }, - 'proto:s' => { name => 'proto' }, - 'token:s' => { name => 'token' }, - 'timeout:s' => { name => 'timeout' }, - 'limit:s' => { name => 'limit' }, - 'config-file:s' => { name => 'config_file' }, - 'namespace:s' => { name => 'namespace' } + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port' }, + 'proto:s' => { name => 'proto' }, + 'token:s' => { name => 'token' }, + 'timeout:s' => { name => 'timeout' }, + 'limit:s' => { name => 'limit' }, + 'config-file:s' => { name => 'config_file' }, + 'namespace:s' => { name => 'namespace' }, + 'legacy-api-beta:s' => { name => 'legacy_api_beta' } }); } $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); @@ -190,9 +191,14 @@ sub request_api_paginate { sub kubernetes_list_cronjobs { my ($self, %options) = @_; + my $url_path=$self->{namespace} ne '' ? '/apis/batch/v1/namespaces/' . $self->{namespace} . '/cronjobs' : '/apis/batch/v1/cronjobs'; + if (defined($self->{legacy_api_beta})){ + $url_path=$self->{namespace} ne '' ? '/apis/batch/v1beta1/namespaces/' . $self->{namespace} . '/cronjobs' : '/apis/batch/v1beta1/cronjobs'; + }; + my $response = $self->request_api_paginate( method => 'GET', - url_path => $self->{namespace} ne '' ? '/apis/batch/v1beta1/namespaces/' . $self->{namespace} . '/cronjobs' : '/apis/batch/v1beta1/cronjobs' + url_path => $url_path ); return $response; @@ -234,9 +240,14 @@ sub kubernetes_list_events { sub kubernetes_list_ingresses { my ($self, %options) = @_; + my $url_path=$self->{namespace} ne '' ? '/apis/networking.k8s.io/v1/namespaces/' . $self->{namespace} . '/ingresses' : '/apis/networking.k8s.io/v1/ingresses'; + if (defined($self->{legacy_api_beta})){ + $url_path=$self->{namespace} ne '' ? '/apis/extensions/v1beta1/namespaces/' . $self->{namespace} . '/ingresses' : '/apis/extensions/v1beta1/ingresses'; + }; + my $response = $self->request_api_paginate( method => 'GET', - url_path => $self->{namespace} ne '' ? '/apis/extensions/v1beta1/namespaces/' . $self->{namespace} . '/ingresses' : '/apis/extensions/v1beta1/ingresses' + url_path => $url_path ); return $response; @@ -369,7 +380,13 @@ See https://kubernetes.io/docs/reference/kubernetes-api/common-parameters/common =item B<--namespace> -Set namespace to get informations. +Set namespace to get information. + +=item B<--legacy-api-beta> + +If this option is set the legacy API path are set for this API calls: +kubernetes_list_cronjobs will use this path: /apis/batch/v1beta1/namespaces/ +kubernetes_list_ingresses will use this path: /apis/extensions/v1beta1/namespaces/ =back diff --git a/tests/resources/spellcheck/stopwords.t b/tests/resources/spellcheck/stopwords.t index d89f57420b..1634dbfe2b 100644 --- a/tests/resources/spellcheck/stopwords.t +++ b/tests/resources/spellcheck/stopwords.t @@ -19,6 +19,7 @@ --force-oid --get-param --ignore-orgs-api-disabled +--legacy-api-beta --lookup-perfdatas-nagios --map-speed-dsl --mqtt @@ -125,3 +126,7 @@ uptime userpass v1 v2 +VDSL2 +Veeam +WSMAN +Kubernetes