Skip to content

Commit

Permalink
Merge pull request kubernetes#30327 from janetkuo/sj-controller-client
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Use unversioned client in scheduledjobs and set group version to batch/v2alpha1

Fixes kubernetes#30323
  • Loading branch information
Kubernetes Submit Queue authored Aug 13, 2016
2 parents f0e5dac + e4269d4 commit dadb332
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
9 changes: 8 additions & 1 deletion cmd/kube-controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
"k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/batch"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/leaderelection"
"k8s.io/kubernetes/pkg/client/record"
Expand Down Expand Up @@ -390,7 +391,13 @@ func StartControllers(s *options.CMServer, kubeClient *client.Client, kubeconfig
glog.Infof("Starting %s apis", groupVersion)
if containsResource(resources, "scheduledjobs") {
glog.Infof("Starting scheduledjob controller")
go scheduledjob.NewScheduledJobController(clientset.NewForConfigOrDie(restclient.AddUserAgent(kubeconfig, "scheduledjob-controller"))).
// TODO: this is a temp fix for allowing kubeClient list v2alpha1 sj, should switch to using clientset
kubeconfig.ContentConfig.GroupVersion = &unversioned.GroupVersion{Group: batch.GroupName, Version: "v2alpha1"}
kubeClient, err := client.New(kubeconfig)
if err != nil {
glog.Fatalf("Invalid API configuration: %v", err)
}
go scheduledjob.NewScheduledJobController(kubeClient).
Run(wait.NeverStop)
time.Sleep(wait.Jitter(s.ControllerStartInterval.Duration, ControllerStartJitter))
time.Sleep(wait.Jitter(s.ControllerStartInterval.Duration, ControllerStartJitter))
Expand Down
15 changes: 7 additions & 8 deletions pkg/controller/scheduledjob/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/batch"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
unversionedcore "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/core/unversioned"
"k8s.io/kubernetes/pkg/client/record"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/controller/job"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/metrics"
Expand All @@ -50,20 +49,20 @@ import (
// Utilities for dealing with Jobs and ScheduledJobs and time.

type ScheduledJobController struct {
kubeClient clientset.Interface
kubeClient *client.Client
jobControl jobControlInterface
sjControl sjControlInterface
recorder record.EventRecorder
}

func NewScheduledJobController(kubeClient clientset.Interface) *ScheduledJobController {
func NewScheduledJobController(kubeClient *client.Client) *ScheduledJobController {
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(glog.Infof)
// TODO: remove the wrapper when every clients have moved to use the clientset.
eventBroadcaster.StartRecordingToSink(&unversionedcore.EventSinkImpl{Interface: kubeClient.Core().Events("")})
eventBroadcaster.StartRecordingToSink(kubeClient.Events(""))

if kubeClient != nil && kubeClient.Batch().GetRESTClient().GetRateLimiter() != nil {
metrics.RegisterMetricAndTrackRateLimiterUsage("scheduledjob_controller", kubeClient.Batch().GetRESTClient().GetRateLimiter())
if kubeClient != nil && kubeClient.GetRateLimiter() != nil {
metrics.RegisterMetricAndTrackRateLimiterUsage("scheduledjob_controller", kubeClient.GetRateLimiter())
}

jm := &ScheduledJobController{
Expand All @@ -76,7 +75,7 @@ func NewScheduledJobController(kubeClient clientset.Interface) *ScheduledJobCont
return jm
}

func NewScheduledJobControllerFromClient(kubeClient clientset.Interface) *ScheduledJobController {
func NewScheduledJobControllerFromClient(kubeClient *client.Client) *ScheduledJobController {
jm := NewScheduledJobController(kubeClient)
return jm
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/scheduledjob/injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"sync"

"k8s.io/kubernetes/pkg/apis/batch"
clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/client/record"
client "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/labels"
)

Expand All @@ -33,7 +33,7 @@ type sjControlInterface interface {

// realSJControl is the default implementation of sjControlInterface.
type realSJControl struct {
KubeClient clientset.Interface
KubeClient *client.Client
}

var _ sjControlInterface = &realSJControl{}
Expand Down Expand Up @@ -69,7 +69,7 @@ type jobControlInterface interface {

// realJobControl is the default implementation of jobControlInterface.
type realJobControl struct {
KubeClient clientset.Interface
KubeClient *client.Client
Recorder record.EventRecorder
}

Expand Down

0 comments on commit dadb332

Please sign in to comment.