From a99c4fa5c9add5deaccacadf31a1f0fb21e77ad3 Mon Sep 17 00:00:00 2001 From: powerfool Date: Tue, 14 May 2024 16:34:22 +0800 Subject: [PATCH] Fixed version check method for legacy compat (#367) --- internal/resource/obcluster/obcluster_task.go | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/internal/resource/obcluster/obcluster_task.go b/internal/resource/obcluster/obcluster_task.go index a55096039..17ef219e3 100644 --- a/internal/resource/obcluster/obcluster_task.go +++ b/internal/resource/obcluster/obcluster_task.go @@ -834,18 +834,51 @@ outerLoop: func CheckClusterMode(m *OBClusterManager) tasktypes.TaskError { modeAnnoVal, modeAnnoExist := resourceutils.GetAnnotationField(m.OBCluster, oceanbaseconst.AnnotationsMode) if modeAnnoExist { - version, _, err := resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace, + versionOutput, _, err := resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace, m.OBCluster.Name+"-get-version", m.OBCluster.Spec.OBServerTemplate.Image, "/home/admin/oceanbase/bin/oceanbase-helper version", ) if err != nil { - return errors.Wrap(err, "Run service mode validate job failed") + // Make compatible with legacy version in which there is no `version` command + var code int32 + switch modeAnnoVal { + case oceanbaseconst.ModeStandalone: + _, code, err = resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace, + m.OBCluster.Name+"-standalone-validate", + m.OBCluster.Spec.OBServerTemplate.Image, + "/home/admin/oceanbase/bin/oceanbase-helper standalone validate", + ) + case oceanbaseconst.ModeService: + _, code, err = resourceutils.RunJob(m.Ctx, m.Client, m.Logger, m.OBCluster.Namespace, + m.OBCluster.Name+"-service-validate", + m.OBCluster.Spec.OBServerTemplate.Image, + "/home/admin/oceanbase/bin/oceanbase-helper service validate", + ) + } + if err != nil && code > 1 { + return errors.Wrap(err, "Failed to run service mode validate job") + } + return nil + } + var version string + lines := strings.Split(versionOutput, "\n") + if len(lines) == 0 { + m.Logger.Info("Get version failed") + return nil + } + if len(lines) > 3 { + versionStr := strings.Split(lines[1], " ") + semVer := versionStr[len(versionStr)-1] + releaseStr := strings.Split(strings.Split(lines[3], " ")[1], "-")[0] + version = fmt.Sprintf("%s-%s", semVer[0:len(semVer)-1], releaseStr) + } else { + version = strings.TrimSpace(lines[0]) } - version = strings.TrimSpace(version) currentVersion, err := helper.ParseOceanBaseVersion(version) if err != nil { - return errors.Wrap(err, "Parse current version") + m.Logger.WithValues("version", version, "err", err.Error()).Info("Failed to parse current version") + return nil } switch modeAnnoVal { case oceanbaseconst.ModeStandalone: