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

Resolve spec.apiServer from kubectl context at runtime #394

Closed
igorwwwwwwwwwwwwwwwwwwww opened this issue Sep 28, 2020 · 11 comments
Closed
Labels
kind/feature Something new should be added

Comments

@igorwwwwwwwwwwwwwwwwwwww

One of the issues we're facing at @GitLab is apiServer being hardcoded in a shared spec.json file used for minikube.

It is possible to set this value automatically using:

tk env set environments/jaeger/dev --server-from-context minikube

However, this will still update the file. So it requires a non-shared (possibly copy-pasted from spec.json.example) spec file, so that users don't keep overriding each other.

Some of the suggestions in #390 may help with this.

But I was wondering if it might make sense for tanka to read kubectl config get-contexts and figure out the apiServer dynamically that way at runtime.

@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label kind/feature to this issue, with a confidence of 0.71. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@issue-label-bot issue-label-bot bot added the kind/feature Something new should be added label Sep 28, 2020
@malcolmholmes
Copy link
Contributor

Thanks for this question. The reason we store the api server in the config is because it is far better for identifying the cluster than a context name. Individual users could name contexts differently, whereas the api server URL will be consistently correct across users. This helps us guarantee that when we do a tk apply, the correct cluster will be used. This behaviour is intentional, and we don't want to change it.

However, the minikube situation is also a valid one - when the same config might be applied to multiple local clusters, with different API server URLs and likely different context names. To meet this case, we'd need to find something that allows supporting minikube, but doesn't risk people using context names for their production clusters.

@malcolmholmes
Copy link
Contributor

The basic idea as I see it is that it needs to be easy to specify the cluster api server URL, and hard to configure a context (but still possible). If we can get that in place, we could have something that works.

@sh0rez
Copy link
Member

sh0rez commented Sep 29, 2020

Hi @igorwwwwwwwwwwwwwwwwwwww! As @malcolmholmes already explained, we chose operational safety over ease of use here back when we designed thius.

As we have been playing with the idea of moving spec.json into Jsonnet itself a lot recently, I think the solution tho this could like within there. Using a combination of advanced Jsonnet concepts, this could certainly be achieved.

Say the env config in Jsonnet would like this:

{
  env: {
    apiVersion: "tanka.dev/v1alpha1",
    kind: "Environment",
    metadata: { name: "/environments/myFancyEnv" },
    spec: {
      apiServer: "https://myFancyCluster:6443",
    }
  }
}

Top level arguments would allow you to dynamically adapt the apiServer url:

-{
+function(apiServer="https://myFancyCluster:6443") {
   env: {
     apiVersion: "tanka.dev/v1alpha1",
     kind: "Environment",
     metadata: { name: "/environments/myFancyEnv" },
     spec: {
-      apiServer: "https://myFancyCluster:6443",
+      apiServer: apiServer,
     }
   }
 }

When invoked without arguments, default value of https://myFancyCluster:6443 is used:

$ tk show environments/myFancyEnv

However, you can now inject this value:

$ tk show environments/myFancyEnv --tla-str "apiServer=https://$(minikube ip):6443"

How does this sound? This should be sufficiently difficult to avoid people doing it automatically, but a suitable solution for dev servers.

@igorwwwwwwwwwwwwwwwwwwww
Copy link
Author

@sh0rez Nice! Yes, I think this would work for us. 👍

@stale
Copy link

stale bot commented Oct 31, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 31, 2020
@stale stale bot closed this as completed Nov 7, 2020
@sh0rez sh0rez reopened this Nov 7, 2020
@stale stale bot removed the stale label Nov 7, 2020
@stale
Copy link

stale bot commented Dec 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 8, 2020
@Duologic Duologic removed the stale label Dec 8, 2020
@Duologic
Copy link
Member

Inline environments is available in v0.13.0, does this resolve your question?

@sh0rez
Copy link
Member

sh0rez commented Dec 30, 2020

The solution outlined in #394 (comment) became possible in #403 thanks to @Duologic. Closing as resolved

@sh0rez sh0rez closed this as completed Dec 30, 2020
@James-Riordan
Copy link

Hi @igorwwwwwwwwwwwwwwwwwwww! As @malcolmholmes already explained, we chose operational safety over ease of use here back when we designed thius.

As we have been playing with the idea of moving spec.json into Jsonnet itself a lot recently, I think the solution tho this could like within there. Using a combination of advanced Jsonnet concepts, this could certainly be achieved.

Say the env config in Jsonnet would like this:

{
  env: {
    apiVersion: "tanka.dev/v1alpha1",
    kind: "Environment",
    metadata: { name: "/environments/myFancyEnv" },
    spec: {
      apiServer: "https://myFancyCluster:6443",
    }
  }
}

Top level arguments would allow you to dynamically adapt the apiServer url:

-{
+function(apiServer="https://myFancyCluster:6443") {
   env: {
     apiVersion: "tanka.dev/v1alpha1",
     kind: "Environment",
     metadata: { name: "/environments/myFancyEnv" },
     spec: {
-      apiServer: "https://myFancyCluster:6443",
+      apiServer: apiServer,
     }
   }
 }

When invoked without arguments, default value of https://myFancyCluster:6443 is used:

$ tk show environments/myFancyEnv

However, you can now inject this value:

$ tk show environments/myFancyEnv --tla-str "apiServer=https://$(minikube ip):6443"

How does this sound? This should be sufficiently difficult to avoid people doing it automatically, but a suitable solution for dev servers.

Can we please make spec.json -> spec.jsonnet? The old paradigm of "one-time create k8s clusters" is no longer the case. K8s clusters should be assumed ephemeral, and thus the dynamic apiServer seems naturally fitting for the evolution of K8s over the years.

@Duologic
Copy link
Member

Duologic commented Jul 7, 2023

Have a look at this, should cover your request: https://tanka.dev/inline-environments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Something new should be added
Projects
None yet
Development

No branches or pull requests

5 participants