From b21cfdcd0f5a9d10464d7a19a0a14bb365197737 Mon Sep 17 00:00:00 2001 From: Irfan Ur Rehman Date: Tue, 15 Nov 2016 17:48:42 +0530 Subject: [PATCH] [Federation] Review comments fixed for dry run support in kubefed init --- federation/pkg/kubefed/init/init.go | 10 +++------- federation/pkg/kubefed/init/init_test.go | 13 ++++++------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/federation/pkg/kubefed/init/init.go b/federation/pkg/kubefed/init/init.go index 595a917a1bf..a07a26786ab 100644 --- a/federation/pkg/kubefed/init/init.go +++ b/federation/pkg/kubefed/init/init.go @@ -230,10 +230,9 @@ func initFederation(cmdOut io.Writer, config util.AdminConfig, cmd *cobra.Comman if !dryRun { return printSuccess(cmdOut, ips, hostnames) - } else { - _, err := fmt.Fprintf(cmdOut, "Federation control plane runs (dry run)\n") - return err } + _, err = fmt.Fprintf(cmdOut, "Federation control plane runs (dry run)\n") + return err } func createNamespace(clientset *client.Clientset, namespace string, dryRun bool) (*api.Namespace, error) { @@ -374,10 +373,7 @@ func createControllerManagerKubeconfigSecret(clientset *client.Clientset, namesp certutil.EncodeCertPEM(entKeyPairs.controllerManager.Cert), ) - if dryRun { - return nil, nil - } - return util.CreateKubeconfigSecret(clientset, config, namespace, kubeconfigName, false) + return util.CreateKubeconfigSecret(clientset, config, namespace, kubeconfigName, dryRun) } func createPVC(clientset *client.Clientset, namespace, svcName, etcdPVCapacity string, dryRun bool) (*api.PersistentVolumeClaim, error) { diff --git a/federation/pkg/kubefed/init/init_test.go b/federation/pkg/kubefed/init/init_test.go index a22d7c9a17e..c8b9ce4e32c 100644 --- a/federation/pkg/kubefed/init/init_test.go +++ b/federation/pkg/kubefed/init/init_test.go @@ -147,13 +147,13 @@ func TestInitFederation(t *testing.T) { cmd.Flags().Set("host-cluster-context", "substrate") cmd.Flags().Set("dns-zone-name", tc.dnsZoneName) cmd.Flags().Set("image", tc.image) - if "" != tc.dnsProvider { + if tc.dnsProvider != "" { cmd.Flags().Set("dns-provider", tc.dnsProvider) } - if "" != tc.etcdPVCapacity { + if tc.etcdPVCapacity != "" { cmd.Flags().Set("etcd-pv-capacity", tc.etcdPVCapacity) } - if "valid-run" == tc.dryRun { + if tc.dryRun == "valid-run" { cmd.Flags().Set("dry-run", "true") } @@ -163,12 +163,11 @@ func TestInitFederation(t *testing.T) { // uses the name from the federation, not the response // Actual data passed are tested in the fake secret and cluster // REST clients. - want := "" - if "" != tc.dryRun { + want := fmt.Sprintf("Federation API server is running at: %s\n", tc.lbIP) + if tc.dryRun != "" { want = fmt.Sprintf("Federation control plane runs (dry run)\n") - } else { - want = fmt.Sprintf("Federation API server is running at: %s\n", tc.lbIP) } + if got := buf.String(); got != want { t.Errorf("[%d] unexpected output: got: %s, want: %s", i, got, want) if cmdErrMsg != "" {