From 62272ed900cfbb1b235f08bf29e246771170f95e Mon Sep 17 00:00:00 2001 From: bijayasharma Date: Fri, 5 Feb 2021 13:53:07 -0500 Subject: [PATCH] Added a warning message that cluster api already initialized * Currently if the cluster init command is run & the cluster-api has already been initialized, the command fails. * So,this commit adds a warning message that cluster-api already initialized. Signed-off-by: bijayasharma Change-Id: I93cc6b141c15fa4bc5661646ae0cbdf08580cbf9 Relates-To: #450 Closes: #450 --- pkg/phase/executors/clusterctl.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/phase/executors/clusterctl.go b/pkg/phase/executors/clusterctl.go index c4f6d1261..410fc6243 100755 --- a/pkg/phase/executors/clusterctl.go +++ b/pkg/phase/executors/clusterctl.go @@ -16,6 +16,7 @@ package executors import ( "bytes" + "fmt" "io" "strings" @@ -147,18 +148,27 @@ func (c *ClusterctlExecutor) init(opts ifc.RunOptions, evtCh chan events.Event) return } + eventMsg := "clusterctl init completed successfully" + // Use cluster name as context in kubeconfig file err = c.Init(kubeConfigFile, context) - if err != nil { + if err != nil && isAlreadyExistsError(err) { + // log the already existed/initialized error as warning and continue + eventMsg = fmt.Sprintf("WARNING: clusterctl is already initialized, received an error : %s", err.Error()) + } else if err != nil { handleError(evtCh, err) return } evtCh <- events.NewEvent().WithClusterctlEvent(events.ClusterctlEvent{ Operation: events.ClusterctlInitEnd, - Message: "clusterctl init completed successfully", + Message: eventMsg, }) } +func isAlreadyExistsError(err error) bool { + return strings.Contains(err.Error(), "there is already an instance") +} + // Validate executor configuration and documents func (c *ClusterctlExecutor) Validate() error { return errors.ErrNotImplemented{}