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

Adds support for specifying valid context names for an environment #674

Merged
merged 5 commits into from
Apr 27, 2022

Conversation

Nashluffy
Copy link
Contributor

@Nashluffy Nashluffy commented Mar 4, 2022

#58 (comment)

I appreciate the protection spec.apiServer provides, but Tanka does not work for our environments without support for matching on context names. I'm happy to update docs if this is something that would potentially be merged.

Our use case is summed up in the comment at the top.

Example spec.json

{
  "apiVersion": "tanka.dev/v1alpha1",
  "kind": "Environment",
  "metadata": {
    "name": "environments/development"
  },
  "spec": {
    "contextNames": ["automation-generated-context", "local-generated-context"],
    "namespace": "default",
    "resourceDefaults": {},
    "expectVersions": {}
  }
}

There's also a bug this PR fixes with an empty env.Spec.APIServer where the value will never be an empty string in (l LoadResult) Connect() because of the regular expression check in func Parse(data []byte, namespace string) (*v1alpha1.Environment, error). The fix is to only prepend that if the APIServer is not an empty string.

@malcolmholmes
Copy link
Contributor

You don't address "why" you cannot use the apiServer address. Without that, I don't think we can reason about why we should add this feature, which, to our minds would be a regression. Can you explain your need?

@Nashluffy
Copy link
Contributor Author

You don't address "why" you cannot use the apiServer address. Without that, I don't think we can reason about why we should add this feature, which, to our minds would be a regression. Can you explain your need?

Sure, I've outlined our use-case in this issue #686. Let me know if more details are needed. Thanks!

@sh0rez
Copy link
Member

sh0rez commented Mar 30, 2022

hi! thanks for the pr :D

I'm generally happy to go forward with this, but I can't follow why you would want to specify multiple contexts in the spec.json.
unless I miss something, kubectl operates on a single context only, and so should tanka (it currently does).

so what's the use-case for having multiple here?

@Nashluffy
Copy link
Contributor Author

Nashluffy commented Mar 30, 2022

There are two ways of pulling a kubeconfig for our clusters: from our cloud provider CLI, or from Teleport. Both use different naming conventions for the context and we have no control over that. The network our Jenkins instance is on cannot reach the network our Teleport instance is on, meaning users pull configs locally via Teleport and Jenkins pulls configs via our cloud provider CLI. Also, the way Jenkins pulls configs is currently our break-glass solution if Teleport is ever down. Supporting both naming conventions means we don't need to change the spec.json depending on where we are running tk from.

The PR actually has two ways to handle this case, using "example-cluster" for the cluster name

Explicitly listing each context name

  "spec": {
    "contextNames": ["automation-example-cluster", "local-example-cluster"],

Using a regular expression

  "spec": {
    "contextNames": [".*example-cluster.*"],

I can restrict the PR to only support one of the two, if that's more desirable.

@Nashluffy
Copy link
Contributor Author

Hi all - let me know if the above explanation justifies the field's support. I also added a reference to this field in the docs as it's currently implemented.

Copy link
Member

@julienduchesne julienduchesne left a comment

Choose a reason for hiding this comment

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

LGTM!

@julienduchesne
Copy link
Member

@sh0rez What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants