Skip to content
Open
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
9 changes: 4 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package cmd
import (
"context"
"fmt"
batchv1 "k8s.io/api/batch/v1"
"os"
"path/filepath"

"github.com/spf13/cobra"
"k8s.io/api/batch/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand All @@ -32,9 +32,9 @@ func Execute() {
}

func init() {
// flags.StringVarP(f.Namespace, flagNamespace, "n", *f.Namespace, "If present, the namespace scope for this CLI request")
rootCmd.PersistentFlags().StringVarP(&namespace, "namespace", "n", "", "If present, the namespace scope for this CLI request")
rootCmd.PersistentFlags().StringVar(&kubecontext, "context", "", "Context")

if home := homedir.HomeDir(); home != "" {
rootCmd.PersistentFlags().StringVar(&kubeconfig, "kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
} else {
Expand Down Expand Up @@ -86,11 +86,10 @@ func getConfig(kubecontext, kubeconfigPath string) (*rest.Config, error) {
return a.ClientConfig()
}

func getCronjob(namespace, cronjob string) *v1beta1.CronJob {

func getCronjob(namespace, cronjob string) *batchv1.CronJob {
clientset := mustGetClientset()

cj, err := clientset.BatchV1beta1().CronJobs(namespace).Get(context.TODO(), cronjob, metav1.GetOptions{})
cj, err := clientset.BatchV1().CronJobs(namespace).Get(context.TODO(), cronjob, metav1.GetOptions{})

if errors.IsNotFound(err) {
fmt.Printf("Cronjob not found\n")
Expand Down
3 changes: 1 addition & 2 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/spf13/cobra"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/api/batch/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
Expand All @@ -31,7 +30,7 @@ func run(_ *cobra.Command, args []string) {
createJob(clientset, cronjobName, cronjob)
}

func createJob(clientset *kubernetes.Clientset, cronjobName string, cronjob *v1beta1.CronJob) {
func createJob(clientset *kubernetes.Clientset, cronjobName string, cronjob *batchv1.CronJob) {
jobsClient := clientset.BatchV1().Jobs(namespace)

suffix := "-" + strconv.Itoa(int(time.Now().Unix()))
Expand Down
2 changes: 1 addition & 1 deletion cmd/suspend.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func toggleSuspend(args []string, status bool) {
cronjob := getCronjob(namespace, cronjobName)

cronjob.Spec.Suspend = &status
_, updateErr := clientset.BatchV1beta1().CronJobs(namespace).Update(context.TODO(), cronjob, metav1.UpdateOptions{})
_, updateErr := clientset.BatchV1().CronJobs(namespace).Update(context.TODO(), cronjob, metav1.UpdateOptions{})
return updateErr
})

Expand Down
18 changes: 13 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ module github.com/iJanki/kubecron
go 1.13

require (
github.com/Azure/go-autorest/autorest v0.11.10 // indirect
cloud.google.com/go v0.97.0 // indirect
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153 // indirect
github.com/form3tech-oss/jwt-go v3.2.2+incompatible // indirect
github.com/getkin/kin-openapi v0.76.0 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/gophercloud/gophercloud v0.13.0 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/spf13/cobra v1.1.0
k8s.io/api v0.19.2
k8s.io/apimachinery v0.19.2
k8s.io/client-go v0.19.2
k8s.io/api v0.28.1
k8s.io/apimachinery v0.28.1
k8s.io/client-go v0.28.1
k8s.io/klog v1.0.0 // indirect
k8s.io/utils v0.0.0-20201015054608-420da100c033 // indirect
)
Loading