Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
fix: have vrrp-only healthchecks going deeper down the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
eliobischof committed Dec 13, 2019
1 parent fbbdb7c commit 125bc3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions internal/kinds/loadbalancers/dynamic/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ vrrp_sync_group VG1 {
}
{{ range $idx, $vip := .VIPs }}vrrp_script chk_{{ $vip.IP }} {
script "{{ healthcmd $vip.Transport }}"
script "{{ healthcmd $root.Self $vip.Transport }}"
interval 2 # check every 2 seconds
fall 15 # require 2 failures for KO
rise 2 # require 2 successes for OK
Expand Down Expand Up @@ -196,7 +196,7 @@ http {
for _, d := range computesData {
wg.Add(2)

go parse(synchronizer, keepaliveDTemplate, d, nodeagent(d.Self), func(result string, na *operator.NodeAgentCurrent) error {
parse(synchronizer, keepaliveDTemplate, d, nodeagent(d.Self), func(result string, na *operator.NodeAgentCurrent) error {
pkg := operator.Package{Config: map[string]string{"keepalived.conf": result}}
if changesAllowed && !na.Software.KeepaliveD.Equals(&pkg) {
na.AllowChanges()
Expand All @@ -217,7 +217,7 @@ http {
return nil
})

go parse(synchronizer, nginxTemplate, d, nodeagent(d.Self), func(result string, na *operator.NodeAgentCurrent) error {
parse(synchronizer, nginxTemplate, d, nodeagent(d.Self), func(result string, na *operator.NodeAgentCurrent) error {
pkg := operator.Package{Config: map[string]string{"nginx.conf": result}}
if changesAllowed && !na.Software.Nginx.Equals(&pkg) {
na.AllowChanges()
Expand Down
20 changes: 13 additions & 7 deletions internal/kinds/loadbalancers/dynamic/adapter/vrrp_healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,36 @@ import (
"fmt"
"strings"

"github.com/caos/orbiter/internal/kinds/clusters/core/infra"
"github.com/caos/orbiter/internal/kinds/loadbalancers/dynamic/model"
)

func vrrpHealthChecksScript(transport []model.Source) string {
return "/usr/local/bin/health " + strings.Join((vrrpHealthCheckArgs(transport)), " ")
func vrrpHealthChecksScript(cmp infra.Compute, transport []model.Source) string {

selfIP, err := cmp.InternalIP()
if err != nil {
panic(err)
}
return "/usr/local/bin/health " + strings.Join((vrrpHealthCheckArgs(*selfIP, transport)), " ")
}

func vrrpHealthCheckArgs(transport []model.Source) []string {
func vrrpHealthCheckArgs(selfIP string, transport []model.Source) []string {

if deriveAny(func(src model.Source) bool {
return len(src.Destinations) > 0
}, transport) {
return []string{stringifyVRRPHealthChecksArg(model.Port(29999), model.HealthChecks{
return []string{stringifyVRRPHealthChecksArg("127.0.0.1", model.Port(29999), model.HealthChecks{
Protocol: "http",
Path: "/ready",
Code: 200,
})}
}

return deriveFmapSourceVRRPHealthChecks(func(src model.Source) string {
return stringifyVRRPHealthChecksArg(src.SourcePort, *src.HealthChecks)
return stringifyVRRPHealthChecksArg(selfIP, src.SourcePort, *src.HealthChecks)
}, transport)
}

func stringifyVRRPHealthChecksArg(port model.Port, hc model.HealthChecks) string {
return fmt.Sprintf(`%d@%s://127.0.0.1:%d%s`, hc.Code, hc.Protocol, port, hc.Path)
func stringifyVRRPHealthChecksArg(ip string, port model.Port, hc model.HealthChecks) string {
return fmt.Sprintf(`%d@%s://%s:%d%s`, hc.Code, ip, hc.Protocol, port, hc.Path)
}

0 comments on commit 125bc3d

Please sign in to comment.