Skip to content

Commit

Permalink
Merge pull request kubernetes#510 from mm4tt/internal_master_ip
Browse files Browse the repository at this point in the history
Set MasterInternalIp in completeConfig if not set.
  • Loading branch information
k8s-ci-robot committed Apr 23, 2019
2 parents dd8f482 + 777f699 commit 3ef6f3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 12 additions & 2 deletions clusterloader2/cmd/clusterloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
ginkgoconfig "github.com/onsi/ginkgo/config"
ginkgoreporters "github.com/onsi/ginkgo/reporters"
ginkgotypes "github.com/onsi/ginkgo/types"
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/klog"
"k8s.io/perf-tests/clusterloader2/pkg/config"
Expand Down Expand Up @@ -112,12 +113,21 @@ func completeConfig(m *framework.MultiClientSet) error {
}
}
if clusterLoaderConfig.ClusterConfig.MasterIP == "" {
masterIP, err := util.GetMasterExternalIP(m.GetClient())
masterIP, err := util.GetMasterIP(m.GetClient(), corev1.NodeExternalIP)
if err == nil {
clusterLoaderConfig.ClusterConfig.MasterIP = masterIP
klog.Infof("ClusterConfig.MasterIP set to %v", masterIP)
} else {
klog.Errorf("Getting master ip error: %v", err)
klog.Errorf("Getting master external ip error: %v", err)
}
}
if clusterLoaderConfig.ClusterConfig.MasterInternalIP == "" {
masterIP, err := util.GetMasterIP(m.GetClient(), corev1.NodeInternalIP)
if err == nil {
clusterLoaderConfig.ClusterConfig.MasterInternalIP = masterIP
klog.Infof("ClusterConfig.MasterInternalIP set to %v", masterIP)
} else {
klog.Errorf("Getting master internal ip error: %v", err)
}
}
return nil
Expand Down
8 changes: 4 additions & 4 deletions clusterloader2/pkg/util/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,20 @@ func GetMasterName(c clientset.Interface) (string, error) {
return "", fmt.Errorf("master node not found")
}

// GetMasterExternalIP returns master node external ip.
func GetMasterExternalIP(c clientset.Interface) (string, error) {
// GetMasterIP returns master node ip of the given type.
func GetMasterIP(c clientset.Interface, addressType corev1.NodeAddressType) (string, error) {
nodeList, err := client.ListNodes(c)
if err != nil {
return "", err
}
for i := range nodeList {
if system.IsMasterNode(nodeList[i].Name) {
for _, address := range nodeList[i].Status.Addresses {
if address.Type == corev1.NodeExternalIP {
if address.Type == addressType && address.Address != "" {
return address.Address, nil
}
}
return "", fmt.Errorf("extrnal IP of the master not found")
return "", fmt.Errorf("%s IP of the master not found", addressType)
}
}
return "", fmt.Errorf("master node not found")
Expand Down

0 comments on commit 3ef6f3c

Please sign in to comment.