2015-05-04 15:11:19 -04:00
|
|
|
/*
|
2016-06-02 20:25:58 -04:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2015-05-04 15:11:19 -04:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-07-03 08:51:42 -04:00
|
|
|
package kubernetesservice
|
2015-05-04 15:11:19 -04:00
|
|
|
|
|
|
|
|
import (
|
2020-01-27 21:19:44 -05:00
|
|
|
"context"
|
2015-05-04 15:11:19 -04:00
|
|
|
"fmt"
|
|
|
|
|
"net"
|
2019-02-27 11:21:47 -05:00
|
|
|
"net/http"
|
2023-07-04 06:58:21 -04:00
|
|
|
"sync"
|
2015-05-04 15:11:19 -04:00
|
|
|
"time"
|
|
|
|
|
|
2018-06-21 17:24:59 -04:00
|
|
|
corev1 "k8s.io/api/core/v1"
|
2017-01-13 12:48:50 -05:00
|
|
|
"k8s.io/apimachinery/pkg/api/errors"
|
2017-01-11 09:09:48 -05:00
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2017-01-27 15:42:17 -05:00
|
|
|
"k8s.io/apimachinery/pkg/util/intstr"
|
2017-01-11 09:09:48 -05:00
|
|
|
"k8s.io/apimachinery/pkg/util/runtime"
|
|
|
|
|
"k8s.io/apimachinery/pkg/util/wait"
|
2021-10-07 03:57:12 -04:00
|
|
|
"k8s.io/apiserver/pkg/storage"
|
2023-07-12 18:05:42 -04:00
|
|
|
v1informers "k8s.io/client-go/informers/core/v1"
|
2022-06-09 05:04:56 -04:00
|
|
|
"k8s.io/client-go/kubernetes"
|
2023-07-12 18:05:42 -04:00
|
|
|
v1listers "k8s.io/client-go/listers/core/v1"
|
|
|
|
|
"k8s.io/client-go/tools/cache"
|
2020-04-17 15:25:06 -04:00
|
|
|
"k8s.io/klog/v2"
|
2023-07-03 14:23:20 -04:00
|
|
|
|
2020-09-02 13:47:23 -04:00
|
|
|
"k8s.io/kubernetes/pkg/controlplane/reconcilers"
|
2015-05-04 15:11:19 -04:00
|
|
|
)
|
|
|
|
|
|
2021-06-17 12:17:50 -04:00
|
|
|
const (
|
|
|
|
|
kubernetesServiceName = "kubernetes"
|
|
|
|
|
)
|
2016-11-21 12:41:49 -05:00
|
|
|
|
2016-12-19 14:04:47 -05:00
|
|
|
// Controller is the controller manager for the core bootstrap Kubernetes
|
2022-12-27 09:55:08 -05:00
|
|
|
// controller loops, which manage creating the "kubernetes" service and
|
|
|
|
|
// provide the IP repair check on service IPs
|
2015-05-04 15:11:19 -04:00
|
|
|
type Controller struct {
|
2023-07-03 14:23:20 -04:00
|
|
|
Config
|
2015-05-04 15:11:19 -04:00
|
|
|
|
2023-07-12 18:05:42 -04:00
|
|
|
client kubernetes.Interface
|
|
|
|
|
serviceLister v1listers.ServiceLister
|
|
|
|
|
serviceSynced cache.InformerSynced
|
2023-07-04 06:58:21 -04:00
|
|
|
|
|
|
|
|
lock sync.Mutex
|
|
|
|
|
stopCh chan struct{} // closed by Stop()
|
2023-07-03 14:23:20 -04:00
|
|
|
}
|
2019-08-19 16:45:22 -04:00
|
|
|
|
2023-07-03 14:23:20 -04:00
|
|
|
type Config struct {
|
|
|
|
|
PublicIP net.IP
|
2015-05-22 18:28:48 -04:00
|
|
|
|
2017-09-11 11:13:47 -04:00
|
|
|
EndpointReconciler reconcilers.EndpointReconciler
|
2016-06-06 17:48:22 -04:00
|
|
|
EndpointInterval time.Duration
|
2015-05-04 15:11:19 -04:00
|
|
|
|
2016-11-21 12:41:49 -05:00
|
|
|
// ServiceIP indicates where the kubernetes service will live. It may not be nil.
|
2015-10-01 22:59:00 -04:00
|
|
|
ServiceIP net.IP
|
|
|
|
|
ServicePort int
|
|
|
|
|
PublicServicePort int
|
|
|
|
|
KubernetesServiceNodePort int
|
2015-05-04 15:11:19 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-03 14:23:20 -04:00
|
|
|
// New returns a controller for watching the kubernetes service endpoints.
|
2023-07-12 18:05:42 -04:00
|
|
|
func New(config Config, client kubernetes.Interface, serviceInformer v1informers.ServiceInformer) *Controller {
|
2023-07-03 14:23:20 -04:00
|
|
|
return &Controller{
|
2023-07-12 18:05:42 -04:00
|
|
|
Config: config,
|
|
|
|
|
client: client,
|
|
|
|
|
serviceLister: serviceInformer.Lister(),
|
|
|
|
|
serviceSynced: serviceInformer.Informer().HasSynced,
|
|
|
|
|
stopCh: make(chan struct{}),
|
2023-07-04 06:58:21 -04:00
|
|
|
}
|
2017-10-12 21:27:31 -04:00
|
|
|
}
|
|
|
|
|
|
2015-05-04 15:11:19 -04:00
|
|
|
// Start begins the core controller loops that must exist for bootstrapping
|
|
|
|
|
// a cluster.
|
2023-07-04 06:58:21 -04:00
|
|
|
func (c *Controller) Start(stopCh <-chan struct{}) {
|
2023-07-12 18:05:42 -04:00
|
|
|
if !cache.WaitForCacheSync(stopCh, c.serviceSynced) {
|
|
|
|
|
runtime.HandleError(fmt.Errorf("timed out waiting for caches to sync"))
|
|
|
|
|
return
|
|
|
|
|
}
|
2019-02-27 11:21:47 -05:00
|
|
|
// Reconcile during first run removing itself until server is ready.
|
2022-01-28 14:44:37 -05:00
|
|
|
endpointPorts := createEndpointPortSpec(c.PublicServicePort, "https")
|
2021-10-07 03:57:12 -04:00
|
|
|
if err := c.EndpointReconciler.RemoveEndpoints(kubernetesServiceName, c.PublicIP, endpointPorts); err == nil {
|
|
|
|
|
klog.Error("Found stale data, removed previous endpoints on kubernetes service, apiserver didn't exit successfully previously")
|
|
|
|
|
} else if !storage.IsNotFound(err) {
|
|
|
|
|
klog.Errorf("Error removing old endpoints from kubernetes service: %v", err)
|
2019-02-27 11:21:47 -05:00
|
|
|
}
|
|
|
|
|
|
2023-07-04 06:58:21 -04:00
|
|
|
localStopCh := make(chan struct{})
|
|
|
|
|
go func() {
|
|
|
|
|
defer close(localStopCh)
|
|
|
|
|
select {
|
|
|
|
|
case <-stopCh: // from Start
|
|
|
|
|
case <-c.stopCh: // from Stop
|
|
|
|
|
}
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
go c.Run(localStopCh)
|
2015-05-04 15:11:19 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-03 12:36:15 -04:00
|
|
|
// Stop cleans up this API Servers endpoint reconciliation leases so another master can take over more quickly.
|
2017-10-12 21:27:31 -04:00
|
|
|
func (c *Controller) Stop() {
|
2023-07-04 06:58:21 -04:00
|
|
|
c.lock.Lock()
|
|
|
|
|
defer c.lock.Unlock()
|
|
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
case <-c.stopCh:
|
|
|
|
|
return // only close once
|
|
|
|
|
default:
|
|
|
|
|
close(c.stopCh)
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 14:44:37 -05:00
|
|
|
endpointPorts := createEndpointPortSpec(c.PublicServicePort, "https")
|
2018-05-02 22:44:28 -04:00
|
|
|
finishedReconciling := make(chan struct{})
|
|
|
|
|
go func() {
|
|
|
|
|
defer close(finishedReconciling)
|
2018-11-09 13:49:10 -05:00
|
|
|
klog.Infof("Shutting down kubernetes service endpoint reconciler")
|
2019-02-27 11:21:47 -05:00
|
|
|
c.EndpointReconciler.StopReconciling()
|
|
|
|
|
if err := c.EndpointReconciler.RemoveEndpoints(kubernetesServiceName, c.PublicIP, endpointPorts); err != nil {
|
2021-10-07 03:57:12 -04:00
|
|
|
klog.Errorf("Unable to remove endpoints from kubernetes service: %v", err)
|
2018-05-02 22:44:28 -04:00
|
|
|
}
|
2022-05-02 15:02:37 -04:00
|
|
|
c.EndpointReconciler.Destroy()
|
2018-05-02 22:44:28 -04:00
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
select {
|
|
|
|
|
case <-finishedReconciling:
|
|
|
|
|
// done
|
|
|
|
|
case <-time.After(2 * c.EndpointInterval):
|
|
|
|
|
// don't block server shutdown forever if we can't reach etcd to remove ourselves
|
2019-02-27 11:21:47 -05:00
|
|
|
klog.Warning("RemoveEndpoints() timed out")
|
2018-05-02 22:44:28 -04:00
|
|
|
}
|
2017-10-12 21:27:31 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-04 06:58:21 -04:00
|
|
|
// Run periodically updates the kubernetes service
|
|
|
|
|
func (c *Controller) Run(ch <-chan struct{}) {
|
2019-02-27 11:21:47 -05:00
|
|
|
// wait until process is ready
|
2024-06-19 13:14:59 -04:00
|
|
|
ctx := wait.ContextForChannel(ch)
|
|
|
|
|
err := wait.PollUntilContextCancel(ctx, 100*time.Millisecond, true, func(context.Context) (bool, error) {
|
2019-02-27 11:21:47 -05:00
|
|
|
var code int
|
2023-07-04 06:58:21 -04:00
|
|
|
c.client.CoreV1().RESTClient().Get().AbsPath("/readyz").Do(context.TODO()).StatusCode(&code)
|
2019-02-27 11:21:47 -05:00
|
|
|
return code == http.StatusOK, nil
|
2024-06-19 13:14:59 -04:00
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2019-02-27 11:21:47 -05:00
|
|
|
|
|
|
|
|
wait.NonSlidingUntil(func() {
|
2015-10-16 14:54:07 -04:00
|
|
|
// Service definition is not reconciled after first
|
|
|
|
|
// run, ports and type will be corrected only during
|
|
|
|
|
// start.
|
|
|
|
|
if err := c.UpdateKubernetesService(false); err != nil {
|
2016-01-15 02:32:10 -05:00
|
|
|
runtime.HandleError(fmt.Errorf("unable to sync kubernetes service: %v", err))
|
2015-05-04 15:11:19 -04:00
|
|
|
}
|
|
|
|
|
}, c.EndpointInterval, ch)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UpdateKubernetesService attempts to update the default Kube service.
|
2015-10-16 14:54:07 -04:00
|
|
|
func (c *Controller) UpdateKubernetesService(reconcile bool) error {
|
2015-05-04 15:11:19 -04:00
|
|
|
// Update service & endpoint records.
|
2022-01-28 14:44:37 -05:00
|
|
|
servicePorts, serviceType := createPortAndServiceSpec(c.ServicePort, c.PublicServicePort, c.KubernetesServiceNodePort, "https")
|
2016-11-21 12:41:49 -05:00
|
|
|
if err := c.CreateOrUpdateMasterServiceIfNeeded(kubernetesServiceName, c.ServiceIP, servicePorts, serviceType, reconcile); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2022-01-28 14:44:37 -05:00
|
|
|
endpointPorts := createEndpointPortSpec(c.PublicServicePort, "https")
|
2016-11-21 12:41:49 -05:00
|
|
|
if err := c.EndpointReconciler.ReconcileEndpoints(kubernetesServiceName, c.PublicIP, endpointPorts, reconcile); err != nil {
|
|
|
|
|
return err
|
2015-05-04 15:11:19 -04:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 22:59:00 -04:00
|
|
|
// createPortAndServiceSpec creates an array of service ports.
|
|
|
|
|
// If the NodePort value is 0, just the servicePort is used, otherwise, a node port is exposed.
|
2022-01-28 14:44:37 -05:00
|
|
|
func createPortAndServiceSpec(servicePort int, targetServicePort int, nodePort int, servicePortName string) ([]corev1.ServicePort, corev1.ServiceType) {
|
|
|
|
|
// Use the Cluster IP type for the service port if NodePort isn't provided.
|
|
|
|
|
// Otherwise, we will be binding the master service to a NodePort.
|
|
|
|
|
servicePorts := []corev1.ServicePort{{
|
|
|
|
|
Protocol: corev1.ProtocolTCP,
|
2016-04-27 00:35:14 -04:00
|
|
|
Port: int32(servicePort),
|
2015-10-07 11:06:05 -04:00
|
|
|
Name: servicePortName,
|
2023-08-16 12:33:01 -04:00
|
|
|
TargetPort: intstr.FromInt32(int32(targetServicePort)),
|
2022-01-28 14:44:37 -05:00
|
|
|
}}
|
2018-11-01 00:11:40 -04:00
|
|
|
serviceType := corev1.ServiceTypeClusterIP
|
2015-10-07 11:06:05 -04:00
|
|
|
if nodePort > 0 {
|
2016-04-27 00:35:14 -04:00
|
|
|
servicePorts[0].NodePort = int32(nodePort)
|
2018-11-01 00:11:40 -04:00
|
|
|
serviceType = corev1.ServiceTypeNodePort
|
2015-10-07 11:06:05 -04:00
|
|
|
}
|
|
|
|
|
return servicePorts, serviceType
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-28 14:44:37 -05:00
|
|
|
// createEndpointPortSpec creates the endpoint ports
|
|
|
|
|
func createEndpointPortSpec(endpointPort int, endpointPortName string) []corev1.EndpointPort {
|
|
|
|
|
return []corev1.EndpointPort{{
|
|
|
|
|
Protocol: corev1.ProtocolTCP,
|
|
|
|
|
Port: int32(endpointPort),
|
|
|
|
|
Name: endpointPortName,
|
2015-10-07 11:06:05 -04:00
|
|
|
}}
|
2015-10-01 22:59:00 -04:00
|
|
|
}
|
|
|
|
|
|
2019-10-03 12:36:15 -04:00
|
|
|
// CreateOrUpdateMasterServiceIfNeeded will create the specified service if it
|
2015-05-04 15:11:19 -04:00
|
|
|
// doesn't already exist.
|
2018-11-01 00:11:40 -04:00
|
|
|
func (c *Controller) CreateOrUpdateMasterServiceIfNeeded(serviceName string, serviceIP net.IP, servicePorts []corev1.ServicePort, serviceType corev1.ServiceType, reconcile bool) error {
|
2023-07-12 18:05:42 -04:00
|
|
|
if s, err := c.serviceLister.Services(metav1.NamespaceDefault).Get(serviceName); err == nil {
|
2015-05-04 15:11:19 -04:00
|
|
|
// The service already exists.
|
2023-07-12 18:05:42 -04:00
|
|
|
// This path is no executed since 1.17 2a9a9fa, keeping it in case it needs to be revisited
|
2015-10-16 14:54:07 -04:00
|
|
|
if reconcile {
|
2022-01-29 10:29:35 -05:00
|
|
|
if svc, updated := getMasterServiceUpdateIfNeeded(s, servicePorts, serviceType); updated {
|
2018-11-09 13:49:10 -05:00
|
|
|
klog.Warningf("Resetting master service %q to %#v", serviceName, svc)
|
2023-07-04 06:58:21 -04:00
|
|
|
_, err := c.client.CoreV1().Services(metav1.NamespaceDefault).Update(context.TODO(), svc, metav1.UpdateOptions{})
|
2015-10-16 14:54:07 -04:00
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-04 15:11:19 -04:00
|
|
|
return nil
|
|
|
|
|
}
|
dual stack services (#91824)
* api: structure change
* api: defaulting, conversion, and validation
* [FIX] validation: auto remove second ip/family when service changes to SingleStack
* [FIX] api: defaulting, conversion, and validation
* api-server: clusterIPs alloc, printers, storage and strategy
* [FIX] clusterIPs default on read
* alloc: auto remove second ip/family when service changes to SingleStack
* api-server: repair loop handling for clusterIPs
* api-server: force kubernetes default service into single stack
* api-server: tie dualstack feature flag with endpoint feature flag
* controller-manager: feature flag, endpoint, and endpointSlice controllers handling multi family service
* [FIX] controller-manager: feature flag, endpoint, and endpointSlicecontrollers handling multi family service
* kube-proxy: feature-flag, utils, proxier, and meta proxier
* [FIX] kubeproxy: call both proxier at the same time
* kubenet: remove forced pod IP sorting
* kubectl: modify describe to include ClusterIPs, IPFamilies, and IPFamilyPolicy
* e2e: fix tests that depends on IPFamily field AND add dual stack tests
* e2e: fix expected error message for ClusterIP immutability
* add integration tests for dualstack
the third phase of dual stack is a very complex change in the API,
basically it introduces Dual Stack services. Main changes are:
- It pluralizes the Service IPFamily field to IPFamilies,
and removes the singular field.
- It introduces a new field IPFamilyPolicyType that can take
3 values to express the "dual-stack(mad)ness" of the cluster:
SingleStack, PreferDualStack and RequireDualStack
- It pluralizes ClusterIP to ClusterIPs.
The goal is to add coverage to the services API operations,
taking into account the 6 different modes a cluster can have:
- single stack: IP4 or IPv6 (as of today)
- dual stack: IPv4 only, IPv6 only, IPv4 - IPv6, IPv6 - IPv4
* [FIX] add integration tests for dualstack
* generated data
* generated files
Co-authored-by: Antonio Ojea <aojea@redhat.com>
2020-10-26 16:15:59 -04:00
|
|
|
singleStack := corev1.IPFamilyPolicySingleStack
|
2018-11-01 00:11:40 -04:00
|
|
|
svc := &corev1.Service{
|
2017-01-16 22:38:19 -05:00
|
|
|
ObjectMeta: metav1.ObjectMeta{
|
2015-05-04 15:11:19 -04:00
|
|
|
Name: serviceName,
|
2017-01-21 22:36:02 -05:00
|
|
|
Namespace: metav1.NamespaceDefault,
|
2015-05-04 15:11:19 -04:00
|
|
|
Labels: map[string]string{"provider": "kubernetes", "component": "apiserver"},
|
|
|
|
|
},
|
2018-11-01 00:11:40 -04:00
|
|
|
Spec: corev1.ServiceSpec{
|
2015-10-07 11:06:05 -04:00
|
|
|
Ports: servicePorts,
|
2015-05-04 15:11:19 -04:00
|
|
|
// maintained by this code, not by the pod selector
|
|
|
|
|
Selector: nil,
|
2015-05-23 16:41:11 -04:00
|
|
|
ClusterIP: serviceIP.String(),
|
dual stack services (#91824)
* api: structure change
* api: defaulting, conversion, and validation
* [FIX] validation: auto remove second ip/family when service changes to SingleStack
* [FIX] api: defaulting, conversion, and validation
* api-server: clusterIPs alloc, printers, storage and strategy
* [FIX] clusterIPs default on read
* alloc: auto remove second ip/family when service changes to SingleStack
* api-server: repair loop handling for clusterIPs
* api-server: force kubernetes default service into single stack
* api-server: tie dualstack feature flag with endpoint feature flag
* controller-manager: feature flag, endpoint, and endpointSlice controllers handling multi family service
* [FIX] controller-manager: feature flag, endpoint, and endpointSlicecontrollers handling multi family service
* kube-proxy: feature-flag, utils, proxier, and meta proxier
* [FIX] kubeproxy: call both proxier at the same time
* kubenet: remove forced pod IP sorting
* kubectl: modify describe to include ClusterIPs, IPFamilies, and IPFamilyPolicy
* e2e: fix tests that depends on IPFamily field AND add dual stack tests
* e2e: fix expected error message for ClusterIP immutability
* add integration tests for dualstack
the third phase of dual stack is a very complex change in the API,
basically it introduces Dual Stack services. Main changes are:
- It pluralizes the Service IPFamily field to IPFamilies,
and removes the singular field.
- It introduces a new field IPFamilyPolicyType that can take
3 values to express the "dual-stack(mad)ness" of the cluster:
SingleStack, PreferDualStack and RequireDualStack
- It pluralizes ClusterIP to ClusterIPs.
The goal is to add coverage to the services API operations,
taking into account the 6 different modes a cluster can have:
- single stack: IP4 or IPv6 (as of today)
- dual stack: IPv4 only, IPv6 only, IPv4 - IPv6, IPv6 - IPv4
* [FIX] add integration tests for dualstack
* generated data
* generated files
Co-authored-by: Antonio Ojea <aojea@redhat.com>
2020-10-26 16:15:59 -04:00
|
|
|
IPFamilyPolicy: &singleStack,
|
2018-11-01 00:11:40 -04:00
|
|
|
SessionAffinity: corev1.ServiceAffinityNone,
|
2015-10-01 22:59:00 -04:00
|
|
|
Type: serviceType,
|
2015-05-04 15:11:19 -04:00
|
|
|
},
|
|
|
|
|
}
|
2015-06-16 01:20:39 -04:00
|
|
|
|
2023-07-04 06:58:21 -04:00
|
|
|
_, err := c.client.CoreV1().Services(metav1.NamespaceDefault).Create(context.TODO(), svc, metav1.CreateOptions{})
|
2016-11-21 12:47:29 -05:00
|
|
|
if errors.IsAlreadyExists(err) {
|
|
|
|
|
return c.CreateOrUpdateMasterServiceIfNeeded(serviceName, serviceIP, servicePorts, serviceType, reconcile)
|
2015-05-04 15:11:19 -04:00
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
2022-01-29 10:29:35 -05:00
|
|
|
|
|
|
|
|
// getMasterServiceUpdateIfNeeded sets service attributes for the given apiserver service.
|
|
|
|
|
func getMasterServiceUpdateIfNeeded(svc *corev1.Service, servicePorts []corev1.ServicePort, serviceType corev1.ServiceType) (s *corev1.Service, updated bool) {
|
|
|
|
|
// Determine if the service is in the format we expect
|
|
|
|
|
// (servicePorts are present and service type matches)
|
|
|
|
|
formatCorrect := checkServiceFormat(svc, servicePorts, serviceType)
|
|
|
|
|
if formatCorrect {
|
|
|
|
|
return svc, false
|
|
|
|
|
}
|
|
|
|
|
svc.Spec.Ports = servicePorts
|
|
|
|
|
svc.Spec.Type = serviceType
|
|
|
|
|
return svc, true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Determine if the service is in the correct format
|
|
|
|
|
// getMasterServiceUpdateIfNeeded expects (servicePorts are correct
|
|
|
|
|
// and service type matches).
|
|
|
|
|
func checkServiceFormat(s *corev1.Service, ports []corev1.ServicePort, serviceType corev1.ServiceType) (formatCorrect bool) {
|
|
|
|
|
if s.Spec.Type != serviceType {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
if len(ports) != len(s.Spec.Ports) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
for i, port := range ports {
|
|
|
|
|
if port != s.Spec.Ports[i] {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|