Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial fixes #2

Merged
merged 2 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ lint: ## Runs linter

.PHONY: vet
vet: ## Runs go vet
@go vet ${PKGS}
@go vet -composites=false ${PKGS}

.PHONY: clean
clean: ## Removes build artifacts
Expand All @@ -43,4 +43,3 @@ bin/ctl: ## Make a link to the executable for this OS type for convenience
.PHONY: test
test: ## Runs go tests on all subdirs
@go test -coverprofile coverage.txt -covermode=atomic ./...

9 changes: 4 additions & 5 deletions cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package cmd

import (
"errors"
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/util/parsing"
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
)

func GetDescribeCmd(c *client.Client) *cobra.Command {
func describeCmd(c *client.Client) *cobra.Command {
return &cobra.Command{
Use: "describe pods [flags]",
Short: "Show details of a specific pod(s)",
Expand All @@ -28,10 +28,9 @@ If context(s) not specified, it will search through all contexts.`,
return err
}
if len(pods) == 0 {
return errors.New("Could not find any matching pods!")
} else {
describePodList(pods)
return errors.New("could not find any matching pods")
}
describePodList(pods)
return nil
},
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestDescribeSingle(t *testing.T) {

cl := client.GetFakeConfigClient(map[string][]runtime.Object{"hi": []runtime.Object{pod.DeepCopyObject()}})

cmd := GetDescribeCmd(cl)
cmd := describeCmd(cl)
cmd.Flags().StringSliceP("context", "x", nil, "Context")
cmd.SetArgs([]string{"test"})

Expand All @@ -47,7 +47,7 @@ func TestDescribeBadContext(t *testing.T) {

cl := client.GetFakeConfigClient(map[string][]runtime.Object{"hi": []runtime.Object{pod.DeepCopyObject()}})

cmd := GetDescribeCmd(cl)
cmd := describeCmd(cl)
cmd.Flags().StringSliceP("context", "x", nil, "Context")
cmd.SetArgs([]string{"test", "--context=wow"})

Expand All @@ -74,7 +74,7 @@ func TestDescribeUnfound(t *testing.T) {

cl := client.GetFakeConfigClient(map[string][]runtime.Object{"hi": []runtime.Object{pod.DeepCopyObject()}})

cmd := GetDescribeCmd(cl)
cmd := describeCmd(cl)
cmd.Flags().StringSliceP("context", "x", nil, "Context")
cmd.SetArgs([]string{"pew"})

Expand Down
4 changes: 2 additions & 2 deletions cmd/get.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package cmd

import (
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/util/parsing"
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
)

func GetGetCmd(c *client.Client) *cobra.Command {
func getCmd(c *client.Client) *cobra.Command {
return &cobra.Command{
Use: "get [flags]",
Short: "Get a list of pods",
Expand Down
2 changes: 1 addition & 1 deletion cmd/kron/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package kron

import (
"fmt"
"github.com/wish/ctl/pkg/client/types"
"github.com/robfig/cron"
"github.com/spf13/viper"
"github.com/wish/ctl/pkg/client/types"
"os"
"time"
)
Expand Down
4 changes: 2 additions & 2 deletions cmd/kron/describe.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package kron

import (
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/util/parsing"
"github.com/wish/ctl/pkg/client"
"github.com/wish/ctl/pkg/client/types"
"github.com/spf13/cobra"
)

// Currently does not support selected job
// Requires job name
func GetDescribeCmd(c *client.Client) *cobra.Command {
func describeCmd(c *client.Client) *cobra.Command {
cmd := &cobra.Command{
Use: "describe [jobs] [flags]",
Short: "Show details about specified cron jobs",
Expand Down
4 changes: 2 additions & 2 deletions cmd/kron/exec.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package kron

import (
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/util/parsing"
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
)

func GetExecCmd(c *client.Client) *cobra.Command {
func execCmd(c *client.Client) *cobra.Command {
return &cobra.Command{
Use: "exec cronjob [flags]",
Short: "Executes a job now",
Expand Down
29 changes: 13 additions & 16 deletions cmd/kron/favorite.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
package kron

import (
"fmt"
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/wish/ctl/pkg/client"
)

func init() {
viper.SetDefault("favorites", make(map[string]location))
viper.SetConfigName("config")
viper.AddConfigPath("$HOME/.kron")
err := viper.ReadInConfig()
if err != nil {
// Write config file
fmt.Println("Creating new config file")
createConfig()
// panic(err.Error())
}
}

func GetFavoriteCmd(c *client.Client) *cobra.Command {
func favoriteCmd(c *client.Client) *cobra.Command {
return &cobra.Command{
Use: "favorite [jobs] [flags]",
Short: "Adds jobs to favorite list",
Long: `Adds specified job(s) to the favorite list. If no job was specified the selected job is added.
A namespace and contexts can be specified to limit matches.`,
PreRun: func(cmd *cobra.Command, args []string) {
viper.SetDefault("favorites", make(map[string]location))
viper.SetConfigName("config")
viper.AddConfigPath("$HOME/.kron")
err := viper.ReadInConfig()
if err != nil {
// Write config file
cmd.Println("Creating new config file")
createConfig()
}
},
RunE: func(cmd *cobra.Command, args []string) error {
// args/flags
ctxs, _ := cmd.Flags().GetStringSlice("context")
Expand Down
2 changes: 1 addition & 1 deletion cmd/kron/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package kron

import (
"fmt"
"github.com/wish/ctl/pkg/client/types"
"github.com/robfig/cron"
"github.com/wish/ctl/pkg/client/types"
"os"
"text/tabwriter"
"time"
Expand Down
6 changes: 3 additions & 3 deletions cmd/kron/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package kron

import (
"errors"
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/util/parsing"
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
"sort"
)

func GetGetCmd(c *client.Client) *cobra.Command {
func getCmd(c *client.Client) *cobra.Command {
cmd := &cobra.Command{
Use: "get [flags]",
Short: "Get a list of cronjobs",
Expand All @@ -31,7 +31,7 @@ If context(s) not specified, it will list from all contexts.`,
E, _ := cmd.Flags().GetBool("by-next-run-reverse")

if l && L || l && e || l && E || L && e || L && E || e && E { // More than one
return errors.New("Only at most one ordering flag may be set!")
return errors.New("at most one ordering flag may be set")
}

list, err := c.ListCronJobsOverContexts(ctxs, namespace, options)
Expand Down
25 changes: 13 additions & 12 deletions cmd/kron/root.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
package kron

import (
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/kron/runs"
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
)

func GetKronCmd(c *client.Client) *cobra.Command {
// Cmd returns the kron subcommand given a client to operate on
func Cmd(c *client.Client) *cobra.Command {
kron := &cobra.Command{
Use: "kron",
Short: "A tool for cron on kubernetes",
Long: "A subcommand for managing and reviewing cron jobs on kubernetes.",
}

kron.AddCommand(GetDescribeCmd(c))
kron.AddCommand(GetExecCmd(c))
kron.AddCommand(GetFavoriteCmd(c))
kron.AddCommand(GetGetCmd(c))
kron.AddCommand(GetSelectCmd(c))
kron.AddCommand(GetSuspendCmd(c))
kron.AddCommand(GetUnfavoriteCmd(c))
kron.AddCommand(GetUnsuspendCmd(c))
kron.AddCommand(GetWebCmd(c))
kron.AddCommand(runs.GetRunsCmd(c))
kron.AddCommand(describeCmd(c))
kron.AddCommand(execCmd(c))
kron.AddCommand(favoriteCmd(c))
kron.AddCommand(getCmd(c))
kron.AddCommand(selectCmd(c))
kron.AddCommand(suspendCmd(c))
kron.AddCommand(unfavoriteCmd(c))
kron.AddCommand(unsuspendCmd(c))
kron.AddCommand(webCmd(c))
kron.AddCommand(runs.Cmd(c))

return kron
}
4 changes: 2 additions & 2 deletions cmd/kron/runs/describe.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package runs

import (
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/util/parsing"
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
)

func GetDescribeCmd(c *client.Client) *cobra.Command {
func describeCmd(c *client.Client) *cobra.Command {
return &cobra.Command{
Use: "describe run",
Short: "Get info about a run",
Expand Down
4 changes: 2 additions & 2 deletions cmd/kron/runs/get.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package runs

import (
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/util/parsing"
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
)

func GetGetCmd(c *client.Client) *cobra.Command {
func getCmd(c *client.Client) *cobra.Command {
return &cobra.Command{
Use: "get cronjob [flags]",
Short: "Get a list of runs of a cron job",
Expand Down
4 changes: 2 additions & 2 deletions cmd/kron/runs/logs.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package runs

import (
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/util/parsing"
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
)

func GetLogsCmd(c *client.Client) *cobra.Command {
func logsCmd(c *client.Client) *cobra.Command {
cmd := &cobra.Command{
Use: "logs pod [flags]",
Aliases: []string{"log"},
Expand Down
11 changes: 6 additions & 5 deletions cmd/kron/runs/root.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package runs

import (
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
"github.com/wish/ctl/pkg/client"
)

func GetRunsCmd(c *client.Client) *cobra.Command {
// Cmd returns the kron/runs subcommand given a client
func Cmd(c *client.Client) *cobra.Command {
cmd := &cobra.Command{
Use: "runs",
Short: "Subcommand on recent runs of a cron job",
Long: `Operate on the jobs started by a cron job
Has a bunch of subcommand just like kron`,
}

cmd.AddCommand(GetDescribeCmd(c))
cmd.AddCommand(GetGetCmd(c))
cmd.AddCommand(GetLogsCmd(c))
cmd.AddCommand(describeCmd(c))
cmd.AddCommand(getCmd(c))
cmd.AddCommand(logsCmd(c))

return cmd
}
28 changes: 13 additions & 15 deletions cmd/kron/select.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
package kron

import (
"fmt"
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/wish/ctl/pkg/client"
)

func init() {
viper.SetDefault("selected", make(map[string]location))
viper.AddConfigPath("$HOME/.kron")
err := viper.ReadInConfig()
if err != nil {
// Write config file
fmt.Println("Creating new config file")
createConfig()
// panic(err.Error())
}
}

func GetSelectCmd(c *client.Client) *cobra.Command {
func selectCmd(c *client.Client) *cobra.Command {
return &cobra.Command{
Use: "select job [flags]",
Short: "Uses list to select a job to operate on",
Long: `Uses list to select a job on which other commands can conveniently operate on.
A namespace and contexts can be specified to limit matches.
If namespace/contexts are not specified, usage will match with all results.`,
Args: cobra.ExactArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
viper.SetDefault("favorites", make(map[string]location))
viper.SetConfigName("config")
viper.AddConfigPath("$HOME/.kron")
err := viper.ReadInConfig()
if err != nil {
// Write config file
cmd.Println("Creating new config file")
createConfig()
}
},
RunE: func(cmd *cobra.Command, args []string) error {
// args/flags
job := args[0]
Expand Down
4 changes: 2 additions & 2 deletions cmd/kron/suspend.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package kron

import (
"github.com/spf13/cobra"
"github.com/wish/ctl/cmd/util/parsing"
"github.com/wish/ctl/pkg/client"
"github.com/spf13/cobra"
)

func GetSuspendCmd(c *client.Client) *cobra.Command {
func suspendCmd(c *client.Client) *cobra.Command {
return &cobra.Command{
Use: "suspend cronjob [flags]",
Short: "Suspend a cron job",
Expand Down
Loading