Skip to content

Commit

Permalink
fix(k8s): tolerate unknown appProtocol (#7133)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
  • Loading branch information
michaelbeaumont authored Jun 28, 2023
1 parent 15a3b97 commit c273973
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
16 changes: 12 additions & 4 deletions pkg/plugins/runtime/k8s/controllers/inbound_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,18 +189,26 @@ func ProtocolTagFor(svc *kube_core.Service, svcPort *kube_core.ServicePort) stri

if svcPort.AppProtocol != nil {
protocolValue = *svcPort.AppProtocol
} else {
protocolValue = svc.Annotations[protocolAnnotation]
// `appProtocol` can be any protocol and if we don't explicitly support
// it, let the default below take effect
if core_mesh.ParseProtocol(protocolValue) == core_mesh.ProtocolUnknown {
protocolValue = ""
}
}

if explicitKumaProtocol, ok := svc.Annotations[protocolAnnotation]; ok && protocolValue == "" {
protocolValue = explicitKumaProtocol
}

if protocolValue == "" {
// if `appProtocol` or `<port>.service.kuma.io/protocol` is missing or has an empty value
// we want Dataplane to have a `protocol: tcp` tag in order to get user's attention
protocolValue = core_mesh.ProtocolTCP
}
// if `appProtocol` or `<port>.service.kuma.io/protocol` field is present but has an invalid value

// if `<port>.service.kuma.io/protocol` field is present but has an invalid value
// we still want Dataplane to have a `protocol: <lowercase value>` tag in order to make it clear
// to a user that at least `appProtocol` or `<port>.service.kuma.io/protocol` has an effect
// to a user that at least `<port>.service.kuma.io/protocol` has an effect
return strings.ToLower(protocolValue)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/runtime/k8s/controllers/pod_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ var _ = Describe("ProtocolTagFor(..)", func() {
}),
Entry("appProtocol has an unknown value", testCase{
appProtocol: utilpointer.String("not-yet-supported-protocol"),
expected: "not-yet-supported-protocol", // we want Kuma's behavior to be straightforward to a user (just copy appProtocol lowercase value)
expected: "tcp", // we want Kuma's behavior to be straightforward to a user (appProtocol is not Kuma specific)
}),
Entry("appProtocol has a lowercase value", testCase{
appProtocol: utilpointer.String("HtTp"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:
k8s.kuma.io/namespace: demo
k8s.kuma.io/service-name: sample
k8s.kuma.io/service-port: "7071"
kuma.io/protocol: mongo
kuma.io/protocol: tcp
kuma.io/service: sample_playground_svc_7071
kuma.io/zone: zone-1
version: "0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
k8s.kuma.io/namespace: demo
k8s.kuma.io/service-name: sample
k8s.kuma.io/service-port: "7071"
kuma.io/protocol: mongo
kuma.io/protocol: tcp
kuma.io/service: sample_playground_svc_7071
kuma.io/zone: zone-1
version: "0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
k8s.kuma.io/namespace: demo
k8s.kuma.io/service-name: sample
k8s.kuma.io/service-port: "7071"
kuma.io/protocol: mongo
kuma.io/protocol: tcp
kuma.io/service: sample_playground_svc_7071
kuma.io/zone: zone-1
version: "0.1"

0 comments on commit c273973

Please sign in to comment.