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{

Check failure on line 2622 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: rules1DualStack

Check failure on line 2622 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: rules1DualStack (typecheck)
false: {
getTestRule(true, 80, false),

Check failure on line 2624 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

too many arguments in call to getTestRule

Check failure on line 2624 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Lint

too many arguments in call to getTestRule
},
true: {
getTestRule(true, 80, true),

Check failure on line 2627 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

too many arguments in call to getTestRule

Check failure on line 2627 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Lint

too many arguments in call to getTestRule
},
}
// 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{

Check failure on line 2631 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: getTestServiceDualStack

Check failure on line 2631 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: getTestServiceDualStack (typecheck)
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 {

Check failure on line 2644 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

cannot use struct{desc string; service v1.Service; loadBalancerSku string; probeProtocol string; probePath string; expectedProbes map[bool][]network.Probe; expectedRules map[bool][]network.LoadBalancingRule; expectedErr bool}{…} (value of type struct{desc string; service "k8s.io/api/core/v1".Service; loadBalancerSku string; probeProtocol string; probePath string; expectedProbes map[bool][]network.Probe; expectedRules map[bool][]network.LoadBalancingRule; expectedErr bool}) as type struct{desc string; service "k8s.io/api/core/v1".Service; loadBalancerSku string; probeProtocol string; probePath string; expectedProbes []network.Probe; expectedRules []network.LoadBalancingRule; expectedErr bool} in argument to append

Check failure on line 2644 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use struct{desc string; service v1.Service; loadBalancerSku string; probeProtocol string; probePath string; expectedProbes map[bool][]network.Probe; expectedRules map[bool][]network.LoadBalancingRule; expectedErr bool}{…} (value of type struct{desc string; service "k8s.io/api/core/v1".Service; loadBalancerSku string; probeProtocol string; probePath string; expectedProbes map[bool][]network.Probe; expectedRules map[bool][]network.LoadBalancingRule; expectedErr bool}) as struct{desc string; service "k8s.io/api/core/v1".Service; loadBalancerSku string; probeProtocol string; probePath string; expectedProbes []network.Probe; expectedRules []network.LoadBalancingRule; expectedErr bool} value in argument to append (typecheck)
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,

Check failure on line 2658 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

cannot use probes (variable of type []network.Probe) as type map[bool][]network.Probe in struct literal

Check failure on line 2658 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Lint

cannot use probes (variable of type []network.Probe) as map[bool][]network.Probe value in struct literal (typecheck)
expectedRules: rules1DualStack,

Check failure on line 2659 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

undefined: rules1DualStack

Check failure on line 2659 in pkg/provider/azure_loadbalancer_test.go

View workflow job for this annotation

GitHub Actions / Lint

undefined: rules1DualStack (typecheck)
})
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.