From c44f5467a22c3d4e5ccbc5fc3e8c89e5102f105c Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Fri, 28 Jan 2022 14:44:37 -0500 Subject: [PATCH] Remove unused and un-enable-able apiserver multiple ports feature Theoretically, the apiserver could be told to advertise additional ports on the kubernetes service, but there was no way to enable this functionality without forking/vendoring the apiserver code. This was apparently added in the distant past for OpenShift to use, but it has not been used in OpenShift since Kubernetes 1.11. --- pkg/controlplane/controller.go | 42 ++++++++++++++-------------------- pkg/controlplane/instance.go | 11 --------- 2 files changed, 17 insertions(+), 36 deletions(-) diff --git a/pkg/controlplane/controller.go b/pkg/controlplane/controller.go index 3f67cf95fd0..65820719b8c 100644 --- a/pkg/controlplane/controller.go +++ b/pkg/controlplane/controller.go @@ -82,8 +82,6 @@ type Controller struct { // ServiceIP indicates where the kubernetes service will live. It may not be nil. ServiceIP net.IP ServicePort int - ExtraServicePorts []corev1.ServicePort - ExtraEndpointPorts []corev1.EndpointPort PublicServicePort int KubernetesServiceNodePort int @@ -137,8 +135,6 @@ func (c *completedConfig) NewBootstrapController(legacyRESTStorage corerest.Lega ServiceIP: c.ExtraConfig.APIServerServiceIP, ServicePort: c.ExtraConfig.APIServerServicePort, - ExtraServicePorts: c.ExtraConfig.ExtraServicePorts, - ExtraEndpointPorts: c.ExtraConfig.ExtraEndpointPorts, PublicServicePort: publicServicePort, KubernetesServiceNodePort: c.ExtraConfig.KubernetesServiceNodePort, }, nil @@ -164,7 +160,7 @@ func (c *Controller) Start() { } // Reconcile during first run removing itself until server is ready. - endpointPorts := createEndpointPortSpec(c.PublicServicePort, "https", c.ExtraEndpointPorts) + endpointPorts := createEndpointPortSpec(c.PublicServicePort, "https") 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) { @@ -216,7 +212,7 @@ func (c *Controller) Stop() { if c.runner != nil { c.runner.Stop() } - endpointPorts := createEndpointPortSpec(c.PublicServicePort, "https", c.ExtraEndpointPorts) + endpointPorts := createEndpointPortSpec(c.PublicServicePort, "https") finishedReconciling := make(chan struct{}) go func() { defer close(finishedReconciling) @@ -278,11 +274,11 @@ func (c *Controller) UpdateKubernetesService(reconcile bool) error { return err } - servicePorts, serviceType := createPortAndServiceSpec(c.ServicePort, c.PublicServicePort, c.KubernetesServiceNodePort, "https", c.ExtraServicePorts) + servicePorts, serviceType := createPortAndServiceSpec(c.ServicePort, c.PublicServicePort, c.KubernetesServiceNodePort, "https") if err := c.CreateOrUpdateMasterServiceIfNeeded(kubernetesServiceName, c.ServiceIP, servicePorts, serviceType, reconcile); err != nil { return err } - endpointPorts := createEndpointPortSpec(c.PublicServicePort, "https", c.ExtraEndpointPorts) + endpointPorts := createEndpointPortSpec(c.PublicServicePort, "https") if err := c.EndpointReconciler.ReconcileEndpoints(kubernetesServiceName, c.PublicIP, endpointPorts, reconcile); err != nil { return err } @@ -291,34 +287,30 @@ func (c *Controller) UpdateKubernetesService(reconcile bool) error { // createPortAndServiceSpec creates an array of service ports. // If the NodePort value is 0, just the servicePort is used, otherwise, a node port is exposed. -func createPortAndServiceSpec(servicePort int, targetServicePort int, nodePort int, servicePortName string, extraServicePorts []corev1.ServicePort) ([]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, +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, Port: int32(servicePort), Name: servicePortName, - TargetPort: intstr.FromInt(targetServicePort)}} + TargetPort: intstr.FromInt(targetServicePort), + }} serviceType := corev1.ServiceTypeClusterIP if nodePort > 0 { servicePorts[0].NodePort = int32(nodePort) serviceType = corev1.ServiceTypeNodePort } - if extraServicePorts != nil { - servicePorts = append(servicePorts, extraServicePorts...) - } return servicePorts, serviceType } -// createEndpointPortSpec creates an array of endpoint ports -func createEndpointPortSpec(endpointPort int, endpointPortName string, extraEndpointPorts []corev1.EndpointPort) []corev1.EndpointPort { - endpointPorts := []corev1.EndpointPort{{Protocol: corev1.ProtocolTCP, - Port: int32(endpointPort), - Name: endpointPortName, +// createEndpointPortSpec creates the endpoint ports +func createEndpointPortSpec(endpointPort int, endpointPortName string) []corev1.EndpointPort { + return []corev1.EndpointPort{{ + Protocol: corev1.ProtocolTCP, + Port: int32(endpointPort), + Name: endpointPortName, }} - if extraEndpointPorts != nil { - endpointPorts = append(endpointPorts, extraEndpointPorts...) - } - return endpointPorts } // CreateOrUpdateMasterServiceIfNeeded will create the specified service if it diff --git a/pkg/controlplane/instance.go b/pkg/controlplane/instance.go index 6f4231bb6f0..20a16c9a53e 100644 --- a/pkg/controlplane/instance.go +++ b/pkg/controlplane/instance.go @@ -159,17 +159,6 @@ type ExtraConfig struct { // The range of ports to be assigned to services with type=NodePort or greater ServiceNodePortRange utilnet.PortRange - // Additional ports to be exposed on the GenericAPIServer service - // extraServicePorts is injectable in the event that more ports - // (other than the default 443/tcp) are exposed on the GenericAPIServer - // and those ports need to be load balanced by the GenericAPIServer - // service because this pkg is linked by out-of-tree projects - // like openshift which want to use the GenericAPIServer but also do - // more stuff. - ExtraServicePorts []apiv1.ServicePort - // Additional ports to be exposed on the GenericAPIServer endpoints - // Port names should align with ports defined in ExtraServicePorts - ExtraEndpointPorts []apiv1.EndpointPort // If non-zero, the "kubernetes" services uses this port as NodePort. KubernetesServiceNodePort int