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 the /var/lib/calico/nodename file if it exists #480

Merged

Conversation

caseydavenport
Copy link
Member

@caseydavenport caseydavenport commented Mar 2, 2018

Description

In combination with projectcalico/calico#1722, will make it much harder to accidentally end up with mismatched node names between the two components.

Fixes projectcalico/calico#1093

Todos

  • Tests
  • Documentation
  • Release note

Release Note

The Calico CNI plugin by default expects the /var/lib/calico/nodename file to be created by calico/node. To disable this feature, set `nodename_file_optional: true` in your CNI network configuration.

calico.go Outdated
}
logrus.Debug("/var/lib/calico/nodename exists")
}

// Allow the nodename to be overridden by the network config
Copy link
Member

Choose a reason for hiding this comment

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

Now that nodename is being instantiated here, I don't think this comment is right

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think the comment was ever right.

return nodename
}

// nodenameFromFile reads the /var/lib/calico/nodename file if it exists and
// returns the nodename within.
func nodenameFromFile() string {
Copy link
Member

Choose a reason for hiding this comment

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

A nodeNameFile that exists but is empty takes an interesting path through this code, but I suppose it is ok...

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, yeah. I suspect we probably want to error in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, let's leave this as it is for now. I think the code will do the right thing and I'm not sure how we'd end up with an empty file anyway.

if nff := nodenameFromFile(); nff != "" {
logrus.Debugf("Read node name from file: %s", nff)
nodename = nff
}
if conf.Nodename != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be an else if? If multiple methods are provided (albeit an unusual edge case), the lowest priority would take precedence.

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 way the code is structured now is acting as designed - the conf.Nodename takes priority over the /var/lib/calico/nodename file.

Copy link
Member

@ozdanborne ozdanborne left a comment

Choose a reason for hiding this comment

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

🆒

@caseydavenport caseydavenport merged commit 292cd16 into projectcalico:master Mar 7, 2018
@caseydavenport caseydavenport deleted the use-nodename-file branch March 7, 2018 01:32
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.

Calico doesn't work if cni config hostname doesnt match calico-node nodename
2 participants