2017-12-07 00:40:44 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/rancher/types/apis/management.cattle.io/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
TestKubeControllerClusterCidr = "10.0.0.0/16"
|
|
|
|
TestKubeControllerServiceClusterIPRange = "10.1.0.0/16"
|
|
|
|
TestKubeControllerImage = "rancher/k8s:latest"
|
2018-01-25 21:29:21 +00:00
|
|
|
TestKubeControllerVolumeBind = "/etc/kubernetes:/etc/kubernetes:z"
|
2017-12-07 00:40:44 +00:00
|
|
|
TestKubeControllerExtraArgs = "--foo=bar"
|
|
|
|
TestClusterCidrPrefix = "--cluster-cidr="
|
|
|
|
TestServiceIPRangePrefix = "--service-cluster-ip-range="
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestKubeControllerConfig(t *testing.T) {
|
|
|
|
|
|
|
|
kubeControllerService := v3.KubeControllerService{}
|
|
|
|
kubeControllerService.Image = TestKubeControllerImage
|
|
|
|
kubeControllerService.ClusterCIDR = TestKubeControllerClusterCidr
|
|
|
|
kubeControllerService.ServiceClusterIPRange = TestKubeControllerServiceClusterIPRange
|
|
|
|
kubeControllerService.ExtraArgs = map[string]string{"foo": "bar"}
|
|
|
|
|
2017-12-14 21:56:19 +00:00
|
|
|
imageCfg, hostCfg := buildKubeControllerConfig(kubeControllerService, "")
|
2017-12-07 00:40:44 +00:00
|
|
|
// Test image and host config
|
|
|
|
assertEqual(t, isStringInSlice(TestClusterCidrPrefix+TestKubeControllerClusterCidr, imageCfg.Entrypoint), true,
|
|
|
|
fmt.Sprintf("Failed to find [%s] in KubeController Command", TestClusterCidrPrefix+TestKubeControllerClusterCidr))
|
|
|
|
assertEqual(t, isStringInSlice(TestServiceIPRangePrefix+TestKubeControllerServiceClusterIPRange, imageCfg.Entrypoint), true,
|
|
|
|
fmt.Sprintf("Failed to find [%s] in KubeController Command", TestServiceIPRangePrefix+TestKubeControllerServiceClusterIPRange))
|
|
|
|
assertEqual(t, TestKubeControllerImage, imageCfg.Image,
|
|
|
|
fmt.Sprintf("Failed to verify [%s] as KubeController Image", TestKubeControllerImage))
|
|
|
|
assertEqual(t, isStringInSlice(TestKubeControllerVolumeBind, hostCfg.Binds), true,
|
|
|
|
fmt.Sprintf("Failed to find [%s] in volume binds of KubeController", TestKubeControllerVolumeBind))
|
|
|
|
assertEqual(t, isStringInSlice(TestKubeControllerExtraArgs, imageCfg.Entrypoint), true,
|
|
|
|
fmt.Sprintf("Failed to find [%s] in extra args of KubeController", TestKubeControllerExtraArgs))
|
|
|
|
assertEqual(t, true, hostCfg.NetworkMode.IsHost(), "")
|
|
|
|
}
|