-
Notifications
You must be signed in to change notification settings - Fork 127
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
feat: tolerate failed checkins / ready #392
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -66,6 +66,7 @@ var ( | |||||
port int | ||||||
} | ||||||
backend string | ||||||
checkIn bool | ||||||
granularity string | ||||||
kubeconfig string | ||||||
topologyLabel string | ||||||
|
@@ -94,7 +95,7 @@ func runRoot(c *cobra.Command, _ []string) error { | |||||
c := kubernetes.NewForConfigOrDie(config) | ||||||
opts.kc = kiloclient.NewForConfigOrDie(config) | ||||||
ec := apiextensions.NewForConfigOrDie(config) | ||||||
opts.backend = k8s.New(c, opts.kc, ec, topologyLabel, log.NewNopLogger()) | ||||||
opts.backend = k8s.New(c, opts.kc, ec, topologyLabel, checkIn, log.NewNopLogger()) | ||||||
default: | ||||||
return fmt.Errorf("backend %s unknown; posible values are: %s", backend, availableBackends) | ||||||
} | ||||||
|
@@ -119,6 +120,7 @@ func main() { | |||||
SilenceErrors: true, | ||||||
} | ||||||
cmd.PersistentFlags().StringVar(&backend, "backend", k8s.Backend, fmt.Sprintf("The backend for the mesh. Possible values: %s", availableBackends)) | ||||||
cmd.PersistentFlags().BoolVar(&checkIn, "check-in", true, "Should kilo consider check-in (LastSeen) in backend") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
cmd.PersistentFlags().StringVar(&granularity, "mesh-granularity", string(mesh.AutoGranularity), fmt.Sprintf("The granularity of the network mesh to create. Possible values: %s", availableGranularities)) | ||||||
defaultKubeconfig := os.Getenv("KUBECONFIG") | ||||||
if _, err := os.Stat(defaultKubeconfig); os.IsNotExist(err) { | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -64,6 +64,8 @@ type Node struct { | |||||||||||||||||||||||||
// LastSeen is a Unix time for the last time | ||||||||||||||||||||||||||
// the node confirmed it was live. | ||||||||||||||||||||||||||
LastSeen int64 | ||||||||||||||||||||||||||
// Whether Ready will check LastSeen value | ||||||||||||||||||||||||||
CheckLastSeen bool | ||||||||||||||||||||||||||
// Leader is a suggestion to Kilo that | ||||||||||||||||||||||||||
// the node wants to lead its segment. | ||||||||||||||||||||||||||
Leader bool | ||||||||||||||||||||||||||
|
@@ -81,11 +83,17 @@ type Node struct { | |||||||||||||||||||||||||
// Ready indicates whether or not the node is ready. | ||||||||||||||||||||||||||
func (n *Node) Ready() bool { | ||||||||||||||||||||||||||
// Nodes that are not leaders will not have WireGuardIPs, so it is not required. | ||||||||||||||||||||||||||
var checkedIn bool | ||||||||||||||||||||||||||
if (n != nil) && (n.Key != wgtypes.Key{}) && (n.Subnet != nil) && (n.CheckLastSeen) { | ||||||||||||||||||||||||||
checkedIn = time.Now().Unix()-n.LastSeen < int64(checkInPeriod)*2/int64(time.Second) | ||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||
checkedIn = true | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+86
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to add more conditions to the check-in logic.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those tests are here to protect against nil values. That was my first implem, but it did not pass the tests. I agree it is not pretty now (return one liner), but did not wanted to refactor too much. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agh yes, I woke up in the middle of the night today and literally said "I understand now". I have a little refactor in mind that might be more legible |
||||||||||||||||||||||||||
return n != nil && | ||||||||||||||||||||||||||
n.Endpoint.Ready() && | ||||||||||||||||||||||||||
n.Key != wgtypes.Key{} && | ||||||||||||||||||||||||||
n.Subnet != nil && | ||||||||||||||||||||||||||
time.Now().Unix()-n.LastSeen < int64(checkInPeriod)*2/int64(time.Second) | ||||||||||||||||||||||||||
checkedIn | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// Peer represents a peer in the network. | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.