| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Per-field schema-fidelity audit for the CRD providers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # The third question in this maint/ family, and the only one that looks at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # field OPTIONS rather than at coverage or at bytes: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # spec-drift-check.pl -- does lib/ cover the upstream Kubernetes API? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # crd-drift-check.pl -- does lib/ match what the emitter renders? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # crd-schema-audit.pl -- does each shipped class agree with its CRD on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # required-ness and the value constraints? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # Why it exists (k120). The obvious reason is hand-modelling: k113 wrote 57 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # generators.external-secrets.io classes by hand and five disagreed with the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # CRD -- a `pattern` dropped (losing a construction-time check), a `required` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # dropped, a `required` invented, and twice a `default` read out of an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # English description sentence that the schema never declared. Nothing found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # those but a field-by-field walk. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # The less obvious reason is why crd-drift-check.pl --check cannot stand in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # for this even at 0 differ. An overlay maps several logical paths onto one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # bare class name, and where the schemas at those paths are NOT identical | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # the render silently keeps whichever it wrote last (render_for's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # `$files{$_} = $rendered->{$_}`), so --check only ever compares the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # survivor. cert-manager v1.21.1 is the live example: `LocalObjectReference` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # is two different upstream types -- corev1's at six imagePullSecrets[] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # positions (`name` has `default: ""`, nothing required) and cert-manager's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # own at four venafi credentialsRef positions (no default, `required: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # [name]`) -- and maint/crd-render/CertManager.yaml names both the same, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # one Perl class carries the corev1 shape and the four credentialsRef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # positions are modelled wrong. --check reports 0 differ throughout. This | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # script is what sees it, which is exactly why it is a separate tool and not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # a --check flag. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # This is a report generator. It reads manifests and the shipped attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # registry, and writes nothing -- not to lib/, not to the karr board, not to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # the manifest cache. It never touches the network either: point it at a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # directory of CRD YAML, or let it read the cache maint/crd-drift-check.pl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # already populated under spec/crd/. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # maint/crd-schema-audit.pl [--provider NAME]... [--dir path] [--lib path] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # [--cache-dir path] [--verbose] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # Examples: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # maint/crd-schema-audit.pl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | # Audit every provider that has a cached manifest. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # maint/crd-schema-audit.pl --provider ExternalSecrets --verbose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # One provider, plus the per-keyword tally of what the k8s DSL cannot | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # express (see "Not expressible" below) and what was skipped. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # maint/crd-schema-audit.pl --provider Cilium --dir /path/to/crds | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # Audit against a manifest directory instead of the cache. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # WHAT IS COMPARED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # Only the option keys the k8s DSL records, since only those can be right or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # wrong in a class: required, pattern, enum, minimum, maximum, default. Each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # is reported in both directions -- DROPPED (the CRD declares it, the class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # does not) and INVENTED (the class declares it, the CRD does not). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | # NOT EXPRESSIBLE -- counted, never reported as a finding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # minLength, maxLength, minItems, maxItems, uniqueItems, multipleOf and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # format are NOT in %FIELD_OPTIONS in IO::K8s::Resource, so no class can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # carry them and their absence is a property of the DSL, not a defect. They | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | # are tallied separately and named under --verbose. This matters: a single | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # provider can declare a couple of thousand of them, and a reader who sees | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | # that number in a findings column will reasonably conclude the tree is on | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # fire. It is not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # STOCK CLASSES ARE NOT WALKED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # A field whose schema matches a shipped core class is typed as that class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # (D5 reuse_core: Meta::V1::LabelSelector, Meta::V1::Condition, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | # Core::V1::SecretReference, ...). Such a class models the core Kubernetes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # API, not this one CRD, so it legitimately carries none of the CRD's own | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # narrowing -- a walk into it would flag every constraint the CRD declares | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # there and drown the real findings. Anything outside the audited provider's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # own IO::K8s::<Provider>:: namespace is therefore skipped and counted under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # `stock_skipped`. That test is used rather than a list of core namespaces | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # because there are four of them (IO::K8s::Api::, ::Apimachinery::, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # ::ApiextensionsApiserver::, ::KubeAggregator::) and missing one silently | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # turns every shared Condition into a page of invented findings. Suspecting | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | # a reused core class of being the wrong shape for a field is a real | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | # question, but it is crd-drift-check.pl's, not this script's. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | use FindBin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | use Getopt::Long qw( GetOptions ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | ▶ | use YAML::PP; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | my $DIST_ROOT = File::Spec->catdir($FindBin::Bin, '..'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | # Same provider list, in the same order, as maint/crd-drift-check.pl. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | my @ALL_PROVIDERS = qw(Cilium GatewayAPI AgentSandbox Traefik CertManager K3s | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | PrometheusOperator VolumeSnapshot ExternalSecrets); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # The option keys a class can carry, hence the only ones that can disagree. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my @COMPARABLE = qw( pattern enum minimum maximum ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | # Declared upstream, unrepresentable in the DSL. See the header. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | my @NOT_EXPRESSIBLE = qw( minLength maxLength minItems maxItems uniqueItems | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | multipleOf format ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub usage { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my ($exit_code) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | print <<"USAGE"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | $0 [--provider NAME]... [options] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | Options: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | --provider NAME Provider to audit (repeatable). One of: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | @ALL_PROVIDERS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | Default: every provider with a cached manifest. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | --dir PATH Read *.yaml CRD manifests from PATH instead of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | cache. Requires exactly one --provider. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | --cache-dir PATH Manifest cache root (default: DIST/spec/crd), as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | populated by maint/crd-drift-check.pl. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | --lib PATH lib/ directory to audit (default: DIST/lib) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | --verbose Also list the not-expressible tally and what was | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | skipped. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | --help This message. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | Reads manifests and lib/; writes nothing, and never uses the network. Run | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | maint/crd-drift-check.pl first if the manifest cache is empty. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | USAGE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | exit $exit_code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | my %opt = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 'cache-dir' => File::Spec->catdir($DIST_ROOT, 'spec', 'crd'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | lib => File::Spec->catdir($DIST_ROOT, 'lib'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | my @providers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 'provider=s' => \@providers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 'dir=s' => \$opt{dir}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 'cache-dir=s' => \$opt{'cache-dir'}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 'lib=s' => \$opt{lib}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 'verbose' => \$opt{verbose}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 'help' => \$opt{help}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | ▶ | ) or usage(2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | ▶ | usage(0) if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1 | ▶ | @providers = @ALL_PROVIDERS unless @providers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | my %known = map { $_ => 1 } @ALL_PROVIDERS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | for my $p (@providers) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | die "crd-schema-audit: unknown provider '$p' (known: @ALL_PROVIDERS)\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | ▶ | unless $known{$p}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | die "crd-schema-audit: --dir requires exactly one --provider\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | ▶ | if $opt{dir} && @providers != 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opt{"dir"} and @providers != 1
MC/DC0%0/2
$opt{"dir"} and @providers != 1
$opt{"dir"}
@providers != 1
Truth table33%1/3
A and B
A= $opt{"dir"}B= @providers != 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | unshift @INC, $opt{lib}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | require IO::K8s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # Manifests | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # Every *.yaml under the provider's cache (or --dir), newest pin wins by | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | # virtue of being the only one crd-drift-check.pl wrote for this version. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | sub manifest_files { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
manifest_files: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | my ($provider) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | ▶ | return sort glob File::Spec->catfile($opt{dir}, '*.yaml') if $opt{dir}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my $root = File::Spec->catdir($opt{'cache-dir'}, $provider); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | return () unless -d $root; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | return sort glob File::Spec->catfile($root, '*', '*.yaml'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # Kind -> CRD document, for every CustomResourceDefinition in those files. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | ▶ | sub load_crds { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_crds: called CC=7 SCAR=21.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | my (@files) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | my $yp = YAML::PP->new(boolean => 'JSON::PP'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | my %crd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | for my $file (@files) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | my @docs = eval { $yp->load_file($file) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | if ($@) { warn "crd-schema-audit: cannot parse $file: $@"; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | for my $d (@docs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | ▶ | next unless ref $d eq 'HASH' && ($d->{kind} // '') eq 'CustomResourceDefinition'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
ref $d eq "HASH" and ($d->{"kind"} // "") eq "CustomResourceDefinition"
$d->{"kind"} // ""
MC/DC0%0/2
ref $d eq "HASH" and ($d->{"kind"} // "") eq "CustomResourceDefinition"
ref $d eq "HASH"
$d->{"kind"}
Truth table33%1/3
A and B
A= ref $d eq "HASH"B= $d->{"kind"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | $crd{ $d->{spec}{names}{kind} } = $d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | return \%crd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # The CRD version whose schema this Perl class actually models. A CRD can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # serve several versions from one document (ExternalSecret is v1 + v1beta1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # while the class lives in exactly one of them, so picking versions[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # blindly compares a V1 class against a v1beta1 schema and invents findings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # wholesale -- the bug this function exists to not have. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | sub version_for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
version_for: called CC=6 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | my ($crd, $class) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | my @versions = @{ $crd->{spec}{versions} || [] } or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$crd->{'spec'}{'versions'} || []
MC/DC0%0/1
$crd->{'spec'}{'versions'} || []
$crd->{'spec'}{'versions'}
Truth table50%1/2
A
A= $crd->{'spec'}{'versions'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | ▶ | if (my ($seg) = $class =~ /::(V\d+(?:alpha|beta)?\d*)::/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | my $want = lc $seg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | for my $v (@versions) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | ▶ | return $v if lc($v->{name}) eq $want; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | return $versions[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # The walk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | my $registry = \%IO::K8s::Resource::_attr_registry; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # apiVersion and kind are declared by every CRD schema but are never k8s | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # attributes -- IO::K8s::Role::APIObject derives them from the class name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # and Role::Resource::TO_JSON writes them. Their absence from the registry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # is correct, so they are not a MISSING FIELD. `metadata` IS an attribute, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # but it comes from the same role rather than from the CRD, so a manifest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # that lists it in the root `required` (cert-manager's Challenge and Order | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # do) is not saying anything a provider class could act on. All three are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # skipped at the ROOT object only -- a CRD is free to declare a field of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # its own called `kind` further down, and that one is audited normally. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | my %ENVELOPE = (apiVersion => 1, kind => 1, metadata => 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | ▶ | sub audit_provider { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
audit_provider: called CC=7 SCAR=22.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | my ($provider) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | my $pkg = "IO::K8s::$provider"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | ▶ | eval { use_module($pkg); 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | or return { provider => $provider, error => "cannot load $pkg: $@" }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | my @files = manifest_files($provider); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | ▶ | return { provider => $provider, error => 'no cached manifest -- run maint/crd-drift-check.pl first' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | unless @files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 1 | my $crds = load_crds(@files); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 1 | my $k8s = IO::K8s->new(with => [$pkg]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1 | my (@findings, %stat, %seen); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | my $own_ns = "IO::K8s::$provider\::"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | my $walk; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | ▶ | $walk = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=45 SCAR=53.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 2 | my ($schema, $class, $where, $is_root) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | ▶ | return unless ref $schema eq 'HASH' && $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $schema eq "HASH" and $class
MC/DC0%0/2
ref $schema eq "HASH" and $class
ref $schema eq "HASH"
$class
Truth table33%1/3
A and B
A= ref $schema eq "HASH"B= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # A reused core class models the core API, not this CRD -- see the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # header. Counted so the report says it happened. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | ▶ | if (index($class, $own_ns) != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $stat{stock_skipped}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | ▶ | return if $seen{"$where|$class"}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | ▶ | eval { use_module($class); 1 } or do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $stat{unloadable}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 2 | ▶ | my $attrs = $registry->{$class} or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 2 | my %by_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 2 | for my $a (keys %$attrs) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | my $i = $attrs->{$a}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 4 | ▶ | $by_key{ $i->{json_key} // $a } = $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$i->{"json_key"} // $a
MC/DC0%0/2
$i->{"json_key"} // $a
$i->{"json_key"}
$a
Truth table33%1/3
A // B
A= $i->{"json_key"}B= $a
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 2 | ▶ | my $props = $schema->{properties} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$schema->{'properties'} || {}
MC/DC0%0/1
$schema->{'properties'} || {}
$schema->{'properties'}
Truth table50%1/2
A
A= $schema->{'properties'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | my %req = map { $_ => 1 } @{ $schema->{required} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$schema->{'required'} || []
MC/DC0%0/1
$schema->{'required'} || []
$schema->{'required'}
Truth table50%1/2
A
A= $schema->{'required'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 2 | for my $key (sort keys %$props) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 3 | my $p = $props->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | my $i = $by_key{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | ▶ | next if $is_root && $ENVELOPE{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$is_root and $ENVELOPE{$key}
MC/DC0%0/2
$is_root and $ENVELOPE{$key}
$is_root
$ENVELOPE{$key}
Truth table66%2/3
A and B
A= $is_rootB= $ENVELOPE{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | ▶ | unless ($i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | push @findings, ["$where.$key", 'MISSING FIELD', 'declared in the CRD, no k8s attribute']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 3 | ▶ | my $o = $i->{options} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$i->{'options'} || {}
MC/DC100%1/1
$i->{'options'} || {}
$i->{'options'}
Truth table100%2/2
A
A= $i->{'options'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # required lives on the PARENT object, not on the field | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 3 | ▶ | if ($req{$key} && !$i->{required}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$req{$key} and not $i->{"required"}
MC/DC0%0/2
$req{$key} and not $i->{"required"}
$req{$key}
not $i->{"required"}
Truth table33%1/3
A and not(B)
A= $req{$key}B= not $i->{"required"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | push @findings, ["$where.$key", 'REQUIRED DROPPED', 'the CRD requires it, the class does not']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | ▶ | elsif (!$req{$key} && $i->{required}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
not $req{$key} and $i->{"required"}
MC/DC0%0/2
not $req{$key} and $i->{"required"}
not $req{$key}
$i->{"required"}
Truth table33%1/3
not(A) and B
A= not $req{$key}B= $i->{"required"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | push @findings, ["$where.$key", 'REQUIRED INVENTED', 'the class requires it, the CRD does not']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # a constraint on an array applies to its items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | my $c = (($p->{type} // '') eq 'array' && ref $p->{items} eq 'HASH') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 3 | ▶ | ? $p->{items} : $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
($p->{"type"} // "") eq "array" and ref $p->{"items"} eq "HASH"
$p->{"type"} // ""
MC/DC0%0/2
($p->{"type"} // "") eq "array" and ref $p->{"items"} eq "HASH"
$p->{"type"}
ref $p->{"items"} eq "HASH"
Truth table0%0/3
A and B
A= $p->{"type"}B= ref $p->{"items"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 3 | for my $k (@COMPARABLE) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 12 | my $crd_has = exists $c->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 12 | my $class_has = exists $o->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # A Quantity field needs no `pattern` option: the Quantity | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # type itself enforces the apimachinery quantity grammar, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # and more tightly than the CRD's regex does. Same value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # carried by the type instead of by an option. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 12 | ▶ | if ($k eq 'pattern' && $crd_has && !$class_has && $i->{is_quantity}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition44%4/9
$k eq "pattern" and $crd_has and not $class_has and $i->{"is_quantity"}
$k eq "pattern" and $crd_has and not $class_has
$k eq "pattern" and $crd_has
MC/DC0%0/4
$k eq "pattern" and $crd_has and not $class_has and $i->{"is_quantity"}
$k eq "pattern"
$crd_has
not $class_has
$i->{"is_quantity"}
Truth table40%2/5
A and B and not(C) and D
A= $k eq "pattern"B= $crd_hasC= not $class_hasD= $i->{"is_quantity"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $stat{quantity_pattern}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 12 | ▶ | push @findings, ["$where.$key", uc($k) . ' DROPPED', 'the CRD declares it, the class does not'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$crd_has and not $class_has
MC/DC0%0/2
$crd_has and not $class_has
$crd_has
not $class_has
Truth table33%1/3
A and not(B)
A= $crd_hasB= not $class_has
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | if $crd_has && !$class_has; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 12 | ▶ | push @findings, ["$where.$key", uc($k) . ' INVENTED', 'the class declares it, the CRD does not'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $crd_has and $class_has
MC/DC0%0/2
not $crd_has and $class_has
not $crd_has
$class_has
Truth table33%1/3
not(A) and B
A= not $crd_hasB= $class_has
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | if !$crd_has && $class_has; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # `default` is a property of the field, never of an array's items | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 3 | ▶ | if (exists $p->{default} && !exists $o->{default}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
exists $p->{"default"} and not exists $o->{"default"}
MC/DC0%0/2
exists $p->{"default"} and not exists $o->{"default"}
exists $p->{"default"}
not exists $o->{"default"}
Truth table33%1/3
A and not(B)
A= exists $p->{"default"}B= not exists $o->{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | push @findings, ["$where.$key", 'DEFAULT DROPPED', 'the CRD declares it, the class does not']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | ▶ | elsif (!exists $p->{default} && exists $o->{default}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not exists $p->{"default"} and exists $o->{"default"}
MC/DC50%1/2
not exists $p->{"default"} and exists $o->{"default"}
not exists $p->{"default"}
exists $o->{"default"}
Truth table66%2/3
not(A) and B
A= not exists $p->{"default"}B= exists $o->{"default"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 1 | my $d = $o->{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 1 | ▶ | push @findings, ["$where.$key", 'DEFAULT INVENTED', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$d // ""
MC/DC0%0/1
$d // ""
$d
Truth table50%1/2
A
A= $d
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | "the class says default => '" . (ref $d ? '...' : ($d // '')) . "', the CRD declares none"]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 3 | $stat{"na_$_"}++ for grep { exists $c->{$_} } @NOT_EXPRESSIBLE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 3 | ▶ | my $target = $i->{class} or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | my $child = (($p->{type} // '') eq 'array') ? $p->{items} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | : $i->{is_hash_of_objects} ?$p->{additionalProperties} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | : $i->{is_hash_of_object_arrays} ? ($p->{additionalProperties} // {})->{items} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | ▶ | : $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition25%1/4
$p->{"type"} // ""
$p->{"additionalProperties"} // {}
MC/DC0%0/1
$p->{"type"} // ""
$p->{"type"}
MC/DC0%0/1
$p->{"additionalProperties"} // {}
$p->{"additionalProperties"}
Truth table50%1/2
A
A= $p->{"type"}
Truth table0%0/2
A
A= $p->{"additionalProperties"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | $walk->($child, $target, "$where.$key"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | for my $kind (sort keys %$crds) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | ▶ | my $class = eval { $k8s->expand_class($kind) } or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | ▶ | my $version = version_for($crds->{$kind}, $class) or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | ▶ | my $root = $version->{schema}{openAPIV3Schema} or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1 | $walk->($root, $class, "$kind($version->{name})", 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | return { provider => $provider, findings => \@findings, stat => \%stat }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | # Report | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # --------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | my $bad = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 1 | for my $provider (@providers) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | my $r = audit_provider($provider); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | printf "########## %s ##########\n", $provider; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | ▶ | if ($r->{error}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | print " skipped: $r->{error}\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 1 | my $f = $r->{findings}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 1 | ▶ | if (@$f) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 1 | $bad = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | printf " %-64s %-18s %s\n", 'PATH', 'FINDING', 'DETAIL'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | printf " %-64s %-18s %s\n", $_->[0], $_->[1], $_->[2] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | for sort { $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1] } @$f; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$main::a->[0] cmp $main::b->[0] || $main::a->[1] cmp $main::b->[1]
MC/DC0%0/2
$main::a->[0] cmp $main::b->[0] || $main::a->[1] cmp $main::b->[1]
$main::a->[0] cmp $main::b->[0]
$main::a->[1] cmp $main::b->[1]
Truth table0%0/3
A || B
A= $main::a->[0] cmp $main::b->[0]B= $main::a->[1] cmp $main::b->[1]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | print " no disagreement between the shipped classes and the CRD\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 1 | my $stat = $r->{stat}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 1 | my $na = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | ▶ | $na += $stat->{"na_$_"} // 0 for @NOT_EXPRESSIBLE; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$stat{"na_$_"} // 0
MC/DC0%0/1
$$stat{"na_$_"} // 0
$$stat{"na_$_"}
Truth table50%1/2
A
A= $$stat{"na_$_"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | printf " --- %d finding(s); %d upstream keyword(s) the k8s DSL cannot express (not a defect)\n", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | scalar @$f, $na; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 1 | ▶ | if ($opt{verbose}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | printf " not expressible: %s\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | join(', ', map { "$_=" . $stat->{"na_$_"} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | grep { $stat->{"na_$_"} } @NOT_EXPRESSIBLE) || '(none)'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
join(', ', map({"$_=" . $$stat{"na_$_"};} grep({$$stat{"na_$_"};} @NOT_EXPRESSIBLE))) || '(none)'
MC/DC0%0/1
join(', ', map({"$_=" . $$stat{"na_$_"};} grep({$$stat{"na_$_"};} @NOT_EXPRESSIBLE))) || '(none)'
join(', ', map({"$_=" . $$stat{"na_$_"};} grep({$$stat{"na_$_"};} @NOT_EXPRESSIBLE)))
Truth table0%0/2
A
A= join(', ', map({"$_=" . $$stat{"na_$_"};} grep({$$stat{"na_$_"};} @NOT_EXPRESSIBLE)))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | printf " stock classes not walked (reuse_core): %d\n", $stat->{stock_skipped} // 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$stat->{"stock_skipped"} // 0
MC/DC0%0/1
$stat->{"stock_skipped"} // 0
$stat->{"stock_skipped"}
Truth table0%0/2
A
A= $stat->{"stock_skipped"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | printf " Quantity fields whose grammar the type carries: %d\n", $stat->{quantity_pattern} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ▶ | if $stat->{quantity_pattern}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | printf " classes that failed to load: %d\n", $stat->{unloadable} // 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | if $stat->{unloadable}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$stat->{"unloadable"} // 0
MC/DC0%0/1
$stat->{"unloadable"} // 0
$stat->{"unloadable"}
Truth table0%0/2
A
A= $stat->{"unloadable"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | ▶ | exit($bad ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||