mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
check for NEG healthcheck with correct name
This commit is contained in:
parent
7d9725e9d0
commit
101dde0c22
@ -924,32 +924,53 @@ func (cont *GCEIngressController) backendMode(svcPorts map[string]v1.ServicePort
|
|||||||
return false, fmt.Errorf("failed to list backend services: %v", err)
|
return false, fmt.Errorf("failed to list backend services: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hcList, err := gceCloud.ListHealthChecks()
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("failed to list health checks: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
uid := cont.UID
|
uid := cont.UID
|
||||||
if len(uid) > 8 {
|
if len(uid) > 8 {
|
||||||
uid = uid[:8]
|
uid = uid[:8]
|
||||||
}
|
}
|
||||||
|
|
||||||
matchingBackendService := 0
|
matchingBackendService := 0
|
||||||
for _, bs := range beList {
|
|
||||||
match := false
|
|
||||||
for svcName, sp := range svcPorts {
|
for svcName, sp := range svcPorts {
|
||||||
|
match := false
|
||||||
|
bsMatch := &compute.BackendService{}
|
||||||
// Non-NEG BackendServices are named with the Nodeport in the name.
|
// Non-NEG BackendServices are named with the Nodeport in the name.
|
||||||
// NEG BackendServices' names contain the a sha256 hash of a string.
|
// NEG BackendServices' names contain the a sha256 hash of a string.
|
||||||
negString := strings.Join([]string{uid, cont.Ns, svcName, sp.TargetPort.String()}, ";")
|
negString := strings.Join([]string{uid, cont.Ns, svcName, sp.TargetPort.String()}, ";")
|
||||||
negHash := fmt.Sprintf("%x", sha256.Sum256([]byte(negString)))[:8]
|
negHash := fmt.Sprintf("%x", sha256.Sum256([]byte(negString)))[:8]
|
||||||
|
for _, bs := range beList {
|
||||||
if strings.Contains(bs.Name, strconv.Itoa(int(sp.NodePort))) ||
|
if strings.Contains(bs.Name, strconv.Itoa(int(sp.NodePort))) ||
|
||||||
strings.Contains(bs.Name, negHash) {
|
strings.Contains(bs.Name, negHash) {
|
||||||
match = true
|
match = true
|
||||||
|
bsMatch = bs
|
||||||
matchingBackendService += 1
|
matchingBackendService += 1
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if match {
|
if match {
|
||||||
for _, be := range bs.Backends {
|
for _, be := range bsMatch.Backends {
|
||||||
if !strings.Contains(be.Group, keyword) {
|
if !strings.Contains(be.Group, keyword) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the correct HealthCheck exists for the BackendService
|
||||||
|
hcMatch := false
|
||||||
|
for _, hc := range hcList {
|
||||||
|
if hc.Name == bsMatch.Name {
|
||||||
|
hcMatch = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !hcMatch {
|
||||||
|
return false, fmt.Errorf("missing healthcheck for backendservice: %v", bsMatch.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return matchingBackendService == len(svcPorts), nil
|
return matchingBackendService == len(svcPorts), nil
|
||||||
|
Loading…
Reference in New Issue
Block a user