mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Use a pointer to mark the nodeport port, if any.
This commit is contained in:
parent
538e57713e
commit
8c1e0593bb
@ -149,6 +149,7 @@ type initFederationOptions struct {
|
|||||||
apiServerServiceType v1.ServiceType
|
apiServerServiceType v1.ServiceType
|
||||||
apiServerAdvertiseAddress string
|
apiServerAdvertiseAddress string
|
||||||
apiServerNodePortPort int32
|
apiServerNodePortPort int32
|
||||||
|
apiServerNodePortPortPtr *int32
|
||||||
apiServerEnableHTTPBasicAuth bool
|
apiServerEnableHTTPBasicAuth bool
|
||||||
apiServerEnableTokenAuth bool
|
apiServerEnableTokenAuth bool
|
||||||
}
|
}
|
||||||
@ -236,6 +237,9 @@ func (i *initFederation) Complete(cmd *cobra.Command, args []string) error {
|
|||||||
if i.options.apiServerServiceType != v1.ServiceTypeNodePort {
|
if i.options.apiServerServiceType != v1.ServiceTypeNodePort {
|
||||||
return fmt.Errorf("%s should be passed only with '%s=NodePort'", apiserverPortFlag, apiserverServiceTypeFlag)
|
return fmt.Errorf("%s should be passed only with '%s=NodePort'", apiserverPortFlag, apiserverServiceTypeFlag)
|
||||||
}
|
}
|
||||||
|
i.options.apiServerNodePortPortPtr = &i.options.apiServerNodePortPort
|
||||||
|
} else {
|
||||||
|
i.options.apiServerNodePortPortPtr = nil
|
||||||
}
|
}
|
||||||
if i.options.apiServerNodePortPort < 0 || i.options.apiServerNodePortPort > 65535 {
|
if i.options.apiServerNodePortPort < 0 || i.options.apiServerNodePortPort > 65535 {
|
||||||
return fmt.Errorf("Please provide a valid port number for %s", apiserverPortFlag)
|
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 {
|
|||||||
|
|
||||||
fmt.Fprint(cmdOut, "Creating federation control plane service...")
|
fmt.Fprint(cmdOut, "Creating federation control plane service...")
|
||||||
glog.V(4).Info("Creating federation control plane service")
|
glog.V(4).Info("Creating federation control plane service")
|
||||||
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)
|
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)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -454,15 +458,15 @@ func createNamespace(clientset client.Interface, federationName, namespace strin
|
|||||||
return clientset.Core().Namespaces().Create(ns)
|
return clientset.Core().Namespaces().Create(ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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) {
|
||||||
port := api.ServicePort{
|
port := api.ServicePort{
|
||||||
Name: "https",
|
Name: "https",
|
||||||
Protocol: "TCP",
|
Protocol: "TCP",
|
||||||
Port: 443,
|
Port: 443,
|
||||||
TargetPort: intstr.FromString(apiServerSecurePortName),
|
TargetPort: intstr.FromString(apiServerSecurePortName),
|
||||||
}
|
}
|
||||||
if apiserverServiceType == v1.ServiceTypeNodePort && apiserverPort > 0 {
|
if apiserverServiceType == v1.ServiceTypeNodePort && apiserverPort != nil {
|
||||||
port.NodePort = apiserverPort
|
port.NodePort = *apiserverPort
|
||||||
}
|
}
|
||||||
svc := &api.Service{
|
svc := &api.Service{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Loading…
Reference in New Issue
Block a user