-
Notifications
You must be signed in to change notification settings - Fork 40
Use node status.addresses for kubelet health-check
#331
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
base: main
Are you sure you want to change the base?
Changes from all commits
e9ef118
cf2d7c4
a7c0f84
471206d
93555dc
1f44fdd
75b95f3
bdd307b
301adbc
0d2173a
b3928f1
59d718a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,10 @@ import ( | |
| "crypto/tls" | ||
| "errors" | ||
| "fmt" | ||
| "net" | ||
| "net/http" | ||
| "os" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/go-logr/logr" | ||
|
|
@@ -22,13 +24,16 @@ import ( | |
| ) | ||
|
|
||
| const ( | ||
| kubeletPort = "10250" | ||
| defaultKubeletPort = "10250" | ||
| ) | ||
|
|
||
| // Manager contains logic and info needed to fence and remediate controlplane nodes | ||
| type Manager struct { | ||
| nodeName string | ||
| nodeRole peers.Role | ||
| preferredAddressTypes []string | ||
| nodeAddresses []corev1.NodeAddress | ||
| kubeletPort string | ||
| endpointHealthCheckUrl string | ||
| wasEndpointAccessibleAtStart bool | ||
| client client.Client | ||
|
|
@@ -37,9 +42,22 @@ type Manager struct { | |
|
|
||
| // NewManager inits a new Manager return nil if init fails | ||
| func NewManager(nodeName string, myClient client.Client) *Manager { | ||
| var preferredAddressTypes []string | ||
| rawPreferredAddressTypes := os.Getenv("PREFERRED_ADDRESS_TYPES") | ||
| if rawPreferredAddressTypes != "" { | ||
| preferredAddressTypes = strings.Split(rawPreferredAddressTypes, ",") | ||
|
Member
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. nit: Via the normal CRD→template path this can't happen (the for i, t := range preferredAddressTypes {
preferredAddressTypes[i] = strings.TrimSpace(t)
} |
||
| } else { | ||
| preferredAddressTypes = []string{"NodeName"} | ||
| } | ||
| for i, addressType := range preferredAddressTypes { | ||
| preferredAddressTypes[i] = strings.TrimSpace(addressType) | ||
| } | ||
|
|
||
| return &Manager{ | ||
| nodeName: nodeName, | ||
| endpointHealthCheckUrl: os.Getenv("END_POINT_HEALTH_CHECK_URL"), | ||
| preferredAddressTypes: preferredAddressTypes, | ||
| kubeletPort: defaultKubeletPort, | ||
| client: myClient, | ||
| wasEndpointAccessibleAtStart: false, | ||
| log: ctrl.Log.WithName("controlPlane").WithName("Manager"), | ||
|
|
@@ -125,6 +143,7 @@ func (manager *Manager) initializeManager() error { | |
| return wrapWithInitError(err) | ||
| } | ||
| manager.setNodeRole(node) | ||
| manager.nodeAddresses = node.Status.Addresses | ||
|
Member
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. note: In practice, this is fine as node addresses rarely change, and the SNR daemonset restarts on config changes. But it's worth documenting this in the CRD field description so users know a pod restart is needed to pick up address changes.
Author
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. I've added a note to the CRD field. It would be nice to automatically update these, but agree that this is rare and probably not worth the complexity until someone complains about it (especially for control-plane nodes, which is the only place this matters, because AFAIK |
||
|
|
||
| manager.wasEndpointAccessibleAtStart = manager.isEndpointAccessible() | ||
| return nil | ||
|
|
@@ -166,24 +185,45 @@ func (manager *Manager) isEndpointAccessible() bool { | |
| } | ||
|
|
||
| func (manager *Manager) isKubeletServiceRunning() bool { | ||
| url := fmt.Sprintf("https://%s:%s/pods", manager.nodeName, kubeletPort) | ||
| for _, addressType := range manager.preferredAddressTypes { | ||
| if addressType == "NodeName" { | ||
| if manager.isKubeletServiceRunningOnAddress(manager.nodeName) { | ||
| return true | ||
| } | ||
| } else { | ||
| nodeAddressType := corev1.NodeAddressType(addressType) | ||
| for _, address := range manager.nodeAddresses { | ||
| if address.Type == nodeAddressType { | ||
| if manager.isKubeletServiceRunningOnAddress(address.Address) { | ||
| return true | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| func (manager *Manager) isKubeletServiceRunningOnAddress(address string) bool { | ||
|
Member
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. pre-existing / follow-up: The Not a blocker for this PR (the no-timeout client is pre-existing on httpClient := &http.Client{
Transport: tr,
Timeout: 10 * time.Second,
} |
||
| url := fmt.Sprintf("https://%s/pods", net.JoinHostPort(address, manager.kubeletPort)) | ||
| tr := &http.Transport{ | ||
| TLSClientConfig: &tls.Config{ | ||
| InsecureSkipVerify: true, | ||
| MinVersion: certificates.TLSMinVersion, | ||
| }, | ||
| } | ||
| httpClient := &http.Client{Transport: tr} | ||
| httpClient := &http.Client{Transport: tr, Timeout: 10 * time.Second} | ||
|
|
||
| req, err := http.NewRequest("GET", url, nil) | ||
| if err != nil { | ||
| manager.log.Error(err, "failed to create a kubelet service request", "node name", manager.nodeName) | ||
| manager.log.Error(err, "failed to create a kubelet service request", "address", address) | ||
| return false | ||
| } | ||
|
|
||
| resp, err := httpClient.Do(req) | ||
| if err != nil { | ||
| manager.log.Error(err, "kubelet service is down", "node name", manager.nodeName) | ||
| manager.log.Error(err, "kubelet service is down", "address", address) | ||
| return false | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.