Skip to content

Commit

Permalink
Merge pull request #3333 from robinpercy/node-port-range
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Added ability to set --service-node-port-range

Addresses: #3052 and #3326 

From what I can tell, `--service-node-port-range` has been a valid option forever, so I haven't worried about k8s versions.

@justinsb @chrislovecnm let me know if any changes are required.
  • Loading branch information
Kubernetes Submit Queue authored Sep 15, 2017
2 parents 159a21c + e1b20c0 commit 893217f
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/cluster_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ spec:
apps/v1alpha1: "true"
```

#### serviceNodePortRange

This value is passed as `--service-node-port-range` for `kube-apiserver`.

```yaml
spec:
kubeAPIServer:
serviceNodePortRange: 30000-33000
```

Will result in the flag `--runtime-config=batch/v2alpha1=true,apps/v1alpha1=true`. Note that `kube-apiserver` accepts `true` as a value for switch-like flags.

### externalDns
Expand Down
6 changes: 6 additions & 0 deletions nodeup/pkg/model/kubeapiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func Test_KubeAPIServer_BuildFlags(t *testing.T) {
},
"--insecure-port=8080 --secure-port=0",
},
{
kops.KubeAPIServerConfig{
ServiceNodePortRange: "30000-33000",
},
"--insecure-port=0 --secure-port=0 --service-node-port-range=30000-33000",
},
}

for _, g := range grid {
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ type KubeAPIServerConfig struct {
AdmissionControl []string `json:"admissionControl,omitempty" flag:"admission-control"`
// ServiceClusterIPRange is the service address range
ServiceClusterIPRange string `json:"serviceClusterIPRange,omitempty" flag:"service-cluster-ip-range"`
// Passed as --service-node-port-range to kube-apiserver. Expects 'startPort-endPort' format. Eg. 30000-33000
ServiceNodePortRange string `json:"serviceNodePortRange,omitempty" flag:"service-node-port-range"`
// EtcdServers is a list of the etcd service to connect
EtcdServers []string `json:"etcdServers,omitempty" flag:"etcd-servers"`
// EtcdServersOverrides is per-resource etcd servers overrides, comma separated. The individual override format: group/resource#servers, where servers are http://ip:port, semicolon separated
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/v1alpha1/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ type KubeAPIServerConfig struct {
AdmissionControl []string `json:"admissionControl,omitempty" flag:"admission-control"`
// ServiceClusterIPRange is the service address range
ServiceClusterIPRange string `json:"serviceClusterIPRange,omitempty" flag:"service-cluster-ip-range"`
// Passed as --service-node-port-range to kube-apiserver. Expects 'startPort-endPort' format. Eg. 30000-33000
ServiceNodePortRange string `json:"serviceNodePortRange,omitempty" flag:"service-node-port-range"`
// EtcdServers is a list of the etcd service to connect
EtcdServers []string `json:"etcdServers,omitempty" flag:"etcd-servers"`
// EtcdServersOverrides is per-resource etcd servers overrides, comma separated. The individual override format: group/resource#servers, where servers are http://ip:port, semicolon separated
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/v1alpha1/zz_generated.conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,7 @@ func autoConvert_v1alpha1_KubeAPIServerConfig_To_kops_KubeAPIServerConfig(in *Ku
out.Address = in.Address
out.AdmissionControl = in.AdmissionControl
out.ServiceClusterIPRange = in.ServiceClusterIPRange
out.ServiceNodePortRange = in.ServiceNodePortRange
out.EtcdServers = in.EtcdServers
out.EtcdServersOverrides = in.EtcdServersOverrides
out.EtcdCAFile = in.EtcdCAFile
Expand Down Expand Up @@ -1732,6 +1733,7 @@ func autoConvert_kops_KubeAPIServerConfig_To_v1alpha1_KubeAPIServerConfig(in *ko
out.Address = in.Address
out.AdmissionControl = in.AdmissionControl
out.ServiceClusterIPRange = in.ServiceClusterIPRange
out.ServiceNodePortRange = in.ServiceNodePortRange
out.EtcdServers = in.EtcdServers
out.EtcdServersOverrides = in.EtcdServersOverrides
out.EtcdCAFile = in.EtcdCAFile
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/v1alpha2/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ type KubeAPIServerConfig struct {
AdmissionControl []string `json:"admissionControl,omitempty" flag:"admission-control"`
// ServiceClusterIPRange is the service address range
ServiceClusterIPRange string `json:"serviceClusterIPRange,omitempty" flag:"service-cluster-ip-range"`
// Passed as --service-node-port-range to kube-apiserver. Expects 'startPort-endPort' format. Eg. 30000-33000
ServiceNodePortRange string `json:"serviceNodePortRange,omitempty" flag:"service-node-port-range"`
// EtcdServers is a list of the etcd service to connect
EtcdServers []string `json:"etcdServers,omitempty" flag:"etcd-servers"`
// EtcdServersOverrides is per-resource etcd servers overrides, comma separated. The individual override format: group/resource#servers, where servers are http://ip:port, semicolon separated
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/v1alpha2/zz_generated.conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,7 @@ func autoConvert_v1alpha2_KubeAPIServerConfig_To_kops_KubeAPIServerConfig(in *Ku
out.Address = in.Address
out.AdmissionControl = in.AdmissionControl
out.ServiceClusterIPRange = in.ServiceClusterIPRange
out.ServiceNodePortRange = in.ServiceNodePortRange
out.EtcdServers = in.EtcdServers
out.EtcdServersOverrides = in.EtcdServersOverrides
out.EtcdCAFile = in.EtcdCAFile
Expand Down Expand Up @@ -1991,6 +1992,7 @@ func autoConvert_kops_KubeAPIServerConfig_To_v1alpha2_KubeAPIServerConfig(in *ko
out.Address = in.Address
out.AdmissionControl = in.AdmissionControl
out.ServiceClusterIPRange = in.ServiceClusterIPRange
out.ServiceNodePortRange = in.ServiceNodePortRange
out.EtcdServers = in.EtcdServers
out.EtcdServersOverrides = in.EtcdServersOverrides
out.EtcdCAFile = in.EtcdCAFile
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/kops/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"k8s.io/apimachinery/pkg/api/validation"
utilnet "k8s.io/apimachinery/pkg/util/net"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field"
"k8s.io/kops/pkg/apis/kops"
Expand Down Expand Up @@ -200,6 +201,14 @@ func validateKubeAPIServer(v *kops.KubeAPIServerConfig, fldPath *field.Path) fie
allErrs = append(allErrs, field.Invalid(fldPath, flds, "ProxyClientCertFile and ProxyClientKeyFile must both be specified (or not all)"))
}

if v.ServiceNodePortRange != "" {
pr := &utilnet.PortRange{}
err := pr.Set(v.ServiceNodePortRange)
if err != nil {
allErrs = append(allErrs, field.Invalid(fldPath, v.ServiceNodePortRange, err.Error()))
}
}

return allErrs
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/kops/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ func TestValidateKubeAPIServer(t *testing.T) {
"Invalid value::KubeAPIServer",
},
},
{
Input: kops.KubeAPIServerConfig{
ServiceNodePortRange: str,
},
ExpectedErrors: []string{
"Invalid value::KubeAPIServer",
},
},
}
for _, g := range grid {
errs := validateKubeAPIServer(&g.Input, field.NewPath("KubeAPIServer"))
Expand Down

0 comments on commit 893217f

Please sign in to comment.