-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mixed protocol support for Services with type=LoadBalancer (#94028)
* Mixed protocol support for Services with type=LoadBalancer KEP: https://github.com/kubernetes/enhancements/blob/master/keps/sig-network/20200103-mixed-protocol-lb.md Add new feature gate to control the support of mixed protocols in Services with type=LoadBalancer Add new fields to the ServiceStatus Add Ports to the LoadBalancerIngress, so cloud provider implementations can report the status of the requested load balanc er ports Add ServiceCondition to the ServiceStatus so Service controllers can indicate the conditions of the Service * regenerate conflicting stuff
- Loading branch information
Laszlo Janosi
committed
Nov 13, 2020
1 parent
0081e0e
commit c970a46
Showing
30 changed files
with
2,219 additions
and
970 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2019 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package validation | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
utilfeature "k8s.io/apiserver/pkg/util/feature" | ||
api "k8s.io/kubernetes/pkg/apis/core" | ||
"k8s.io/kubernetes/pkg/features" | ||
) | ||
|
||
// ValidateConditionalService validates conditionally valid fields. | ||
func ValidateConditionalService(service, oldService *api.Service) field.ErrorList { | ||
var errs field.ErrorList | ||
|
||
errs = append(errs, validateMixedProtocolLBService(service, oldService)...) | ||
|
||
return errs | ||
} | ||
|
||
// validateMixedProtocolLBService checks if the old Service has type=LoadBalancer and whether the Service has different Protocols | ||
// on its ports. If the MixedProtocolLBService feature flag is disabled the usage of different Protocols in the new Service is | ||
// valid only if the old Service has different Protocols, too. | ||
func validateMixedProtocolLBService(service, oldService *api.Service) (errs field.ErrorList) { | ||
if service.Spec.Type != api.ServiceTypeLoadBalancer { | ||
return | ||
} | ||
if utilfeature.DefaultFeatureGate.Enabled(features.MixedProtocolLBService) { | ||
return | ||
} | ||
|
||
if serviceHasMixedProtocols(service) && !serviceHasMixedProtocols(oldService) { | ||
errs = append(errs, field.Invalid(field.NewPath("spec", "ports"), service.Spec.Ports, "may not contain more than 1 protocol when type is 'LoadBalancer'")) | ||
} | ||
return | ||
} | ||
|
||
func serviceHasMixedProtocols(service *api.Service) bool { | ||
if service == nil { | ||
return false | ||
} | ||
protos := map[string]bool{} | ||
for _, port := range service.Spec.Ports { | ||
protos[string(port.Protocol)] = true | ||
} | ||
return len(protos) > 1 | ||
} |
Oops, something went wrong.