Skip to content

tiltfile: object identifiers are not case sensitive#3429

Merged
jazzdan merged 4 commits into
masterfrom
dmiller/k8s-resource-object-selector-not-case-sensitive
Jun 9, 2020
Merged

tiltfile: object identifiers are not case sensitive#3429
jazzdan merged 4 commits into
masterfrom
dmiller/k8s-resource-object-selector-not-case-sensitive

Conversation

@jazzdan

@jazzdan jazzdan commented Jun 8, 2020

Copy link
Copy Markdown
Contributor

Fixes #3423

@jazzdan
jazzdan requested review from landism, maiamcc and nicks June 8, 2020 22:12
}

for i, o := range opts.objects {
entities, ok := fragmentsToEntities[o]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i'm surprised they're not stored in objects as lowercase?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm it might be weird to use a different string than the one the user entered in error messages though, even if we treat it as case insensitive. I think I want to preserve the original string.

Comment thread internal/tiltfile/tiltfile_state.go Outdated
exactOrEmptyRegex(name),
exactOrEmptyRegex(namespace),
)
func newExactCaseInsensitiveK8sObjectSelector(apiVersion string, kind string, name string, namespace string) (k8sObjectSelector, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I feel like the nomenclature here needs to be cleaned up a bit, in particular:

  • All functions are case insensitive now, but only one of them has "CaseInsensitive" in the name. That seems weird?
  • The usage of the word "exact" here is not something i've seen before. I think python calls this "FullMatch"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ooh I like FullMatch. And I agree, I'll clean this stuff up.

return ret, nil
}

func makeCaseInsensitive(s string) string {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i feel like half the problem here is that we're passing around a regexp around as a DSL string, rather than something more structured, and i wonder if this code would be easier to follow if we had something like

type re struct {
  pattern string
  ignoreCase bool
  fullMatch bool
}

func (r re) compile() { ... }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeahhh I tried something like this back when I was originally writing this a couple weeks ago. I'll give it another shot with fresh eyes.

@landism

landism commented Jun 9, 2020

Copy link
Copy Markdown
Member

Did you end up finding a source or some evidence for whether k8s allows two objects to have the same name with different casing? It's probably worth writing down the evidence/assumption, given we were unclear on it.

@nicks

nicks commented Jun 9, 2020

Copy link
Copy Markdown
Contributor

Here are some references:
https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#api-conventions
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names

As a general rule of thumb, Kubernetes tends to convert everything to lowercase, since they end up getting converted to case-insensitive HTTP endpoints

@jazzdan

jazzdan commented Jun 9, 2020

Copy link
Copy Markdown
Contributor Author

Yeah that stuff is what I went off of.

I'm still a little unclear on kind names, but it seems that most everything has been lowercase in my testing.

Like in this part of the docs

Resource collections should be all lowercase and plural, whereas kinds are CamelCase and singular. Group names must be lower case and be valid DNS subdomains.

It doesn't explicitly say that kind names are case insensitive, but I wasn't able to test this myself yet.

@nicks

nicks commented Jun 9, 2020

Copy link
Copy Markdown
Contributor

Ya, I think the API docs are being super-precise in a way that's helpful if you understand the internals, but hard to parse if you do not.

There are two different things:

  • kinds (which require camel case)
  • resources (which are exposed as lowercase)

and there's a mapping from Kind -> resource that converts to lowercase

but to a user (e.g., someone who's just using kubectl and writing yaml), because there's a 1<>1 mapping, it's easy to read that as "oh, it's case-insensitive", when what's actually happening is that you're interacting with different things and it's not always obvious to you which one you're interacting with

Does that make sense?

@jazzdan

jazzdan commented Jun 9, 2020

Copy link
Copy Markdown
Contributor Author

Yeahhh that makes sense. Thanks @nicks!

@jazzdan

jazzdan commented Jun 9, 2020

Copy link
Copy Markdown
Contributor Author

I updated some nomenclature but left the refactor as a TODO because, once again, I ran in to weird test failures. I think we're depending on some regex behavior that is unclear to me and super finicky.

@jazzdan
jazzdan merged commit f42d5dc into master Jun 9, 2020
@nicks
nicks deleted the dmiller/k8s-resource-object-selector-not-case-sensitive branch February 3, 2022 16:53
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.

k8s_resource object selector error message makes no sense

3 participants