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

Change nomad.Config to autoscaler.Nomad.Config when providing configuration for plugins. #945

Closed
wants to merge 1 commit into from

Conversation

jorgemarey
Copy link
Contributor

Fixes #944

The config.Address is mutated when using unix sockets so when that address is provided for the nomad target plugin, the client created there doesn't use the unix address. This fixes that by using the autoscaler nomad config instead of the nomad api config.

@jorgemarey jorgemarey force-pushed the b-unix-api branch 2 times, most recently from b8a3a17 to ea04ece Compare August 7, 2024 11:06
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.

Hi @jorgemarey! This passes tests but I'm concerned about dropping the use of a.nomadCfg here specifically because the documentation for that field says:

// nomadCfg is the merged Nomad API configuration that should be used when
// setting up all clients. It is the result of the Nomad api.DefaultConfig
// merged with the user-specified Nomad config.Nomad.

That implies we could be missing default field values if we're using a.config.Nomad directly. Where is it that you're seeing the mutation that's breaking things?

@jorgemarey
Copy link
Contributor Author

Hi @tgross

Here nomad api mutates de the Address field when it's an unix://

So first when the autoscaler calls api.NewClient here that Address changes, so later when using that configuration to generate a new client for the target plugin, that client has an http://127.0.0.1 as the address for the client.

I changed the api.Config to a nomad autoscaler config because I thought made sense that both clients we're creating from the same configuration (both from the nomad autoscaler configuration).

@tgross
Copy link
Member

tgross commented Aug 9, 2024

Here nomad api mutates de the Address field when it's an unix://

Oh, I see... this looks like it's actually a bug in api.NewClient! The reason that mutation breaks reuse is that the Config's private url field is updated here: https://github.com/hashicorp/nomad/blob/v1.8.2/api/api.go#L513 from the address. It should only ever update that if the value is unset (as it will be if you haven't constructed a client from the config before). Let me do a little bit of testing of that and I think we'll want to fix this in the api package and then rev that here. That'll also fix the problem for all consumers and not just the autoscaler.

tgross added a commit to hashicorp/nomad that referenced this pull request Aug 9, 2024
In #16872 we added support for configuring the API client with a unix domain
socket. In order to set the host correctly, we parse the address before mutating
the Address field in the configuration. But this prevents the configuration from
being reused across multiple clients, as the next time we parse the address it
will no longer be pointing to the socket. This breaks consumers like the
autoscaler, which reuse the API config between plugins.

Update the `NewClient` constructor to only override the `url` field if it hasn't
already been parsed. Include a test demonstrating safe reuse with a unix domain
socket.

Ref: hashicorp/nomad-autoscaler#944
Ref: hashicorp/nomad-autoscaler#945
@tgross
Copy link
Member

tgross commented Aug 9, 2024

I've fixed that here: hashicorp/nomad#23785

I'm going to close this PR, and once #23785 has been merged, we can get the autoscaler's version of the Nomad api package updated when Nomad 1.8.3 gets released (next week).

Thanks so much for opening this PR though, as it definitely helped us debug what's going on!

@tgross tgross closed this Aug 9, 2024
tgross added a commit to hashicorp/nomad that referenced this pull request Aug 9, 2024
In #16872 we added support for configuring the API client with a unix domain
socket. In order to set the host correctly, we parse the address before mutating
the Address field in the configuration. But this prevents the configuration from
being reused across multiple clients, as the next time we parse the address it
will no longer be pointing to the socket. This breaks consumers like the
autoscaler, which reuse the API config between plugins.

Update the `NewClient` constructor to only override the `url` field if it hasn't
already been parsed. Include a test demonstrating safe reuse with a unix domain
socket.

Ref: hashicorp/nomad-autoscaler#944
Ref: hashicorp/nomad-autoscaler#945
@jorgemarey
Copy link
Contributor Author

Great. Thanks @tgross!

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

Successfully merging this pull request may close these issues.

Nomad unix socket doesn't work.
2 participants