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

Feature: Generate Kubernetes CRD YAML files via cli #426

Closed
alexellis opened this issue Jul 2, 2018 · 12 comments

Comments

Projects
None yet
3 participants
@alexellis
Copy link
Member

commented Jul 2, 2018

The new definition for the Kubernetes CRD used in OpenFaaS Operator is different from the current stack file YAML definition.

I think the faas-cli should be used to generate/build/test functions in the stack.yml format and then if deployment is needed via kubectl then we should add a command to generate OpenFaaS Operator YAML.

Example conversion

stack.yml

provider:
  name: faas
  gateway: http://127.0.0.1:8080

functions:
  nodeinfo:
    lang: node
    handler: ./nodeinfo
    image: nodeinfo

The Kubernetes YAML omits any build-context such as the language or the handler folder, but will keep anything such as the environment, labels and etc.

Generates this:

apiVersion: openfaas.com/v1alpha2
kind: Function
metadata:
  name: nodeinfo
  namespace: openfaas-fn
spec:
  name: nodeinfo
  image: functions/nodeinfo
  environment:
    write_debug: "true"

Workflow

  • Create two functions
faas-cli new --lang python fn-1 --username=alexellis2
faas-cli new --apend=./fn-1.yml --lang python fn-2  --username=alexellis2
  • Build the functions and push them
faas-cli build -f fn-1.yml
faas-cli push -f fn-1.yml
  • Apply to Kubernetes
faas-cli generate --api=openfaas.com/v1alpha2 --yaml fn-1.yml | kubectl apply  -f

Suggested CLI command:

faas-cli generate --api=openfaas.com/v1alpha2 -f stack.yml

# Pipe to kubectl:
faas-cli generate --api=openfaas.com/v1alpha2 --yaml stack.yml | kubectl apply  -f

This would go to stdout and could be piped into a yaml file for use with kubectl

Unsure on the wording for generate, but this should be a new sub-command.

cc @affix @johnmccabe @openfaas/kubernetes

@alexellis alexellis changed the title Generate Kubernetes CRD YAML files via cli Feature: Generate Kubernetes CRD YAML files via cli Jul 2, 2018

@alexellis

This comment has been minimized.

Copy link
Member Author

commented Jul 9, 2018

Two primary ideas for implementation:

  1. reference ClientSet, create struct, populate from stack.yml and write to YAML

The ClientSet will be a huge dependency and only useful for Kubernetes, it may bloat the repo and binary a lot. On the flip side it will also mean versioning is easier. Slightly less maintenance is needed because bringing in schema changes means just revendoring.

  1. Maintain separate struct and marshal into that before writing it to YAML file

Creating a parallel struct with a simple .go file would be much less of a burden. Slightly more maintenance will be needed for this as changes in the ClientSet have to be brought into the local struct copy.

@affix

This comment has been minimized.

Copy link

commented Jul 9, 2018

I could take a stab at this at some point this week @alexellis

I suggest calling it create-crd instead of generate, generate could be misleading

@alexellis

This comment has been minimized.

Copy link
Member Author

commented Jul 9, 2018

Create could also be misleading as that's a kubectl verb.

Thoughts on my two suggestions for approaching implementation?

@affix

This comment has been minimized.

Copy link

commented Jul 9, 2018

I’d prefer option 2. It’s a lot cleaner by having a separate strict for the crd.

Maybe add an option to save it instead of dump to stdout

@alexellis

This comment has been minimized.

Copy link
Member Author

commented Jul 16, 2018

Hi @affix we're one week on so I wanted to check on progress. What's your ETA for completion with option 2?

Thanks,

Alex

@alexellis

This comment has been minimized.

Copy link
Member Author

commented Jul 19, 2018

@affix is on a long vacation now.

I would consider this work as available for someone to work on. It's important to get in soon.

@alexellis

This comment has been minimized.

Copy link
Member Author

commented Jul 19, 2018

Derek add label: priority/high

@derek derek bot added the priority/high label Jul 19, 2018

@alexellis

This comment has been minimized.

Copy link
Member Author

commented Jul 20, 2018

@viveksyngh did you want to take this on?

Alex

@alexellis

This comment has been minimized.

Copy link
Member Author

commented Jul 20, 2018

@viveksyngh

This comment has been minimized.

Copy link
Member

commented Jul 20, 2018

Yes I will work on this one.

@viveksyngh

This comment has been minimized.

Copy link
Member

commented Jul 23, 2018

how does this work .. if stack file contains more than one function? @alexellis

@alexellis

This comment has been minimized.

Copy link
Member Author

commented Jul 23, 2018

In Kubernetes/YAML it's valid to have multiple definitions in file they are separated by --- and a new line.

viveksyngh added a commit to viveksyngh/faas-cli that referenced this issue Jul 24, 2018

Add `generate` command to create CRD YAML files
This commit adds new subcommand `generate` faas-cli which can be used to
generate YAML file definition for Kubernetes CRD.

Output of this command can be piped to `kubectl` to apply to
Kubernetes cluster.

Usage: `faas-cli generate --api=openfaas.com/v1alpha2 --yaml fn-1.yml |
kubectl apply  -f -`

Fixes: openfaas#426

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>

viveksyngh added a commit to viveksyngh/faas-cli that referenced this issue Jul 25, 2018

Add `generate` command to create CRD YAML files
This commit adds new subcommand `generate` faas-cli which can be used to
generate YAML file definition for Kubernetes CRD.

Output of this command can be piped to `kubectl` to apply to
Kubernetes cluster.

Usage: `faas-cli generate --api=openfaas.com/v1alpha2 --yaml fn-1.yml |
kubectl apply  -f -`

Fixes: openfaas#426

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>

@viveksyngh viveksyngh referenced this issue Jul 25, 2018

Merged

Add `generate` command to create CRD YAML files #474

4 of 11 tasks complete

viveksyngh added a commit to viveksyngh/faas-cli that referenced this issue Jul 29, 2018

Add `generate` command to create CRD YAML files
This commit adds new subcommand `generate` faas-cli which can be used to
generate YAML file definition for Kubernetes CRD.

Output of this command can be piped to `kubectl` to apply to
Kubernetes cluster.

Usage: `faas-cli generate --api=openfaas.com/v1alpha2 --yaml fn-1.yml |
kubectl apply  -f -`

Fixes: openfaas#426

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>

viveksyngh added a commit to viveksyngh/faas-cli that referenced this issue Aug 1, 2018

Add `generate` command to create CRD YAML files
This commit adds new subcommand `generate` faas-cli which can be used to
generate YAML file definition for Kubernetes CRD.

Output of this command can be piped to `kubectl` to apply to
Kubernetes cluster.

Usage: `faas-cli generate --api=openfaas.com/v1alpha2 --yaml fn-1.yml |
kubectl apply  -f -`

Fixes: openfaas#426

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>

alexellis added a commit that referenced this issue Aug 2, 2018

Add `generate` command to create CRD YAML files
This commit adds new subcommand `generate` faas-cli which can be used to
generate YAML file definition for Kubernetes CRD.

Output of this command can be piped to `kubectl` to apply to
Kubernetes cluster.

Usage: `faas-cli generate --api=openfaas.com/v1alpha2 --yaml fn-1.yml |
kubectl apply  -f -`

Fixes: #426

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.