Skip to content

Commit

Permalink
Filter images using labels
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGustafsson committed Feb 10, 2025
1 parent 60e8503 commit 6ce82f5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/cupdate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,12 @@ func main() {

for graph := range graphs {
slog.DebugContext(ctx, "Got updated platform graph")

// Delete ignored images / trees
graph.DeleteFunc(func(n platform.Node) bool {
return n.Labels().Ignore()
})

roots := graph.Roots()

for _, root := range roots {
Expand Down
34 changes: 34 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,37 @@ done using environment variables.
| `CUPDATE_OTEL_TARGET` | Target URL to an Open Telemetry GRPC ingest endpoint. | Required to use Open Telemetry. |
| `CUPDATE_OTEL_INSECURE` | Disable client transport security for the Open Telemetry GRPC connection. | `false` |
| `CUPDATE_REGISTRY_SECRETS` | Path to a JSON file containing registry secrets. See Docker's config.json and Kubernetes' `imagePullSecrets`. | None |

### Labels

Cupdate can take additional resource-specific configuration via the use of
labels. For Docker, this means annotating the container image or the container /
service itself. In Kubernetes, any resource in the image's tree can be annotated
to configure Cupdate. See below for examples.

Each label has two aliases to follow both the Docker and Kubernetes conventions.

| Label | Description | Default |
| -------------------------------------------------- | -------------------------------------------------------------------- | ------- |
| `config.cupdate/ignore` or `cupdate.config.ignore` | Set to `true` to ignore the resource subtree (e.g. container / pod). | `false` |

#### Examples

```yaml
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: cupdate
config.cupdate/ignore: "true"
# ...
```

```yaml
# compose.yaml
services:
cupdate:
labels:
- cupdate.config.ignore: "true"
```
4 changes: 4 additions & 0 deletions internal/platform/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ type Node interface {
type Labels map[string]string

func (l Labels) Ignore() bool {
if l == nil {
return false
}

if v, ok := l["config.cupdate/ignore"]; ok {
return v == "true"
}
Expand Down

0 comments on commit 6ce82f5

Please sign in to comment.