Skip to content

Commit

Permalink
use custom probe rule when externalTrafficPolicy is local and PLSProx…
Browse files Browse the repository at this point in the history
…yProtocol is enabled
  • Loading branch information
MartinForReal authored and k8s-infra-cherrypick-robot committed May 22, 2023
1 parent 8be839b commit 5083f82
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pkg/consts/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ func IsLBRuleOnK8sServicePortDisabled(annotations map[string]string, port int32)
return expectAttributeInSvcAnnotationBeEqualTo(annotations, BuildAnnotationKeyForPort(port, PortAnnotationNoLBRule), TrueAnnotationValue), nil
}

// IsPLSProxyProtocolEnabled return true if ServiceAnnotationPLSProxyProtocol is true
func IsPLSProxyProtocolEnabled(annotations map[string]string) bool {
return expectAttributeInSvcAnnotationBeEqualTo(annotations, ServiceAnnotationPLSProxyProtocol, TrueAnnotationValue)
}

// IsPLSEnabled return true if ServiceAnnotationPLSCreation is true
func IsPLSEnabled(annotations map[string]string) bool {
return expectAttributeInSvcAnnotationBeEqualTo(annotations, ServiceAnnotationPLSCreation, TrueAnnotationValue)
}

// Getint32ValueFromK8sSvcAnnotation get health probe configuration for port
func Getint32ValueFromK8sSvcAnnotation(annotations map[string]string, key string, validators ...Int32BusinessValidator) (*int32, error) {
val, err := GetAttributeValueInSvcAnnotation(annotations, key)
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/azure_loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,7 @@ func (az *Cloud) getExpectedLBRules(
// healthcheck proxy server serves http requests
// https://github.com/kubernetes/kubernetes/blob/7c013c3f64db33cf19f38bb2fc8d9182e42b0b7b/pkg/proxy/healthcheck/service_health.go#L236
var nodeEndpointHealthprobe *network.Probe
if servicehelpers.NeedsHealthCheck(service) {
if servicehelpers.NeedsHealthCheck(service) && !(consts.IsPLSEnabled(service.Annotations) && consts.IsPLSProxyProtocolEnabled(service.Annotations)) {
podPresencePath, podPresencePort := servicehelpers.GetServiceHealthCheckPathPort(service)
lbRuleName := az.getLoadBalancerRuleName(service, v1.ProtocolTCP, podPresencePort)

Expand Down
39 changes: 39 additions & 0 deletions pkg/provider/azure_loadbalancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2619,6 +2619,45 @@ func TestReconcileLoadBalancerRule(t *testing.T) {
expectedProbes: probes,
expectedRules: rules1,
})
rules1DualStack = map[bool][]network.LoadBalancingRule{
false: {
getTestRule(true, 80, false),
},
true: {
getTestRule(true, 80, true),
},
}
// When the service spec externalTrafficPolicy is Local and azure-disable-service-health-port-probe is set, should return default
svc = getTestServiceDualStack("test1", v1.ProtocolTCP, map[string]string{
consts.ServiceAnnotationPLSCreation: "true",
consts.ServiceAnnotationPLSProxyProtocol: "true",
consts.ServiceAnnotationLoadBalancerHealthProbeProtocol: "tcp",
consts.ServiceAnnotationLoadBalancerHealthProbeRequestPath: "/broken/global/path",
consts.BuildHealthProbeAnnotationKeyForPort(80, consts.HealthProbeParamsProbeInterval): "10",
consts.BuildHealthProbeAnnotationKeyForPort(80, consts.HealthProbeParamsProtocol): "https",
consts.BuildHealthProbeAnnotationKeyForPort(80, consts.HealthProbeParamsRequestPath): "/broken/local/path",
consts.BuildHealthProbeAnnotationKeyForPort(80, consts.HealthProbeParamsNumOfProbe): "10",
}, 80)
svc.Spec.ExternalTrafficPolicy = v1.ServiceExternalTrafficPolicyTypeLocal
svc.Spec.HealthCheckNodePort = 34567
probes = getTestProbes("Https", "/broken/local/path", pointer.Int32(10), pointer.Int32(80), pointer.Int32(10080), pointer.Int32(10))
testCases = append(testCases, struct {
desc string
service v1.Service
loadBalancerSku string
probeProtocol string
probePath string
expectedProbes map[bool][]network.Probe
expectedRules map[bool][]network.LoadBalancingRule
expectedErr bool
}{
desc: "getExpectedLBRules should return expected rules when externalTrafficPolicy is local and service.beta.kubernetes.io/azure-pls-proxy-protocol is enabled",
service: svc,
loadBalancerSku: "standard",
probeProtocol: "https",
expectedProbes: probes,
expectedRules: rules1DualStack,
})
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
az := GetTestCloud(ctrl)
Expand Down

0 comments on commit 5083f82

Please sign in to comment.