blib/lib/IO/K8s/Role/APIObject.pm

filter: Statementstmt 92.2% 237 / 257 Branchbran 77.3% 116 / 150 Conditioncond 51.4% 54 / 105 MC/DCmcdc 26.5% 17 / 64 Subroutinesub 97.6% 41 / 42 Podpod 100% 24 / 24 totaltotal 76.1% 489 / 642 CC 120 SCAR 28.8
CC
120
Cov
79%
is_owned_by
95.5
set_owner
24.6
_extract_conditions
17.6
CRAP 17.8
« blib/lib/IO/K8s/Resource.pm ↑ Summary lib/IO/K8s/CRD/Emitter.pm »
1 package IO::K8s::Role::APIObject;
2 # ABSTRACT: Role for top-level Kubernetes API objects
3 143 our $VERSION = '1.112';
4 143 ▶use Types::Standard qw( InstanceOf Maybe );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 143 ▶use IO::K8s::Resource ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 143 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 143 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 143 ▶use mro ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 # Imports above `use Moo::Role` on purpose: Role::Tiny treats subs already in
10 # the package as not-methods, so their names stay off every consumer. A `use`
11 # below that line composes its exports onto all shipped classes (k118).
12 143 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 # Composed here rather than only onto CRD classes in IO::K8s::APIObject's
14 # import (k103). The builder roles -- CertManaged, HelmManaged,
15 # MiddlewareBuilder, MiddlewareTCPBuilder, Loadbalanced, Routable,
16 # NetworkPolicy -- build their specs through spec_set/spec_push/..., and
17 # two of them (Routable, NetworkPolicy) are composed onto core Kinds that
18 # are not CRDs. With SpecBuilder only on CRD classes that coupling could
19 # not be declared: a `requires 'spec_set'` in those roles would have
20 # rejected networking/v1 Ingress and networking/v1 NetworkPolicy. Composing
21 # it for every top-level Kind is what makes the requires correct, and it is
22 # harmless on a typed core spec since D2 taught the walk to go through the
23 # attribute registry.
24 #
25 # It widens the public surface deliberately: spec_get/spec_set/spec_array/
26 # spec_hash/spec_push/spec_merge/spec_delete are now on all ~213 shipped
27 # APIObject classes. The 32 Kinds with no `spec` field at all carry them
28 # too and croak naming the class -- see IO::K8s::Role::SpecBuilder.
29 143 with 'IO::K8s::Role::SpecBuilder';
30  
31 # Written once, used by both the type constraint and the coercion below so
32 # they cannot name different classes.
33 143 my $OBJECT_META = 'IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::ObjectMeta';
34  
35 # metadata is the one object-bearing field of a top-level Kind that the k8s
36 # DSL does not create: this role composes first, and IO::K8s::APIObject::import
37 # (like IO::K8s::AutoGen) then only registers it through
38 # IO::K8s::Resource::_k8s_adopt, which installs nothing (k144). What that
39 # means is that the coercion has to be declared here instead.
40 # _object_coercer is _k8s's own, so `metadata` coerces exactly
41 # like every other is_object field -- Pod->new(metadata => { name => 'x' })
42 # builds an ObjectMeta through the same call FROM_HASH makes (k115).
43 #
44 # `use IO::K8s::Resource ()`, with the empty import list: its import turns
45 # the caller into a Moo class via _setup_class, which is not what a role
46 # wants. Nothing IO::K8s::Resource loads leads back here, so this closes no
47 # cycle -- and _object_coercer only builds the closure, it does not reach
48 # for IO::K8s until something is actually coerced.
49 143 has metadata => (
50 is => 'rw',
51 isa => Maybe[InstanceOf[$OBJECT_META]],
52 coerce => IO::K8s::Resource::_object_coercer($OBJECT_META),
53 );
54  
55  
56 # Map IO::K8s short group names to full Kubernetes API group names
57 143 my %API_GROUP_MAP = (
58 rbac => 'rbac.authorization.k8s.io',
59 networking => 'networking.k8s.io',
60 storage => 'storage.k8s.io',
61 admissionregistration => 'admissionregistration.k8s.io',
62 certificates => 'certificates.k8s.io',
63 coordination => 'coordination.k8s.io',
64 events => 'events.k8s.io',
65 scheduling => 'scheduling.k8s.io',
66 authentication => 'authentication.k8s.io',
67 authorization => 'authorization.k8s.io',
68 node => 'node.k8s.io',
69 discovery => 'discovery.k8s.io',
70 flowcontrol => 'flowcontrol.apiserver.k8s.io',
71 resource => 'resource.k8s.io',
72 apiserverinternal => 'internal.apiserver.k8s.io',
73 storagemigration => 'storagemigration.k8s.io',
74 lifecycle => 'lifecycle.k8s.io',
75 );
76  
77 # Derive apiVersion from a class-name string in a known namespace:
78 # IO::K8s::Api::Core::V1::Pod -> v1
79 # IO::K8s::Api::Apps::V1::Deployment -> apps/v1
80 # IO::K8s::Api::Rbac::V1::Role -> rbac.authorization.k8s.io/v1
81 # IO::K8s::ApiextensionsApiserver::...::V1::CustomResourceDefinition -> apiextensions.k8s.io/v1
82 # IO::K8s::KubeAggregator::...::V1::APIService -> apiregistration.k8s.io/v1
83 3677 ▶sub _api_version_from_class {
Subroutine _api_version_from_class: called CC=6 SCAR=17.9
84 3677 my ($class) = @_;
85  
86 # Standard API: IO::K8s::Api::Group::Version::Kind
87 3677 ▶ if ($class =~ /^IO::K8s::Api::(\w+)::(\w+)::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /^IO::K8s::Api::(\w+)::(\w+)::/) 3452 225 3677
88 3452 my ($group, $version) = ($1, $2);
89 3452 $version = lc($version);
90 3452 ▶ return $version if $group eq 'Core';
Branch: 1 branch
BranchTrueFalseTotal
if $group eq "Core" 976 2476 3452
91 2476 my $group_lc = lc($group);
92 2476 ▶ return ($API_GROUP_MAP{$group_lc} // $group_lc) . '/' . $version;
Condition66%2/3
$API_GROUP_MAP{$group_lc} // $group_lc
l!l&&r!l&&!r
20244520
MC/DC0%0/2
$API_GROUP_MAP{$group_lc} // $group_lc
$API_GROUP_MAP{$group_lc} $group_lc
Truth table66%2/3
A // B
A= $API_GROUP_MAP{$group_lc}B= $group_lc
ABresult
1X1
011
000
93 }
94  
95 # Apiextensions: IO::K8s::ApiextensionsApiserver::Pkg::Apis::Apiextensions::Version::Kind
96 225 ▶ if ($class =~ /^IO::K8s::ApiextensionsApiserver::Pkg::Apis::Apiextensions::(\w+)::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /^IO::K8s::ApiextensionsApiserver::Pkg::Apis::Apiextensions::(\w+)::/) 160 65 225
97 160 return 'apiextensions.k8s.io/' . lc($1);
98 }
99  
100 # KubeAggregator: IO::K8s::KubeAggregator::Pkg::Apis::Apiregistration::Version::Kind
101 65 ▶ if ($class =~ /^IO::K8s::KubeAggregator::Pkg::Apis::Apiregistration::(\w+)::/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /^IO::K8s::KubeAggregator::Pkg::Apis::Apiregistration::(\w+)::/) 28 37 65
102 28 return 'apiregistration.k8s.io/' . lc($1);
103 }
104  
105 37 return undef;
106 }
107  
108 # Kind -> plural resource name. Two generated tables, looked up in this
109 # order by _resource_plural_from_class() below:
110 #
111 # 1. %RESOURCE_PLURAL keyed "$api_version/$Kind"
112 # 2. %RESOURCE_PLURAL_BY_GROUP keyed "$group|$Kind"
113 #
114 # Tier 1 is the exact GVK: the same domain-qualified key shape as
115 # %DEFAULT_RESOURCE_MAP's qualified keys in IO::K8s, and exactly what
116 # api_version() below returns joined to kind(). The group is folded into the
117 # api_version, so core/v1 Event and events.k8s.io/v1 Event stay distinct
118 # entries. It is consulted first because it is the more specific fact and
119 # keeps the exact-GVK answer authoritative.
120 #
121 # Tier 2 is the GroupResource, and it is the *correct* key for the consumer
122 # this exists for rather than a loosening of tier 1: RBAC addresses
123 # resources by apiGroups + resources, with no version in the rule at all, so
124 # the plural is a property of the group and the Kind. It covers the shipped
125 # classes that sit on API tracks upstream no longer serves
126 # (resource.k8s.io/v1alpha3, flowcontrol.apiserver.k8s.io/v1beta3,
127 # storage.k8s.io/v1alpha1, ...), which have no tier-1 key of their own but
128 # whose served siblings do. Core is a group of its own (the empty group), so
129 # core Event and events.k8s.io Event stay distinct here too -- this is
130 # group+Kind, never a bare Kind, and the generator only emits an entry when
131 # every version of that group in the spec agrees on the plural (k36).
132 #
133 # Generated, not hand-written: the plural is not derivable from the Kind
134 # (Endpoints -> endpoints, NetworkPolicy -> networkpolicies, Ingress ->
135 # ingresses, PriorityClass -> priorityclasses), but it is authoritative in
136 # the upstream spec's REST paths. maint/spec-resource-plural-gen.pl reads it
137 # off there and rewrites both blocks below; do not edit them by hand.
138 #
139 # Central rather than per-class for the same reason api_version is: one
140 # table beats writing a literal into ~180 shipped classes, and the @ISA
141 # fallback then gives class_namespaces subclasses the plural for free. An
142 # explicit per-class resource_plural -- a CRD's
143 # `use IO::K8s::APIObject resource_plural => ...`, or IO::K8s::AutoGen's
144 # option -- is installed into the package *before* this role is composed,
145 # so it still wins over everything here.
146 #
147 # Absent on purpose from both tables, and staying undef: subresources
148 # (Eviction, Scale, TokenRequest -- addressed as pods/eviction,
149 # deployments/scale, serviceaccounts/token, never as a resource of their
150 # own), the embedded *Template / *TemplateSpec types that have no GVK at
151 # all, and any Kind the spec has no collection endpoint for anywhere in its
152 # group. A miss in both tiers returns undef; nothing falls back to a guess,
153 # because a wrong plural is indistinguishable from a denied permission at
154 # the RBAC layer, which is the whole reason these tables exist (k33).
155 # --- BEGIN GENERATED resource plural table (v1.37.0) ---
156 # Regenerate with: maint/spec-resource-plural-gen.pl --spec spec/v1.37.0.json
157 143 my %RESOURCE_PLURAL = (
158 # core
159 'v1/Binding' => 'bindings',
160 'v1/ComponentStatus' => 'componentstatuses',
161 'v1/ConfigMap' => 'configmaps',
162 'v1/Endpoints' => 'endpoints',
163 'v1/Event' => 'events',
164 'v1/LimitRange' => 'limitranges',
165 'v1/Namespace' => 'namespaces',
166 'v1/Node' => 'nodes',
167 'v1/PersistentVolume' => 'persistentvolumes',
168 'v1/PersistentVolumeClaim' => 'persistentvolumeclaims',
169 'v1/Pod' => 'pods',
170 'v1/PodTemplate' => 'podtemplates',
171 'v1/ReplicationController' => 'replicationcontrollers',
172 'v1/ResourceQuota' => 'resourcequotas',
173 'v1/Secret' => 'secrets',
174 'v1/Service' => 'services',
175 'v1/ServiceAccount' => 'serviceaccounts',
176  
177 # admissionregistration.k8s.io
178 'admissionregistration.k8s.io/v1/MutatingAdmissionPolicy' => 'mutatingadmissionpolicies',
179 'admissionregistration.k8s.io/v1/MutatingAdmissionPolicyBinding' => 'mutatingadmissionpolicybindings',
180 'admissionregistration.k8s.io/v1/MutatingWebhookConfiguration' => 'mutatingwebhookconfigurations',
181 'admissionregistration.k8s.io/v1/ValidatingAdmissionPolicy' => 'validatingadmissionpolicies',
182 'admissionregistration.k8s.io/v1/ValidatingAdmissionPolicyBinding' => 'validatingadmissionpolicybindings',
183 'admissionregistration.k8s.io/v1/ValidatingWebhookConfiguration' => 'validatingwebhookconfigurations',
184 'admissionregistration.k8s.io/v1alpha1/MutatingAdmissionPolicy' => 'mutatingadmissionpolicies',
185 'admissionregistration.k8s.io/v1alpha1/MutatingAdmissionPolicyBinding' => 'mutatingadmissionpolicybindings',
186 'admissionregistration.k8s.io/v1beta1/MutatingAdmissionPolicy' => 'mutatingadmissionpolicies',
187 'admissionregistration.k8s.io/v1beta1/MutatingAdmissionPolicyBinding' => 'mutatingadmissionpolicybindings',
188  
189 # apiextensions.k8s.io
190 'apiextensions.k8s.io/v1/CustomResourceDefinition' => 'customresourcedefinitions',
191  
192 # apiregistration.k8s.io
193 'apiregistration.k8s.io/v1/APIService' => 'apiservices',
194  
195 # apps
196 'apps/v1/ControllerRevision' => 'controllerrevisions',
197 'apps/v1/DaemonSet' => 'daemonsets',
198 'apps/v1/Deployment' => 'deployments',
199 'apps/v1/ReplicaSet' => 'replicasets',
200 'apps/v1/StatefulSet' => 'statefulsets',
201  
202 # authentication.k8s.io
203 'authentication.k8s.io/v1/SelfSubjectReview' => 'selfsubjectreviews',
204 'authentication.k8s.io/v1/TokenReview' => 'tokenreviews',
205  
206 # authorization.k8s.io
207 'authorization.k8s.io/v1/LocalSubjectAccessReview' => 'localsubjectaccessreviews',
208 'authorization.k8s.io/v1/SelfSubjectAccessReview' => 'selfsubjectaccessreviews',
209 'authorization.k8s.io/v1/SelfSubjectRulesReview' => 'selfsubjectrulesreviews',
210 'authorization.k8s.io/v1/SubjectAccessReview' => 'subjectaccessreviews',
211  
212 # autoscaling
213 'autoscaling/v1/HorizontalPodAutoscaler' => 'horizontalpodautoscalers',
214 'autoscaling/v2/HorizontalPodAutoscaler' => 'horizontalpodautoscalers',
215  
216 # batch
217 'batch/v1/CronJob' => 'cronjobs',
218 'batch/v1/Job' => 'jobs',
219  
220 # certificates.k8s.io
221 'certificates.k8s.io/v1/CertificateSigningRequest' => 'certificatesigningrequests',
222 'certificates.k8s.io/v1/ClusterTrustBundle' => 'clustertrustbundles',
223 'certificates.k8s.io/v1/PodCertificateRequest' => 'podcertificaterequests',
224 'certificates.k8s.io/v1beta1/ClusterTrustBundle' => 'clustertrustbundles',
225 'certificates.k8s.io/v1beta1/PodCertificateRequest' => 'podcertificaterequests',
226  
227 # coordination.k8s.io
228 'coordination.k8s.io/v1/Lease' => 'leases',
229 'coordination.k8s.io/v1alpha2/LeaseCandidate' => 'leasecandidates',
230 'coordination.k8s.io/v1beta1/LeaseCandidate' => 'leasecandidates',
231  
232 # discovery.k8s.io
233 'discovery.k8s.io/v1/EndpointSlice' => 'endpointslices',
234  
235 # events.k8s.io
236 'events.k8s.io/v1/Event' => 'events',
237  
238 # flowcontrol.apiserver.k8s.io
239 'flowcontrol.apiserver.k8s.io/v1/FlowSchema' => 'flowschemas',
240 'flowcontrol.apiserver.k8s.io/v1/PriorityLevelConfiguration' => 'prioritylevelconfigurations',
241  
242 # internal.apiserver.k8s.io
243 'internal.apiserver.k8s.io/v1alpha1/StorageVersion' => 'storageversions',
244  
245 # lifecycle.k8s.io
246 'lifecycle.k8s.io/v1alpha1/Eviction' => 'evictions',
247 'lifecycle.k8s.io/v1alpha1/EvictionRequest' => 'evictionrequests',
248  
249 # networking.k8s.io
250 'networking.k8s.io/v1/IPAddress' => 'ipaddresses',
251 'networking.k8s.io/v1/Ingress' => 'ingresses',
252 'networking.k8s.io/v1/IngressClass' => 'ingressclasses',
253 'networking.k8s.io/v1/NetworkPolicy' => 'networkpolicies',
254 'networking.k8s.io/v1/ServiceCIDR' => 'servicecidrs',
255  
256 # node.k8s.io
257 'node.k8s.io/v1/RuntimeClass' => 'runtimeclasses',
258  
259 # policy
260 'policy/v1/PodDisruptionBudget' => 'poddisruptionbudgets',
261  
262 # rbac.authorization.k8s.io
263 'rbac.authorization.k8s.io/v1/ClusterRole' => 'clusterroles',
264 'rbac.authorization.k8s.io/v1/ClusterRoleBinding' => 'clusterrolebindings',
265 'rbac.authorization.k8s.io/v1/Role' => 'roles',
266 'rbac.authorization.k8s.io/v1/RoleBinding' => 'rolebindings',
267  
268 # resource.k8s.io
269 'resource.k8s.io/v1/DeviceClass' => 'deviceclasses',
270 'resource.k8s.io/v1/DeviceTaintRule' => 'devicetaintrules',
271 'resource.k8s.io/v1/ResourceClaim' => 'resourceclaims',
272 'resource.k8s.io/v1/ResourceClaimTemplate' => 'resourceclaimtemplates',
273 'resource.k8s.io/v1/ResourceSlice' => 'resourceslices',
274 'resource.k8s.io/v1alpha3/DeviceTaintRule' => 'devicetaintrules',
275 'resource.k8s.io/v1alpha3/ResourcePoolStatusRequest' => 'resourcepoolstatusrequests',
276 'resource.k8s.io/v1beta1/DeviceClass' => 'deviceclasses',
277 'resource.k8s.io/v1beta1/ResourceClaim' => 'resourceclaims',
278 'resource.k8s.io/v1beta1/ResourceClaimTemplate' => 'resourceclaimtemplates',
279 'resource.k8s.io/v1beta1/ResourceSlice' => 'resourceslices',
280 'resource.k8s.io/v1beta2/DeviceClass' => 'deviceclasses',
281 'resource.k8s.io/v1beta2/DeviceTaintRule' => 'devicetaintrules',
282 'resource.k8s.io/v1beta2/ResourceClaim' => 'resourceclaims',
283 'resource.k8s.io/v1beta2/ResourceClaimTemplate' => 'resourceclaimtemplates',
284 'resource.k8s.io/v1beta2/ResourceSlice' => 'resourceslices',
285  
286 # scheduling.k8s.io
287 'scheduling.k8s.io/v1/PriorityClass' => 'priorityclasses',
288 'scheduling.k8s.io/v1alpha3/CompositePodGroup' => 'compositepodgroups',
289 'scheduling.k8s.io/v1alpha3/PodGroup' => 'podgroups',
290 'scheduling.k8s.io/v1alpha3/Workload' => 'workloads',
291 'scheduling.k8s.io/v1beta1/PodGroup' => 'podgroups',
292 'scheduling.k8s.io/v1beta1/Workload' => 'workloads',
293  
294 # storage.k8s.io
295 'storage.k8s.io/v1/CSIDriver' => 'csidrivers',
296 'storage.k8s.io/v1/CSINode' => 'csinodes',
297 'storage.k8s.io/v1/CSIStorageCapacity' => 'csistoragecapacities',
298 'storage.k8s.io/v1/StorageClass' => 'storageclasses',
299 'storage.k8s.io/v1/VolumeAttachment' => 'volumeattachments',
300 'storage.k8s.io/v1/VolumeAttributesClass' => 'volumeattributesclasses',
301  
302 # storagemigration.k8s.io
303 'storagemigration.k8s.io/v1/StorageVersionMigration' => 'storageversionmigrations',
304 'storagemigration.k8s.io/v1beta1/StorageVersionMigration' => 'storageversionmigrations',
305 );
306 # --- END GENERATED resource plural table ---
307  
308 # --- BEGIN GENERATED group resource plural table (v1.37.0) ---
309 # Regenerate with: maint/spec-resource-plural-gen.pl --spec spec/v1.37.0.json
310 143 my %RESOURCE_PLURAL_BY_GROUP = (
311 # core
312 '|Binding' => 'bindings',
313 '|ComponentStatus' => 'componentstatuses',
314 '|ConfigMap' => 'configmaps',
315 '|Endpoints' => 'endpoints',
316 '|Event' => 'events',
317 '|LimitRange' => 'limitranges',
318 '|Namespace' => 'namespaces',
319 '|Node' => 'nodes',
320 '|PersistentVolume' => 'persistentvolumes',
321 '|PersistentVolumeClaim' => 'persistentvolumeclaims',
322 '|Pod' => 'pods',
323 '|PodTemplate' => 'podtemplates',
324 '|ReplicationController' => 'replicationcontrollers',
325 '|ResourceQuota' => 'resourcequotas',
326 '|Secret' => 'secrets',
327 '|Service' => 'services',
328 '|ServiceAccount' => 'serviceaccounts',
329  
330 # admissionregistration.k8s.io
331 'admissionregistration.k8s.io|MutatingAdmissionPolicy' => 'mutatingadmissionpolicies',
332 'admissionregistration.k8s.io|MutatingAdmissionPolicyBinding' => 'mutatingadmissionpolicybindings',
333 'admissionregistration.k8s.io|MutatingWebhookConfiguration' => 'mutatingwebhookconfigurations',
334 'admissionregistration.k8s.io|ValidatingAdmissionPolicy' => 'validatingadmissionpolicies',
335 'admissionregistration.k8s.io|ValidatingAdmissionPolicyBinding' => 'validatingadmissionpolicybindings',
336 'admissionregistration.k8s.io|ValidatingWebhookConfiguration' => 'validatingwebhookconfigurations',
337  
338 # apiextensions.k8s.io
339 'apiextensions.k8s.io|CustomResourceDefinition' => 'customresourcedefinitions',
340  
341 # apiregistration.k8s.io
342 'apiregistration.k8s.io|APIService' => 'apiservices',
343  
344 # apps
345 'apps|ControllerRevision' => 'controllerrevisions',
346 'apps|DaemonSet' => 'daemonsets',
347 'apps|Deployment' => 'deployments',
348 'apps|ReplicaSet' => 'replicasets',
349 'apps|StatefulSet' => 'statefulsets',
350  
351 # authentication.k8s.io
352 'authentication.k8s.io|SelfSubjectReview' => 'selfsubjectreviews',
353 'authentication.k8s.io|TokenReview' => 'tokenreviews',
354  
355 # authorization.k8s.io
356 'authorization.k8s.io|LocalSubjectAccessReview' => 'localsubjectaccessreviews',
357 'authorization.k8s.io|SelfSubjectAccessReview' => 'selfsubjectaccessreviews',
358 'authorization.k8s.io|SelfSubjectRulesReview' => 'selfsubjectrulesreviews',
359 'authorization.k8s.io|SubjectAccessReview' => 'subjectaccessreviews',
360  
361 # autoscaling
362 'autoscaling|HorizontalPodAutoscaler' => 'horizontalpodautoscalers',
363  
364 # batch
365 'batch|CronJob' => 'cronjobs',
366 'batch|Job' => 'jobs',
367  
368 # certificates.k8s.io
369 'certificates.k8s.io|CertificateSigningRequest' => 'certificatesigningrequests',
370 'certificates.k8s.io|ClusterTrustBundle' => 'clustertrustbundles',
371 'certificates.k8s.io|PodCertificateRequest' => 'podcertificaterequests',
372  
373 # coordination.k8s.io
374 'coordination.k8s.io|Lease' => 'leases',
375 'coordination.k8s.io|LeaseCandidate' => 'leasecandidates',
376  
377 # discovery.k8s.io
378 'discovery.k8s.io|EndpointSlice' => 'endpointslices',
379  
380 # events.k8s.io
381 'events.k8s.io|Event' => 'events',
382  
383 # flowcontrol.apiserver.k8s.io
384 'flowcontrol.apiserver.k8s.io|FlowSchema' => 'flowschemas',
385 'flowcontrol.apiserver.k8s.io|PriorityLevelConfiguration' => 'prioritylevelconfigurations',
386  
387 # internal.apiserver.k8s.io
388 'internal.apiserver.k8s.io|StorageVersion' => 'storageversions',
389  
390 # lifecycle.k8s.io
391 'lifecycle.k8s.io|Eviction' => 'evictions',
392 'lifecycle.k8s.io|EvictionRequest' => 'evictionrequests',
393  
394 # networking.k8s.io
395 'networking.k8s.io|IPAddress' => 'ipaddresses',
396 'networking.k8s.io|Ingress' => 'ingresses',
397 'networking.k8s.io|IngressClass' => 'ingressclasses',
398 'networking.k8s.io|NetworkPolicy' => 'networkpolicies',
399 'networking.k8s.io|ServiceCIDR' => 'servicecidrs',
400  
401 # node.k8s.io
402 'node.k8s.io|RuntimeClass' => 'runtimeclasses',
403  
404 # policy
405 'policy|PodDisruptionBudget' => 'poddisruptionbudgets',
406  
407 # rbac.authorization.k8s.io
408 'rbac.authorization.k8s.io|ClusterRole' => 'clusterroles',
409 'rbac.authorization.k8s.io|ClusterRoleBinding' => 'clusterrolebindings',
410 'rbac.authorization.k8s.io|Role' => 'roles',
411 'rbac.authorization.k8s.io|RoleBinding' => 'rolebindings',
412  
413 # resource.k8s.io
414 'resource.k8s.io|DeviceClass' => 'deviceclasses',
415 'resource.k8s.io|DeviceTaintRule' => 'devicetaintrules',
416 'resource.k8s.io|ResourceClaim' => 'resourceclaims',
417 'resource.k8s.io|ResourceClaimTemplate' => 'resourceclaimtemplates',
418 'resource.k8s.io|ResourcePoolStatusRequest' => 'resourcepoolstatusrequests',
419 'resource.k8s.io|ResourceSlice' => 'resourceslices',
420  
421 # scheduling.k8s.io
422 'scheduling.k8s.io|CompositePodGroup' => 'compositepodgroups',
423 'scheduling.k8s.io|PodGroup' => 'podgroups',
424 'scheduling.k8s.io|PriorityClass' => 'priorityclasses',
425 'scheduling.k8s.io|Workload' => 'workloads',
426  
427 # storage.k8s.io
428 'storage.k8s.io|CSIDriver' => 'csidrivers',
429 'storage.k8s.io|CSINode' => 'csinodes',
430 'storage.k8s.io|CSIStorageCapacity' => 'csistoragecapacities',
431 'storage.k8s.io|StorageClass' => 'storageclasses',
432 'storage.k8s.io|VolumeAttachment' => 'volumeattachments',
433 'storage.k8s.io|VolumeAttributesClass' => 'volumeattributesclasses',
434  
435 # storagemigration.k8s.io
436 'storagemigration.k8s.io|StorageVersionMigration' => 'storageversionmigrations',
437 );
438 # --- END GENERATED group resource plural table ---
439  
440 # Walk @ISA depth-first, left to right (same shape as
441 # IO::K8s::Role::Resource::_merged_attr_info) so a consumer subclass
442 # registered via class_namespaces derives the apiVersion from the first
443 # ancestor that is a known namespace.
444 17 ▶sub _api_version_from_isa {
Subroutine _api_version_from_isa: called CC=4 SCAR=16.1
445 17 my ($class) = @_;
446 143 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
447 17 for my $parent (@{"${class}::ISA"}) {
448 17 my $version = _api_version_from_class($parent);
449 17 ▶ return $version if defined $version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 17 0 17
450 0 $version = _api_version_from_isa($parent);
451 0 ▶ return $version if defined $version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 0 0 0
452 }
453 0 return undef;
454 }
455  
456  
457 3013 ▶sub api_version {
Subroutine api_version: called CC=4 SCAR=13.9
Pod documented
458 3013 my ($self) = @_;
459 3013 ▶ croak __PACKAGE__.'->api_version is derived from the class name and cannot be set'
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 1 3012 3013
460 if @_ > 1;
461 3012 ▶ my $class = ref($self) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
26293830
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
462  
463 3012 my $version = _api_version_from_class($class);
464 3012 ▶ return $version if defined $version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 2995 17 3012
465  
466 17 return _api_version_from_isa($class);
467 }
468  
469 # Look the plural up under the same "$api_version/$Kind" key the generated
470 # table is written with, then fall back to "$group|$Kind". Both halves come
471 # from the class name, so this is only ever a hit for a class in one of the
472 # known namespaces -- a CRD class with an explicitly installed api_version()
473 # never reaches here at all (its own resource_plural, if it declared one,
474 # shadows this role's).
475 #
476 # The group is recovered from the api_version the same way the generator
477 # folded it in: everything before the last '/', and the empty string for a
478 # core-group version like "v1". A miss in both tiers is undef, never a
479 # guess.
480 648 ▶sub _resource_plural_from_class {
Subroutine _resource_plural_from_class: called CC=5 SCAR=16.2
481 648 my ($class) = @_;
482  
483 648 my $version = _api_version_from_class($class);
484 648 ▶ return undef unless defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 20 628 648
485  
486 628 my ($kind) = $class =~ /::(\w+)\z/;
487 628 ▶ return undef unless defined $kind;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $kind 0 628 628
488  
489 628 my $plural = $RESOURCE_PLURAL{"$version/$kind"};
490 628 ▶ return $plural if defined $plural;
Branch: 1 branch
BranchTrueFalseTotal
if defined $plural 513 115 628
491  
492 115 my ($group) = $version =~ m{\A(.*)/[^/]+\z};
493 115 ▶ $group = '' unless defined $group;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $group 0 115 115
494  
495 115 return $RESOURCE_PLURAL_BY_GROUP{"$group|$kind"};
496 }
497  
498 # Same depth-first, left-to-right @ISA walk as _api_version_from_isa, for
499 # the same reason: a consumer subclass registered via class_namespaces
500 # ('My::K8s::Api::Core::V1::Pod' -> IO::K8s::Api::Core::V1::Pod) inherits
501 # the plural from the first ancestor in a known namespace.
502 33 ▶sub _resource_plural_from_isa {
Subroutine _resource_plural_from_isa: called CC=4 SCAR=13.9
503 33 my ($class) = @_;
504 143 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
505 33 for my $parent (@{"${class}::ISA"}) {
506 19 my $plural = _resource_plural_from_class($parent);
507 19 ▶ return $plural if defined $plural;
Branch: 1 branch
BranchTrueFalseTotal
if defined $plural 4 15 19
508 15 $plural = _resource_plural_from_isa($parent);
509 15 ▶ return $plural if defined $plural;
Branch: 1 branch
BranchTrueFalseTotal
if defined $plural 1 14 15
510 }
511 28 return undef;
512 }
513  
514  
515 5734 ▶sub kind {
Subroutine kind: called CC=5 SCAR=16.4
Pod documented
516 5734 my ($self) = @_;
517 5734 ▶ croak __PACKAGE__.'->kind is derived from the class name and cannot be set'
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 3 5731 5734
518 if @_ > 1;
519 5731 ▶ my $class = ref($self) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
48948370
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
520  
521 5731 ▶ if ($class =~ /::(\w+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /::(\w+)$/) 5708 23 5731
522 5708 return $1;
523 }
524  
525 # No '::' at all: a CRD registered as a single-segment top-level package,
526 # reached as '+Widget' or through a resource_map value of '+Widget'. That
527 # is a supported shape -- '+Name' is the documented route to a
528 # single-segment class of your own, and k35 is what made those names
529 # reliably reachable -- so the whole name is the last segment. Without
530 # this the class is reachable but TO_JSON emits no kind: at all, which the
531 # API server rejects (k38).
532 23 ▶ if ($class =~ /\A(\w+)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /\A(\w+)\z/) 23 0 23
533 23 return $1;
534 }
535  
536 0 return undef;
537 }
538  
539  
540 630 ▶sub resource_plural {
Subroutine resource_plural: called CC=4 SCAR=13.9
Pod documented
541 630 my ($self) = @_;
542 630 ▶ croak __PACKAGE__.'->resource_plural is derived from the class name and cannot be set'
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 1 629 630
543 if @_ > 1;
544 629 ▶ my $class = ref($self) || $self;
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
56240
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
545  
546 629 my $plural = _resource_plural_from_class($class);
547 629 ▶ return $plural if defined $plural;
Branch: 1 branch
BranchTrueFalseTotal
if defined $plural 611 18 629
548  
549 18 return _resource_plural_from_isa($class);
550 }
551  
552 2486 ▶sub _is_resource { 1 }
Subroutine _is_resource: called CC=1 SCAR=0.0
553  
554  
555 291 ▶sub to_crd {
Subroutine to_crd: called CC=2 SCAR=7.0
Pod documented
556 291 my ($self) = @_;
557 291 require IO::K8s::CRD;
558 291 ▶ return IO::K8s::CRD::crd_for_class(ref($self) || $self);
Condition66%2/3
ref $self || $self
l!l&&r!l&&!r
12900
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table66%2/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
559 }
560  
561 # One YAML emitter for every object: IO::K8s::Role::Resource's TO_YAML (k188).
562 0 ▶sub to_yaml {
Subroutine to_yaml: not called CC=1 SCAR=6.9
Pod documented
563 0 my ($self) = @_;
564 0 return $self->TO_YAML;
565 }
566  
567  
568 11 ▶sub save {
Subroutine save: called CC=4 SCAR=14.1
Pod documented
569 11 my ($self, $file) = @_;
570 11 ▶ open my $fh, '>:encoding(UTF-8)', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">:encoding(UTF-8)", $file or croak('Cannot write to ' . $file . ': ' . $!) 10 1 11
571 or croak 'Cannot write to '.$file.': '.$!;
572 10 ▶ print $fh $self->to_yaml
Branch: 1 branch
BranchTrueFalseTotal
print $fh $self->to_yaml or croak('Cannot write to ' . $file . ': ' . $!) 10 0 10
573 or croak 'Cannot write to '.$file.': '.$!;
574 10 ▶ close $fh
Branch: 1 branch
BranchTrueFalseTotal
close $fh or croak('Cannot write to ' . $file . ': ' . $!) 10 0 10
575 or croak 'Cannot write to '.$file.': '.$!;
576 10 return $self;
577 }
578  
579  
580 # ============================================================
581 # Label & annotation convenience methods
582 # ============================================================
583  
584 18 ▶sub _ensure_metadata {
Subroutine _ensure_metadata: called CC=2 SCAR=6.9
585 18 my ($self) = @_;
586 18 ▶ unless ($self->metadata) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->metadata) 1 17 18
587 1 require IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::ObjectMeta;
588 1 $self->metadata(IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::ObjectMeta->new);
589 }
590 18 return $self->metadata;
591 }
592  
593  
594 7 ▶sub add_label {
Subroutine add_label: called CC=2 SCAR=6.9
Pod documented
595 7 my ($self, $key, $value) = @_;
596 7 my $meta = $self->_ensure_metadata;
597 7 ▶ my $labels = $meta->labels // {};
Condition100%2/2
$meta->labels // {}
l!l
34
MC/DC100%1/1
$meta->labels // {}
$meta->labels
Truth table100%2/2
A
A= $meta->labels
Aresult
11
00
598 7 $labels->{$key} = $value;
599 7 $meta->labels($labels);
600 7 return $self;
601 }
602  
603  
604 1 ▶sub add_labels {
Subroutine add_labels: called CC=2 SCAR=7.0
Pod documented
605 1 my ($self, %pairs) = @_;
606 1 my $meta = $self->_ensure_metadata;
607 1 ▶ my $labels = $meta->labels // {};
Condition50%1/2
$meta->labels // {}
l!l
01
MC/DC0%0/1
$meta->labels // {}
$meta->labels
Truth table50%1/2
A
A= $meta->labels
Aresult
11
00
608 1 @{$labels}{keys %pairs} = values %pairs;
609 1 $meta->labels($labels);
610 1 return $self;
611 }
612  
613  
614 9 ▶sub label {
Subroutine label: called CC=3 SCAR=11.0
Pod documented
615 9 my ($self, $key) = @_;
616 9 ▶ my $labels = $self->metadata ? $self->metadata->labels : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->metadata ? : 8 1 9
617 9 ▶ return defined $labels ? $labels->{$key} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $labels ? : 8 1 9
618 }
619  
620  
621 7 ▶sub has_label {
Subroutine has_label: called CC=4 SCAR=13.9
Pod documented
622 7 my ($self, $key) = @_;
623 7 ▶ my $labels = $self->metadata ? $self->metadata->labels : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->metadata ? : 6 1 7
624 7 ▶ return defined $labels && exists $labels->{$key} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $labels && exists $labels->{$key} ? : 4 3 7
Condition100%3/3
defined $labels and exists $labels->{$key}
!ll&&!rl&&r
124
MC/DC100%2/2
defined $labels and exists $labels->{$key}
defined $labels exists $labels->{$key}
Truth table100%3/3
A and B
A= defined $labelsB= exists $labels->{$key}
ABresult
0X0
100
111
625 }
626  
627  
628 1 ▶sub remove_label {
Subroutine remove_label: called CC=3 SCAR=12.0
Pod documented
629 1 my ($self, $key) = @_;
630 1 ▶ if ($self->metadata && $self->metadata->labels) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->metadata and $self->metadata->labels) 1 0 1
Condition33%1/3
$self->metadata and $self->metadata->labels
!ll&&!rl&&r
001
MC/DC0%0/2
$self->metadata and $self->metadata->labels
$self->metadata $self->metadata->labels
Truth table33%1/3
A and B
A= $self->metadataB= $self->metadata->labels
ABresult
0X0
100
111
631 1 delete $self->metadata->labels->{$key};
632 }
633 1 return $self;
634 }
635  
636  
637 5 ▶sub match_labels {
Subroutine match_labels: called CC=6 SCAR=17.9
Pod documented
638 5 my ($self, %expected) = @_;
639 5 ▶ my $labels = $self->metadata ? $self->metadata->labels : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->metadata ? : 4 1 5
640 5 ▶ return 0 unless defined $labels;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $labels 1 4 5
641 4 for my $key (keys %expected) {
642 5 ▶ return 0 unless exists $labels->{$key} && $labels->{$key} eq $expected{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $labels->{$key} and $labels->{$key} eq $expected{$key} 2 3 5
Condition100%3/3
exists $labels->{$key} and $labels->{$key} eq $expected{$key}
!ll&&!rl&&r
113
MC/DC100%2/2
exists $labels->{$key} and $labels->{$key} eq $expected{$key}
exists $labels->{$key} $labels->{$key} eq $expected{$key}
Truth table100%3/3
A and B
A= exists $labels->{$key}B= $labels->{$key} eq $expected{$key}
ABresult
0X0
100
111
643 }
644 2 return 1;
645 }
646  
647  
648 2 ▶sub add_annotation {
Subroutine add_annotation: called CC=2 SCAR=7.0
Pod documented
649 2 my ($self, $key, $value) = @_;
650 2 my $meta = $self->_ensure_metadata;
651 2 ▶ my $annotations = $meta->annotations // {};
Condition50%1/2
$meta->annotations // {}
l!l
02
MC/DC0%0/1
$meta->annotations // {}
$meta->annotations
Truth table50%1/2
A
A= $meta->annotations
Aresult
11
00
652 2 $annotations->{$key} = $value;
653 2 $meta->annotations($annotations);
654 2 return $self;
655 }
656  
657  
658 3 ▶sub annotation {
Subroutine annotation: called CC=3 SCAR=11.0
Pod documented
659 3 my ($self, $key) = @_;
660 3 ▶ my $annotations = $self->metadata ? $self->metadata->annotations : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->metadata ? : 2 1 3
661 3 ▶ return defined $annotations ? $annotations->{$key} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $annotations ? : 2 1 3
662 }
663  
664  
665 5 ▶sub has_annotation {
Subroutine has_annotation: called CC=4 SCAR=13.9
Pod documented
666 5 my ($self, $key) = @_;
667 5 ▶ my $annotations = $self->metadata ? $self->metadata->annotations : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->metadata ? : 4 1 5
668 5 ▶ return defined $annotations && exists $annotations->{$key} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $annotations && exists $annotations->{$key} ? : 2 3 5
Condition100%3/3
defined $annotations and exists $annotations->{$key}
!ll&&!rl&&r
122
MC/DC100%2/2
defined $annotations and exists $annotations->{$key}
defined $annotations exists $annotations->{$key}
Truth table100%3/3
A and B
A= defined $annotationsB= exists $annotations->{$key}
ABresult
0X0
100
111
669 }
670  
671  
672 1 ▶sub remove_annotation {
Subroutine remove_annotation: called CC=3 SCAR=12.0
Pod documented
673 1 my ($self, $key) = @_;
674 1 ▶ if ($self->metadata && $self->metadata->annotations) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->metadata and $self->metadata->annotations) 1 0 1
Condition33%1/3
$self->metadata and $self->metadata->annotations
!ll&&!rl&&r
001
MC/DC0%0/2
$self->metadata and $self->metadata->annotations
$self->metadata $self->metadata->annotations
Truth table33%1/3
A and B
A= $self->metadataB= $self->metadata->annotations
ABresult
0X0
100
111
675 1 delete $self->metadata->annotations->{$key};
676 }
677 1 return $self;
678 }
679  
680 # ============================================================
681 # Status condition convenience methods
682 # ============================================================
683  
684 # The helpers of this role that give way to a declared k8s wire field of
685 # the same name: a class that declares such a field gets it installed over
686 # the composed helper instead of being refused by IO::K8s::Resource's
687 # declaration preflight (k144), which reads this table from whichever role
688 # a colliding method comes from. Exactly conditions, because upstream's
689 # core/v1 ComponentStatus carries its conditions at the top level rather
690 # than under status. Every other helper here stays a collision.
691 143 our %YIELDS_TO_K8S_FIELD = ( conditions => 1 );
692  
693 38 ▶sub _extract_conditions {
Subroutine _extract_conditions: called CC=11 SCAR=28.7
694 38 my ($self) = @_;
695 # A class that declares its own top-level conditions field (merged
696 # registry, so inherited counts too) keeps its conditions there.
697 38 ▶ if ($self->can('_k8s_attr_info') && $self->_k8s_attr_info->{conditions}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can("_k8s_attr_info") and $self->_k8s_attr_info->{"conditions"}) 13 25 38
Condition66%2/3
$self->can("_k8s_attr_info") and $self->_k8s_attr_info->{"conditions"}
!ll&&!rl&&r
02513
MC/DC50%1/2
$self->can("_k8s_attr_info") and $self->_k8s_attr_info->{"conditions"}
$self->can("_k8s_attr_info") $self->_k8s_attr_info->{"conditions"}
Truth table66%2/3
A and B
A= $self->can("_k8s_attr_info")B= $self->_k8s_attr_info->{"conditions"}
ABresult
0X0
100
111
698 13 my $conds = $self->_conditions_field_value;
699 13 ▶ return ref $conds eq 'ARRAY' ? $conds : [];
Branch: 1 branch
BranchTrueFalseTotal
ref $conds eq 'ARRAY' ? : 13 0 13
700 }
701 25 ▶ return [] unless $self->can('status') && defined $self->status;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can("status") and defined $self->status 4 21 25
Condition66%2/3
$self->can("status") and defined $self->status
!ll&&!rl&&r
0421
MC/DC50%1/2
$self->can("status") and defined $self->status
$self->can("status") defined $self->status
Truth table66%2/3
A and B
A= $self->can("status")B= defined $self->status
ABresult
0X0
100
111
702 21 my $status = $self->status;
703  
704 # Typed status object with conditions accessor
705 21 ▶ if (blessed($status) && $status->can('conditions')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($status) and $status->can("conditions")) 21 0 21
Condition33%1/3
builtin::blessed($status) and $status->can("conditions")
!ll&&!rl&&r
0021
MC/DC0%0/2
builtin::blessed($status) and $status->can("conditions")
builtin::blessed($status) $status->can("conditions")
Truth table33%1/3
A and B
A= builtin::blessed($status)B= $status->can("conditions")
ABresult
0X0
100
111
706 21 my $conds = $status->conditions;
707 21 ▶ return $conds if ref $conds eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $conds eq "ARRAY" 18 3 21
708 3 return [];
709 }
710  
711 # Opaque hashref (CRDs)
712 0 ▶ if (ref $status eq 'HASH' && ref $status->{conditions} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $status eq "HASH" and ref $status->{"conditions"} eq "ARRAY") 0 0 0
Condition0%0/3
ref $status eq "HASH" and ref $status->{"conditions"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $status eq "HASH" and ref $status->{"conditions"} eq "ARRAY"
ref $status eq "HASH" ref $status->{"conditions"} eq "ARRAY"
Truth table0%0/3
A and B
A= ref $status eq "HASH"B= ref $status->{"conditions"} eq "ARRAY"
ABresult
0X0
100
111
713 0 return $status->{conditions};
714 }
715  
716 0 return [];
717 }
718  
719 # The value of that top-level conditions field, through its accessor --
720 # but never through $self->conditions blindly: where the field won, that is
721 # the accessor, yet a subclass that composes this role again gets the
722 # helper back in its own stash, and calling the helper from here would
723 # recurse. So the first conditions sub along the MRO that is not this
724 # role's helper is the accessor. Any arguments go to it unchanged, so the
725 # helper can forward a setter call (see conditions below).
726 25 ▶sub _conditions_field_value {
Subroutine _conditions_field_value: called CC=4 SCAR=13.9
727 25 my ($self, @args) = @_;
728 25 my $helper = \&conditions;
729 143 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
730 25 for my $class (@{ mro::get_linear_isa(ref $self) }) {
731 41 ▶ next unless defined &{"${class}::conditions"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${class}::conditions";} 0 41 41
732 41 my $code = \&{"${class}::conditions"};
733 41 ▶ next if $code == $helper;
Branch: 1 branch
BranchTrueFalseTotal
if $code == $helper 16 25 41
734 25 return $self->$code(@args);
735 }
736 0 return;
737 }
738  
739 54 ▶sub _condition_field {
Subroutine _condition_field: called CC=4 SCAR=20.4
740 54 my ($cond, $field) = @_;
741 54 ▶ if (blessed($cond) && $cond->can($field)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($cond) and $cond->can($field)) 54 0 54
Condition33%1/3
builtin::blessed($cond) and $cond->can($field)
!ll&&!rl&&r
0054
MC/DC0%0/2
builtin::blessed($cond) and $cond->can($field)
builtin::blessed($cond) $cond->can($field)
Truth table33%1/3
A and B
A= builtin::blessed($cond)B= $cond->can($field)
ABresult
0X0
100
111
742 54 return $cond->$field;
743 }
744 0 ▶ if (ref $cond eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cond eq "HASH") 0 0 0
745 0 return $cond->{$field};
746 }
747 0 return undef;
748 }
749  
750  
751 17 ▶sub conditions {
Subroutine conditions: called CC=3 SCAR=11.0
Pod documented
752 17 my ($self, @args) = @_;
753 # Where a declared conditions field won, this helper is normally gone
754 # from the class's stash. But Role::Tiny composes against the target's
755 # own stash only, so a subclass that composes this role again gets the
756 # helper back, shadowing the inherited accessor -- and a setter call
757 # landing here would silently do nothing. So with such a field the
758 # helper is transparent: it hands every argument to the accessor.
759 return $self->_conditions_field_value(@args)
760 17 ▶ if $self->can('_k8s_attr_info') && $self->_k8s_attr_info->{conditions};
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("_k8s_attr_info") and $self->_k8s_attr_info->{"conditions"} 12 5 17
Condition66%2/3
$self->can("_k8s_attr_info") and $self->_k8s_attr_info->{"conditions"}
!ll&&!rl&&r
0512
MC/DC50%1/2
$self->can("_k8s_attr_info") and $self->_k8s_attr_info->{"conditions"}
$self->can("_k8s_attr_info") $self->_k8s_attr_info->{"conditions"}
Truth table66%2/3
A and B
A= $self->can("_k8s_attr_info")B= $self->_k8s_attr_info->{"conditions"}
ABresult
0X0
100
111
761 5 return $self->_extract_conditions;
762 }
763  
764  
765 33 ▶sub get_condition {
Subroutine get_condition: called CC=4 SCAR=13.9
Pod documented
766 33 my ($self, $type) = @_;
767 33 for my $cond (@{ $self->_extract_conditions }) {
768 38 my $ctype = _condition_field($cond, 'type');
769 38 ▶ return $cond if defined $ctype && $ctype eq $type;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ctype and $ctype eq $type 23 15 38
Condition66%2/3
defined $ctype and $ctype eq $type
!ll&&!rl&&r
01523
MC/DC50%1/2
defined $ctype and $ctype eq $type
defined $ctype $ctype eq $type
Truth table66%2/3
A and B
A= defined $ctypeB= $ctype eq $type
ABresult
0X0
100
111
770 }
771 10 return undef;
772 }
773  
774  
775 19 ▶sub is_condition_true {
Subroutine is_condition_true: called CC=4 SCAR=13.9
Pod documented
776 19 my ($self, $type) = @_;
777 19 my $cond = $self->get_condition($type);
778 19 ▶ return 0 unless defined $cond;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cond 8 11 19
779 11 my $status = _condition_field($cond, 'status');
780 11 ▶ return defined $status && $status eq 'True' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $status && $status eq 'True' ? : 7 4 11
Condition66%2/3
defined $status and $status eq "True"
!ll&&!rl&&r
047
MC/DC50%1/2
defined $status and $status eq "True"
defined $status $status eq "True"
Truth table66%2/3
A and B
A= defined $statusB= $status eq "True"
ABresult
0X0
100
111
781 }
782  
783  
784 7 ▶sub is_ready {
Subroutine is_ready: called CC=3 SCAR=11.0
Pod documented
785 7 my ($self) = @_;
786 7 ▶ return 1 if $self->is_condition_true('Ready');
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_condition_true("Ready") 3 4 7
787 4 ▶ return 1 if $self->is_condition_true('Available');
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_condition_true("Available") 1 3 4
788 3 return 0;
789 }
790  
791  
792 6 ▶sub condition_message {
Subroutine condition_message: called CC=2 SCAR=6.9
Pod documented
793 6 my ($self, $type) = @_;
794 6 my $cond = $self->get_condition($type);
795 6 ▶ return undef unless defined $cond;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cond 1 5 6
796 5 return _condition_field($cond, 'message');
797 }
798  
799 # ============================================================
800 # Owner reference convenience methods
801 # ============================================================
802  
803  
804 10 ▶sub set_owner {
Subroutine set_owner: called CC=22 SCAR=32.0
Pod documented
805 10 my ($self, $owner, %opts) = @_;
806 10 require IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::OwnerReference;
807  
808 10 ▶ my $controller = exists $opts{controller} ? ($opts{controller} ? 1 : 0) : 1;
Branch: 2 branches
BranchTrueFalseTotal
exists $opts{'controller'} ? : 6 4 10
$opts{'controller'} ? : 4 2 6
809  
810 10 my $owner_kind = $owner->kind;
811 10 my $owner_meta = $owner->metadata;
812 10 ▶ my $owner_name = $owner_meta ? $owner_meta->name : undef;
Branch: 1 branch
BranchTrueFalseTotal
$owner_meta ? : 9 1 10
813 10 ▶ my $owner_desc = defined $owner_name ? "$owner_kind/$owner_name" : $owner_kind;
Branch: 1 branch
BranchTrueFalseTotal
defined $owner_name ? : 9 1 10
814  
815 10 ▶ my $owner_uid = $owner_meta ? $owner_meta->uid : undef;
Branch: 1 branch
BranchTrueFalseTotal
$owner_meta ? : 9 1 10
816 10 ▶ if (!defined $owner_uid || $owner_uid eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $owner_uid or $owner_uid eq "") 2 8 10
Condition66%2/3
not defined $owner_uid or $owner_uid eq ""
l!l&&r!l&&!r
208
MC/DC50%1/2
not defined $owner_uid or $owner_uid eq ""
not defined $owner_uid $owner_uid eq ""
Truth table66%2/3
not(A) or B
A= not defined $owner_uidB= $owner_uid eq ""
ABresult
1X1
011
000
817 2 die "set_owner: cannot reference $owner_desc: owner has no uid;"
818 . " the uid is assigned by the API server, so only an object"
819 . " read back from the cluster can be referenced\n";
820 }
821  
822 8 my $meta = $self->_ensure_metadata;
823 8 ▶ my $refs = $meta->ownerReferences // [];
Condition100%2/2
$meta->ownerReferences // []
l!l
35
MC/DC100%1/1
$meta->ownerReferences // []
$meta->ownerReferences
Truth table100%2/2
A
A= $meta->ownerReferences
Aresult
11
00
824  
825 8 my $existing_controller;
826 8 for my $ref (@$refs) {
827 4 my ($ruid, $rctl, $rkind, $rname);
828 4 ▶ if (blessed($ref) && $ref->can('uid')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($ref) and $ref->can('uid')) { } 4 0 4
elsif (ref $ref eq 'HASH') { } 0 0 0
Condition33%1/3
builtin::blessed($ref) and $ref->can("uid")
!ll&&!rl&&r
004
MC/DC0%0/2
builtin::blessed($ref) and $ref->can("uid")
builtin::blessed($ref) $ref->can("uid")
Truth table33%1/3
A and B
A= builtin::blessed($ref)B= $ref->can("uid")
ABresult
0X0
100
111
829 4 ($ruid, $rctl, $rkind, $rname)
830 = ($ref->uid, $ref->controller, $ref->kind, $ref->name);
831 } elsif (ref $ref eq 'HASH') {
832 0 ($ruid, $rctl, $rkind, $rname) = @{$ref}{qw(uid controller kind name)};
833 }
834  
835 # Same owner already referenced: idempotent no-op (checked before
836 # the controller conflict -- the reference exists, nothing changes).
837 4 ▶ return $self if defined $ruid && $ruid eq $owner_uid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ruid and $ruid eq $owner_uid 1 3 4
Condition66%2/3
defined $ruid and $ruid eq $owner_uid
!ll&&!rl&&r
031
MC/DC50%1/2
defined $ruid and $ruid eq $owner_uid
defined $ruid $ruid eq $owner_uid
Truth table66%2/3
A and B
A= defined $ruidB= $ruid eq $owner_uid
ABresult
0X0
100
111
838  
839 3 ▶ $existing_controller //= { kind => $rkind, name => $rname } if $rctl;
Branch: 1 branch
BranchTrueFalseTotal
if $rctl 2 1 3
Condition50%1/2
$existing_controller //= {"kind", $rkind, "name", $rname}
l!l
02
MC/DC0%0/1
$existing_controller //= {"kind", $rkind, "name", $rname}
$existing_controller
Truth table50%1/2
A
A= $existing_controller
Aresult
11
00
840 }
841  
842 7 ▶ if ($controller && $existing_controller) {
Branch: 1 branch
BranchTrueFalseTotal
if ($controller and $existing_controller) 1 6 7
Condition100%3/3
$controller and $existing_controller
!ll&&!rl&&r
241
MC/DC100%2/2
$controller and $existing_controller
$controller $existing_controller
Truth table100%3/3
A and B
A= $controllerB= $existing_controller
ABresult
0X0
100
111
843 2 ▶ my $have = join '/', grep { defined && length }
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
002
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
844 1 $existing_controller->{kind}, $existing_controller->{name};
845 1 ▶ $have = 'an existing ownerReference' unless length $have;
Branch: 1 branch
BranchTrueFalseTotal
unless length $have 0 1 1
846 1 die "set_owner: cannot add $owner_desc as controller: $have is"
847 . " already the controller reference; Kubernetes allows at most"
848 . " one, pass controller => 0 to add a non-controlling owner\n";
849 }
850  
851 6 ▶ my $ref = IO::K8s::Apimachinery::Pkg::Apis::Meta::V1::OwnerReference->new(
Branch: 1 branch
BranchTrueFalseTotal
$controller ? : 4 2 6
852 apiVersion => $owner->api_version,
853 kind => $owner_kind,
854 name => $owner_name,
855 uid => $owner_uid,
856 ($controller ? (controller => 1) : ()),
857 );
858  
859 6 $meta->ownerReferences([@$refs, $ref]);
860 6 return $self;
861 }
862  
863  
864 2 ▶sub is_owned_by {
Subroutine is_owned_by: called CC=18 SCAR=45.6
Pod documented
865 2 my ($self, $owner) = @_;
866 2 my $refs = $self->owner_refs;
867 2 ▶ my $owner_uid = $owner->metadata ? $owner->metadata->uid : undef;
Branch: 1 branch
BranchTrueFalseTotal
$owner->metadata ? : 2 0 2
868 2 ▶ my $owner_name = $owner->metadata ? $owner->metadata->name : undef;
Branch: 1 branch
BranchTrueFalseTotal
$owner->metadata ? : 2 0 2
869 2 my $owner_kind = $owner->kind;
870  
871 2 for my $ref (@$refs) {
872 2 my ($rname, $ruid, $rkind);
873 2 ▶ if (blessed($ref) && $ref->can('name')) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::blessed($ref) and $ref->can('name')) { } 2 0 2
elsif (ref $ref eq 'HASH') { } 0 0 0
Condition33%1/3
builtin::blessed($ref) and $ref->can("name")
!ll&&!rl&&r
002
MC/DC0%0/2
builtin::blessed($ref) and $ref->can("name")
builtin::blessed($ref) $ref->can("name")
Truth table33%1/3
A and B
A= builtin::blessed($ref)B= $ref->can("name")
ABresult
0X0
100
111
874 2 $rname = $ref->name;
875 2 $ruid = $ref->uid;
876 2 $rkind = $ref->kind;
877 } elsif (ref $ref eq 'HASH') {
878 0 $rname = $ref->{name};
879 0 $ruid = $ref->{uid};
880 0 $rkind = $ref->{kind};
881 }
882  
883 # Match by UID if both have it, otherwise by name+kind
884 2 ▶ if (defined $owner_uid && $owner_uid ne '' && defined $ruid && $ruid ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $owner_uid and $owner_uid ne '' and defined $ruid and $ruid ne '') { } 2 0 2
elsif (defined $owner_name and defined $rname and defined $owner_kind and defined $rkind) { } 0 0 0
Condition33%3/9
defined $owner_uid and $owner_uid ne "" and defined $ruid and $ruid ne ""
!ll&&!rl&&r
002
defined $owner_uid and $owner_uid ne "" and defined $ruid
!ll&&!rl&&r
002
defined $owner_uid and $owner_uid ne ""
!ll&&!rl&&r
002
MC/DC0%0/4
defined $owner_uid and $owner_uid ne "" and defined $ruid and $ruid ne ""
defined $owner_uid $owner_uid ne "" defined $ruid $ruid ne ""
Truth table20%1/5
A and B and C and D
A= defined $owner_uidB= $owner_uid ne ""C= defined $ruidD= $ruid ne ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
885 2 ▶ return 1 if $ruid eq $owner_uid;
Branch: 1 branch
BranchTrueFalseTotal
if $ruid eq $owner_uid 2 0 2
886 ▶ } elsif (defined $owner_name && defined $rname && defined $owner_kind && defined $rkind) {
Condition0%0/9
defined $owner_name and defined $rname and defined $owner_kind and defined $rkind
!ll&&!rl&&r
000
defined $owner_name and defined $rname and defined $owner_kind
!ll&&!rl&&r
000
defined $owner_name and defined $rname
!ll&&!rl&&r
000
MC/DC0%0/4
defined $owner_name and defined $rname and defined $owner_kind and defined $rkind
defined $owner_name defined $rname defined $owner_kind defined $rkind
Truth table0%0/5
A and B and C and D
A= defined $owner_nameB= defined $rnameC= defined $owner_kindD= defined $rkind
ABCDresult
0XXX0
10XX0
110X0
11100
11111
887 0 ▶ return 1 if $rname eq $owner_name && $rkind eq $owner_kind;
Branch: 1 branch
BranchTrueFalseTotal
if $rname eq $owner_name and $rkind eq $owner_kind 0 0 0
Condition0%0/3
$rname eq $owner_name and $rkind eq $owner_kind
!ll&&!rl&&r
000
MC/DC0%0/2
$rname eq $owner_name and $rkind eq $owner_kind
$rname eq $owner_name $rkind eq $owner_kind
Truth table0%0/3
A and B
A= $rname eq $owner_nameB= $rkind eq $owner_kind
ABresult
0X0
100
111
888 }
889 }
890 0 return 0;
891 }
892  
893  
894 2 ▶sub owner_refs {
Subroutine owner_refs: called CC=3 SCAR=11.7
Pod documented
895 2 my ($self) = @_;
896 2 ▶ return [] unless $self->metadata;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->metadata 0 2 2
897 2 ▶ return $self->metadata->ownerReferences // [];
Condition50%1/2
$self->metadata->ownerReferences // []
l!l
20
MC/DC0%0/1
$self->metadata->ownerReferences // []
$self->metadata->ownerReferences
Truth table50%1/2
A
A= $self->metadata->ownerReferences
Aresult
11
00
898 }
899  
900 143 1;
901  
902 __END__
« blib/lib/IO/K8s/Resource.pm ↑ Summary lib/IO/K8s/CRD/Emitter.pm »