Skip to content

Conversation

@rbtr
Copy link
Collaborator

@rbtr rbtr commented Oct 19, 2021

Reason for Change:

Strips the cns/imdsclient package of dead code, adds tests, and turns what is left in to a better client.

Issue Fixed:

Requirements:

Notes:

Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>
Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>
@rbtr rbtr changed the title chore: tidy up the IMDS client and usage chore: tidy up the wireserver client and usage Oct 19, 2021
Copy link
Contributor

@ramiro-gamarra ramiro-gamarra left a comment

Choose a reason for hiding this comment

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

few comments/questions

// queries the IMDS to get the primary interface info and caches it in the server state
// before returning the result.
func (service *HTTPRestService) getPrimaryHostInterface(ctx context.Context) (*wireserver.InterfaceInfo, error) {
if service.state.primaryInterface == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

  • does lock need to be taken?
  • flip condition and return early?

break
}

if !found {
Copy link
Contributor

Choose a reason for hiding this comment

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

is the flag necessary? could just build the InterfaceInfo in the loop and return from there. If the loop is done, there was no primary interface


ifInfo, err := service.imdsClient.GetPrimaryInterfaceInfoFromMemory()
var ifInfo *wireserver.InterfaceInfo
ifInfo, err = service.getPrimaryHostInterface(context.TODO())
Copy link
Contributor

Choose a reason for hiding this comment

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

curious about this change

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

least effort fix to the linter complaining about err shadowing

Copy link
Contributor

Choose a reason for hiding this comment

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

erm... something is off if the linter will favor this style over the previous one

// HostPrimaryIP 10.0.0.4
HostPrimaryIP = "10.0.0.4"
// HostSubnet 10.0.0.0/24
HostSubnet = "10.0.0.0/24"
Copy link
Contributor

Choose a reason for hiding this comment

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

consts? otherwise, if they need to be mutated for tests, make them part of the fake?

// Create CNS object.
httpRestService, err := restserver.NewHTTPRestService(&config, new(imdsclient.ImdsClient), nmaclient)

httpRestService, err := restserver.NewHTTPRestService(&config, &wireserver.Client{HTTPClient: &http.Client{}}, nmaclient)
Copy link
Contributor

Choose a reason for hiding this comment

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

http.DefaultClient

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

DefaultClient can be mutated - I don't want a custom client, I explicitly want a default client

@rbtr rbtr merged commit 17bd942 into Azure:master Oct 20, 2021
@rbtr rbtr deleted the x/imds-client branch October 20, 2021 19:23
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.

3 participants