Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

feat: Add --driver kubernetes #560

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

technosophos
Copy link
Member

This runs the invocation image inside of a Kubernetes cluster.

Use --driver kubernetes or --driver k8s to use this driver.

The driver respects the following env vars:

$KUBE_CONFIG
$KUBE_CONTEXT
$KUBE_NAMESPACE
$VERBOSE

It works by creating a secret and a pod.

  • The Pod contains the invocation image
  • The secret contains all files and env vars
  • The secret's properties are attached to the Pod at startup
  • the secret is destroyed when the pod is done

@technosophos technosophos added the WIP work in progress label Dec 1, 2018
@technosophos technosophos added this to In progress in MVP via automation Dec 1, 2018
This runs the invocation image inside of a Kubernetes cluster.
@technosophos
Copy link
Member Author

  • Print logs back to Duffle

case "KUBE_CONTEXT":
d.KubeContext = v
case "VERBOSE":
d.Verbose = v == "1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one took some thinking on a Saturday evening...

opts := meta.ListOptions{
LabelSelector: fmt.Sprintf("heritage=duffle,release=%s,revision=%s", op.Installation, op.Revision),
}
req, err := d.Client.CoreV1().Pods(d.Namespace).Watch(opts)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, this makes it so much cleaner than having an informer + controller (which is the solution I used when I tried this, a few Kubernetes versions ago).

// Unhandled cases are Unknown and Pending, both of which should
// cause the loop to spin.
case "Running", "Succeeded":
req.Stop()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic for waiting here is a bit confusing - as the comment when calling this function is // Waid for the pod to run to completion., but this waits for the pod to either be in Running or Succeeded state, it means the function returns when the pod first enters Running state.

I think I understand that we need to know when the pod is in Running state so we can stream the logs, but the wording here is a bit confusing.

@radu-matei
Copy link
Member

This looks really great!

Some inspiration for attaching to the pod and streaming logs (if anyone gets to working on this before the beginning of next week) - it's for an older Kubernetes version, so there might be a shiny new way to do this.

@radu-matei
Copy link
Member

Tried to use a bundle that requires credentials, in this case a file path:

$ duffle install hellohelm-test -f ../bundles/hellohelm/bundle.json --insecure -c hellohelm-creds --driver k8s
Executing install action...
Error: Install step failed: Secret "hellohelm-test-01cxn93m90vwgg3aga06020kwt" is invalid: data[/root/.kube/config]: Invalid value: "/root/.kube/config": a valid config key must consist of alphanumeric characters, '-', '_' or
'.' (e.g. 'key.name',  or 'KEY_NAME',  or 'key-name', regex used for validation is '[-._a-zA-Z0-9]+')

$ duffle creds show hellohelm-creds
name: hellohelm-creds
credentials:
- name: kubeconfig
  source:
    path: /home/radu/.kube/config

@technosophos technosophos added this to In progress in 0.2.0 via automation Jan 15, 2019
@technosophos technosophos removed this from In progress in MVP Jan 15, 2019
@jlegrone jlegrone mentioned this pull request Jun 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
in progress WIP work in progress
Projects
0.2.0
  
In progress
Development

Successfully merging this pull request may close these issues.

None yet

2 participants