Skip to content
This repository was archived by the owner on Mar 26, 2021. It is now read-only.

Commit 92c6b6c

Browse files
committed
Use a pointer to mark the nodeport port, if any.
1 parent 1625dc6 commit 92c6b6c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

pkg/kubefed/init/init.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ type initFederationOptions struct {
149149
apiServerServiceType v1.ServiceType
150150
apiServerAdvertiseAddress string
151151
apiServerNodePortPort int32
152+
apiServerNodePortPortPtr *int32
152153
apiServerEnableHTTPBasicAuth bool
153154
apiServerEnableTokenAuth bool
154155
}
@@ -236,6 +237,9 @@ func (i *initFederation) Complete(cmd *cobra.Command, args []string) error {
236237
if i.options.apiServerServiceType != v1.ServiceTypeNodePort {
237238
return fmt.Errorf("%s should be passed only with '%s=NodePort'", apiserverPortFlag, apiserverServiceTypeFlag)
238239
}
240+
i.options.apiServerNodePortPortPtr = &i.options.apiServerNodePortPort
241+
} else {
242+
i.options.apiServerNodePortPortPtr = nil
239243
}
240244
if i.options.apiServerNodePortPort < 0 || i.options.apiServerNodePortPort > 65535 {
241245
return fmt.Errorf("Please provide a valid port number for %s", apiserverPortFlag)
@@ -304,7 +308,7 @@ func (i *initFederation) Run(cmdOut io.Writer, config util.AdminConfig) error {
304308

305309
fmt.Fprint(cmdOut, "Creating federation control plane service...")
306310
glog.V(4).Info("Creating federation control plane service")
307-
svc, ips, hostnames, err := createService(cmdOut, hostClientset, i.commonOptions.FederationSystemNamespace, serverName, i.commonOptions.Name, i.options.apiServerAdvertiseAddress, i.options.apiServerNodePortPort, i.options.apiServerServiceType, i.options.dryRun)
311+
svc, ips, hostnames, err := createService(cmdOut, hostClientset, i.commonOptions.FederationSystemNamespace, serverName, i.commonOptions.Name, i.options.apiServerAdvertiseAddress, i.options.apiServerNodePortPortPtr, i.options.apiServerServiceType, i.options.dryRun)
308312
if err != nil {
309313
return err
310314
}
@@ -454,15 +458,15 @@ func createNamespace(clientset client.Interface, federationName, namespace strin
454458
return clientset.Core().Namespaces().Create(ns)
455459
}
456460

457-
func createService(cmdOut io.Writer, clientset client.Interface, namespace, svcName, federationName, apiserverAdvertiseAddress string, apiserverPort int32, apiserverServiceType v1.ServiceType, dryRun bool) (*api.Service, []string, []string, error) {
461+
func createService(cmdOut io.Writer, clientset client.Interface, namespace, svcName, federationName, apiserverAdvertiseAddress string, apiserverPort *int32, apiserverServiceType v1.ServiceType, dryRun bool) (*api.Service, []string, []string, error) {
458462
port := api.ServicePort{
459463
Name: "https",
460464
Protocol: "TCP",
461465
Port: 443,
462466
TargetPort: intstr.FromString(apiServerSecurePortName),
463467
}
464-
if apiserverServiceType == v1.ServiceTypeNodePort && apiserverPort > 0 {
465-
port.NodePort = apiserverPort
468+
if apiserverServiceType == v1.ServiceTypeNodePort && apiserverPort != nil {
469+
port.NodePort = *apiserverPort
466470
}
467471
svc := &api.Service{
468472
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)