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

Sync Catalog: Add k8s endpoint health state to consul health check #3874

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3874.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:sync-catalog
Add Endpoint health state to registered consul service
```
12 changes: 9 additions & 3 deletions control-plane/catalog/to-consul/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const (
// consulKubernetesCheckName is the name of health check in Consul for Kubernetes readiness status.
consulKubernetesCheckName = "Kubernetes Readiness Check"
kubernetesSuccessReasonMsg = "Kubernetes health checks passing"
kubernetesFailureReasonMsg = "Kubernetes health checks failing"
)

type NodePortSyncType string
Expand Down Expand Up @@ -693,7 +694,6 @@ func (t *ServiceResource) generateRegistrations(key string) {
}
}
}

}
}
}
Expand Down Expand Up @@ -800,11 +800,17 @@ func (t *ServiceResource) registerServiceInstance(
Name: consulKubernetesCheckName,
Namespace: baseService.Namespace,
Type: consulKubernetesCheckType,
Status: consulapi.HealthPassing,
ServiceID: serviceID(r.Service.Service, addr),
Output: kubernetesSuccessReasonMsg,
}

// Consider endpoint health state for registered consul service
if endpoint.Conditions.Ready != nil && *endpoint.Conditions.Ready {
r.Check.Status = consulapi.HealthPassing
r.Check.Output = kubernetesSuccessReasonMsg
} else {
r.Check.Status = consulapi.HealthCritical
r.Check.Output = kubernetesFailureReasonMsg
}
t.consulMap[key] = append(t.consulMap[key], &r)
}
}
Expand Down
15 changes: 13 additions & 2 deletions control-plane/catalog/to-consul/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ func createEndpointSlice(t *testing.T, client *fake.Clientset, serviceName strin
{
Addresses: []string{"1.1.1.1"},
Conditions: discoveryv1.EndpointConditions{
Ready: ptr.To(true),
Ready: nil,
Serving: ptr.To(true),
Terminating: ptr.To(false),
},
Expand All @@ -2154,11 +2154,22 @@ func createEndpointSlice(t *testing.T, client *fake.Clientset, serviceName strin
Conditions: discoveryv1.EndpointConditions{
Ready: ptr.To(true),
Serving: ptr.To(true),
Terminating: ptr.To(false),
Terminating: nil,
},
NodeName: &node2,
Zone: ptr.To("us-west-2b"),
},
{
Addresses: []string{"3.3.3.3"},
Conditions: discoveryv1.EndpointConditions{
Ready: ptr.To(false),
Serving: ptr.To(false),
Terminating: ptr.To(true),
},
TargetRef: &targetRef,
NodeName: &node1,
Zone: ptr.To("us-west-2a"),
},
jukie marked this conversation as resolved.
Show resolved Hide resolved
},
Ports: []discoveryv1.EndpointPort{
{
Expand Down
Loading