GithubHelp home page GithubHelp logo

sap / image-mapper Goto Github PK

View Code? Open in Web Editor NEW
0.0 5.0 0.0 103 KB

Kubernetes admission webhook to rewrite container images

License: Apache License 2.0

Shell 1.62% Dockerfile 3.47% Makefile 9.60% Go 85.30%
sap-cns sap-cs-devops

image-mapper's Introduction

Kubernetes Image Mapper

REUSE status

About this project

This service can act as a Mutating Kubernetes Admission Webhook for pods, and allows to dynamically adjust the images used by the containers of a pod, according to configurable rules.

All pods for which the admission webhook is called by the Kubernetes API server are subject to the replacement (if pods should be excluded, this has to be done by selectors in the webhook registration). For each of the pod's containers, the replacement rules are evaluated, and the first matching rule defines the replacement for the image. Rules are specified in the file provided by command line switch -mapping-file. The file should contain a JSON array in the following form:

[
  {
    "pattern": "(.+/my-image):.*",
    "replacement": "$1:latest"
  },
  {
    "pattern": "some-registry/.*",
    "replacement": "other-registry/${repository}:${tag}"
  },
  ...
]

The pattern can be an arbitrary regular expressions (go syntax) which will be automatically anchored (so adding anchors is not necessary). If the pattern contains any capturing groups, then the according matches can be used in the replacement as $1, $2, ..., as usual. If it does not, then the variables ${registry}, ${repository} and ${tag} will be populated, and can be used in the replacement.

To simplify the rules, the image will be normalized before the rule processing happens, in the following sense:

  • images which do not specify a tag, will be implicitly matched with suffix :latest
  • images which do not specify a registry (i.e. Docker hub) will be implicitly matched with prefix docker.io/.

If at least one image was replaced, then configurable labels or annotations can be added, as specified via the command line arguments -add-label-if-modified and -add-annotation-if-modified (which can be repeated), in the usual format key=value.

Note: in case this webhook has to reliably work with pods that are created or mutated by other webhooks, this one probably has to be registered with reinvocationPolicy: IfNeeded.

Command line flags

Flag Optional Default Description
-bind-address string yes :2443 Webhook bind address
-tls-key-file no - File containing the TLS private key used for SSL termination
-tls-cert-file no - File containing the TLS certificate matching the private key
-mapping-file no - File containing the mapping rules
-add-label-if-modified yes - Label to be set if pod was mutated (can be repeated)
-add-annotation-if-modified yes - Annotation to be set if pod was mutated (can be repeated)

Requirements and Setup

The recommended deployment method is to use the Helm chart:

helm upgrade -i image-mapper oci://ghcr.io/sap/image-mapper-helm/image-mapper

Documentation

The API reference is here: https://pkg.go.dev/github.com/sap/image-mapper.

Support, Feedback, Contributing

This project is open to feature requests/suggestions, bug reports etc. via GitHub issues. Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.

Code of Conduct

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.

Licensing

Copyright 2023 SAP SE or an SAP affiliate company and image-mapper contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.

image-mapper's People

Contributors

cbarbian-sap avatar erp4sme-devops-github-admin-user avatar renovate[bot] avatar shegox avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

image-mapper's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

dockerfile
Dockerfile
  • golang 1.22.3
github-actions
.github/workflows/build.yaml
  • actions/checkout v4
  • actions/setup-go v5
  • actions/checkout v4
  • docker/setup-buildx-action v3
  • docker/metadata-action v5
  • docker/build-push-action v5
  • actions/upload-artifact v4
  • ubuntu 22.04
  • ubuntu 22.04
.github/workflows/publish.yaml
  • actions/checkout v4
  • docker/setup-buildx-action v3
  • docker/login-action v3
  • docker/metadata-action v5
  • docker/build-push-action v5
  • actions/checkout v4
  • actions/checkout v4
  • benc-uk/workflow-dispatch v1
  • ubuntu 22.04
  • ubuntu 22.04
.github/workflows/release.yaml
  • actions/checkout v4
  • ubuntu 22.04
gomod
go.mod
  • go 1.22.3
  • github.com/go-logr/logr v1.4.2
  • github.com/onsi/ginkgo/v2 v2.18.0
  • github.com/onsi/gomega v1.33.1
  • github.com/pkg/errors v0.9.1
  • github.com/sap/admission-webhook-runtime v0.1.30
  • k8s.io/api v0.30.1
  • k8s.io/apimachinery v0.30.1
  • k8s.io/klog/v2 v2.120.1

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.