devspace icon indicating copy to clipboard operation
devspace copied to clipboard

Allow devspace.yaml to define a namespace

Open hendrikheil opened this issue 2 years ago • 3 comments

Is your feature request related to a problem? We are using devspace v6 pretty extensively in our organization. We're trying really hard to make sure that our deployments in development look as close to production as possible. That also includes deploying each service to its own namespace. It's pretty important to have this in development as well, as sometimes we notice limitations with the tools we are using when it comes to namespace borders. We are already able to set a namespace for each deployment individually, but devspace still doesn't know about what namespace we are targeting in general. This leads to devspace asking if you really want to deploy to "default", sometimes showing an alternative namespace to deploy to (which leads to user error), devspace logs and devspace enter requiring the namespace you've actually deployed to etc. It's also currently impossible to define a namespace for a pullsecret. Devspace will just put it into whatever namespace you define through -n. For us this meant we had to update our helm charts to create pullsecrets, since we were unable to create the pullsecret for the namespace we are actually deploying to.

Which solution do you suggest? It would be pretty helpful to allow users to set a devspace.yaml wide namespace that is used by default.

Here are some of the config options that should use the root namespace as default, in our opinion. Having them use the default would remove a lot of duplicate definitions on where things are actually running. https://github.com/loft-sh/devspace/blob/master/pkg/devspace/config/versions/latest/schema.go#L600 https://github.com/loft-sh/devspace/blob/master/pkg/devspace/config/versions/latest/schema.go#L844 https://github.com/loft-sh/devspace/blob/master/pkg/devspace/config/versions/latest/schema.go#L1380

These options here are probably also benefitting from this behavior, though I have no experience to go off of here. https://github.com/loft-sh/devspace/blob/master/pkg/devspace/config/versions/latest/schema.go#L363 https://github.com/loft-sh/devspace/blob/master/pkg/devspace/config/versions/latest/schema.go#L412

Which alternative solutions exist? You can use -n for every devspace command you run. But that is cumbersome, error prone and hard to remember.

Additional context I'm not sure what the best approach for https://github.com/loft-sh/devspace/blob/master/pkg/devspace/config/versions/latest/schema.go#L1250 would be. I think most people would define a namespace per devspace.yaml file and use that for the most part. This option could probably be used to overwrite the new namespace property.

/kind feature

hendrikheil avatar Jul 01 '22 11:07 hendrikheil

@CiiDyR thanks for creating this issue! Your use case makes sense and we'll think about how we can incorporate this into DevSpace

FabianKramm avatar Jul 05 '22 17:07 FabianKramm

For others encountering this, you can currently achieve this by using a variable called DEVSPACE_FLAGS. By using it like this, you are basically achieving the same thing as described in my original comment:

vars:
  DEVSPACE_FLAGS:
    value: "-n mynamespace"

You can also set --no-warn (or any other flags you want for that matter) to disable questions like if you really want to switch the namespace

hendrikheil avatar Aug 25 '22 07:08 hendrikheil

https://github.com/loft-sh/devspace/issues/2151#issuecomment-1226903878

Okay, seems like this isn't quite right. Using it this way will cause devspace to not know about dependencies deployed in other namespaces. My use-case was specifically about deploying one devspace-project (in my case a single service and it's unshared dependencies like redis) in one namespace. Using default flags will cause devspace to track the dependency deployments separately. So right now it seems like we could define a default namespace like that to make sure devspace uses the same state, but to enter logs or a container, you still need to supply devspace with the right namespace flag.

hendrikheil avatar Aug 26 '22 14:08 hendrikheil