Skip to content

Commit

Permalink
add corev1, coordinationv1 scheme for leader election when LeaderElec…
Browse files Browse the repository at this point in the history
…tion option is true

Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
  • Loading branch information
troy0820 committed Aug 30, 2023
1 parent aa9f8c9 commit e92e5ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 12 additions & 2 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"time"

"github.com/go-logr/logr"
coordinationv1 "k8s.io/api/coordination/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -353,7 +355,16 @@ func New(config *rest.Config, options Options) (Manager, error) {
leaderRecorderProvider = recorderProvider
} else {
leaderConfig = rest.CopyConfig(options.LeaderElectionConfig)
leaderRecorderProvider, err = options.newRecorderProvider(leaderConfig, cluster.GetHTTPClient(), cluster.GetScheme(), options.Logger.WithName("events"), options.makeBroadcaster)
scheme := cluster.GetScheme()
err := corev1.AddToScheme(scheme)
if err != nil {
return nil, err
}
err = coordinationv1.AddToScheme(scheme)
if err != nil {
return nil, err
}
leaderRecorderProvider, err = options.newRecorderProvider(leaderConfig, cluster.GetHTTPClient(), scheme, options.Logger.WithName("events"), options.makeBroadcaster)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -396,7 +407,6 @@ func New(config *rest.Config, options Options) (Manager, error) {

errChan := make(chan error)
runnables := newRunnables(options.BaseContext, errChan)

return &controllerManager{
stopProcedureEngaged: pointer.Int64(0),
cluster: cluster,
Expand Down
7 changes: 6 additions & 1 deletion pkg/manager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ import (
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/goleak"
authenticationv1 "k8s.io/api/authentication/v1"
coordinationv1 "k8s.io/api/coordination/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/leaderelection/resourcelock"
configv1alpha1 "k8s.io/component-base/config/v1alpha1"
Expand Down Expand Up @@ -313,7 +315,10 @@ var _ = Describe("manger.Manager", func() {
PprofBindAddress: "0",
})
Expect(err).ToNot(HaveOccurred())

gvkcorev1 := schema.GroupVersionKind{Group: corev1.SchemeGroupVersion.Group, Version: corev1.SchemeGroupVersion.Version, Kind: "ConfigMap"}
gvkcoordinationv1 := schema.GroupVersionKind{Group: coordinationv1.SchemeGroupVersion.Group, Version: coordinationv1.SchemeGroupVersion.Version, Kind: "Lease"}
Expect(m.GetScheme().Recognizes(gvkcorev1)).To(BeTrue())
Expect(m.GetScheme().Recognizes(gvkcoordinationv1)).To(BeTrue())
runnableDone := make(chan struct{})
slowRunnable := RunnableFunc(func(ctx context.Context) error {
<-ctx.Done()
Expand Down

0 comments on commit e92e5ee

Please sign in to comment.