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

Use short name for tag value in development mode #810

Closed
wants to merge 1 commit into from
Closed

Conversation

pietern
Copy link
Contributor

@pietern pietern commented Sep 27, 2023

Changes

The jobs API expects tag values to match the regex ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$. The display name can contain anything. With this change we modify the tag value to equal the short name as used in the name prefix.

This won't work in all cases because the short name can contain accents but is strictly better than the display name.

A better solution adds a separate property to the user struct with some kind of normalized display name, or normalized tag value name, that always strictly matches the regex above.

Tests

Tests pass.

r.Jobs[i].Tags["dev"] = b.Config.Workspace.CurrentUser.DisplayName
// Note: tag values in jobs must match the following pattern:
// ^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$
r.Jobs[i].Tags["dev"] = b.Config.Workspace.CurrentUser.ShortName
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we just do something like

func getShortUserName(emailAddress string) string {
to make the name match this mold?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should, working on a fix. The allowed patterns vary per cloud so the change is a little more involved.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. +1 for merging this for now.

@andrewnester
Copy link
Contributor

andrewnester commented Sep 27, 2023

Fixes #809

@pietern
Copy link
Contributor Author

pietern commented Sep 28, 2023

This is superseded by a more robust fix #821.

@pietern pietern closed this Sep 28, 2023
@pietern pietern deleted the fix-job-tag branch September 28, 2023 21:36
github-merge-queue bot pushed a commit that referenced this pull request Sep 29, 2023
## Changes

Prompted by the proposed fix for a tagging-related problem in #810, I
investigated how tag validation works. This turned out to be quite a bit
more complex than anticipated. Tags at the job level (or cluster level)
are passed through to the underlying compute infrastructure and as such
are tested against cloud-specific validation rules. GCP appears to be
the most restrictive. It would be disappointing to always restrict to
`\w+`, so this package implements validation and normalization rules for
each cloud. It can pick the right cloud to use using a Go SDK
configuration.

## Tests

Exhaustive unit tests. The regular expressions were pulled by #814.
github-merge-queue bot pushed a commit that referenced this pull request Oct 2, 2023
## Changes

The jobs backend propagates job tags to the underlying cloud provider's
resources. As such, they need to match the constraints a cloud provider
places on tag values. The display name can contain anything. With this
change, we modify the tag value to equal the short name as used in the
name prefix.

Additionally, we leverage tag normalization as introduced in #819 to
make sure characters that aren't accepted are removed before using the
value as a tag value.

This is a new stab at #810 and should completely eliminate this class of
problems.

## Tests

Tests pass.
hectorcast-db pushed a commit that referenced this pull request Oct 13, 2023
## Changes

Prompted by the proposed fix for a tagging-related problem in #810, I
investigated how tag validation works. This turned out to be quite a bit
more complex than anticipated. Tags at the job level (or cluster level)
are passed through to the underlying compute infrastructure and as such
are tested against cloud-specific validation rules. GCP appears to be
the most restrictive. It would be disappointing to always restrict to
`\w+`, so this package implements validation and normalization rules for
each cloud. It can pick the right cloud to use using a Go SDK
configuration.

## Tests

Exhaustive unit tests. The regular expressions were pulled by #814.
hectorcast-db pushed a commit that referenced this pull request Oct 13, 2023
## Changes

The jobs backend propagates job tags to the underlying cloud provider's
resources. As such, they need to match the constraints a cloud provider
places on tag values. The display name can contain anything. With this
change, we modify the tag value to equal the short name as used in the
name prefix.

Additionally, we leverage tag normalization as introduced in #819 to
make sure characters that aren't accepted are removed before using the
value as a tag value.

This is a new stab at #810 and should completely eliminate this class of
problems.

## Tests

Tests pass.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants