Code reference¶
Generated from the docstrings of the app's package, app/pubgrade_sidecar.
App¶
App factory, and entry point for development.
The image serves the app with Gunicorn (pubgrade_sidecar.app:create_app(),
with FOCA's settings, foca.gunicorn_config); python -m pubgrade_sidecar.app
(in app/) runs it with Flask's development server.
create_app ¶
Create the app from its configuration.
Gunicorn calls this in its worker, after forking. The sidecar keeps its deliveries in memory, so it must run in a single worker process (as with FOCA's Gunicorn settings), with threads.
Returns:
| Type | Description |
|---|---|
App
|
Connexion app. |
main ¶
Run the app with Flask's development server, on the configured port.
For development; not for production.
Controllers¶
Controllers of the API: read and update the image tags of Deployments.
ImageCheck
dataclass
¶
Outcome of a check whether a registry has an image.
Attributes:
| Name | Type | Description |
|---|---|---|
available |
bool
|
Whether the registry has the image. |
reason |
str | None
|
Why it isn't available, e.g., "registry answered 429 (rate
limit reached; ratelimit-remaining: 0)": the status and the
registry's |
retry_after |
float | None
|
Seconds that the registry asks to wait before the next
request ( |
getDeployment ¶
List the deployments that the sidecar manages.
Returns:
| Type | Description |
|---|---|
list[str]
|
Names of the deployments, as |
list[str]
|
|
Raises:
| Type | Description |
|---|---|
Unauthorized
|
If the token is missing or wrong. |
Forbidden
|
If the sidecar has no right to read the deployments. |
getImage ¶
Report the image and the rollout status of a deployment.
The record of the delivery is read before the Deployment, so that a delivery that was just patched can't be combined with an older Deployment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployment_name
|
str
|
Name of the deployment. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
JSON response with the image and the status. The last notification |
Response
|
per image repository, if any, is known until the sidecar restarts: a |
Response
|
failed or waiting delivery of any of them counts over the |
Response
|
Deployment's own status, a failed one first. |
Raises:
| Type | Description |
|---|---|
Unauthorized
|
If the token is missing or wrong. |
NotFound
|
If the deployment doesn't exist. |
Forbidden
|
If |
updateDeployment ¶
Accept a notification of a new image and start the delivery.
Every container of the deployment whose image repository equals the
notification's changes, and only its tag. The delivery runs in the
background; GET /deployment/{deployment-name} reports its state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
deployment_name
|
str
|
Name of the deployment. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
JSON response with the image and status code 202, or 200 if the |
int
|
deployment already uses that image: then nothing is rolled out. |
Raises:
| Type | Description |
|---|---|
Unauthorized
|
If the token is missing or wrong. |
NotFound
|
If the deployment doesn't exist. |
Forbidden
|
If |
BadRequest
|
If the tag is invalid, or the image name has a tag or a digest. |
ImageRepositoryMismatch
|
If no container of the deployment uses the repository. |
TagNotAllowed
|
If the tag doesn't match |
DowngradeRefused
|
With |
InternalServerError
|
If |
updateDeployments ¶
Accept a notification of a new image for all deployments that use it.
In every deployment that the sidecar manages, every container whose image
repository equals the notification's changes, and only its tag. The
sidecar manages the deployments named in the environment variable
TARGET_DEPLOYMENTS (comma-separated), or all in its namespace without
it; with DEPLOYMENT_LABEL (key=value, or key for any value), only
those with this label. Listed deployments that don't exist are skipped.
Each deployment gets its own delivery, whose state
GET /deployment/{deployment-name} reports.
Returns:
| Type | Description |
|---|---|
Response
|
JSON response with the name and the new image of each deployment that |
int
|
rolls out, and status code 202; or, if all deployments that use the |
tuple[Response, int]
|
repository already use the image, with each of them and its image, |
tuple[Response, int]
|
and status code 200: then nothing is rolled out. |
Raises:
| Type | Description |
|---|---|
Unauthorized
|
If the token is missing or wrong. |
BadRequest
|
If the tag is invalid, or the image name has a tag or a digest. |
NotFound
|
If no container of these deployments uses the repository. |
Forbidden
|
If the sidecar has no right to read the deployments. |
TagNotAllowed
|
If the tag doesn't match |
DowngradeRefused
|
With |
InternalServerError
|
If |
check_image ¶
Check whether the registry of an image has it, and if not, why not.
Asks the registry for the image's manifest (OCI distribution API), over
HTTPS, or HTTP for the hosts in INSECURE_REGISTRIES, with a token or
Basic authentication if the registry asks for it (see _head_manifest).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_repo
|
str
|
Canonical repository of the image, see |
required |
tag
|
str
|
Tag of the image. |
'latest'
|
Returns:
| Type | Description |
|---|---|
ImageCheck
|
The outcome. Network and authentication errors count as not |
ImageCheck
|
available; the reason names the status or the class of the error, |
ImageCheck
|
never its message, which could quote URLs. |
check_image_availability ¶
Check whether the registry of an image has it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_repo
|
str
|
Canonical repository of the image, see |
required |
tag
|
str
|
Tag of the image. |
'latest'
|
Returns:
| Type | Description |
|---|---|
bool
|
Whether the image is available (see |
bool
|
why not). |
Errors¶
Errors of the API and the responses that FOCA returns for them.
ImageUnavailable ¶
Bases: NotFound
Raised when the image of a notification isn't in its registry.
Only raised in the background, while a delivery waits for the image, so never returned to clients.
Attributes:
| Name | Type | Description |
|---|---|---|
reason |
Why the last check failed, safe to log and report (see
|
ImageRepositoryMismatch ¶
Bases: Conflict
Raised when a notification is for another image repository.
DowngradeRefused ¶
Bases: Conflict
Raised when a notification isn't an upgrade.
Only with REFUSE_DOWNGRADES: its tag isn't a higher version than the
current tag of each container it would change, or than the tag of a
delivery that still waits, or one of these tags isn't a version.
TagNotAllowed ¶
Bases: Conflict
Raised when the tag of a notification doesn't match ALLOWED_TAGS.