Skip to content

Commit

Permalink
Ctor 713 custom cloud kuberneted custom change kubenetes api path v1b…
Browse files Browse the repository at this point in the history
…eta in v1 (#5109)

Co-authored-by: Tpo76 <fthepaut@centreon.com>
Fixed unrelevant path on latest k8s version for cronjob api and ingress api
Co-authored-by: Lucie Dubrunfaut <ldubrunfaut@CNTR-PORT-A198>
Added an option --legacy-api-beta if old path should be use.
  • Loading branch information
lucie-dubrunfaut authored Jul 16, 2024
1 parent e7ab992 commit 5f8386c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
39 changes: 28 additions & 11 deletions src/cloud/kubernetes/custom/api.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/resources/spellcheck/stopwords.t
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
--force-oid
--get-param
--ignore-orgs-api-disabled
--legacy-api-beta
--lookup-perfdatas-nagios
--map-speed-dsl
--mqtt
Expand Down Expand Up @@ -125,3 +126,7 @@ uptime
userpass
v1
v2
VDSL2
Veeam
WSMAN
Kubernetes

0 comments on commit 5f8386c

Please sign in to comment.