Skip to content

Commit

Permalink
fix #1182 #1167
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Jul 1, 2021
1 parent 0f95aec commit ac79232
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
16 changes: 5 additions & 11 deletions internal/dao/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ func (c *CronJob) ScanSA(ctx context.Context, fqn string, wait bool) (Refs, erro

// ToggleSuspend toggles suspend/resume on a CronJob.
func (c *CronJob) ToggleSuspend(ctx context.Context, path string) error {
ns, _ := client.Namespaced(path)

ns, n := client.Namespaced(path)
auth, err := c.Client().CanI(cronJobGVR, ns, []string{client.GetVerb, client.UpdateVerb})
if err != nil {
return err
Expand All @@ -122,28 +121,23 @@ func (c *CronJob) ToggleSuspend(ctx context.Context, path string) error {
return fmt.Errorf("user is not authorized to run jobs")
}

o, err := c.Get(ctx, path)
dial, err := c.Client().Dial()
if err != nil {
return err
}
var cj batchv1.CronJob
err = runtime.DefaultUnstructuredConverter.FromUnstructured(o.(*unstructured.Unstructured).Object, &cj)
if err != nil {
return errors.New("expecting CronJob resource")
}

dial, err := c.Client().Dial()
cj, err := dial.BatchV1beta1().CronJobs(ns).Get(ctx, n, metav1.GetOptions{})
if err != nil {
return err
}

if cj.Spec.Suspend != nil {
current := !*cj.Spec.Suspend
cj.Spec.Suspend = &current
} else {
true := true
cj.Spec.Suspend = &true
}
_, err = dial.BatchV1().CronJobs(ns).Update(ctx, &cj, metav1.UpdateOptions{})
_, err = dial.BatchV1beta1().CronJobs(ns).Update(ctx, cj, metav1.UpdateOptions{})

return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/model/cluster_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (c *ClusterInfo) fetchK9sLatestRev() string {

latestRev, err := fetchLatestRev()
if err != nil {
log.Warn().Err(err).Msgf("k9s latest rev fetch failed")
log.Warn().Msgf("k9s latest rev fetch failed %s", err)
} else {
c.cache.Add(k9sLatestRevKey, latestRev, cacheExpiry)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/view/scale_extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *ScaleExtender) showScaleDialog(path string) {
s.App().Content.ShowPage(scaleDialogKey)
}

func (s *ScaleExtender) valueOf(col string, rowIndex int) (string, error) {
func (s *ScaleExtender) valueOf(col string) (string, error) {
colIdx, ok := s.GetTable().HeaderIndex(col)
if !ok {
return "", fmt.Errorf("no column index for %s", col)
Expand All @@ -74,7 +74,7 @@ func (s *ScaleExtender) valueOf(col string, rowIndex int) (string, error) {
func (s *ScaleExtender) makeScaleForm(sel string) (*tview.Form, error) {
f := s.makeStyledForm()

replicas, err := s.valueOf("READY", s.GetTable().GetSelectedRowIndex()-1)
replicas, err := s.valueOf("READY")
if err != nil {
return nil, err
}
Expand Down

0 comments on commit ac79232

Please sign in to comment.