Skip to main content

Operator for syncing photos from Flickr to Immich on Kubernetes

Project description

flickr-immich-k8s-sync-operator

black-lint mypy and pytests Cumulative Clones Docker Pulls

Kubernetes operator that watches per-user Flickr download Jobs in a namespace, restarts failed Jobs after a configurable delay, and retrieves pod logs and exit codes for failed Jobs before restarting them. Designed to run alongside Immich (self-hosted photo management).

Status

Beta (v0.0.1) — the core job-restart loop is implemented and functional. The project scaffolding (packaging, Docker image, CI) is in place.

Architecture

  • Runs as a single-replica Deployment in a dedicated namespace (default: flickr-downloader)
  • Uses the Kubernetes Python client with in-cluster config
  • Periodically checks configured Job names for failure conditions
  • On failure (after a configurable delay), deletes the Job with Foreground propagation policy and recreates it from a cached manifest
  • Logs pod exit codes and tail logs before every restart

Prerequisites

  • A running Kubernetes cluster
  • Flickr download Jobs already deployed — the operator manages their lifecycle (restart on failure), not initial creation
  • An Immich instance (for planned sync functionality)

Configuration

Variable Description Default
LOGURU_LEVEL Log verbosity (DEBUG, INFO, WARNING, …) DEBUG
NAMESPACE Namespace to watch flickr-downloader
JOB_NAMES Comma-separated Job names to monitor (required)
CHECK_INTERVAL Seconds between check cycles 60
RESTART_DELAY Seconds to wait after failure before restart 3600

Kubernetes Deployment

RBAC

The operator requires a ServiceAccount with a Role scoped to the target namespace:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: flickr-operator
  namespace: flickr-downloader
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: flickr-operator
  namespace: flickr-downloader
rules:
  - apiGroups: ["batch"]
    resources: ["jobs"]
    verbs: ["get", "list", "create", "delete"]
  - apiGroups: [""]
    resources: ["pods"]
    verbs: ["get", "list", "delete"]
  - apiGroups: [""]
    resources: ["pods/log"]
    verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: flickr-operator
  namespace: flickr-downloader
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: flickr-operator
subjects:
  - kind: ServiceAccount
    name: flickr-operator
    namespace: flickr-downloader

Deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: flickr-operator
  namespace: flickr-downloader
spec:
  replicas: 1
  selector:
    matchLabels:
      app: flickr-operator
  template:
    metadata:
      labels:
        app: flickr-operator
    spec:
      serviceAccountName: flickr-operator
      containers:
        - name: operator
          image: flickr-immich-k8s-sync-operator:latest
          env:
            - name: JOB_NAMES
              value: "flickr-downloader-alice,flickr-downloader-bob"
            - name: LOGURU_LEVEL
              value: "DEBUG"
            # - name: NAMESPACE
            #   value: "flickr-downloader"      # default
            # - name: CHECK_INTERVAL
            #   value: "60"                      # default
            # - name: RESTART_DELAY
            #   value: "3600"                    # default
          resources:
            requests:
              cpu: 50m
              memory: 64Mi
            limits:
              cpu: 1500m
              memory: 128Mi

Installation

From PyPI

pip install flickr-immich-k8s-sync-operator

From source

git clone https://github.com/vroomfondel/flickr-immich-k8s-sync-operator.git
cd flickr-immich-k8s-sync-operator
make venv
source .venv/bin/activate
pip install .

Docker

docker build -t flickr-immich-k8s-sync-operator .
docker run --rm flickr-immich-k8s-sync-operator

Or via Makefile:

make docker

Usage

# Run directly
flickr-immich-k8s-sync-operator

# Or via Python module
python -m flickr_immich_k8s_sync_operator

Development

Makefile targets

Target Description
make venv Create virtualenv and install all dependencies
make tests Run pytest
make lint Format code with black (line length 120)
make isort Sort imports with isort
make tcheck Static type checking with mypy
make commit-checks Run pre-commit hooks on all files
make prepare Run tests + commit-checks
make pypibuild Build sdist + wheel with hatch
make pypipush Publish to PyPI with hatch
make docker Build Docker image

License

GNU Lesser General Public License v3

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flickr_immich_k8s_sync_operator-0.0.1.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file flickr_immich_k8s_sync_operator-0.0.1.tar.gz.

File metadata

File hashes

Hashes for flickr_immich_k8s_sync_operator-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a9b7e3a622bbf69d7c189a52d054bacfb051a593e5fb12775f5ca42f32b3f877
MD5 54fd364eca4194e8a0cf142a0aa08ee9
BLAKE2b-256 b5a5e13e08974124590371b4edcd6447eda1ccf0fefea02c5a9540786f280973

See more details on using hashes here.

File details

Details for the file flickr_immich_k8s_sync_operator-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flickr_immich_k8s_sync_operator-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2e7b1dbb683697fdb5de74e930596b2c6ae3db721601c66d275ea2857f86de51
MD5 07da8cc10c8f9b4e3c8493ff30954dce
BLAKE2b-256 40e91a932c1163565639d115c036b23df317a12751dadc4cf5b238a955ec40cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page