Skip to content

Commit

Permalink
Sync Catalog: Add k8s endpoint health state to consul health check (#…
Browse files Browse the repository at this point in the history
…3874)



Signed-off-by: jukie <[email protected]>

---------

Signed-off-by: jukie <[email protected]>
  • Loading branch information
jukie authored Oct 14, 2024
1 parent 8c23289 commit 124e38b
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 33 deletions.
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
Loading

0 comments on commit 124e38b

Please sign in to comment.