| 1 | package MCP::K8s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: MCP Server for Kubernetes with RBAC-aware dynamic tools | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | our $VERSION = '0.004'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use MCP::Server; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | extends 'MCP::Server'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use MCP::K8s::Permissions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use Kubernetes::REST; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use Kubernetes::REST::Kubeconfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use Scalar::Util qw( blessed weaken ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Map common resource short names to their plural form for RBAC checking. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # This is necessary because RBAC rules use plural resource names (e.g. "pods") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # while the Kubernetes::REST API accepts singular Kind names (e.g. "Pod"). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 11 | my %RESOURCE_PLURALS = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | Pod => 'pods', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | Service => 'services', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | Deployment => 'deployments', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ReplicaSet => 'replicasets', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | StatefulSet => 'statefulsets', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | DaemonSet => 'daemonsets', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | Job => 'jobs', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | CronJob => 'cronjobs', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | ConfigMap => 'configmaps', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | Secret => 'secrets', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | Namespace => 'namespaces', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | Node => 'nodes', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | PersistentVolume => 'persistentvolumes', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | PersistentVolumeClaim => 'persistentvolumeclaims', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ServiceAccount => 'serviceaccounts', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | Role => 'roles', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | RoleBinding => 'rolebindings', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ClusterRole => 'clusterroles', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ClusterRoleBinding => 'clusterrolebindings', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | Ingress => 'ingresses', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | NetworkPolicy => 'networkpolicies', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | HorizontalPodAutoscaler => 'horizontalpodautoscalers', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | Event => 'events', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | Endpoints => 'endpoints', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | LimitRange => 'limitranges', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ResourceQuota => 'resourcequotas', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | has context_name => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 16 | ▶ | default => sub { $ENV{MCP_K8S_CONTEXT} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 11 | predicate => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 11 | has kubeconfig_path => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | predicate => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | has token => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 27 | ▶ | default => sub { $ENV{MCP_K8S_TOKEN} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 11 | predicate => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | has server_endpoint => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 9 | ▶ | default => sub { $ENV{MCP_K8S_SERVER} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 11 | predicate => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 11 | has namespaces => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | builder => '_build_namespaces', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 11 | has api => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | builder => '_build_api', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 11 | has permissions => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | builder => '_build_permissions', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | has _resource_plurals_cache => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 47 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 11 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | # Kind => 1 (namespaced) / 0 (cluster-scoped), filled by the discovery | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | has _resource_scopes => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 47 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 11 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | # Plural => 1 (namespaced) / 0 (cluster-scoped), filled by the discovery | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | has _plural_scopes => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 47 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 11 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # Whether the discovery ran at all - a failed discovery must not be retried | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # on every lookup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 11 | has _discovery_done => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # Stores [tool_ref, base_desc, verb] tuples for lazy description updates | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | has _tool_desc_map => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 47 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 11 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 11 | has _descriptions_updated => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | default => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | has json => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 6 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 6 | JSON::MaybeXS->new(utf8 => 1, pretty => 1, canonical => 1, convert_blessed => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 11 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 47 | ▶ | sub server { $_[0] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
server: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 47 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=14.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 47 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 47 | ▶ | $self->name('MCP-K8s') if $self->name eq 'PerlServer'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 47 | ▶ | $self->version($MCP::K8s::VERSION || 'dev') if $self->version eq '1.0.0'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$MCP::K8s::VERSION || 'dev'
MC/DC0%0/1
$MCP::K8s::VERSION || 'dev'
$MCP::K8s::VERSION
Truth table50%1/2
A
A= $MCP::K8s::VERSION
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 47 | $self->_register_tools; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 11 | my $IN_CLUSTER_TOKEN_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/token'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 11 | my $IN_CLUSTER_CA_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 11 | my $IN_CLUSTER_NS_PATH = '/var/run/secrets/kubernetes.io/serviceaccount/namespace'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 11 | my $IN_CLUSTER_DEFAULT_SERVER = 'https://kubernetes.default.svc.cluster.local'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | ▶ | sub _read_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_file: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | my ($self, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | ▶ | open my $fh, '<', $path or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | my $content = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | ▶ | chomp $content if defined $content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | return $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 26 | ▶ | sub _build_api { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_api: called CC=16 SCAR=33.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 26 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # Materialize the env-backed attributes up-front. The lazy `default` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | # subs read $ENV{MCP_K8S_TOKEN} / $ENV{MCP_K8S_SERVER}, but `has_token` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # and `has_server_endpoint` are still false until the reader is called | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # once. Gating Tier 1 on the predicates silently skipped Tier 1 when the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # token came purely from the environment — see Issue #1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 26 | my $token = $self->token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # Tier 1: Direct token from MCP_K8S_TOKEN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 26 | ▶ | if (defined $token && length $token) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $token and length $token
MC/DC100%2/2
defined $token and length $token
defined $token
length $token
Truth table100%3/3
A and B
A= defined $tokenB= length $token
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 7 | my $endpoint = $self->server_endpoint; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 7 | ▶ | $endpoint = $IN_CLUSTER_DEFAULT_SERVER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $endpoint and length $endpoint
MC/DC100%2/2
defined $endpoint and length $endpoint
defined $endpoint
length $endpoint
Truth table100%3/3
A and B
A= defined $endpointB= length $endpoint
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | unless defined $endpoint && length $endpoint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 7 | my %server = (endpoint => $endpoint); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 7 | ▶ | $server{ssl_ca_file} = $IN_CLUSTER_CA_PATH if -f $IN_CLUSTER_CA_PATH; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 7 | return Kubernetes::REST->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | server => \%server, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | credentials => { token => $token }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # Tier 2: In-cluster service account token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 19 | ▶ | if (-f $IN_CLUSTER_TOKEN_PATH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $sa_token = $self->_read_file($IN_CLUSTER_TOKEN_PATH); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if (defined $sa_token && length $sa_token) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $sa_token and length $sa_token
MC/DC0%0/2
defined $sa_token and length $sa_token
defined $sa_token
length $sa_token
Truth table0%0/3
A and B
A= defined $sa_tokenB= length $sa_token
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my $endpoint = $self->server_endpoint; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | $endpoint = $IN_CLUSTER_DEFAULT_SERVER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $endpoint and length $endpoint
MC/DC0%0/2
defined $endpoint and length $endpoint
defined $endpoint
length $endpoint
Truth table0%0/3
A and B
A= defined $endpointB= length $endpoint
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | unless defined $endpoint && length $endpoint; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my %server = (endpoint => $endpoint); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | $server{ssl_ca_file} = $IN_CLUSTER_CA_PATH if -f $IN_CLUSTER_CA_PATH; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | return Kubernetes::REST->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | server => \%server, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | credentials => { token => $sa_token }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | # Tier 3: Kubeconfig. Same predicate-with-lazy-default trap as Tier 1: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # `has_context_name` stays false until the reader fires, so an env-only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # MCP_K8S_CONTEXT would be silently dropped. Pass the materialized value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # through, dropping empty/undef so Kubeconfig keeps its current-context | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # fallback when nothing is set. kubeconfig_path has no env default, but | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | # the same gate applies: Kubeconfig's own kubeconfig_path default is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | # plain (non-lazy) default, so an explicit undef or '' would override | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # its KUBECONFIG / ~/.kube/config lookup instead of leaving it alone. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 19 | my $context_name = $self->context_name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 19 | my $kubeconfig_path = $self->kubeconfig_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 19 | my %kc_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 19 | ▶ | $kc_args{context_name} = $context_name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $context_name and length $context_name
MC/DC100%2/2
defined $context_name and length $context_name
defined $context_name
length $context_name
Truth table100%3/3
A and B
A= defined $context_nameB= length $context_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | if defined $context_name && length $context_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 19 | ▶ | $kc_args{kubeconfig_path} = $kubeconfig_path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $kubeconfig_path and length $kubeconfig_path
MC/DC100%2/2
defined $kubeconfig_path and length $kubeconfig_path
defined $kubeconfig_path
length $kubeconfig_path
Truth table100%3/3
A and B
A= defined $kubeconfig_pathB= length $kubeconfig_path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | if defined $kubeconfig_path && length $kubeconfig_path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 19 | my $kc = Kubernetes::REST::Kubeconfig->new(%kc_args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 19 | return $kc->api; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | ▶ | sub _build_namespaces { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_namespaces: called CC=14 SCAR=49.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # From environment variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | ▶ | if (my $env = $ENV{MCP_K8S_NAMESPACES}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | my @ns = grep { length } split /\s*,\s*/, $env =~ s/^\s+|\s+$//gr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | ▶ | return \@ns if @ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # In-cluster: read mounted namespace as default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if (-f $IN_CLUSTER_NS_PATH) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $ns = $self->_read_file($IN_CLUSTER_NS_PATH); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if (defined $ns && length $ns) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $ns and length $ns
MC/DC0%0/2
defined $ns and length $ns
defined $ns
length $ns
Truth table0%0/3
A and B
A= defined $nsB= length $ns
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | # Try to discover more, but use in-cluster namespace as fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $list = eval { $self->api->list('Namespace') }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if (!$@ && $list) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $@ and $list
MC/DC0%0/2
not $@ and $list
not $@
$list
Truth table0%0/3
not(A) and B
A= not $@B= $list
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | my @ns = map { $_->metadata->name } @{ $list->items // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$list->items // []
MC/DC0%0/1
$list->items // []
$list->items
Truth table0%0/2
A
A= $list->items
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | return \@ns if @ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | return [$ns]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # Auto-discover from cluster | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my $list = eval { $self->api->list('Namespace') }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | if ($@ || !$list) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$@ or not $list
MC/DC0%0/2
$@ or not $list
$@
not $list
Truth table0%0/3
A or not(B)
A= $@B= not $list
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | return ['default']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my @ns = map { $_->metadata->name } @{ $list->items // [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$list->items // []
MC/DC0%0/1
$list->items // []
$list->items
Truth table0%0/2
A
A= $list->items
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | return @ns ? \@ns : ['default']; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 9 | ▶ | sub _build_permissions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_permissions: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 9 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # The resolver tells the RBAC discovery which resources are cluster-scoped, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | # so a namespaced resource never lands in the cluster-scope map. It holds a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | # weak reference back to the server: a strong one would make the server and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # its Permissions object keep each other alive. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 9 | my $weak_self = $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 9 | weaken($weak_self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | return MCP::K8s::Permissions->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | api => $self->api, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | namespaces => $self->namespaces, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 161 | ▶ | scope_resolver => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 161 | my ($plural) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 161 | ▶ | return undef unless $weak_self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 161 | return $weak_self->_scope_of_plural($plural); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 9 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 25 | ▶ | sub _to_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_json: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 25 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 25 | return $self->json->encode($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 93 | ▶ | sub _resource_plural { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resource_plural: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 93 | my ($self, $resource) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # Tier 1: Static map (fast path) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 93 | ▶ | return $RESOURCE_PLURALS{$resource} if $RESOURCE_PLURALS{$resource}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # Tier 2: resource_plural() on the IO::K8s class the Kind resolves to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # Built-in Kinds resolve from the client's built-in map without a request; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # an unknown Kind costs the client's aggregated discovery (GET /api, /apis), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # which the tool's own API call right after would trigger anyway. A Kind | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # nothing ships resolves to a fabricated name or IO::K8s::Unstructured, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # neither of which can resource_plural, so it falls through to tier 3. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 27 | my $class = eval { $self->api->expand_class($resource) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 27 | ▶ | if ($class && $class->can('resource_plural')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$class and $class->can("resource_plural")
MC/DC100%2/2
$class and $class->can("resource_plural")
$class
$class->can("resource_plural")
Truth table100%3/3
A and B
A= $classB= $class->can("resource_plural")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 8 | my $plural = eval { $class->resource_plural }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 8 | ▶ | return $plural if defined $plural && length $plural; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $plural and length $plural
MC/DC0%0/2
defined $plural and length $plural
defined $plural
length $plural
Truth table33%1/3
A and B
A= defined $pluralB= length $plural
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | # Tier 3: API server discovery (cached) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 19 | my $cache = $self->_resource_plurals_cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 19 | ▶ | unless ($self->_discovery_done) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 3 | $self->_discover_resource_plurals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 3 | $cache = $self->_resource_plurals_cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 19 | ▶ | return $cache->{$resource} if $cache->{$resource}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # Tier 4: Heuristic fallback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 12 | my $plural = lc($resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 12 | ▶ | $plural .= 's' unless $plural =~ /s$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 12 | $plural =~ s/([^aeiou])ys$/$1ies/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 12 | return $plural; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 12 | ▶ | sub _discover_resource_plurals { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_discover_resource_plurals: called CC=25 SCAR=35.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 12 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 12 | my %cache; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | my %kind_scopes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 12 | my %plural_scopes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | # Query /api/v1 for core resources | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 12 | my $core = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 12 | my $resp = $self->api->_request('GET', '/api/v1'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 4 | ▶ | return undef if !$resp || $resp->status >= 400; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $resp or $resp->status >= 400
MC/DC50%1/2
not $resp or $resp->status >= 400
not $resp
$resp->status >= 400
Truth table66%2/3
not(A) or B
A= not $respB= $resp->status >= 400
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 3 | JSON::MaybeXS->new->decode($resp->content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 12 | ▶ | if ($core && $core->{resources}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$core and $$core{"resources"}
MC/DC50%1/2
$core and $$core{"resources"}
$core
$$core{"resources"}
Truth table66%2/3
A and B
A= $coreB= $$core{"resources"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 3 | for my $r (@{ $core->{resources} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 15 | ▶ | next if ($r->{name} // '') =~ m{/}; # skip subresources | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$r{"name"} // ""
MC/DC0%0/1
$$r{"name"} // ""
$$r{"name"}
Truth table50%1/2
A
A= $$r{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 12 | ▶ | $cache{ $r->{kind} } = $r->{name} if $r->{kind} && $r->{name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$r{"kind"} and $$r{"name"}
MC/DC0%0/2
$$r{"kind"} and $$r{"name"}
$$r{"kind"}
$$r{"name"}
Truth table33%1/3
A and B
A= $$r{"kind"}B= $$r{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 12 | $self->_record_scope(\%kind_scopes, \%plural_scopes, $r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # Query /apis for API groups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 12 | my $groups = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 12 | my $resp = $self->api->_request('GET', '/apis'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 4 | ▶ | return undef if !$resp || $resp->status >= 400; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $resp or $resp->status >= 400
MC/DC50%1/2
not $resp or $resp->status >= 400
not $resp
$resp->status >= 400
Truth table66%2/3
not(A) or B
A= not $respB= $resp->status >= 400
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 3 | JSON::MaybeXS->new->decode($resp->content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 12 | ▶ | if ($groups && $groups->{groups}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$groups and $$groups{"groups"}
MC/DC50%1/2
$groups and $$groups{"groups"}
$groups
$$groups{"groups"}
Truth table66%2/3
A and B
A= $groupsB= $$groups{"groups"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 3 | for my $group (@{ $groups->{groups} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 3 | ▶ | my $pv = $group->{preferredVersion}{groupVersion} // next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$group{"preferredVersion"}{"groupVersion"} // (next)
MC/DC0%0/1
$$group{"preferredVersion"}{"groupVersion"} // (next)
$$group{"preferredVersion"}{"groupVersion"}
Truth table50%1/2
A
A= $$group{"preferredVersion"}{"groupVersion"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | my $group_resources = eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 3 | my $resp = $self->api->_request('GET', "/apis/$pv"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 3 | ▶ | return undef if !$resp || $resp->status >= 400; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $resp or $resp->status >= 400
MC/DC0%0/2
not $resp or $resp->status >= 400
not $resp
$resp->status >= 400
Truth table33%1/3
not(A) or B
A= not $respB= $resp->status >= 400
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 3 | JSON::MaybeXS->new->decode($resp->content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 3 | ▶ | if ($group_resources && $group_resources->{resources}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$group_resources and $$group_resources{"resources"}
MC/DC0%0/2
$group_resources and $$group_resources{"resources"}
$group_resources
$$group_resources{"resources"}
Truth table33%1/3
A and B
A= $group_resourcesB= $$group_resources{"resources"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 3 | for my $r (@{ $group_resources->{resources} }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 5 | ▶ | next if ($r->{name} // '') =~ m{/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$r{"name"} // ""
MC/DC0%0/1
$$r{"name"} // ""
$$r{"name"}
Truth table50%1/2
A
A= $$r{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 5 | ▶ | $cache{ $r->{kind} } = $r->{name} if $r->{kind} && $r->{name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$r{"kind"} and $$r{"name"}
MC/DC0%0/2
$$r{"kind"} and $$r{"name"}
$$r{"kind"}
$$r{"name"}
Truth table33%1/3
A and B
A= $$r{"kind"}B= $$r{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 5 | $self->_record_scope(\%kind_scopes, \%plural_scopes, $r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 12 | $self->_resource_plurals_cache(\%cache); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 12 | $self->_resource_scopes(\%kind_scopes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 12 | $self->_plural_scopes(\%plural_scopes); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 12 | $self->_discovery_done(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 17 | ▶ | sub _record_scope { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_record_scope: called CC=8 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 17 | my ($self, $kind_scopes, $plural_scopes, $resource) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 17 | my $namespaced = $resource->{namespaced}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 17 | ▶ | return unless defined $namespaced; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 17 | ▶ | my $scope = $namespaced ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 17 | ▶ | $kind_scopes->{ $resource->{kind} } = $scope if $resource->{kind}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # A plural that is namespaced in one API group and cluster-scoped in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # another is ambiguous. The namespaced reading wins: it is the one that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # keeps the resource out of the cluster-scope map. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 17 | ▶ | my $plural = $resource->{name} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 17 | ▶ | $plural_scopes->{$plural} = 1 if $scope; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 17 | ▶ | $plural_scopes->{$plural} = 0 if !$scope && !exists $plural_scopes->{$plural}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$scope || exists $$plural_scopes{$plural}
MC/DC50%1/2
$scope || exists $$plural_scopes{$plural}
$scope
exists $$plural_scopes{$plural}
Truth table66%2/3
A || B
A= $scopeB= exists $$plural_scopes{$plural}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 41 | ▶ | sub _resource_scope { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resource_scope: called CC=7 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 41 | my ($self, $resource) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # The IO::K8s class carries its scope - no request needed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 41 | my $class = eval { $self->api->expand_class($resource) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 41 | ▶ | if ($class && $class->can('resource_plural')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$class and $class->can("resource_plural")
MC/DC0%0/2
$class and $class->can("resource_plural")
$class
$class->can("resource_plural")
Truth table33%1/3
A and B
A= $classB= $class->can("resource_plural")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | my $scope = eval { $class->does('IO::K8s::Role::Namespaced') ? 1 : 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | return $scope if defined $scope; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # Fall back to the discovery cache (CRDs without a class). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 41 | ▶ | unless ($self->_discovery_done) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 5 | $self->_discover_resource_plurals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 41 | my $cache = $self->_resource_scopes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 41 | ▶ | return $cache->{$resource} if exists $cache->{$resource}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 37 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 161 | ▶ | sub _scope_of_plural { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scope_of_plural: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 161 | my ($self, $plural) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 161 | ▶ | unless ($self->_discovery_done) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 4 | $self->_discover_resource_plurals; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 161 | my $cache = $self->_plural_scopes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 161 | ▶ | return $cache->{$plural} if exists $cache->{$plural}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 155 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 51 | ▶ | sub _resolve_namespace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_namespace: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 51 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 51 | my $ns = $args->{namespace}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 51 | ▶ | return $ns if defined $ns && length $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $ns and length $ns
MC/DC100%2/2
defined $ns and length $ns
defined $ns
length $ns
Truth table100%3/3
A and B
A= defined $nsB= length $ns
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # Auto-fill if only one namespace accessible | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 9 | my @allowed = $self->permissions->allowed_namespaces; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 9 | ▶ | return $allowed[0] if @allowed == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 4 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 41 | ▶ | sub _scope_context { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scope_context: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 41 | my ($self, $args, $resource) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 41 | my $scope = $self->_resource_scope($resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 41 | ▶ | my $cluster = defined $scope && !$scope ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $scope and not $scope
MC/DC100%2/2
defined $scope and not $scope
defined $scope
not $scope
Truth table100%3/3
A and not(B)
A= defined $scopeB= not $scope
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 41 | ▶ | my $ns = $cluster ? undef : $self->_resolve_namespace($args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 41 | my $error; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 41 | ▶ | if (!$cluster && !defined $ns && defined $scope) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $cluster || defined $ns and defined $scope
$cluster || defined $ns
MC/DC66%2/3
not $cluster || defined $ns and defined $scope
$cluster
defined $ns
defined $scope
Truth table75%3/4
not(A || B) and C
A= $clusterB= defined $nsC= defined $scope
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 1 | $error = $self->_namespace_required_message($resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 41 | ▶ | scope => $scope, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$ns // ""
MC/DC100%1/1
$ns // ""
$ns
Truth table100%2/2
A
A= $ns
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | cluster => $cluster, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | ns => $ns, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | perm_ns => $cluster ? '' : ($ns // ''), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | error => $error, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 1 | ▶ | sub _namespace_required_message { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_namespace_required_message: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | my ($self, $resource) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | my @available = $self->permissions->allowed_namespaces; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 1 | ▶ | my $hint = @available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | ? ' (available: '.join(', ', @available).')' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 1 | return "namespace required: $resource is a namespaced resource, specify a namespace".$hint; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 13 | ▶ | sub _is_conflict_error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_conflict_error: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 13 | my ($self, $err) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 13 | ▶ | return 0 unless defined $err; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 12 | ▶ | return $err->is_conflict ? 1 : 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
builtin::blessed($err) and $err->isa("Kubernetes::REST::APIError")
MC/DC50%1/2
builtin::blessed($err) and $err->isa("Kubernetes::REST::APIError")
builtin::blessed($err)
$err->isa("Kubernetes::REST::APIError")
Truth table66%2/3
A and B
A= builtin::blessed($err)B= $err->isa("Kubernetes::REST::APIError")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | if blessed($err) && $err->isa('Kubernetes::REST::APIError'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 10 | ▶ | return "$err" =~ /409|AlreadyExists/i ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 22 | ▶ | sub _format_resource_summary { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_resource_summary: called CC=56 SCAR=48.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 22 | my ($self, $obj) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 22 | my %summary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 22 | ▶ | if ($obj->can('metadata') && $obj->metadata) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$obj->can("metadata") and $obj->metadata
MC/DC0%0/2
$obj->can("metadata") and $obj->metadata
$obj->can("metadata")
$obj->metadata
Truth table33%1/3
A and B
A= $obj->can("metadata")B= $obj->metadata
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 22 | my $meta = $obj->metadata; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 22 | ▶ | $summary{name} = $meta->name if $meta->can('name'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 22 | ▶ | $summary{namespace} = $meta->namespace if $meta->can('namespace') && $meta->namespace; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$meta->can("namespace") and $meta->namespace
MC/DC100%2/2
$meta->can("namespace") and $meta->namespace
$meta->can("namespace")
$meta->namespace
Truth table100%3/3
A and B
A= $meta->can("namespace")B= $meta->namespace
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 22 | ▶ | $summary{labels} = $meta->labels if $meta->can('labels') && $meta->labels; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$meta->can("labels") and $meta->labels
MC/DC100%2/2
$meta->can("labels") and $meta->labels
$meta->can("labels")
$meta->labels
Truth table100%3/3
A and B
A= $meta->can("labels")B= $meta->labels
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 22 | ▶ | $summary{creationTimestamp} = $meta->creationTimestamp if $meta->can('creationTimestamp') && $meta->creationTimestamp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$meta->can("creationTimestamp") and $meta->creationTimestamp
MC/DC100%2/2
$meta->can("creationTimestamp") and $meta->creationTimestamp
$meta->can("creationTimestamp")
$meta->creationTimestamp
Truth table100%3/3
A and B
A= $meta->can("creationTimestamp")B= $meta->creationTimestamp
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 22 | ▶ | if ($obj->can('kind') && $obj->kind) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$obj->can("kind") and $obj->kind
MC/DC0%0/2
$obj->can("kind") and $obj->kind
$obj->can("kind")
$obj->kind
Truth table33%1/3
A and B
A= $obj->can("kind")B= $obj->kind
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 22 | $summary{kind} = $obj->kind; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | # Events carry their payload at the top level (core/v1) or under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | # note/regarding (events.k8s.io), not in spec/status. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 22 | ▶ | if (($obj->can('kind') && ($obj->kind // '') eq 'Event') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition63%7/11
$obj->can("kind") and ($obj->kind // "") eq "Event" or $obj->can("involvedObject") or $obj->can("regarding")
$obj->can("kind") and ($obj->kind // "") eq "Event" or $obj->can("involvedObject")
$obj->can("kind") and ($obj->kind // "") eq "Event"
$obj->kind // ""
MC/DC0%0/4
$obj->can("kind") and ($obj->kind // "") eq "Event" or $obj->can("involvedObject") or $obj->can("regarding")
$obj->can("kind")
$obj->kind
$obj->can("involvedObject")
$obj->can("regarding")
Truth table14%1/7
A and B or C or D
A= $obj->can("kind")B= $obj->kindC= $obj->can("involvedObject")D= $obj->can("regarding")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | || $obj->can('involvedObject') || $obj->can('regarding')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 5 | for my $f (qw( type reason message note count firstTimestamp lastTimestamp eventTime )) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 40 | ▶ | next unless $obj->can($f); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 7 | my $v = $obj->$f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 7 | ▶ | $summary{$f} = $v if defined $v && $v ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $v and $v ne ""
MC/DC50%1/2
defined $v and $v ne ""
defined $v
$v ne ""
Truth table66%2/3
A and B
A= defined $vB= $v ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 5 | for my $f (qw( involvedObject regarding )) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 10 | ▶ | next unless $obj->can($f) && $obj->$f; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$obj->can($f) and $obj->$f
MC/DC50%1/2
$obj->can($f) and $obj->$f
$obj->can($f)
$obj->$f
Truth table66%2/3
A and B
A= $obj->can($f)B= $obj->$f
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | my $ref = $obj->$f; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | ▶ | my %r = map { $ref->can($_) && defined $ref->$_ ? ( $_ => $ref->$_ ) : () } qw( kind name ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ref->can($_) and defined $ref->$_
MC/DC0%0/2
$ref->can($_) and defined $ref->$_
$ref->can($_)
defined $ref->$_
Truth table33%1/3
A and B
A= $ref->can($_)B= defined $ref->$_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 1 | ▶ | $summary{$f} = \%r if %r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 22 | ▶ | if ($obj->can('status') && $obj->status) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$obj->can("status") and $obj->status
MC/DC100%2/2
$obj->can("status") and $obj->status
$obj->can("status")
$obj->status
Truth table100%3/3
A and B
A= $obj->can("status")B= $obj->status
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 13 | my $status = $obj->status; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 13 | ▶ | $summary{phase} = $status->phase if $status->can('phase') && $status->phase; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$status->can("phase") and $status->phase
MC/DC0%0/2
$status->can("phase") and $status->phase
$status->can("phase")
$status->phase
Truth table33%1/3
A and B
A= $status->can("phase")B= $status->phase
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 13 | ▶ | $summary{replicas} = $status->replicas if $status->can('replicas') && defined $status->replicas; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$status->can("replicas") and defined $status->replicas
MC/DC0%0/2
$status->can("replicas") and defined $status->replicas
$status->can("replicas")
defined $status->replicas
Truth table33%1/3
A and B
A= $status->can("replicas")B= defined $status->replicas
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 13 | ▶ | $summary{readyReplicas} = $status->readyReplicas if $status->can('readyReplicas') && defined $status->readyReplicas; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$status->can("readyReplicas") and defined $status->readyReplicas
MC/DC0%0/2
$status->can("readyReplicas") and defined $status->readyReplicas
$status->can("readyReplicas")
defined $status->readyReplicas
Truth table33%1/3
A and B
A= $status->can("readyReplicas")B= defined $status->readyReplicas
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 13 | ▶ | $summary{availableReplicas} = $status->availableReplicas if $status->can('availableReplicas') && defined $status->availableReplicas; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$status->can("availableReplicas") and defined $status->availableReplicas
MC/DC0%0/2
$status->can("availableReplicas") and defined $status->availableReplicas
$status->can("availableReplicas")
defined $status->availableReplicas
Truth table33%1/3
A and B
A= $status->can("availableReplicas")B= defined $status->availableReplicas
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 13 | ▶ | $summary{conditions} = $status->conditions if $status->can('conditions') && $status->conditions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$status->can("conditions") and $status->conditions
MC/DC0%0/2
$status->can("conditions") and $status->conditions
$status->can("conditions")
$status->conditions
Truth table33%1/3
A and B
A= $status->can("conditions")B= $status->conditions
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 22 | ▶ | if ($obj->can('spec') && $obj->spec) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$obj->can("spec") and $obj->spec
MC/DC100%2/2
$obj->can("spec") and $obj->spec
$obj->can("spec")
$obj->spec
Truth table100%3/3
A and B
A= $obj->can("spec")B= $obj->spec
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 2 | my $spec = $obj->spec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 2 | ▶ | $summary{replicas} //= $spec->replicas if $spec->can('replicas') && defined $spec->replicas; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$spec->can("replicas") and defined $spec->replicas
$summary{"replicas"} //= $spec->replicas
MC/DC0%0/2
$spec->can("replicas") and defined $spec->replicas
$spec->can("replicas")
defined $spec->replicas
MC/DC0%0/2
$summary{"replicas"} //= $spec->replicas
$summary{"replicas"}
$spec->replicas
Truth table33%1/3
A and B
A= $spec->can("replicas")B= defined $spec->replicas
Truth table0%0/3
A //= B
A= $summary{"replicas"}B= $spec->replicas
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 2 | ▶ | if ($spec->can('containers') && $spec->containers) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$spec->can("containers") and $spec->containers
MC/DC50%1/2
$spec->can("containers") and $spec->containers
$spec->can("containers")
$spec->containers
Truth table66%2/3
A and B
A= $spec->can("containers")B= $spec->containers
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 1 | $summary{containers} = [ map { $_->name } @{ $spec->containers } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 2 | ▶ | if ($spec->can('type') && $spec->type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$spec->can("type") and $spec->type
MC/DC50%1/2
$spec->can("type") and $spec->type
$spec->can("type")
$spec->type
Truth table66%2/3
A and B
A= $spec->can("type")B= $spec->type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 1 | $summary{type} = $spec->type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 2 | ▶ | if ($spec->can('ports') && $spec->ports) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$spec->can("ports") and $spec->ports
MC/DC50%1/2
$spec->can("ports") and $spec->ports
$spec->can("ports")
$spec->ports
Truth table66%2/3
A and B
A= $spec->can("ports")B= $spec->ports
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | $summary{ports} = [ map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 2 | my $p = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 2 | my %port; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 2 | ▶ | $port{port} = $p->port if $p->can('port') && defined $p->port; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$p->can("port") and defined $p->port
MC/DC0%0/2
$p->can("port") and defined $p->port
$p->can("port")
defined $p->port
Truth table33%1/3
A and B
A= $p->can("port")B= defined $p->port
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 2 | ▶ | $port{targetPort} = $p->targetPort if $p->can('targetPort') && defined $p->targetPort; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$p->can("targetPort") and defined $p->targetPort
MC/DC0%0/2
$p->can("targetPort") and defined $p->targetPort
$p->can("targetPort")
defined $p->targetPort
Truth table33%1/3
A and B
A= $p->can("targetPort")B= defined $p->targetPort
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 2 | ▶ | $port{protocol} = $p->protocol if $p->can('protocol') && $p->protocol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$p->can("protocol") and $p->protocol
MC/DC0%0/2
$p->can("protocol") and $p->protocol
$p->can("protocol")
$p->protocol
Truth table33%1/3
A and B
A= $p->can("protocol")B= $p->protocol
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 2 | \%port; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 1 | } @{ $spec->ports } ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 22 | return \%summary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 10 | ▶ | sub _format_list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_format_list: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 10 | my ($self, $items) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 10 | my @summaries; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 10 | ▶ | for my $item (@{ $items // [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$items // []
MC/DC100%1/1
$items // []
$items
Truth table100%2/2
A
A= $items
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 15 | push @summaries, $self->_format_resource_summary($item); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 10 | return \@summaries; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 16 | ▶ | sub _available_resources_desc { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_available_resources_desc: called CC=6 SCAR=19.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 16 | my ($self, $verb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 16 | my @parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 16 | for my $ns ($self->permissions->allowed_namespaces) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 16 | my @resources = $self->permissions->allowed_resources($verb, $ns); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 16 | ▶ | if (@resources) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 16 | my @display = grep { $_ ne '*' } @resources; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 16 | ▶ | if (grep { $_ eq '*' } @resources) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | push @parts, "$ns: all resources"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } elsif (@display > 10) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | push @parts, "$ns: " . join(', ', @display[0..9]) . ", ..."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 16 | push @parts, "$ns: " . join(', ', @display); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 16 | ▶ | return join('; ', @parts) || 'none discovered'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
join('; ', @parts) || 'none discovered'
MC/DC0%0/1
join('; ', @parts) || 'none discovered'
join('; ', @parts)
Truth table50%1/2
A
A= join('; ', @parts)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 2 | ▶ | sub _update_tool_descriptions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_update_tool_descriptions: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 2 | ▶ | return if $self->_descriptions_updated; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 2 | $self->permissions->ensure_discovered; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 2 | for my $entry (@{ $self->_tool_desc_map }) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 18 | my ($tool, $base, $verb) = @$entry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 18 | ▶ | if ($verb eq '_logs') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | my @log_ns = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 2 | $self->permissions->can_read_logs($_) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } $self->permissions->allowed_namespaces; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 2 | ▶ | $tool->description($base . (join(', ', @log_ns) || 'none')); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
join(', ', @log_ns) || 'none'
MC/DC0%0/1
join(', ', @log_ns) || 'none'
join(', ', @log_ns)
Truth table50%1/2
A
A= join(', ', @log_ns)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 16 | $tool->description($base . $self->_available_resources_desc($verb)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 2 | $self->_descriptions_updated(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | ▶ | sub _tools { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tools: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 1 | my ($self, $context) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 1 | $self->_update_tool_descriptions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 1 | return $self->SUPER::_tools($context); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 47 | ▶ | sub _register_tools { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_register_tools: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 47 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 47 | my @desc_map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | # ---- Tool 1: k8s_permissions ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | $self->tool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | name => 'k8s_permissions', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | description => 'Show what this Kubernetes service account is allowed to do (RBAC permissions). Call this first to understand available capabilities.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | input_schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | properties => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 2 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 2 | my ($tool, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 2 | return $self->permissions->summary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 47 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | # ---- Tool 2: k8s_list ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 47 | my $list_desc = 'List Kubernetes resources.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | push @desc_map, [$self->tool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | name => 'k8s_list', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | description => $list_desc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | input_schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | properties => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | resource => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | description => 'Resource type (e.g. Pod, Deployment, Service, ConfigMap)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | namespace => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | description => 'Namespace (auto-detected if only one available)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | label_selector => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | description => 'Label selector filter (e.g. app=web)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | field_selector => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | description => 'Field selector filter (e.g. status.phase=Running)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | required => ['resource'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 7 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 7 | my ($tool, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 7 | my $resource = $args->{resource}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 7 | my $ctx = $self->_scope_context($args, $resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 7 | ▶ | return $ctx->{error} if $ctx->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 6 | my $ns = $ctx->{ns}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 6 | my $plural = $self->_resource_plural($resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 6 | ▶ | unless ($self->permissions->can_do('list', $plural, $ctx->{perm_ns})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 1 | ▶ | return "Permission denied: cannot list $resource" . ($ns ? " in namespace $ns" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 5 | my %api_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 5 | ▶ | $api_args{namespace} = $ns if defined $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 5 | ▶ | $api_args{labelSelector} = $args->{label_selector} if $args->{label_selector}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 5 | ▶ | $api_args{fieldSelector} = $args->{field_selector} if $args->{field_selector}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 5 | my $list = eval { $self->api->list($resource, %api_args) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 5 | ▶ | return "Failed to list $resource: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 5 | ▶ | my $items = $list->items // []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$list->items // []
MC/DC0%0/1
$list->items // []
$list->items
Truth table50%1/2
A
A= $list->items
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 5 | ▶ | return "No $resource resources found" unless @$items; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 5 | my $summaries = $self->_format_list($items); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 5 | return $self->_to_json({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | count => scalar @$items, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | items => $summaries, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 47 | ), 'List Kubernetes resources. Available: ', 'list']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | # ---- Tool 3: k8s_get ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 47 | my $get_desc = 'Get a single Kubernetes resource.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | push @desc_map, [$self->tool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | name => 'k8s_get', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | description => $get_desc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | input_schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | properties => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | resource => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | description => 'Resource type (e.g. Pod, Deployment, Service)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | name => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | description => 'Resource name', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | namespace => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | description => 'Namespace (auto-detected if only one available)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | output => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | description => 'Output format: summary (default), json, yaml', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | enum => ['summary', 'json', 'yaml'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | required => ['resource', 'name'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 9 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=23.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 9 | my ($tool, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 9 | my $resource = $args->{resource}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 9 | my $name = $args->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 9 | my $ctx = $self->_scope_context($args, $resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 9 | ▶ | return $ctx->{error} if $ctx->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 9 | my $ns = $ctx->{ns}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 9 | ▶ | my $output = $args->{output} // 'summary'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$args{"output"} // "summary"
MC/DC100%1/1
$$args{"output"} // "summary"
$$args{"output"}
Truth table100%2/2
A
A= $$args{"output"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 9 | my $plural = $self->_resource_plural($resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 9 | ▶ | unless ($self->permissions->can_do('get', $plural, $ctx->{perm_ns})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 1 | ▶ | return "Permission denied: cannot get $resource" . ($ns ? " in namespace $ns" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 8 | my %api_args = (name => $name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 8 | ▶ | $api_args{namespace} = $ns if defined $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 8 | my $obj = eval { $self->api->get($resource, %api_args) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 8 | ▶ | return "Failed to get $resource/$name: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 8 | ▶ | if ($output eq 'json') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 2 | return $self->_to_json($obj->TO_JSON); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | } elsif ($output eq 'yaml') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | # IO::K8s::Role::APIObject::to_yaml, not a YAML dump of TO_JSON. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | # TO_JSON hands out JSON::PP::Boolean objects for every boolean field, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | # and a generic dumper serialises those as Perl internals — | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | # "hostNetwork: !!perl/scalar:JSON::PP::Boolean 1" instead of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | # "hostNetwork: true", which kubectl apply rejects. to_yaml runs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | # YAML::PP with the JSON schema and boolean => 'JSON::PP', which is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | # what makes the output a manifest. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 3 | ▶ | unless ($obj->can('to_yaml')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 1 | return "Cannot render $resource/$name as YAML: " . ref($obj) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | . " does not implement to_yaml (not a top-level Kubernetes API" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | . " object). Retry with output 'json'."; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 2 | return $obj->to_yaml; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 3 | return $self->_to_json($self->_format_resource_summary($obj)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 47 | ), 'Get a single Kubernetes resource. Available: ', 'get']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | # ---- Tool 4: k8s_create ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 47 | my $create_desc = 'Create a Kubernetes resource.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | push @desc_map, [$self->tool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | name => 'k8s_create', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | description => $create_desc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | input_schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | properties => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | resource => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | description => 'Resource type (e.g. Pod, Deployment, ConfigMap)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | namespace => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | description => 'Namespace for the resource', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | manifest => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | description => 'Resource manifest (apiVersion/kind auto-populated from resource type)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | required => ['resource', 'manifest'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 2 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=25.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 2 | my ($tool, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 2 | my $resource = $args->{resource}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 2 | my $ctx = $self->_scope_context($args, $resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 2 | ▶ | return $ctx->{error} if $ctx->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 2 | my $ns = $ctx->{ns}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 2 | my $manifest = $args->{manifest}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 2 | my $plural = $self->_resource_plural($resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 2 | ▶ | unless ($self->permissions->can_do('create', $plural, $ctx->{perm_ns})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 1 | ▶ | return "Permission denied: cannot create $resource" . ($ns ? " in namespace $ns" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | # Auto-populate namespace in metadata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 1 | ▶ | if (defined $ns) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 1 | ▶ | $manifest->{metadata} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$manifest{"metadata"} //= {}
MC/DC0%0/1
$$manifest{"metadata"} //= {}
$$manifest{"metadata"}
Truth table50%1/2
A
A= $$manifest{"metadata"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 1 | ▶ | $manifest->{metadata}{namespace} //= $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$$manifest{"metadata"}{"namespace"} //= $ns
MC/DC0%0/2
$$manifest{"metadata"}{"namespace"} //= $ns
$$manifest{"metadata"}{"namespace"}
$ns
Truth table33%1/3
A //= B
A= $$manifest{"metadata"}{"namespace"}B= $ns
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 1 | my $obj = eval { $self->api->new_object($resource, $manifest) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 1 | ▶ | return "Failed to build $resource object: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 1 | my $created = eval { $self->api->create($obj) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 1 | ▶ | return "Failed to create $resource: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 1 | ▶ | my $created_name = eval { $created->metadata->name } // 'unknown'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
$created->metadata->name
}
} // "unknown"
MC/DC0%0/1
eval {
do {
$created->metadata->name
}
} // "unknown"
eval {
do {
$created->metadata->name
}
}
Truth table50%1/2
A
A= eval {
do {
$created->metadata->name
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 1 | ▶ | return $self->_to_json({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | status => 'created', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | kind => $resource, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | name => $created_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | ($ns ? (namespace => $ns) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 47 | ), 'Create a Kubernetes resource. Available: ', 'create']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | # ---- Tool 5: k8s_patch ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 47 | my $patch_desc = 'Patch (partial update) a Kubernetes resource.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | push @desc_map, [$self->tool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | name => 'k8s_patch', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | description => $patch_desc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | input_schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | properties => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | resource => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | description => 'Resource type (e.g. Deployment, Service)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | name => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | description => 'Resource name', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | namespace => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | description => 'Namespace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | patch => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | description => 'Patch body (fields to change)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | patch_type => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | description => 'Patch strategy: strategic (default, merge for status), merge, json', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | enum => ['strategic', 'merge', 'json'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | subresource => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | description => 'Write to a subresource instead of the main endpoint. ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | . 'Use "status" for status fields: the API server strips status ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | . 'from writes to the main endpoint and still answers 2xx.', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | enum => ['status'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | required => ['resource', 'name', 'patch'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 7 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=16 SCAR=27.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 7 | my ($tool, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | 7 | my $resource = $args->{resource}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 7 | my $name = $args->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 7 | my $ctx = $self->_scope_context($args, $resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | 7 | ▶ | return $ctx->{error} if $ctx->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 7 | my $ns = $ctx->{ns}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 7 | my $patch = $args->{patch}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | 7 | my $subresource = $args->{subresource}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 7 | my $plural = $self->_resource_plural($resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | 7 | ▶ | if (defined $subresource && $subresource ne 'status') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $subresource and $subresource ne "status"
MC/DC100%2/2
defined $subresource and $subresource ne "status"
defined $subresource
$subresource ne "status"
Truth table100%3/3
A and B
A= defined $subresourceB= $subresource ne "status"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | 1 | return "Unsupported subresource '$subresource': only 'status' is supported"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | 6 | ▶ | my $to_status = defined $subresource && $subresource eq 'status'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $subresource && $subresource eq 'status'
MC/DC50%1/2
defined $subresource && $subresource eq 'status'
defined $subresource
$subresource eq 'status'
Truth table66%2/3
A && B
A= defined $subresourceB= $subresource eq 'status'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | # The status subresource is its own RBAC resource: patch on <plural> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | # does not grant patch on <plural>/status. The plural cache cannot help | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | # here — _discover_resource_plurals skips names containing '/' — so the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | # subresource is appended to the base plural. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | 6 | ▶ | my $rbac_resource = $to_status ? "$plural/status" : $plural; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | 6 | ▶ | unless ($self->permissions->can_do('patch', $rbac_resource, $ctx->{perm_ns})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 2 | ▶ | return "Permission denied: cannot patch " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | . ($to_status ? "$resource status" : $resource) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | . ($ns ? " in namespace $ns" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | # Status writes default to a merge patch: custom resources answer 415 to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | # a strategic merge patch. An explicit patch_type still wins. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | my $patch_type = $args->{patch_type} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 4 | ▶ | // ($to_status ? 'merge' : 'strategic'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$$args{"patch_type"} // ($to_status ? "merge" : "strategic")
MC/DC100%1/1
$$args{"patch_type"} // ($to_status ? "merge" : "strategic")
$$args{"patch_type"}
Truth table100%2/2
A
A= $$args{"patch_type"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 4 | my %api_args = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | patch => $patch, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | type => $patch_type, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 4 | ▶ | $api_args{namespace} = $ns if defined $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | # patch() writes the main endpoint, which silently drops a status stanza | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | # for every resource that has a status subresource. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 4 | ▶ | my $method = $to_status ? 'patch_status' : 'patch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 4 | my $patched = eval { $self->api->$method($resource, $name, %api_args) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 4 | ▶ | return "Failed to patch $resource/$name: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 4 | ▶ | return $self->_to_json({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | status => 'patched', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | kind => $resource, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | ($to_status ? (subresource => 'status') : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | ($ns ? (namespace => $ns) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 47 | ), 'Patch (partial update) a Kubernetes resource. Available: ', 'patch']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | # ---- Tool 6: k8s_delete ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 47 | my $delete_desc = 'Delete a Kubernetes resource.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | push @desc_map, [$self->tool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | name => 'k8s_delete', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | description => $delete_desc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | input_schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | properties => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | resource => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | description => 'Resource type (e.g. Pod, Deployment)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | name => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | description => 'Resource name', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | namespace => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | description => 'Namespace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | required => ['resource', 'name'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | 2 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 2 | my ($tool, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | 2 | my $resource = $args->{resource}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 2 | my $name = $args->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | 2 | my $ctx = $self->_scope_context($args, $resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | 2 | ▶ | return $ctx->{error} if $ctx->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 2 | my $ns = $ctx->{ns}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | 2 | my $plural = $self->_resource_plural($resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | 2 | ▶ | unless ($self->permissions->can_do('delete', $plural, $ctx->{perm_ns})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 1 | ▶ | return "Permission denied: cannot delete $resource" . ($ns ? " in namespace $ns" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 1 | my %api_args = (name => $name); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | 1 | ▶ | $api_args{namespace} = $ns if defined $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 1 | eval { $self->api->delete($resource, %api_args) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 1 | ▶ | return "Failed to delete $resource/$name: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | 1 | ▶ | return $self->_to_json({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | status => 'deleted', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | kind => $resource, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | ($ns ? (namespace => $ns) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | 47 | ), 'Delete a Kubernetes resource. Available: ', 'delete']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | # ---- Tool 7: k8s_logs ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | 47 | my $logs_desc = 'Get pod logs from Kubernetes pods.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | push @desc_map, [$self->tool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | name => 'k8s_logs', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | description => $logs_desc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | input_schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | properties => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | name => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | description => 'Pod name', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | namespace => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | description => 'Namespace (auto-detected if only one available)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | container => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | description => 'Container name (required for multi-container pods)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | tail_lines => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | type => 'integer', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | description => 'Number of lines from end (default: 100)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | previous => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | type => 'boolean', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | description => 'Get logs from previous container instance', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | required => ['name'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | 6 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | 6 | my ($tool, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | 6 | my $name = $args->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | 6 | my $ns = $self->_resolve_namespace($args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | 6 | my $container = $args->{container}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | 6 | ▶ | my $tail_lines = $args->{tail_lines} // 100; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$args{"tail_lines"} // 100
MC/DC100%1/1
$$args{"tail_lines"} // 100
$$args{"tail_lines"}
Truth table100%2/2
A
A= $$args{"tail_lines"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | 6 | ▶ | my $previous = $args->{previous} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$args{"previous"} // 0
MC/DC100%1/1
$$args{"previous"} // 0
$$args{"previous"}
Truth table100%2/2
A
A= $$args{"previous"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | 6 | ▶ | unless ($ns) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | 1 | return "Namespace required for pod logs"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | 5 | ▶ | unless ($self->permissions->can_read_logs($ns)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | 1 | return "Permission denied: cannot read pod logs in namespace $ns"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | # Kubernetes::REST's log() builds /api/v1/namespaces/$ns/pods/$name/log | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | # and the query parameters itself. It raises API errors (404, 403, ...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | # instead of handing back the response, so the status check lives in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | # eval now. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | 4 | my %log_args = (name => $name, namespace => $ns); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | 4 | ▶ | $log_args{tailLines} = $tail_lines if $tail_lines; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | 4 | ▶ | $log_args{container} = $container if $container; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | 4 | ▶ | $log_args{previous} = 1 if $previous; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | 4 | my $content = eval { $self->api->log('Pod', %log_args) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | 4 | ▶ | return "Failed to get logs for pod/$name: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | 3 | ▶ | return ($content // '') || "(no log output)"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
($content // '') || '(no log output)'
$content // ""
MC/DC0%0/1
($content // '') || '(no log output)'
$content
Truth table50%1/2
A
A= $content
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | 47 | ), 'Get pod logs. Available in namespaces: ', '_logs']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | # ---- Tool 8: k8s_events ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | 47 | my $events_desc = 'Get Kubernetes events for debugging.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | push @desc_map, [$self->tool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | name => 'k8s_events', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | description => $events_desc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | input_schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | properties => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | namespace => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | description => 'Namespace (auto-detected if only one available)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | involved_object => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | description => 'Filter events by involved object name (e.g. a pod name)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | field_selector => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | description => 'Field selector filter (e.g. reason=BackOff)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | 3 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | 3 | my ($tool, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | 3 | my $ctx = $self->_scope_context($args, 'Event'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | 3 | ▶ | return $ctx->{error} if $ctx->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | 3 | my $ns = $ctx->{ns}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | 3 | ▶ | unless ($self->permissions->can_do('list', 'events', $ctx->{perm_ns})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | 1 | ▶ | return "Permission denied: cannot list events" . ($ns ? " in namespace $ns" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | 2 | my %api_args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | 2 | ▶ | $api_args{namespace} = $ns if defined $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | 2 | my @selectors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | 2 | ▶ | if (my $obj = $args->{involved_object}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | 1 | push @selectors, "involvedObject.name=$obj"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | 2 | ▶ | if (my $fs = $args->{field_selector}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | 0 | push @selectors, $fs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | 2 | ▶ | $api_args{fieldSelector} = join(',', @selectors) if @selectors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | 2 | my $list = eval { $self->api->list('Event', %api_args) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | 2 | ▶ | return "Failed to list events: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | 2 | ▶ | my $items = $list->items // []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$list->items // []
MC/DC0%0/1
$list->items // []
$list->items
Truth table50%1/2
A
A= $list->items
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | 2 | ▶ | return "No events found" unless @$items; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | 2 | my $summaries = $self->_format_list($items); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | 2 | return $self->_to_json({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | count => scalar @$items, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | items => $summaries, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | 47 | ), 'Get Kubernetes events for debugging. Available in: ', 'list']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | # ---- Tool 9: k8s_rollout_restart ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | 47 | my $restart_desc = 'Trigger rolling restart of a Deployment, StatefulSet, or DaemonSet.'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | push @desc_map, [$self->tool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | name => 'k8s_rollout_restart', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | description => $restart_desc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | input_schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | properties => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | resource => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | description => 'Resource type: Deployment, StatefulSet, or DaemonSet', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | enum => ['Deployment', 'StatefulSet', 'DaemonSet'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | name => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | description => 'Resource name', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | namespace => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | description => 'Namespace', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | required => ['resource', 'name'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | 2 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | 2 | my ($tool, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | 2 | my $resource = $args->{resource}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | 2 | my $name = $args->{name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | 2 | my $ctx = $self->_scope_context($args, $resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | 2 | ▶ | return $ctx->{error} if $ctx->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | 2 | my $ns = $ctx->{ns}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | 2 | my $plural = $self->_resource_plural($resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | 2 | ▶ | unless ($self->permissions->can_do('patch', $plural, $ctx->{perm_ns})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | 1 | ▶ | return "Permission denied: cannot patch $resource" . ($ns ? " in namespace $ns" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | # Generate ISO 8601 timestamp without POSIX dependency | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | 1 | my @t = gmtime; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | 1 | my $timestamp = sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | $t[5] + 1900, $t[4] + 1, $t[3], $t[2], $t[1], $t[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | 1 | my $patch = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | spec => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | template => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | metadata => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | annotations => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | 'kubectl.kubernetes.io/restartedAt' => $timestamp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | 1 | my %api_args = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | patch => $patch, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | type => 'strategic', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | 1 | ▶ | $api_args{namespace} = $ns if defined $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | 1 | my $patched = eval { $self->api->patch($resource, $name, %api_args) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | 1 | ▶ | return "Failed to restart $resource/$name: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | 1 | ▶ | return $self->_to_json({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | status => 'restarting', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | kind => $resource, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | restartAt => $timestamp, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | ($ns ? (namespace => $ns) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | 47 | ), 'Trigger rolling restart of a Deployment, StatefulSet, or DaemonSet. Available: ', 'patch']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | # ---- Tool 10: k8s_apply ---- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | 47 | my $apply_desc = 'Create or update a Kubernetes resource (like kubectl apply).'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | push @desc_map, [$self->tool( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | name => 'k8s_apply', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | description => $apply_desc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | input_schema => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | properties => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | resource => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | description => 'Resource type (e.g. Deployment, ConfigMap)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | namespace => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | type => 'string', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | description => 'Namespace for the resource', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | manifest => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | type => 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | description => 'Resource manifest (must include metadata.name)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | required => ['resource', 'manifest'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | 9 | ▶ | code => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=23 SCAR=34.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | 9 | my ($tool, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | 9 | my $resource = $args->{resource}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | 9 | my $ctx = $self->_scope_context($args, $resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | 9 | ▶ | return $ctx->{error} if $ctx->{error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | 9 | my $ns = $ctx->{ns}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | 9 | my $manifest = $args->{manifest}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | 9 | my $plural = $self->_resource_plural($resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | 9 | my $can_create = $self->permissions->can_do('create', $plural, $ctx->{perm_ns}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | 9 | my $can_patch = $self->permissions->can_do('patch', $plural, $ctx->{perm_ns}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | 9 | ▶ | unless ($can_create || $can_patch) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$can_create or $can_patch
MC/DC50%1/2
$can_create or $can_patch
$can_create
$can_patch
Truth table66%2/3
A or B
A= $can_createB= $can_patch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | 1 | ▶ | return "Permission denied: cannot create or patch $resource" . ($ns ? " in namespace $ns" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | 8 | my $res_name = eval { $manifest->{metadata}{name} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | 8 | ▶ | return "manifest must include metadata.name" unless defined $res_name && length $res_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $res_name and length $res_name
MC/DC50%1/2
defined $res_name and length $res_name
defined $res_name
length $res_name
Truth table66%2/3
A and B
A= defined $res_nameB= length $res_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | # Auto-populate namespace in metadata | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | 7 | ▶ | if (defined $ns) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | 7 | ▶ | $manifest->{metadata} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$manifest{"metadata"} //= {}
MC/DC0%0/1
$$manifest{"metadata"} //= {}
$$manifest{"metadata"}
Truth table50%1/2
A
A= $$manifest{"metadata"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | 7 | ▶ | $manifest->{metadata}{namespace} //= $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$$manifest{"metadata"}{"namespace"} //= $ns
MC/DC0%0/2
$$manifest{"metadata"}{"namespace"} //= $ns
$$manifest{"metadata"}{"namespace"}
$ns
Truth table33%1/3
A //= B
A= $$manifest{"metadata"}{"namespace"}B= $ns
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | # Try create first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | 7 | ▶ | if ($can_create) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | 7 | my $obj = eval { $self->api->new_object($resource, $manifest) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | 7 | ▶ | return "Failed to build $resource object: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | 7 | my $created = eval { $self->api->create($obj) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | 7 | ▶ | if (!$@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | 1 | ▶ | my $created_name = eval { $created->metadata->name } // $res_name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
eval {
do {
$created->metadata->name
}
} // $res_name
MC/DC0%0/2
eval {
do {
$created->metadata->name
}
} // $res_name
eval {
do {
$created->metadata->name
}
}
$res_name
Truth table33%1/3
A // B
A= eval {
do {
$created->metadata->name
}
}B= $res_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | 1 | ▶ | return $self->_to_json({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | status => 'created', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | kind => $resource, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | name => $created_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | ($ns ? (namespace => $ns) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | # If 409 Conflict / AlreadyExists, fall through to patch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | 6 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | 6 | ▶ | unless ($self->_is_conflict_error($err)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | 2 | return "Failed to create $resource: $err"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | # Fall back to a patch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | 4 | ▶ | unless ($can_patch) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | 0 | ▶ | return "Resource already exists and cannot patch $resource" . ($ns ? " in namespace $ns" : ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | # Strategic merge is understood by the built-in kinds only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | # (IO::K8s::Api::*); a custom resource answers it with 415, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | # everything else gets a JSON merge patch. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | 4 | ▶ | my $class = eval { $self->api->expand_class($resource) } // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
eval {
do {
$self->api->expand_class($resource)
}
} // ""
MC/DC0%0/1
eval {
do {
$self->api->expand_class($resource)
}
} // ""
eval {
do {
$self->api->expand_class($resource)
}
}
Truth table50%1/2
A
A= eval {
do {
$self->api->expand_class($resource)
}
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | 4 | ▶ | my %api_args = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1238 | patch => $manifest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1239 | type => $class =~ /^IO::K8s::Api::/ ? 'strategic' : 'merge', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1240 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1241 | 4 | ▶ | $api_args{namespace} = $ns if defined $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1243 | 4 | my $patched = eval { $self->api->patch($resource, $res_name, %api_args) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1244 | 4 | ▶ | return "Failed to update $resource/$res_name: $@" if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1246 | 4 | ▶ | return $self->_to_json({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1247 | status => 'updated', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1248 | kind => $resource, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1249 | name => $res_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1250 | ($ns ? (namespace => $ns) : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1251 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1252 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1253 | 47 | ), 'Create or update a Kubernetes resource (like kubectl apply). Available: ', 'create']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1255 | 47 | $self->_tool_desc_map(\@desc_map); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1258 | 0 | ▶ | sub run_stdio { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_stdio: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1259 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1262 | 0 | ▶ | $self = $self->new unless ref $self; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1263 | # Not redundant with the _tools override: fails fast before to_stdio. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1264 | 0 | $self->_update_tool_descriptions; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1265 | 0 | $self->to_stdio; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1268 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1270 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||