| 1 | package Kubernetes::REST::V0Group; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | our $VERSION = '1.110'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Base class for backwards-compatible v0 API group wrappers | ||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use Carp qw(croak carp); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use IO::K8s (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | has api => (is => 'ro', required => 1); | |||||||||||||||||||||||||||||||||||||||||
| 9 | 9 | has group => (is => 'ro', required => 1); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 94 | ▶ | has version => (is => 'ro', default => sub { 'v1' }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | # Kinds whose own name ends in Status - ComponentStatus is the only built-in | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # one. _parse_method's non-greedy resource capture would otherwise read | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # ListComponentStatus as the Kind Component plus a Status subresource suffix | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # and die loading a non-existent IO::K8s::Api::Core::V1::Component. Built once | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # from what the installed IO::K8s ships (bare Kind names, not the versioned | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # aliases), so a future Status-named Kind is handled too (karr k66). | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | my %STATUS_KIND = map { $_ => 1 } | |||||||||||||||||||||||||||||||||||||||||
| 19 | 1836 | ▶ | grep { /Status\z/ && !m{/} } | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
/Status\z/ && !m[/]
MC/DC100%2/2
/Status\z/ && !m[/]
/Status\z/
!m[/]
Truth table100%3/3
A && not(B)
A= /Status\z/B= !m[/]
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 9 | keys %{ IO::K8s->default_resource_map }; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # BACKWARDS COMPATIBILITY LAYER (v0 API → v1 API) | ||||||||||||||||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # The original Kubernetes::REST (v0.01/v0.02, by JLMARTIN) used method names | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # like $api->Core->ListNamespacedPod(...) with dedicated Call classes in | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # lib/Kubernetes/REST/Call/v1/Core/ListNamespacedPod.pm (978 classes total). | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # Our v1 rewrite simplified this to $api->list('Pod', namespace => ...). | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # AUTOLOAD catches the old method names (e.g. "ListNamespacedPod"), parses | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # them into action + resource, and dispatches to the new API. Each call | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # emits a deprecation warning showing the new equivalent call. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # Subclasses (Kubernetes::REST::Core, ::Apps, ::Batch, etc.) only set the | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # 'group' attribute. AUTOLOAD + _parse_method + _dispatch handle the rest. | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # Pattern: {Action}{Namespaced?}{Resource}{ForAllNamespaces?} | ||||||||||||||||||||||||||||||||||||||||||
| 39 | # Actions: List, Read, Create, Replace, Patch, Delete, Watch | ||||||||||||||||||||||||||||||||||||||||||
| 40 | # Example: ListNamespacedPod → list('IO::K8s::Api::Core::V1::Pod', ...) | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # The old Call classes no longer ship here at all - their names are tombstoned | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # in Kubernetes-REST-Deprecated. This layer is the only thing left keeping the | ||||||||||||||||||||||||||||||||||||||||||
| 44 | # v0 method names alive, and can go once no downstream code uses them. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | # ============================================================================ | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | # AUTOLOAD dispatches to list/get/update/... in Kubernetes::REST, so an | ||||||||||||||||||||||||||||||||||||||||||
| 50 | # APIError thrown there - or a plain croak - has this layer's frames between | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # it and the caller. Trust Kubernetes::REST so Carp's bidirectional check | ||||||||||||||||||||||||||||||||||||||||||
| 52 | # walks past both packages and blames the code that made the v0 call, not | ||||||||||||||||||||||||||||||||||||||||||
| 53 | # V0Group.pm; the object model's own errors are unaffected (karr k67). | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 9 | our @CARP_NOT = ('Kubernetes::REST'); | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 150 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 150 | my ($self, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 150 | my $method = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 150 | $method =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 150 | ▶ | return if $method eq 'DESTROY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # Parse method name: ListNamespacedPod, ReadNamespacedPod, CreateNamespacedPod, etc. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 54 | my ($action, $namespaced, $resource, $status) = _parse_method($method); | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 54 | ▶ | unless ($action && $resource) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$action and $resource
MC/DC50%1/2
$action and $resource
$action
$resource
Truth table66%2/3
A and B
A= $actionB= $resource
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | croak "Unknown method: $method"; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | # Build class name | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 53 | my $class = $self->_build_class($resource); | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # Convert args to hash if needed | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 53 | ▶ | my %params = @args == 1 && ref($args[0]) eq 'HASH' ? %{$args[0]} : @args; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@args == 1 and ref $args[0] eq "HASH"
MC/DC50%1/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1
ref $args[0] eq "HASH"
Truth table66%2/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | # Read*Status reads the status subresource, not the object itself (karr | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # k62); get takes it since k58. Set here, the warning names it too. | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 53 | ▶ | $params{subresource} = 'status' if $status && $action eq 'read'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$status and $action eq "read"
MC/DC100%2/2
$status and $action eq "read"
$status
$action eq "read"
Truth table100%3/3
A and B
A= $statusB= $action eq "read"
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | # Show deprecation warning | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 53 | $self->_warn_deprecated($method, $action, $class, \%params, $status); | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | # Call new API | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 53 | return $self->_dispatch($action, $class, \%params, $status); | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 157 | ▶ | sub _parse_method { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_method: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 157 | my ($method) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | # Patterns: List/Read/Create/Replace/Patch/Delete/Watch + Namespaced? + Resource + ForAllNamespaces|Status? | ||||||||||||||||||||||||||||||||||||||||||
| 91 | # The fourth value says whether the name ends in Status. | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 157 | ▶ | if ($method =~ /^(List|Read|Create|Replace|Patch|Delete|Watch)(Namespaced)?(\w+?)(ForAllNamespaces|Status)?$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 59 | my ($action, $namespaced, $resource, $suffix) = ($1, $2, $3, $4); | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # A Kind that itself ends in Status (ComponentStatus) is one whole | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # resource, not a shorter Kind plus a Status subresource: the | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # non-greedy capture split it, so put the suffix back (karr k66). | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 59 | ▶ | if ($suffix && $suffix eq 'Status' && $STATUS_KIND{$resource . $suffix}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$suffix and $suffix eq "Status" and $STATUS_KIND{$resource . $suffix}
$suffix and $suffix eq "Status"
MC/DC100%3/3
$suffix and $suffix eq "Status" and $STATUS_KIND{$resource . $suffix}
$suffix
$suffix eq "Status"
$STATUS_KIND{$resource . $suffix}
Truth table100%4/4
A and B and C
A= $suffixB= $suffix eq "Status"C= $STATUS_KIND{$resource . $suffix}
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | $resource .= $suffix; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | $suffix = undef; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 59 | ▶ | $namespaced = 0 if $suffix && $suffix eq 'ForAllNamespaces'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$suffix and $suffix eq "ForAllNamespaces"
MC/DC100%2/2
$suffix and $suffix eq "ForAllNamespaces"
$suffix
$suffix eq "ForAllNamespaces"
Truth table100%3/3
A and B
A= $suffixB= $suffix eq "ForAllNamespaces"
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 59 | ▶ | return (lc($action), $namespaced ? 1 : 0, $resource, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$suffix and $suffix eq "Status"
MC/DC100%2/2
$suffix and $suffix eq "Status"
$suffix
$suffix eq "Status"
Truth table100%3/3
A and B
A= $suffixB= $suffix eq "Status"
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | ($suffix && $suffix eq 'Status') ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 98 | return (undef, undef, undef); | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | # v0 group name -> IO::K8s group path. Only entries that actually rename | ||||||||||||||||||||||||||||||||||||||||||
| 112 | # something belong here; anything else falls through to the group name as | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # written, which is already the IO::K8s spelling for every shipped group. | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 9 | my %GROUP_MAP = ( | |||||||||||||||||||||||||||||||||||||||||
| 115 | RbacAuthorization => 'Rbac', | ||||||||||||||||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 77 | ▶ | sub _build_class { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_class: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 77 | my ($self, $resource) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 77 | my $group = $self->group; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 77 | my $version = ucfirst(lc($self->version)); | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 77 | ▶ | my $io_group = $GROUP_MAP{$group} // $group; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$GROUP_MAP{$group} // $group
MC/DC0%0/2
$GROUP_MAP{$group} // $group
$GROUP_MAP{$group}
$group
Truth table66%2/3
A // B
A= $GROUP_MAP{$group}B= $group
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | # Not every group lives under IO::K8s::Api:: - apiextensions and | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # apiregistration sit in their own staging namespaces. Kubernetes::REST | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # owns that table, so ask it rather than reimplementing the exception | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # here; the two copies drifting apart is exactly what broke this before. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 77 | return 'IO::K8s::' . $self->api->_io_k8s_namespace_for_group_path($io_group) | |||||||||||||||||||||||||||||||||||||||||
| 130 | . "::${version}::${resource}"; | ||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 53 | ▶ | sub _warn_deprecated { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_warn_deprecated: called CC=17 SCAR=31.6
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 53 | my ($self, $method, $action, $class, $params, $status) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 53 | ▶ | return if $ENV{HIDE_KUBERNETES_REST_V0_API_WARNING}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | my $group = $self->group; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 7 | my $new_call; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 7 | ▶ | if ($action eq 'list') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | ▶ | my $ns = $params->{namespace} ? ", namespace => '$params->{namespace}'" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | $new_call = "\$api->list('$class'$ns)"; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } elsif ($action eq 'read') { | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 3 | ▶ | my $ns = $params->{namespace} ? ", namespace => '$params->{namespace}'" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | ▶ | my $sub = $params->{subresource} ? ", subresource => '$params->{subresource}'" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 3 | $new_call = "\$api->get('$class', name => '$params->{name}'$ns$sub)"; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } elsif ($action eq 'create') { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $new_call = "\$api->create(\$object)"; | |||||||||||||||||||||||||||||||||||||||||
| 150 | } elsif ($action eq 'replace') { | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | $new_call = $status ? "\$api->update_status(\$object)" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | : "\$api->update(\$object)"; | ||||||||||||||||||||||||||||||||||||||||||
| 153 | } elsif ($action eq 'delete') { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | my $ns = $params->{namespace} ? ", namespace => '$params->{namespace}'" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | $new_call = "\$api->delete('$class', name => '$params->{name}'$ns)"; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } elsif ($action eq 'patch') { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | ▶ | my $ns = $params->{namespace} ? ", namespace => '$params->{namespace}'" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | ▶ | my $name = $status ? 'patch_status' : 'patch'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | $new_call = "\$api->$name('$class', name => '$params->{name}'$ns, patch => \\%patch)"; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } elsif ($action eq 'watch') { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $ns = $params->{namespace} ? ", namespace => '$params->{namespace}'" : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $new_call = "\$api->watch('$class'$ns, on_event => sub { ... })"; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $new_call = "\$api->$action('$class', ...)"; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 7 | carp "Kubernetes::REST v0 API is deprecated: \$api->$group->$method(...) should be: $new_call"; | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 53 | ▶ | sub _dispatch { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dispatch: called CC=17 SCAR=28.8
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 53 | my ($self, $action, $class, $params, $status) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 172 | 53 | my $api = $self->api; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 53 | ▶ | if ($action eq 'list') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | # list, get and watch croak on arguments they do not take, as delete | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # does (below). The v0 parameters they have no use for (limit, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | # pretty, watch, timeoutSeconds, ...) were ignored all along; they | ||||||||||||||||||||||||||||||||||||||||||
| 178 | # stay ignored rather than break v0 callers. A List* name goes with | ||||||||||||||||||||||||||||||||||||||||||
| 179 | # them: it made the request a GET of one object, read as an empty | ||||||||||||||||||||||||||||||||||||||||||
| 180 | # list (karr k58). | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 27 | ▶ | my %args = map { exists $params->{$_} ? ($_ => $params->{$_}) : () } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | qw(namespace labelSelector fieldSelector); | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 27 | return $api->list($class, %args); | |||||||||||||||||||||||||||||||||||||||||
| 184 | } elsif ($action eq 'read') { | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 13 | ▶ | my %args = map { exists $params->{$_} ? ($_ => $params->{$_}) : () } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | qw(name namespace subresource); | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 13 | return $api->get($class, %args); | |||||||||||||||||||||||||||||||||||||||||
| 188 | } elsif ($action eq 'create') { | ||||||||||||||||||||||||||||||||||||||||||
| 189 | # For create, we need the body object | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my $body = $params->{body} // croak "create requires 'body' parameter"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$params->{"body"} // croak("create requires 'body' parameter")
MC/DC0%0/1
$params->{"body"} // croak("create requires 'body' parameter")
$params->{"body"}
Truth table0%0/2
A
A= $params->{"body"}
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | return $api->create($body); | |||||||||||||||||||||||||||||||||||||||||
| 192 | } elsif ($action eq 'replace') { | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 4 | ▶ | my $body = $params->{body} // croak "replace requires 'body' parameter"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$params->{"body"} // croak("replace requires 'body' parameter")
MC/DC0%0/1
$params->{"body"} // croak("replace requires 'body' parameter")
$params->{"body"}
Truth table50%1/2
A
A= $params->{"body"}
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | # Replace*Status replaces through the /status subresource: a plain | ||||||||||||||||||||||||||||||||||||||||||
| 195 | # update writes the main endpoint, where the server drops the status | ||||||||||||||||||||||||||||||||||||||||||
| 196 | # and still answers 2xx, losing it silently (karr k65). | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 4 | ▶ | return $status ? $api->update_status($body) : $api->update($body); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | } elsif ($action eq 'delete') { | ||||||||||||||||||||||||||||||||||||||||||
| 199 | # delete croaks on arguments it does not take. The v0 parameters it | ||||||||||||||||||||||||||||||||||||||||||
| 200 | # has no use for (body, gracePeriodSeconds, dryRun, ...) were ignored | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # all along; they stay ignored rather than break v0 callers. | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 3 | ▶ | my %args = map { exists $params->{$_} ? ($_ => $params->{$_}) : () } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | qw(name namespace propagationPolicy); | ||||||||||||||||||||||||||||||||||||||||||
| 204 | 3 | return $api->delete($class, %args); | |||||||||||||||||||||||||||||||||||||||||
| 205 | } elsif ($action eq 'patch') { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | # patch croaks on arguments it does not take (karr k61); the v0 | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # parameters it has no use for (pretty, dryRun, fieldManager, ...) | ||||||||||||||||||||||||||||||||||||||||||
| 208 | # stay ignored, as with delete above. | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 5 | ▶ | my %args = map { exists $params->{$_} ? ($_ => $params->{$_}) : () } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | qw(name namespace patch type); | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # Patch*Status patches through /status, for the same reason as | ||||||||||||||||||||||||||||||||||||||||||
| 212 | # Replace*Status above (karr k65). | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 5 | ▶ | return $status ? $api->patch_status($class, %args) : $api->patch($class, %args); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | } elsif ($action eq 'watch') { | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | ▶ | my %args = map { exists $params->{$_} ? ($_ => $params->{$_}) : () } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | qw(on_event timeout resourceVersion labelSelector fieldSelector namespace); | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | return $api->watch($class, %args); | |||||||||||||||||||||||||||||||||||||||||
| 218 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | croak "Unknown action: $action"; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | # Prevent AUTOLOAD from being called for can() | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 211 | ▶ | sub can { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 211 | my ($self, $method) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 211 | ▶ | return $self->SUPER::can($method) if $self->SUPER::can($method); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | # For v0 API methods, we always "can" | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 99 | my ($action, $namespaced, $resource) = _parse_method($method); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | return sub { $self->$method(@_) } if $action && $resource; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.2
Branch: 1 branch
Condition66%2/3
$action and $resource
MC/DC50%1/2
$action and $resource
$action
$resource
Truth table66%2/3
A and B
A= $actionB= $resource
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 97 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | __END__ | ||||||||||||||||||||||||||||||||||||||||||