Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(k8s): tolerate unknown appProtocol #7133

Merged
merged 1 commit into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == "" {
michaelbeaumont marked this conversation as resolved.
Show resolved Hide resolved
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
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)
michaelbeaumont marked this conversation as resolved.
Show resolved Hide resolved
}),
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"