mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #32654 from soltysh/sj_clientset
Automatic merge from submit-queue Switch ScheduledJob controller to use clientset **What this PR does / why we need it**: This is part of #25442. I've applied here the same fix I've applied in the manual client in #29187, see the 1st commit for that (@caesarxuchao we've talked about it in #29856). @deads2k as promised @janetkuo ptal
This commit is contained in:
commit
e8fbcb1669
@ -404,13 +404,9 @@ func StartControllers(s *options.CMServer, kubeClient *client.Client, kubeconfig
|
||||
glog.Infof("Starting %s apis", groupVersion)
|
||||
if containsResource(resources, "scheduledjobs") {
|
||||
glog.Infof("Starting scheduledjob controller")
|
||||
// TODO: this is a temp fix for allowing kubeClient list v2alpha1 sj, should switch to using clientset
|
||||
// // 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).
|
||||
go scheduledjob.NewScheduledJobController(clientset.NewForConfigOrDie(restclient.AddUserAgent(kubeconfig, "scheduledjob-controller"))).
|
||||
Run(wait.NeverStop)
|
||||
time.Sleep(wait.Jitter(s.ControllerStartInterval.Duration, ControllerStartJitter))
|
||||
time.Sleep(wait.Jitter(s.ControllerStartInterval.Duration, ControllerStartJitter))
|
||||
|
@ -204,12 +204,10 @@ func setConfigDefaults(config *$.Config|raw$) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = $.DefaultKubernetesUserAgent|raw$()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = $.codecs|raw$
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -74,12 +74,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -89,12 +89,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -79,12 +79,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -74,12 +74,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -74,12 +74,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -74,12 +74,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -84,12 +84,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -74,12 +74,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -79,12 +79,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -74,12 +74,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -149,12 +149,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -109,12 +109,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -89,12 +89,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -74,12 +74,10 @@ func setConfigDefaults(config *restclient.Config) error {
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||
}
|
||||
// TODO: Unconditionally set the config.Version, until we fix the config.
|
||||
//if config.Version == "" {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
//}
|
||||
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != g.GroupVersion.Group {
|
||||
copyGroupVersion := g.GroupVersion
|
||||
config.GroupVersion = ©GroupVersion
|
||||
}
|
||||
config.NegotiatedSerializer = api.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
|
@ -38,8 +38,9 @@ import (
|
||||
"k8s.io/kubernetes/pkg/api/errors"
|
||||
"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"
|
||||
utilerrors "k8s.io/kubernetes/pkg/util/errors"
|
||||
@ -51,21 +52,21 @@ import (
|
||||
// Utilities for dealing with Jobs and ScheduledJobs and time.
|
||||
|
||||
type ScheduledJobController struct {
|
||||
kubeClient *client.Client
|
||||
kubeClient clientset.Interface
|
||||
jobControl jobControlInterface
|
||||
sjControl sjControlInterface
|
||||
podControl podControlInterface
|
||||
recorder record.EventRecorder
|
||||
}
|
||||
|
||||
func NewScheduledJobController(kubeClient *client.Client) *ScheduledJobController {
|
||||
func NewScheduledJobController(kubeClient clientset.Interface) *ScheduledJobController {
|
||||
eventBroadcaster := record.NewBroadcaster()
|
||||
eventBroadcaster.StartLogging(glog.Infof)
|
||||
// TODO: remove the wrapper when every clients have moved to use the clientset.
|
||||
eventBroadcaster.StartRecordingToSink(kubeClient.Events(""))
|
||||
eventBroadcaster.StartRecordingToSink(&unversionedcore.EventSinkImpl{Interface: kubeClient.Core().Events("")})
|
||||
|
||||
if kubeClient != nil && kubeClient.GetRateLimiter() != nil {
|
||||
metrics.RegisterMetricAndTrackRateLimiterUsage("scheduledjob_controller", kubeClient.GetRateLimiter())
|
||||
if kubeClient != nil && kubeClient.Core().GetRESTClient().GetRateLimiter() != nil {
|
||||
metrics.RegisterMetricAndTrackRateLimiterUsage("scheduledjob_controller", kubeClient.Core().GetRESTClient().GetRateLimiter())
|
||||
}
|
||||
|
||||
jm := &ScheduledJobController{
|
||||
@ -73,13 +74,13 @@ func NewScheduledJobController(kubeClient *client.Client) *ScheduledJobControlle
|
||||
jobControl: realJobControl{KubeClient: kubeClient},
|
||||
sjControl: &realSJControl{KubeClient: kubeClient},
|
||||
podControl: &realPodControl{KubeClient: kubeClient},
|
||||
recorder: eventBroadcaster.NewRecorder(api.EventSource{Component: "scheduled-job-controller"}),
|
||||
recorder: eventBroadcaster.NewRecorder(api.EventSource{Component: "scheduledjob-controller"}),
|
||||
}
|
||||
|
||||
return jm
|
||||
}
|
||||
|
||||
func NewScheduledJobControllerFromClient(kubeClient *client.Client) *ScheduledJobController {
|
||||
func NewScheduledJobControllerFromClient(kubeClient clientset.Interface) *ScheduledJobController {
|
||||
jm := NewScheduledJobController(kubeClient)
|
||||
return jm
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"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"
|
||||
)
|
||||
|
||||
@ -34,7 +34,7 @@ type sjControlInterface interface {
|
||||
|
||||
// realSJControl is the default implementation of sjControlInterface.
|
||||
type realSJControl struct {
|
||||
KubeClient *client.Client
|
||||
KubeClient clientset.Interface
|
||||
}
|
||||
|
||||
var _ sjControlInterface = &realSJControl{}
|
||||
@ -73,7 +73,7 @@ type jobControlInterface interface {
|
||||
|
||||
// realJobControl is the default implementation of jobControlInterface.
|
||||
type realJobControl struct {
|
||||
KubeClient *client.Client
|
||||
KubeClient clientset.Interface
|
||||
Recorder record.EventRecorder
|
||||
}
|
||||
|
||||
@ -182,18 +182,18 @@ type podControlInterface interface {
|
||||
|
||||
// realPodControl is the default implementation of podControlInterface.
|
||||
type realPodControl struct {
|
||||
KubeClient *client.Client
|
||||
KubeClient clientset.Interface
|
||||
Recorder record.EventRecorder
|
||||
}
|
||||
|
||||
var _ podControlInterface = &realPodControl{}
|
||||
|
||||
func (r realPodControl) ListPods(namespace string, opts api.ListOptions) (*api.PodList, error) {
|
||||
return r.KubeClient.Pods(namespace).List(opts)
|
||||
return r.KubeClient.Core().Pods(namespace).List(opts)
|
||||
}
|
||||
|
||||
func (r realPodControl) DeletePod(namespace string, name string) error {
|
||||
return r.KubeClient.Pods(namespace).Delete(name, nil)
|
||||
return r.KubeClient.Core().Pods(namespace).Delete(name, nil)
|
||||
}
|
||||
|
||||
type fakePodControl struct {
|
||||
|
Loading…
Reference in New Issue
Block a user