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

consul/connect: interpolate connect block #9586

Merged
merged 3 commits into from
Dec 9, 2020
Merged

consul/connect: interpolate connect block #9586

merged 3 commits into from
Dec 9, 2020

Conversation

shoenig
Copy link
Member

@shoenig shoenig commented Dec 9, 2020

This PR enables job submitters to use interpolation in the connect
block of jobs making use of consul connect. Before, only the name of
the connect service would be interpolated, and only for a few select
identifiers related to the job itself (#6853). Now, all connect fields
can be interpolated using the full spectrum of runtime parameters.

Note that the service name is interpolated at job-submission time,
and cannot make use of values known only at runtime.

Fixes #7221

@vercel vercel bot temporarily deployed to Preview – nomad December 9, 2020 14:43 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad-storybook-and-ui December 9, 2020 14:43 Inactive
@shoenig
Copy link
Member Author

shoenig commented Dec 9, 2020

TODO

  • add changelog entry

This PR enables job submitters to use interpolation in the connect
block of jobs making use of consul connect. Before, only the name of
the connect service would be interpolated, and only for a few select
identifiers related to the job itself (#6853). Now, all connect fields
can be interpolated using the full spectrum of runtime parameters.

Note that the service name is interpolated at job-submission time,
and cannot make use of values known only at runtime.

Fixes #7221
@vercel vercel bot temporarily deployed to Preview – nomad December 9, 2020 15:10 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad-storybook-and-ui December 9, 2020 15:10 Inactive
Copy link
Member

@tgross tgross left a comment

Choose a reason for hiding this comment

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

LGTM with the changelog fix. I left a few questions but if you feel like you have good answers feel free to move on without me. 😁

CHANGELOG.md Outdated Show resolved Hide resolved
}

service.Name = taskEnv.ReplaceEnv(service.Name)
service.PortLabel = taskEnv.ReplaceEnv(service.PortLabel)
service.Tags = taskEnv.ParseAndReplace(service.Tags)
service.CanaryTags = taskEnv.ParseAndReplace(service.CanaryTags)
service.Meta = interpolateMapStringString(taskEnv, service.Meta)
service.CanaryMeta = interpolateMapStringString(taskEnv, service.CanaryMeta)
service.Connect = interpolateConnect(taskEnv, service.Connect)
Copy link
Member

Choose a reason for hiding this comment

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

Somewhat related because we're potentially setting these to nil and not empty maps, none of these three fields is Canonicalized. Should we be doing that and/or should we be assigning an empty map here for safety?

Copy link
Member Author

Choose a reason for hiding this comment

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

The canonicalized form of empty maps is nil (at least in services + consul)

// Ensure empty maps/slices are treated as null to avoid scheduling

Copy also make use of the helper.Copy* functions which also reduce to nil if there are no elements
https://github.com/hashicorp/nomad/blob/master/helper/funcs.go#L282

}

// make one copy and interpolate in-place on that
modified := orig.Copy()
Copy link
Member

Choose a reason for hiding this comment

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

The caller copies Service... shouldn't we already have a copy of the structs.ConsulConnect too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Indeed there's no reason to create an extra copy here.

for k, v := range proxy.EnvoyGatewayBindAddresses {
m[taskEnv.ReplaceEnv(k)] = &structs.ConsulGatewayBindAddress{
Address: taskEnv.ReplaceEnv(v.Address),
Port: v.Port,
Copy link
Member

Choose a reason for hiding this comment

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

It looks like you interpolate the sidecar port below. Is there a reason we're not can't for this port?

Copy link
Member Author

Choose a reason for hiding this comment

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

The ConsulGatewayBindAddress field is an int, and there's (currently?) no way to interpolate int values
https://github.com/hashicorp/nomad/blob/master/nomad/structs/services.go#L1291

Co-authored-by: Tim Gross <[email protected]>
@vercel vercel bot temporarily deployed to Preview – nomad December 9, 2020 17:27 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad-storybook-and-ui December 9, 2020 17:27 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad December 9, 2020 17:44 Inactive
@vercel vercel bot temporarily deployed to Preview – nomad-storybook-and-ui December 9, 2020 17:44 Inactive
@shoenig shoenig merged commit b38ccaa into master Dec 9, 2020
@shoenig shoenig deleted the f-connect-interp branch December 9, 2020 19:21
@github-actions
Copy link

github-actions bot commented Dec 6, 2022

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Connect stanza interpolation limitations
2 participants