diff --git a/kind/actions/cluster_actions.go b/kind/actions/cluster_actions.go index 6c12862..ab78912 100644 --- a/kind/actions/cluster_actions.go +++ b/kind/actions/cluster_actions.go @@ -24,6 +24,7 @@ import ( "github.com/pkg/errors" k8sversion "k8s.io/apimachinery/pkg/util/version" + constkind "sigs.k8s.io/cluster-api-provider-docker/kind/constants" "sigs.k8s.io/cluster-api-provider-docker/kind/kubeadm" "sigs.k8s.io/cluster-api-provider-docker/third_party/forked/loadbalancer" "sigs.k8s.io/kind/pkg/cluster/constants" @@ -99,7 +100,7 @@ func ConfigureLoadBalancer(clusterName string) error { if err != nil { return errors.Wrapf(err, "failed to get IP for node %s", n.Name()) } - backendServers[n.Name()] = fmt.Sprintf("%s:%d", controlPlaneIPv4, 6443) + backendServers[n.Name()] = fmt.Sprintf("%s:%d", controlPlaneIPv4, constkind.APIServerPort) } // create loadbalancer config data @@ -126,7 +127,8 @@ func KubeadmConfig(node *nodes.Node, clusterName, lbip string) error { return errors.Wrap(err, "failed to get kubernetes version from node") } - kubeadmConfig, err := kubeadm.InitConfiguration(kubeVersion, clusterName, fmt.Sprintf("%s:%d", lbip, 6443)) + kubeadmConfig, err := kubeadm.InitConfiguration(kubeVersion, clusterName, + fmt.Sprintf("%s:%d", lbip, constkind.APIServerPort)) if err != nil { return errors.Wrap(err, "failed to generate kubeadm config content") diff --git a/kind/actions/kind.go b/kind/actions/kind.go index b933841..74d1479 100644 --- a/kind/actions/kind.go +++ b/kind/actions/kind.go @@ -27,6 +27,7 @@ import ( "strings" "github.com/pkg/errors" + constkind "sigs.k8s.io/cluster-api-provider-docker/kind/constants" "sigs.k8s.io/cluster-api-provider-docker/third_party/forked/loadbalancer" "sigs.k8s.io/kind/pkg/cluster/config/defaults" "sigs.k8s.io/kind/pkg/cluster/constants" @@ -247,7 +248,7 @@ func GetLoadBalancerHostAndPort(allNodes []nodes.Node) (string, int32, error) { if err != nil { return "", 0, err } - port, err := node.Ports(6443) + port, err := node.Ports(constkind.APIServerPort) return ipv4, port, err } diff --git a/kind/constants/constants.go b/kind/constants/constants.go new file mode 100644 index 0000000..34e195b --- /dev/null +++ b/kind/constants/constants.go @@ -0,0 +1,21 @@ +/* +Copyright 2019 The Kubernetes Authors. + +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. +*/ + +package constants + +// APIServerPort is the expected default APIServerPort on the control plane node(s) +// https://kubernetes.io/docs/reference/access-authn-authz/controlling-access/#api-server-ports-and-ips +const APIServerPort = 6443 diff --git a/kind/kubeadm/config.go b/kind/kubeadm/config.go index 1656462..ce8a59b 100644 --- a/kind/kubeadm/config.go +++ b/kind/kubeadm/config.go @@ -24,6 +24,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kubeadmv1beta1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta1" "k8s.io/kubernetes/pkg/kubelet/apis/config" + "sigs.k8s.io/cluster-api-provider-docker/kind/constants" ) const ( @@ -52,7 +53,7 @@ func InitConfiguration(version, name, controlPlaneEndpoint string) ([]byte, erro }, }, LocalAPIEndpoint: kubeadmv1beta1.APIEndpoint{ - BindPort: int32(6443), + BindPort: int32(constants.APIServerPort), }, NodeRegistration: kubeadmv1beta1.NodeRegistrationOptions{ CRISocket: "/run/containerd/containerd.sock",