diff --git a/internal/cli/cmd/cluster/delete.go b/internal/cli/cmd/cluster/delete.go index c557b2cf2..fcc0718a5 100644 --- a/internal/cli/cmd/cluster/delete.go +++ b/internal/cli/cmd/cluster/delete.go @@ -36,7 +36,7 @@ func NewDeleteCmd() *cobra.Command { if err != nil { logger.Fatalln(err) } - logger.Printf("Delete ob cluster %s success", o.Name) + logger.Printf("Delete ob cluster %s successfully", o.Name) }, } o.AddFlags(cmd) diff --git a/internal/cli/cmd/cluster/scale.go b/internal/cli/cmd/cluster/scale.go index 2ff0d4d56..0d320ee3a 100644 --- a/internal/cli/cmd/cluster/scale.go +++ b/internal/cli/cmd/cluster/scale.go @@ -51,7 +51,7 @@ func NewScaleCmd() *cobra.Command { if _, err = clients.CreateOBClusterOperation(cmd.Context(), op); err != nil { logger.Fatalln(err) } - logger.Printf("Create scale operation for obcluster %s success", op.Spec.OBCluster) + logger.Printf("Create scale operation for obcluster %s successfully", op.Spec.OBCluster) }, } o.AddFlags(cmd) diff --git a/internal/cli/cmd/cluster/show.go b/internal/cli/cmd/cluster/show.go index c5e2d5eed..aba1bb963 100644 --- a/internal/cli/cmd/cluster/show.go +++ b/internal/cli/cmd/cluster/show.go @@ -38,7 +38,7 @@ func NewShowCmd() *cobra.Command { if err != nil { logger.Fatalln(err) } - obclusterOperation, err := clients.GetOBClusterOperations(cmd.Context(), obcluster) + obclusterOperationList, err := clients.GetOBClusterOperations(cmd.Context(), obcluster) if err != nil { logger.Fatalln(err) } @@ -57,12 +57,12 @@ func NewShowCmd() *cobra.Command { } } - if len(obclusterOperation.Items) > 0 { - sort.Slice(obclusterOperation.Items, func(i, j int) bool { - return obclusterOperation.Items[i].Name < obclusterOperation.Items[j].Name + if len(obclusterOperationList.Items) > 0 { + sort.Slice(obclusterOperationList.Items, func(i, j int) bool { + return obclusterOperationList.Items[i].Name < obclusterOperationList.Items[j].Name }) tbLog.Println("OPERATION TYPE \t TTLDAYS \t STATUS \t CREATETIME") - for _, op := range obclusterOperation.Items { + for _, op := range obclusterOperationList.Items { tbLog.Printf("%s \t %d \t %s \t %s\n", op.Spec.Type, op.Spec.TTLDays, op.Status.Status, op.CreationTimestamp) } } else { diff --git a/internal/cli/cmd/cluster/update.go b/internal/cli/cmd/cluster/update.go index ceb33048e..efb9b2cd7 100644 --- a/internal/cli/cmd/cluster/update.go +++ b/internal/cli/cmd/cluster/update.go @@ -50,7 +50,7 @@ func NewUpdateCmd() *cobra.Command { if _, err = clients.CreateOBClusterOperation(cmd.Context(), op); err != nil { logger.Fatalln(err) } - logger.Printf("Create update operation for obcluster %s success", op.Spec.OBCluster) + logger.Printf("Create update operation for obcluster %s successfully", op.Spec.OBCluster) }, } o.AddFlags(cmd) diff --git a/internal/cli/cmd/cluster/upgrade.go b/internal/cli/cmd/cluster/upgrade.go index e203cefac..3e570d06b 100644 --- a/internal/cli/cmd/cluster/upgrade.go +++ b/internal/cli/cmd/cluster/upgrade.go @@ -47,7 +47,7 @@ func NewUpgradeCmd() *cobra.Command { if _, err = clients.CreateOBClusterOperation(cmd.Context(), op); err != nil { logger.Fatalln(err) } - logger.Printf("Create upgrade operation for obcluster %s success", op.Spec.OBCluster) + logger.Printf("Create upgrade operation for obcluster %s successfully", op.Spec.OBCluster) }, } o.AddFlags(cmd) diff --git a/internal/cli/cmd/tenant/activate.go b/internal/cli/cmd/tenant/activate.go index 90d03f8b5..bf8248320 100644 --- a/internal/cli/cmd/tenant/activate.go +++ b/internal/cli/cmd/tenant/activate.go @@ -53,7 +53,7 @@ func NewActivateCmd() *cobra.Command { if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil { logger.Fatalln(err) } - logger.Printf("Create activate operation for tenant %s success", o.Name) + logger.Printf("Create activate operation for tenant %s successfully", o.Name) }, } o.AddFlags(cmd) diff --git a/internal/cli/cmd/tenant/changepwd.go b/internal/cli/cmd/tenant/changepwd.go index 948afae26..2bb05304d 100644 --- a/internal/cli/cmd/tenant/changepwd.go +++ b/internal/cli/cmd/tenant/changepwd.go @@ -54,7 +54,7 @@ func NewChangePwdCmd() *cobra.Command { if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil { logger.Fatalln(err) } - logger.Printf("Create changepwd operation for obtenant %s success", o.Name) + logger.Printf("Create changepwd operation for obtenant %s successfully", o.Name) }, } o.AddFlags(cmd) diff --git a/internal/cli/cmd/tenant/delete.go b/internal/cli/cmd/tenant/delete.go index 655d2893e..0f3b53b61 100644 --- a/internal/cli/cmd/tenant/delete.go +++ b/internal/cli/cmd/tenant/delete.go @@ -40,7 +40,7 @@ func NewDeleteCmd() *cobra.Command { if err != nil { logger.Fatalln(err) } - logger.Printf("Delete ob tenant %s success", o.Name) + logger.Printf("Delete ob tenant %s successfully", o.Name) }, } o.AddFlags(cmd) diff --git a/internal/cli/cmd/tenant/replaylog.go b/internal/cli/cmd/tenant/replaylog.go index 63f41b092..5ef8a1c23 100644 --- a/internal/cli/cmd/tenant/replaylog.go +++ b/internal/cli/cmd/tenant/replaylog.go @@ -51,7 +51,7 @@ func NewReplayLogCmd() *cobra.Command { if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil { logger.Fatalln(err) } - logger.Printf("Create replay log operation of tenant %s success", o.Name) + logger.Printf("Create replay log operation of tenant %s successfully", o.Name) }, } o.AddFlags(cmd) diff --git a/internal/cli/cmd/tenant/scale.go b/internal/cli/cmd/tenant/scale.go index 9b9208fde..95a36bb83 100644 --- a/internal/cli/cmd/tenant/scale.go +++ b/internal/cli/cmd/tenant/scale.go @@ -55,7 +55,7 @@ func NewScaleCmd() *cobra.Command { if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil { logger.Fatalln(err) } - logger.Printf("Create scale operation for obtenant %s success", o.Name) + logger.Printf("Create scale operation for obtenant %s successfully", o.Name) }, } o.AddFlags(cmd) diff --git a/internal/cli/cmd/tenant/show.go b/internal/cli/cmd/tenant/show.go index d85df6c71..182954d54 100644 --- a/internal/cli/cmd/tenant/show.go +++ b/internal/cli/cmd/tenant/show.go @@ -42,7 +42,7 @@ func NewShowCmd() *cobra.Command { if err != nil { logger.Fatalln(err) } - obtenantOperation, err := clients.GetOBTenantOperations(cmd.Context(), obtenant) + obtenantOperationList, err := clients.GetOBTenantOperations(cmd.Context(), obtenant) if err != nil { logger.Fatalln(err) } @@ -54,12 +54,12 @@ func NewShowCmd() *cobra.Command { tbLog.Printf("%s \t %d \t %d\n\n", pool.ZoneList, pool.UnitNumber, pool.Priority) } } - if len(obtenantOperation.Items) > 0 { - sort.Slice(obtenantOperation.Items, func(i, j int) bool { - return obtenantOperation.Items[i].Name < obtenantOperation.Items[j].Name + if len(obtenantOperationList.Items) > 0 { + sort.Slice(obtenantOperationList.Items, func(i, j int) bool { + return obtenantOperationList.Items[i].Name < obtenantOperationList.Items[j].Name }) tbLog.Println("OPERATION TYPE \t STATUS \t CREATETIME") - for _, op := range obtenantOperation.Items { + for _, op := range obtenantOperationList.Items { tbLog.Printf("%s \t %s \t %s\n", op.Spec.Type, op.Status.Status, op.CreationTimestamp) } } else { diff --git a/internal/cli/cmd/tenant/switchover.go b/internal/cli/cmd/tenant/switchover.go index 098dfaef3..81658305a 100644 --- a/internal/cli/cmd/tenant/switchover.go +++ b/internal/cli/cmd/tenant/switchover.go @@ -66,7 +66,7 @@ func NewSwitchOverCmd() *cobra.Command { if _, err := clients.CreateOBTenantOperation(cmd.Context(), op); err != nil { logger.Fatalln(err) } - logger.Printf("Create switchover operation for primary tenant %s and standby tenant %s success", o.PrimaryTenant, o.StandbyTenant) + logger.Printf("Create switchover operation for primary tenant %s and standby tenant %s successfully", o.PrimaryTenant, o.StandbyTenant) }, } o.AddFlags(cmd) diff --git a/internal/cli/cmd/tenant/update.go b/internal/cli/cmd/tenant/update.go index 47abb80cd..ef14efc9b 100644 --- a/internal/cli/cmd/tenant/update.go +++ b/internal/cli/cmd/tenant/update.go @@ -29,7 +29,7 @@ func NewUpdateCmd() *cobra.Command { cmd := &cobra.Command{ Use: "update ", Short: "Update ob tenant", - Long: "Update ob tenant, support unitNumber/charset/connectWhiteList/priority of zones", + Long: "Update ob tenant, support unitNumber/connectWhiteList/priority of zones", Args: cobra.ExactArgs(1), Aliases: []string{"ud"}, PreRunE: o.Parse, @@ -56,7 +56,7 @@ func NewUpdateCmd() *cobra.Command { if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil { logger.Fatalln(err) } - logger.Printf("Create update operation for obtenant %s success", o.Name) + logger.Printf("Create update operation for obtenant %s successfully", o.Name) }, } o.AddFlags(cmd) diff --git a/internal/cli/cmd/tenant/upgrade.go b/internal/cli/cmd/tenant/upgrade.go index 75349df39..3f8a25f22 100644 --- a/internal/cli/cmd/tenant/upgrade.go +++ b/internal/cli/cmd/tenant/upgrade.go @@ -51,7 +51,7 @@ func NewUpgradeCmd() *cobra.Command { if _, err = clients.CreateOBTenantOperation(cmd.Context(), op); err != nil { logger.Fatalln(err) } - logger.Printf("Create upgrade operation for obtenant %s success", o.Name) + logger.Printf("Create upgrade operation for obtenant %s successfully", o.Name) }, } o.AddFlags(cmd) diff --git a/internal/cli/tenant/activate.go b/internal/cli/tenant/activate.go index 4fe2ae64e..85ada0937 100644 --- a/internal/cli/tenant/activate.go +++ b/internal/cli/tenant/activate.go @@ -36,7 +36,7 @@ func NewActivateOptions() *ActivateOptions { func GetActivateOperation(o *ActivateOptions) *v1alpha1.OBTenantOperation { activateOp := &v1alpha1.OBTenantOperation{ ObjectMeta: v1.ObjectMeta{ - Name: o.Name + "-change-role-" + rand.String(6), + Name: o.Name + "-activate-" + rand.String(6), Namespace: o.Namespace, Labels: map[string]string{oceanbaseconst.LabelRefOBTenantOp: o.Name}, }, diff --git a/internal/cli/tenant/switchover.go b/internal/cli/tenant/switchover.go index 2b3b55949..da1d7bd24 100644 --- a/internal/cli/tenant/switchover.go +++ b/internal/cli/tenant/switchover.go @@ -44,7 +44,7 @@ func (o *SwitchOverOptions) Parse(_ *cobra.Command, args []string) error { func GetSwitchOverOperation(o *SwitchOverOptions) *v1alpha1.OBTenantOperation { switchOverOp := &v1alpha1.OBTenantOperation{ ObjectMeta: v1.ObjectMeta{ - Name: o.PrimaryTenant + "-change-role-" + rand.String(6), + Name: o.PrimaryTenant + "-switchover-" + rand.String(6), Namespace: o.Namespace, Labels: map[string]string{oceanbaseconst.LabelRefOBTenantOp: o.PrimaryTenant}, }, diff --git a/internal/cli/utils/utils.go b/internal/cli/utils/utils.go index 82545662e..79aa7a2ea 100644 --- a/internal/cli/utils/utils.go +++ b/internal/cli/utils/utils.go @@ -60,12 +60,7 @@ func GenerateClusterID() int64 { // CheckResourceName checks resource name in k8s func CheckResourceName(name string) bool { regex := `[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*` - - re, err := regexp.Compile(regex) - if err != nil { - panic("error when compiling regex expressions") - } - + re := regexp.MustCompile(regex) return re.MatchString(name) } @@ -104,12 +99,7 @@ func CheckPassword(password string) bool { // CheckTenantName check Tenant name when creating tenant func CheckTenantName(name string) bool { regex := `^[_a-zA-Z][^-]*$` - - re, err := regexp.Compile(regex) - if err != nil { - panic("error when compiling regex expressions") - } - + re := regexp.MustCompile(regex) return re.MatchString(name) }