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

Fix #146 add annotation for add http check #148

Closed
wants to merge 7 commits into from
Closed
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
9 changes: 9 additions & 0 deletions connect-inject/container_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type initContainerCommandData struct {
ServiceName string
ProxyServiceName string
ServicePort int32
ServiceCheck string
// ServiceProtocol is the protocol for the service-defaults config
// that will be written if WriteServiceDefaults is true.
ServiceProtocol string
Expand Down Expand Up @@ -66,6 +67,7 @@ func (h *Handler) containerInit(pod *corev1.Pod, k8sNamespace string) (corev1.Co
ConsulNamespace: h.consulNamespace(k8sNamespace),
NamespaceMirroringEnabled: h.EnableK8SNSMirroring,
ConsulCACert: h.ConsulCACert,
ServiceCheck: pod.Annotations[annotationCheck],
}
if data.ServiceName == "" {
// Assertion, since we call defaultAnnotations above and do
Expand Down Expand Up @@ -325,6 +327,13 @@ services {
{{- end }}
}
{{- end}}
{{- if .ServiceCheck}}
check {
name = "{{ .ServiceName }}-check"
http = "http://${POD_IP}:{{ .ServicePort }}{{ .ServiceCheck }}"
interval = "1s"
}
{{- end}}
}
EOF

Expand Down
4 changes: 4 additions & 0 deletions connect-inject/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ const (
// consul-k8s lifecycle-sidecar command. This flag controls how often the
// service is synced (i.e. re-registered) with the local agent.
annotationSyncPeriod = "consul.hashicorp.com/connect-sync-period"

// annotationCheck is the key of the annotation that is added to
// http check specified URL. Any 2xx code is considered passing
annotationCheck = "consul.hashicorp.com/connect-service-check"
)

var (
Expand Down