Skip to content

Commit

Permalink
avoid hardcoding port in clusterclient.go (kubernetes-sigs#734)
Browse files Browse the repository at this point in the history
In clusterclient.go client.UpdateClusterObjectEndpoint checks if the value
fetched from the provider is in the host:port format, if no port is present
appends the default API server port (443).

Fixes: kubernetes-sigs#559
  • Loading branch information
frapposelli authored and k8s-ci-robot committed Feb 7, 2019
1 parent 7704642 commit 9153bcf
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions cmd/clusterctl/clusterdeployer/clusterclient/clusterclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package clusterclient

import (
"io/ioutil"
"net"
"os"
"os/exec"
"strconv"
"strings"
"sync"
"time"
Expand All @@ -37,7 +39,7 @@ import (
)

const (
apiServerPort = 443
defaultAPIServerPort = "443"
retryIntervalKubectlApply = 10 * time.Second
retryIntervalResourceReady = 10 * time.Second
retryIntervalResourceDelete = 10 * time.Second
Expand Down Expand Up @@ -405,16 +407,29 @@ func newDeleteOptions() *metav1.DeleteOptions {
}
}

// UpdateClusterObjectEndpoint updates the status of a cluster API endpoint, clusterEndpoint
// can be passed as hostname or hostname:port, if port is not present the default port 443 is applied.
// TODO: Test this function
func (c *client) UpdateClusterObjectEndpoint(controlPlaneIP, clusterName, namespace string) error {
func (c *client) UpdateClusterObjectEndpoint(clusterEndpoint, clusterName, namespace string) error {
cluster, err := c.GetClusterObject(clusterName, namespace)
if err != nil {
return err
}
endpointHost, endpointPort, err := net.SplitHostPort(clusterEndpoint)
if err != nil {
// We rely on provider.GetControlPlaneEndpoint to provide a correct hostname/IP, no
// further validation is done.
endpointHost = clusterEndpoint
endpointPort = defaultAPIServerPort
}
endpointPortInt, err := strconv.Atoi(endpointPort)
if err != nil {
return errors.Wrapf(err, "error while converting cluster endpoint port %q", endpointPort)
}
cluster.Status.APIEndpoints = append(cluster.Status.APIEndpoints,
clusterv1.APIEndpoint{
Host: controlPlaneIP,
Port: apiServerPort,
Host: endpointHost,
Port: endpointPortInt,
})
_, err = c.clientSet.ClusterV1alpha1().Clusters(namespace).UpdateStatus(cluster)
return err
Expand Down

0 comments on commit 9153bcf

Please sign in to comment.