| 1 | package Example::Comb::DB; | ||||||||||||||||||||||
| 2 | # ABSTRACT: Example Comb: a PostgreSQL database, borrowed in the examples | ||||||||||||||||||||||
| 3 | |||||||||||||||||||||||
| 4 | # The examples do not run this one: they give it an upstream, so it borrows | ||||||||||||||||||||||
| 5 | # the database from another layer and deploys only the bridge -- a Service | ||||||||||||||||||||||
| 6 | # of the same name pointing there. Its manifests are what runs in the layer | ||||||||||||||||||||||
| 7 | # the others borrow from. The class knows nothing about that: borrowing is | ||||||||||||||||||||||
| 8 | # a state of the instance, decided by whoever builds it. | ||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||
| 10 | # The password is a Secret the Comb does not create: never credentials in | ||||||||||||||||||||||
| 11 | # the custom resource. Create it next to the Comb: | ||||||||||||||||||||||
| 12 | # | ||||||||||||||||||||||
| 13 | # kubectl create secret generic db-credentials --from-literal=password=... | ||||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | 1 | ▶ | use Moo; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 16 | 1 | extends 'Kubernetes::Comb'; | |||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | 1 | ▶ | use namespace::autoclean; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | 0 | ▶ | sub endpoints { { name => 'postgres', port => 5432 } } | ||||||||||||||||||||
|
Subroutine
endpoints: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | 1 | ▶ | sub manifests { | ||||||||||||||||||||
|
Subroutine
manifests: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||
| 23 | 1 | my ( $self ) = @_; | |||||||||||||||||||||
| 24 | 1 | my $name = $self->name; | |||||||||||||||||||||
| 25 | 1 | my %app = ( app => $name ); | |||||||||||||||||||||
| 26 | return ( | ||||||||||||||||||||||
| 27 | { | ||||||||||||||||||||||
| 28 | apiVersion => 'apps/v1', | ||||||||||||||||||||||
| 29 | kind => 'StatefulSet', | ||||||||||||||||||||||
| 30 | metadata => { name => $name }, | ||||||||||||||||||||||
| 31 | spec => { | ||||||||||||||||||||||
| 32 | serviceName => $name, | ||||||||||||||||||||||
| 33 | replicas => 1, | ||||||||||||||||||||||
| 34 | selector => { matchLabels => {%app} }, | ||||||||||||||||||||||
| 35 | template => { | ||||||||||||||||||||||
| 36 | metadata => { labels => {%app} }, | ||||||||||||||||||||||
| 37 | spec => { containers => [ { | ||||||||||||||||||||||
| 38 | name => 'postgres', | ||||||||||||||||||||||
| 39 | image => $self->config->{image} // 'postgres:16-alpine', | ||||||||||||||||||||||
| 40 | env => [ | ||||||||||||||||||||||
| 41 | { name => 'PGDATA', value => '/var/lib/postgresql/data/pgdata' }, | ||||||||||||||||||||||
| 42 | { name => 'POSTGRES_PASSWORD', valueFrom => { secretKeyRef => { | ||||||||||||||||||||||
| 43 | name => $name.'-credentials', | ||||||||||||||||||||||
| 44 | key => 'password' | ||||||||||||||||||||||
| 45 | } } } | ||||||||||||||||||||||
| 46 | ], | ||||||||||||||||||||||
| 47 | ports => [ { name => 'postgres', containerPort => 5432 } ], | ||||||||||||||||||||||
| 48 | readinessProbe => { exec => { command => [ 'pg_isready', '-U', 'postgres' ] } }, | ||||||||||||||||||||||
| 49 | volumeMounts => [ { name => 'data', mountPath => '/var/lib/postgresql/data' } ] | ||||||||||||||||||||||
| 50 | } ] } | ||||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||||
| 52 | volumeClaimTemplates => [ { | ||||||||||||||||||||||
| 53 | metadata => { name => 'data' }, | ||||||||||||||||||||||
| 54 | spec => { | ||||||||||||||||||||||
| 55 | accessModes => [ 'ReadWriteOnce' ], | ||||||||||||||||||||||
| 56 | 1 | ▶ | resources => { requests => { storage => $self->config->{storage} // '1Gi' } } | ||||||||||||||||||||
|
Condition50%2/4
$self->config->{"image"} // "postgres:16-alpine"
$self->config->{"storage"} // "1Gi"
MC/DC0%0/1
$self->config->{"image"} // "postgres:16-alpine"
$self->config->{"image"}
MC/DC0%0/1
$self->config->{"storage"} // "1Gi"
$self->config->{"storage"}
Truth table50%1/2
A
A= $self->config->{"image"}
Truth table50%1/2
A
A= $self->config->{"storage"}
| |||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||
| 58 | } ] | ||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||
| 62 | apiVersion => 'v1', | ||||||||||||||||||||||
| 63 | kind => 'Service', | ||||||||||||||||||||||
| 64 | metadata => { name => $name }, | ||||||||||||||||||||||
| 65 | spec => { | ||||||||||||||||||||||
| 66 | selector => {%app}, | ||||||||||||||||||||||
| 67 | ports => [ { name => 'postgres', port => 5432 } ] | ||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | 1 | 1; | |||||||||||||||||||||