From ce8b43441c2eb37012264c44bd1fe1cf7fb487ec Mon Sep 17 00:00:00 2001 From: wl-chen Date: Tue, 15 Mar 2022 18:33:08 +0800 Subject: [PATCH] fix(installer): helm uninstall chart after helm install chart wrong --- cmd/tke-installer/app/installer/installer.go | 33 +++++++++++++++++-- .../baremetal/phases/kubeadm/kubeadm.go | 3 +- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/cmd/tke-installer/app/installer/installer.go b/cmd/tke-installer/app/installer/installer.go index 6256bdb20..a69edee48 100644 --- a/cmd/tke-installer/app/installer/installer.go +++ b/cmd/tke-installer/app/installer/installer.go @@ -1583,12 +1583,21 @@ func (t *TKE) installTKEGatewayChart(ctx context.Context) error { ReleaseName: "tke-gateway", DependencyUpdate: false, Values: values, - Timeout: 60 * time.Second, + Timeout: 10 * time.Minute, ChartPathOptions: *chartPathOptions, } chartFilePath := constants.ChartDirName + "tke-gateway/" if _, err := t.helmClient.InstallWithLocal(installOptions, chartFilePath); err != nil { + uninstallOptions := helmaction.UninstallOptions{ + Timeout: 10 * time.Minute, + ReleaseName: "tke-gateway", + Namespace: t.namespace, + } + reponse, err := t.helmClient.Uninstall(&uninstallOptions) + if err != nil { + return fmt.Errorf("%s uninstall fail, err = %s", reponse.Release.Name, err.Error()) + } return err } @@ -1699,12 +1708,21 @@ func (t *TKE) installTKEAuthChart(ctx context.Context) error { ReleaseName: "tke-auth", DependencyUpdate: false, Values: values, - Timeout: 60 * time.Second, + Timeout: 10 * time.Minute, ChartPathOptions: *chartPathOptions, } chartFilePath := constants.ChartDirName + "tke-auth/" if _, err := t.helmClient.InstallWithLocal(installOptions, chartFilePath); err != nil { + uninstallOptions := helmaction.UninstallOptions{ + Timeout: 10 * time.Minute, + ReleaseName: "tke-auth", + Namespace: t.namespace, + } + reponse, err := t.helmClient.Uninstall(&uninstallOptions) + if err != nil { + return fmt.Errorf("%s uninstall fail, err = %s", reponse.Release.Name, err.Error()) + } return err } @@ -1811,12 +1829,21 @@ func (t *TKE) installTKEPlatformChart(ctx context.Context) error { ReleaseName: "tke-platform", DependencyUpdate: false, Values: values, - Timeout: 60 * time.Second, + Timeout: 10 * time.Minute, ChartPathOptions: *chartPathOptions, } chartFilePath := constants.ChartDirName + "tke-platform/" if _, err := t.helmClient.InstallWithLocal(installOptions, chartFilePath); err != nil { + uninstallOptions := helmaction.UninstallOptions{ + Timeout: 10 * time.Minute, + ReleaseName: "tke-platform", + Namespace: t.namespace, + } + reponse, err := t.helmClient.Uninstall(&uninstallOptions) + if err != nil { + return fmt.Errorf("%s uninstall fail, err = %s", reponse.Release.Name, err.Error()) + } return err } diff --git a/pkg/platform/provider/baremetal/phases/kubeadm/kubeadm.go b/pkg/platform/provider/baremetal/phases/kubeadm/kubeadm.go index 29ba45916..4d9df411a 100644 --- a/pkg/platform/provider/baremetal/phases/kubeadm/kubeadm.go +++ b/pkg/platform/provider/baremetal/phases/kubeadm/kubeadm.go @@ -86,7 +86,8 @@ func Install(s ssh.Interface, option *Option) error { cmd := "tar -C %s -xvaf %s %s --strip-components=3" _, stderr, exit, err := s.Execf(cmd, constants.DstBinDir, dstFile, constants.KubeadmPathInNodePackge) if err != nil || exit != 0 { - return fmt.Errorf("exec %q failed:exit %d:stderr %s:error %s", cmd, exit, stderr, err) + cmdStr := fmt.Sprintf(cmd, constants.DstBinDir, dstFile, constants.KubeadmPathInNodePackge) + return fmt.Errorf("exec %q failed:exit %d:stderr %s:error %s", cmdStr, exit, stderr, err.Error()) } data, err := template.ParseFile(path.Join(constants.ConfDir, "kubeadm/10-kubeadm.conf"), option)