refactor: optimize code

This commit is contained in:
naison
2025-03-07 02:53:52 +00:00
parent ae9c23550f
commit 210767d908
2 changed files with 9 additions and 3 deletions

View File

@@ -44,10 +44,10 @@ func CmdUpgrade(_ cmdutil.Factory) *cobra.Command {
return err
}
if !needsUpgrade {
_, _ = fmt.Fprintf(os.Stdout, "Already up to date, don't needs to upgrade, version: %s", latestVersion)
_, _ = fmt.Fprintln(os.Stdout, fmt.Sprintf("Already up to date, don't needs to upgrade, version: %s", latestVersion))
return nil
}
_, _ = fmt.Fprintf(os.Stdout, "Current version is: %s less than latest version: %s, needs to upgrade", config.Version, latestVersion)
_, _ = fmt.Fprintln(os.Stdout, fmt.Sprintf("Current version is: %s less than latest version: %s, needs to upgrade", config.Version, latestVersion))
_ = os.Setenv(envLatestUrl, url)
_ = quit(cmd.Context(), false)
_ = quit(cmd.Context(), true)

View File

@@ -103,7 +103,10 @@ func (m *Mapper) Run() {
var lastLocalPort2EnvoyRulePort map[int32]int32
for m.ctx.Err() == nil {
localPort2EnvoyRulePort, err := m.getLocalPort2EnvoyRulePort()
if err != nil && errors.Is(err, context.Canceled) {
if err != nil {
if errors.Is(err, context.Canceled) {
continue
}
logrus.Errorf("failed to get local port to envoy rule port: %v", err)
time.Sleep(time.Second * 2)
continue
@@ -119,6 +122,9 @@ func (m *Mapper) Run() {
list, err := util.GetRunningPodList(m.ctx, m.clientset, m.ns, m.labels)
if err != nil {
if errors.Is(err, context.Canceled) {
continue
}
logrus.Errorf("failed to list running pod: %v", err)
time.Sleep(time.Second * 2)
continue