Fake out the kubernetes version in phase testing in order to avoid resolving…

Fake out the kubernetes version in phase testing in order to avoid resolving things manually (which can lead to flakes)
parent 9dc2e508
...@@ -38,14 +38,22 @@ func NewCmdCerts() *cobra.Command { ...@@ -38,14 +38,22 @@ func NewCmdCerts() *cobra.Command {
RunE: cmdutil.SubCmdRunE("certs"), RunE: cmdutil.SubCmdRunE("certs"),
} }
cmd.AddCommand(getCertsSubCommands()...) cmd.AddCommand(getCertsSubCommands("")...)
return cmd return cmd
} }
// getCertsSubCommands returns sub commands for certs phase // getCertsSubCommands returns sub commands for certs phase
func getCertsSubCommands() []*cobra.Command { func getCertsSubCommands(defaultKubernetesVersion string) []*cobra.Command {
cfg := &kubeadmapiext.MasterConfiguration{} cfg := &kubeadmapiext.MasterConfiguration{}
// This is used for unit testing only...
// If we wouldn't set this to something, the code would dynamically look up the version from the internet
// By setting this explicitely for tests workarounds that
if defaultKubernetesVersion != "" {
cfg.KubernetesVersion = defaultKubernetesVersion
}
// Default values for the cobra help text // Default values for the cobra help text
api.Scheme.Default(cfg) api.Scheme.Default(cfg)
......
...@@ -33,9 +33,12 @@ import ( ...@@ -33,9 +33,12 @@ import (
cmdtestutil "k8s.io/kubernetes/cmd/kubeadm/test/cmd" cmdtestutil "k8s.io/kubernetes/cmd/kubeadm/test/cmd"
) )
// phaseTestK8sVersion is a fake kubernetes version to use when testing
const phaseTestK8sVersion = "v1.8.0"
func TestCertsSubCommandsHasFlags(t *testing.T) { func TestCertsSubCommandsHasFlags(t *testing.T) {
subCmds := getCertsSubCommands() subCmds := getCertsSubCommands(phaseTestK8sVersion)
commonFlags := []string{ commonFlags := []string{
"cert-dir", "cert-dir",
...@@ -89,7 +92,7 @@ func TestCertsSubCommandsHasFlags(t *testing.T) { ...@@ -89,7 +92,7 @@ func TestCertsSubCommandsHasFlags(t *testing.T) {
func TestSubCmdCertsCreateFilesWithFlags(t *testing.T) { func TestSubCmdCertsCreateFilesWithFlags(t *testing.T) {
subCmds := getCertsSubCommands() subCmds := getCertsSubCommands(phaseTestK8sVersion)
var tests = []struct { var tests = []struct {
subCmds []string subCmds []string
...@@ -138,7 +141,7 @@ func TestSubCmdCertsCreateFilesWithFlags(t *testing.T) { ...@@ -138,7 +141,7 @@ func TestSubCmdCertsCreateFilesWithFlags(t *testing.T) {
func TestSubCmdCertsApiServerForwardsFlags(t *testing.T) { func TestSubCmdCertsApiServerForwardsFlags(t *testing.T) {
subCmds := getCertsSubCommands() subCmds := getCertsSubCommands(phaseTestK8sVersion)
// Create temp folder for the test case // Create temp folder for the test case
tmpdir := testutil.SetupTempDir(t) tmpdir := testutil.SetupTempDir(t)
...@@ -180,7 +183,7 @@ func TestSubCmdCertsApiServerForwardsFlags(t *testing.T) { ...@@ -180,7 +183,7 @@ func TestSubCmdCertsApiServerForwardsFlags(t *testing.T) {
func TestSubCmdCertsCreateFilesWithConfigFile(t *testing.T) { func TestSubCmdCertsCreateFilesWithConfigFile(t *testing.T) {
subCmds := getCertsSubCommands() subCmds := getCertsSubCommands(phaseTestK8sVersion)
var tests = []struct { var tests = []struct {
subCmds []string subCmds []string
......
...@@ -36,14 +36,22 @@ func NewCmdControlplane() *cobra.Command { ...@@ -36,14 +36,22 @@ func NewCmdControlplane() *cobra.Command {
} }
manifestPath := kubeadmconstants.GetStaticPodDirectory() manifestPath := kubeadmconstants.GetStaticPodDirectory()
cmd.AddCommand(getControlPlaneSubCommands(manifestPath)...) cmd.AddCommand(getControlPlaneSubCommands(manifestPath, "")...)
return cmd return cmd
} }
// getControlPlaneSubCommands returns sub commands for Controlplane phase // getControlPlaneSubCommands returns sub commands for Controlplane phase
func getControlPlaneSubCommands(outDir string) []*cobra.Command { func getControlPlaneSubCommands(outDir, defaultKubernetesVersion string) []*cobra.Command {
cfg := &kubeadmapiext.MasterConfiguration{} cfg := &kubeadmapiext.MasterConfiguration{}
// This is used for unit testing only...
// If we wouldn't set this to something, the code would dynamically look up the version from the internet
// By setting this explicitely for tests workarounds that
if defaultKubernetesVersion != "" {
cfg.KubernetesVersion = defaultKubernetesVersion
}
// Default values for the cobra help text // Default values for the cobra help text
api.Scheme.Default(cfg) api.Scheme.Default(cfg)
......
...@@ -30,7 +30,7 @@ import ( ...@@ -30,7 +30,7 @@ import (
func TestControlPlaneSubCommandsHasFlags(t *testing.T) { func TestControlPlaneSubCommandsHasFlags(t *testing.T) {
subCmds := getControlPlaneSubCommands("") subCmds := getControlPlaneSubCommands("", phaseTestK8sVersion)
commonFlags := []string{ commonFlags := []string{
"cert-dir", "cert-dir",
...@@ -137,7 +137,7 @@ func TestControlPlaneCreateFilesWithFlags(t *testing.T) { ...@@ -137,7 +137,7 @@ func TestControlPlaneCreateFilesWithFlags(t *testing.T) {
defer os.RemoveAll(tmpdir) defer os.RemoveAll(tmpdir)
// Get subcommands working in the temporary directory // Get subcommands working in the temporary directory
subCmds := getControlPlaneSubCommands(tmpdir) subCmds := getControlPlaneSubCommands(tmpdir, phaseTestK8sVersion)
// Execute the subcommand // Execute the subcommand
certDirFlag := fmt.Sprintf("--cert-dir=%s", tmpdir) certDirFlag := fmt.Sprintf("--cert-dir=%s", tmpdir)
......
...@@ -36,14 +36,22 @@ func NewCmdEtcd() *cobra.Command { ...@@ -36,14 +36,22 @@ func NewCmdEtcd() *cobra.Command {
} }
manifestPath := kubeadmconstants.GetStaticPodDirectory() manifestPath := kubeadmconstants.GetStaticPodDirectory()
cmd.AddCommand(getEtcdSubCommands(manifestPath)...) cmd.AddCommand(getEtcdSubCommands(manifestPath, "")...)
return cmd return cmd
} }
// getEtcdSubCommands returns sub commands for etcd phase // getEtcdSubCommands returns sub commands for etcd phase
func getEtcdSubCommands(outDir string) []*cobra.Command { func getEtcdSubCommands(outDir, defaultKubernetesVersion string) []*cobra.Command {
cfg := &kubeadmapiext.MasterConfiguration{} cfg := &kubeadmapiext.MasterConfiguration{}
// This is used for unit testing only...
// If we wouldn't set this to something, the code would dynamically look up the version from the internet
// By setting this explicitely for tests workarounds that
if defaultKubernetesVersion != "" {
cfg.KubernetesVersion = defaultKubernetesVersion
}
// Default values for the cobra help text // Default values for the cobra help text
api.Scheme.Default(cfg) api.Scheme.Default(cfg)
......
...@@ -30,7 +30,7 @@ import ( ...@@ -30,7 +30,7 @@ import (
func TestEtcdSubCommandsHasFlags(t *testing.T) { func TestEtcdSubCommandsHasFlags(t *testing.T) {
subCmds := getEtcdSubCommands("") subCmds := getEtcdSubCommands("", phaseTestK8sVersion)
commonFlags := []string{ commonFlags := []string{
"cert-dir", "cert-dir",
...@@ -73,7 +73,7 @@ func TestEtcdCreateFilesWithFlags(t *testing.T) { ...@@ -73,7 +73,7 @@ func TestEtcdCreateFilesWithFlags(t *testing.T) {
defer os.RemoveAll(tmpdir) defer os.RemoveAll(tmpdir)
// Get subcommands working in the temporary directory // Get subcommands working in the temporary directory
subCmds := getEtcdSubCommands(tmpdir) subCmds := getEtcdSubCommands(tmpdir, phaseTestK8sVersion)
// Execute the subcommand // Execute the subcommand
certDirFlag := fmt.Sprintf("--cert-dir=%s", tmpdir) certDirFlag := fmt.Sprintf("--cert-dir=%s", tmpdir)
......
...@@ -38,14 +38,22 @@ func NewCmdKubeConfig(out io.Writer) *cobra.Command { ...@@ -38,14 +38,22 @@ func NewCmdKubeConfig(out io.Writer) *cobra.Command {
RunE: cmdutil.SubCmdRunE("kubeconfig"), RunE: cmdutil.SubCmdRunE("kubeconfig"),
} }
cmd.AddCommand(getKubeConfigSubCommands(out, kubeadmconstants.KubernetesDir)...) cmd.AddCommand(getKubeConfigSubCommands(out, kubeadmconstants.KubernetesDir, "")...)
return cmd return cmd
} }
// getKubeConfigSubCommands returns sub commands for kubeconfig phase // getKubeConfigSubCommands returns sub commands for kubeconfig phase
func getKubeConfigSubCommands(out io.Writer, outDir string) []*cobra.Command { func getKubeConfigSubCommands(out io.Writer, outDir, defaultKubernetesVersion string) []*cobra.Command {
cfg := &kubeadmapiext.MasterConfiguration{} cfg := &kubeadmapiext.MasterConfiguration{}
// This is used for unit testing only...
// If we wouldn't set this to something, the code would dynamically look up the version from the internet
// By setting this explicitely for tests workarounds that
if defaultKubernetesVersion != "" {
cfg.KubernetesVersion = defaultKubernetesVersion
}
// Default values for the cobra help text // Default values for the cobra help text
api.Scheme.Default(cfg) api.Scheme.Default(cfg)
......
...@@ -38,7 +38,7 @@ import ( ...@@ -38,7 +38,7 @@ import (
func TestKubeConfigCSubCommandsHasFlags(t *testing.T) { func TestKubeConfigCSubCommandsHasFlags(t *testing.T) {
subCmds := getKubeConfigSubCommands(nil, "") subCmds := getKubeConfigSubCommands(nil, "", phaseTestK8sVersion)
commonFlags := []string{ commonFlags := []string{
"cert-dir", "cert-dir",
...@@ -174,7 +174,7 @@ func TestKubeConfigSubCommandsThatCreateFilesWithFlags(t *testing.T) { ...@@ -174,7 +174,7 @@ func TestKubeConfigSubCommandsThatCreateFilesWithFlags(t *testing.T) {
} }
// Get subcommands working in the temporary directory // Get subcommands working in the temporary directory
subCmds := getKubeConfigSubCommands(nil, tmpdir) subCmds := getKubeConfigSubCommands(nil, tmpdir, phaseTestK8sVersion)
// Execute the subcommand // Execute the subcommand
certDirFlag := fmt.Sprintf("--cert-dir=%s", pkidir) certDirFlag := fmt.Sprintf("--cert-dir=%s", pkidir)
...@@ -282,7 +282,7 @@ func TestKubeConfigSubCommandsThatCreateFilesWithConfigFile(t *testing.T) { ...@@ -282,7 +282,7 @@ func TestKubeConfigSubCommandsThatCreateFilesWithConfigFile(t *testing.T) {
cfgPath := testutil.SetupMasterConfigurationFile(t, tmpdir, cfg) cfgPath := testutil.SetupMasterConfigurationFile(t, tmpdir, cfg)
// Get subcommands working in the temporary directory // Get subcommands working in the temporary directory
subCmds := getKubeConfigSubCommands(nil, tmpdir) subCmds := getKubeConfigSubCommands(nil, tmpdir, phaseTestK8sVersion)
// Execute the subcommand // Execute the subcommand
configFlag := fmt.Sprintf("--config=%s", cfgPath) configFlag := fmt.Sprintf("--config=%s", cfgPath)
...@@ -354,7 +354,7 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) { ...@@ -354,7 +354,7 @@ func TestKubeConfigSubCommandsThatWritesToOut(t *testing.T) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
// Get subcommands working in the temporary directory // Get subcommands working in the temporary directory
subCmds := getKubeConfigSubCommands(buf, tmpdir) subCmds := getKubeConfigSubCommands(buf, tmpdir, phaseTestK8sVersion)
// Execute the subcommand // Execute the subcommand
allFlags := append(commonFlags, test.additionalFlags...) allFlags := append(commonFlags, test.additionalFlags...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment