mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 22:20:51 +00:00
Add ServiceType = NodePort; wire everything up
This commit is contained in:
@@ -75,10 +75,9 @@ func (c *Repair) RunOnce() error {
|
||||
}
|
||||
|
||||
r := portallocator.NewPortAllocator(c.portRange)
|
||||
for _, svc := range list.Items {
|
||||
ports := []int{}
|
||||
|
||||
// TODO(justinsb): Collect NodePorts
|
||||
for i := range list.Items {
|
||||
svc := &list.Items[i]
|
||||
ports := service.CollectServiceNodePorts(svc)
|
||||
if len(ports) == 0 {
|
||||
continue
|
||||
}
|
||||
|
@@ -153,7 +153,7 @@ func (rs *REST) Delete(ctx api.Context, id string) (runtime.Object, error) {
|
||||
rs.portals.Release(net.ParseIP(service.Spec.PortalIP))
|
||||
}
|
||||
|
||||
for _, nodePort := range collectServiceNodePorts(service) {
|
||||
for _, nodePort := range CollectServiceNodePorts(service) {
|
||||
err := rs.serviceNodePorts.Release(nodePort)
|
||||
if err != nil {
|
||||
// these should be caught by an eventual reconciliation / restart
|
||||
@@ -223,7 +223,7 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
|
||||
|
||||
assignNodePorts := shouldAssignNodePorts(service)
|
||||
|
||||
oldNodePorts := collectServiceNodePorts(oldService)
|
||||
oldNodePorts := CollectServiceNodePorts(oldService)
|
||||
|
||||
newNodePorts := []int{}
|
||||
if assignNodePorts {
|
||||
@@ -328,7 +328,7 @@ func contains(haystack []int, needle int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func collectServiceNodePorts(service *api.Service) []int {
|
||||
func CollectServiceNodePorts(service *api.Service) []int {
|
||||
servicePorts := []int{}
|
||||
for i := range service.Spec.Ports {
|
||||
servicePort := &service.Spec.Ports[i]
|
||||
@@ -340,17 +340,15 @@ func collectServiceNodePorts(service *api.Service) []int {
|
||||
}
|
||||
|
||||
func shouldAssignNodePorts(service *api.Service) bool {
|
||||
// TODO(justinsb): Switch on service.Spec.Type
|
||||
// switch service.Spec.Type {
|
||||
// case api.ServiceVisibilityLoadBalancer:
|
||||
// return true
|
||||
// case api.ServiceVisibilityNodePort:
|
||||
// return true
|
||||
// case api.ServiceVisibilityCluster:
|
||||
// return false
|
||||
// default:
|
||||
// glog.Errorf("Unknown visibility value: %v", service.Spec.Visibility)
|
||||
// return false
|
||||
// }
|
||||
return false
|
||||
switch service.Spec.Type {
|
||||
case api.ServiceTypeLoadBalancer:
|
||||
return true
|
||||
case api.ServiceTypeNodePort:
|
||||
return true
|
||||
case api.ServiceTypeClusterIP:
|
||||
return false
|
||||
default:
|
||||
glog.Errorf("Unknown service type: %v", service.Spec.Type)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user