Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for kustomizing function images without patches #1767

Open
2 of 3 tasks
eran-bt opened this issue Nov 15, 2022 · 0 comments
Open
2 of 3 tasks

Support for kustomizing function images without patches #1767

eran-bt opened this issue Nov 15, 2022 · 0 comments

Comments

@eran-bt
Copy link

eran-bt commented Nov 15, 2022

My actions before raising this issue

Why do you need this?

I want to use different images for the same function, based on the environment in which the function runs (dev/staging/prod)

Who is this for?

Private usage.
What company is this for? Are you listed in the ADOPTERS.md file?

Expected Behaviour

I would like the ability to define a Kustomization Component with image replacement, like this:

apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

images:
- name: tasks
  newName: registry/tasks
  newTag: dev
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component

images:
- name: tasks
  newName: registry/tasks
  newTag: prod

And have it impact my base function definition:

apiVersion: openfaas.com/v1
kind: Function
metadata:
  name: tasks
  namespace: openfaas-fn
spec:
  name: tasks
  image: tasks

And within each env I will have the following kustomization.yaml:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ../base/tasks
components:
  - ../dev/extension-api
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
  - ../base/tasks
components:
  - ../prod/extension-api

Such that when I run
kubectl kustomize envs/dev/tasks
The resulting yaml for the function would be:

apiVersion: openfaas.com/v1
kind: Function
metadata:
  name: tasks
  namespace: openfaas-fn
spec:
  name: tasks
  image: registry/tasks:dev

and when I run
kubectl kustomize envs/prod/tasks
The resulting yaml for the function would be:

apiVersion: openfaas.com/v1
kind: Function
metadata:
  name: tasks
  namespace: openfaas-fn
spec:
  name: tasks
  image: registry/tasks:prod

Current Behaviour

When defining the files as the above structure, the component is ignored, and runnin kubectl kustomize simply produces the same yaml as the base yaml, without replacing the image.

Are you a GitHub Sponsor (Yes/No?)

Check at: https://github.com/sponsors/openfaas

  • Yes
  • No

List All Possible Solutions and Workarounds

As a workaround, I define a partial function yaml in each env, with only the image replaced, and add a patchesStrategicMerge section to apply the changes.
In my project the are only 2 variants: prod & non-prod, and for each env (local/dev/staging/prod), I would like to use one of the variants. Without image replacement, this requires redundant code, and updating the tag in each env, instead of update the tag in a single location and have it impact all the relevant envs.

Which Solution Do You Recommend?

As per the official documentation:

In addition to patches, Kustomize also offers customizing container images or injecting field values from other objects into containers without creating patches. For example, you can change the image used inside containers by specifying the new image in images field in kustomization.yaml.

As function CRDs are eventually translated to a deployment CRD with a container & image, I believe the same replacement logic can apply to function images.

Steps to Reproduce (for bugs)

  1. Create the files in the description above, and run kubectl kustomize

Context

Your Environment

  • FaaS-CLI version ( Full output from: faas-cli version ):
  ___                   _____           ____
 / _ \ _ __   ___ _ __ |  ___|_ _  __ _/ ___|
| | | | '_ \ / _ \ '_ \| |_ / _` |/ _` \___ \
| |_| | |_) |  __/ | | |  _| (_| | (_| |___) |
 \___/| .__/ \___|_| |_|_|  \__,_|\__,_|____/
      |_|

CLI:
 commit:  addf6bb9866689e0f5a862caf49c60dac06152fb
 version: 0.15.2

Gateway
 uri:     http://127.0.0.1:8080
 version: 0.25.2
 sha:     bc2eeff4678407583faec982c1c7d1da915dd60c


Provider
 name:          openfaas-operator
 orchestration: kubernetes
 version:       0.15.4
 sha:           330ac2a6d2e0db392a673b7fac97320d3e788139
Your faas-cli version (0.15.2) may be out of date. Version: 0.15.4 is now available on GitHub.
  • Docker version docker version (e.g. Docker 17.0.05 ):
 20.10.17
  • Are you using OpenFaaS on Kubernetes or faasd?
    Kubernetes

  • Operating System and version (e.g. Linux, Windows, MacOS):
    Linux/WSL

  • Code example or link to GitHub repo or gist to reproduce problem:

  • Other diagnostic information / logs from troubleshooting guide

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant