Tilt: Namespace Support

Created on 5 Feb 2019  路  4Comments  路  Source: tilt-dev/tilt

Tilt should have build in support for setting a Kubernetes namespace that all objects get created in for the duration of the session.

Tiltfile syntax could look like this:

set_namespace("dan-dev")

Tilt would remember the namespace that you specify and append it as a command line flag every time it invokes kubectl.

enhancement

Most helpful comment

For now, I am using the following

def set_namespace(namespace):
  command = 'kubectl config set-context $(kubectl config current-context) --namespace=%s' % (namespace)
  current_context = str(local(command)).rstrip('\n')

def set_context(context, namespace=''):
  command = 'kubectl config use-context %s' % (context)
  current_context = str(local(command)).rstrip('\n')
  if namespace:
    set_namespace(namespace)

set_context('docker-for-desktop')
# set_context('docker-for-desktop', 'dev')
set_namespace('dev')

It does change your default context which I am ok with for now. but ideally it would be nice to have it scoped to the title process.

All 4 comments

For now, I am using the following

def set_namespace(namespace):
  command = 'kubectl config set-context $(kubectl config current-context) --namespace=%s' % (namespace)
  current_context = str(local(command)).rstrip('\n')

def set_context(context, namespace=''):
  command = 'kubectl config use-context %s' % (context)
  current_context = str(local(command)).rstrip('\n')
  if namespace:
    set_namespace(namespace)

set_context('docker-for-desktop')
# set_context('docker-for-desktop', 'dev')
set_namespace('dev')

It does change your default context which I am ok with for now. but ideally it would be nice to have it scoped to the title process.

@jazzdan : Would it make sense for that command set_namespace, to create the namespace if it didn鈥檛 already exist? See https://kubernetes.slack.com/archives/CESBL84MV/p1589465928081300?thread_ts=1589454049.073200&channel=CESBL84MV&message_ts=1589465928.081300

@victorwuky yup I think that could make sense.

What would happen if kubens created the namespace for every typo that a user typed?

These should be seperate functions/commands Linux philosophy here do one thing and one thing well. If people want the namespace they could use a create_namespace

Just for the record I would love to tilt to be able to create namespaces but I would hate it creating namespaces for me when I am trying to set the namespace/context.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DblK picture DblK  路  5Comments

kvokka picture kvokka  路  7Comments

tamer-hassan picture tamer-hassan  路  5Comments

bandrade picture bandrade  路  5Comments

matthiasak picture matthiasak  路  4Comments