Skip to content

Commit 6d8b14c

Browse files
committed
Switch to external informers
1 parent d9109a3 commit 6d8b14c

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

pkg/admission/custominitializer/interfaces.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ package custominitializer
1818

1919
import (
2020
"k8s.io/apiserver/pkg/admission"
21-
informers "github.com/programming-kubernetes/custom-apiserver/pkg/generated/informers/internalversion"
21+
22+
informers "github.com/programming-kubernetes/custom-apiserver/pkg/generated/informers/externalversions"
2223
)
2324

24-
// WantsInternalRestaurantInformerFactory defines a function which sets InformerFactory for admission plugins that need it
25-
type WantsInternalRestaurantInformerFactory interface {
26-
SetInternalRestaurantInformerFactory(informers.SharedInformerFactory)
25+
// WantsRestaurantInformerFactory defines a function which sets InformerFactory for admission plugins that need it
26+
type WantsRestaurantInformerFactory interface {
27+
SetRestaurantInformerFactory(informers.SharedInformerFactory)
2728
admission.InitializationValidator
2829
}

pkg/admission/custominitializer/restaurantinformer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ package custominitializer
1818

1919
import (
2020
"k8s.io/apiserver/pkg/admission"
21-
informers "github.com/programming-kubernetes/custom-apiserver/pkg/generated/informers/internalversion"
21+
22+
informers "github.com/programming-kubernetes/custom-apiserver/pkg/generated/informers/externalversions"
2223
)
2324

2425
type restaurantInformerPluginInitializer struct {
@@ -37,7 +38,7 @@ func New(informers informers.SharedInformerFactory) restaurantInformerPluginInit
3738
// Initialize checks the initialization interfaces implemented by a plugin
3839
// and provide the appropriate initialization data
3940
func (i restaurantInformerPluginInitializer) Initialize(plugin admission.Interface) {
40-
if wants, ok := plugin.(WantsInternalRestaurantInformerFactory); ok {
41-
wants.SetInternalRestaurantInformerFactory(i.informers)
41+
if wants, ok := plugin.(WantsRestaurantInformerFactory); ok {
42+
wants.SetRestaurantInformerFactory(i.informers)
4243
}
4344
}

pkg/admission/custominitializer/restaurantinformer_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,36 +21,37 @@ import (
2121
"time"
2222

2323
"k8s.io/apiserver/pkg/admission"
24+
2425
"github.com/programming-kubernetes/custom-apiserver/pkg/admission/custominitializer"
25-
"github.com/programming-kubernetes/custom-apiserver/pkg/generated/clientset/internalversion/fake"
26-
informers "github.com/programming-kubernetes/custom-apiserver/pkg/generated/informers/internalversion"
26+
"github.com/programming-kubernetes/custom-apiserver/pkg/generated/clientset/versioned/fake"
27+
informers "github.com/programming-kubernetes/custom-apiserver/pkg/generated/informers/externalversions"
2728
)
2829

2930
// TestWantsInternalRestaurantInformerFactory ensures that the informer factory is injected
30-
// when the WantsInternalRestaurantInformerFactory interface is implemented by a plugin.
31+
// when the WantsRestaurantInformerFactory interface is implemented by a plugin.
3132
func TestWantsInternalRestaurantInformerFactory(t *testing.T) {
3233
cs := &fake.Clientset{}
3334
sf := informers.NewSharedInformerFactory(cs, time.Duration(1)*time.Second)
3435
target := custominitializer.New(sf)
3536

36-
wantRestaurantInformerFactory := &wantInternalRestaurantInformerFactory{}
37+
wantRestaurantInformerFactory := &wantRestaurantInformerFactory{}
3738
target.Initialize(wantRestaurantInformerFactory)
3839
if wantRestaurantInformerFactory.sf != sf {
3940
t.Errorf("expected informer factory to be initialized")
4041
}
4142
}
4243

43-
// wantInternalRestaurantInformerFactory is a test stub that fulfills the WantsInternalRestaurantInformerFactory interface
44-
type wantInternalRestaurantInformerFactory struct {
44+
// wantRestaurantInformerFactory is a test stub that fulfills the WantsRestaurantInformerFactory interface
45+
type wantRestaurantInformerFactory struct {
4546
sf informers.SharedInformerFactory
4647
}
4748

48-
func (self *wantInternalRestaurantInformerFactory) SetInternalRestaurantInformerFactory(sf informers.SharedInformerFactory) {
49+
func (self *wantRestaurantInformerFactory) SetRestaurantInformerFactory(sf informers.SharedInformerFactory) {
4950
self.sf = sf
5051
}
51-
func (self *wantInternalRestaurantInformerFactory) Admit(a admission.Attributes) error { return nil }
52-
func (self *wantInternalRestaurantInformerFactory) Handles(o admission.Operation) bool { return false }
53-
func (self *wantInternalRestaurantInformerFactory) ValidateInitialization() error { return nil }
52+
func (self *wantRestaurantInformerFactory) Admit(a admission.Attributes) error { return nil }
53+
func (self *wantRestaurantInformerFactory) Handles(o admission.Operation) bool { return false }
54+
func (self *wantRestaurantInformerFactory) ValidateInitialization() error { return nil }
5455

55-
var _ admission.Interface = &wantInternalRestaurantInformerFactory{}
56-
var _ custominitializer.WantsInternalRestaurantInformerFactory = &wantInternalRestaurantInformerFactory{}
56+
var _ admission.Interface = &wantRestaurantInformerFactory{}
57+
var _ custominitializer.WantsRestaurantInformerFactory = &wantRestaurantInformerFactory{}

pkg/admission/plugin/pizzatoppings/admission.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import (
2525

2626
"github.com/programming-kubernetes/custom-apiserver/pkg/admission/custominitializer"
2727
"github.com/programming-kubernetes/custom-apiserver/pkg/apis/restaurant"
28-
informers "github.com/programming-kubernetes/custom-apiserver/pkg/generated/informers/internalversion"
29-
listers "github.com/programming-kubernetes/custom-apiserver/pkg/generated/listers/restaurant/internalversion"
28+
informers "github.com/programming-kubernetes/custom-apiserver/pkg/generated/informers/externalversions"
29+
listers "github.com/programming-kubernetes/custom-apiserver/pkg/generated/listers/restaurant/v1alpha1"
3030
)
3131

3232
// Register registers a plugin
@@ -41,7 +41,7 @@ type PizzaToppingsPlugin struct {
4141
toppingLister listers.ToppingLister
4242
}
4343

44-
var _ = custominitializer.WantsInternalRestaurantInformerFactory(&PizzaToppingsPlugin{})
44+
var _ = custominitializer.WantsRestaurantInformerFactory(&PizzaToppingsPlugin{})
4545

4646
// Admit ensures that the object in-flight is of kind Pizza.
4747
// In addition checks that the toppings are known.
@@ -69,11 +69,11 @@ func (d *PizzaToppingsPlugin) Validate(a admission.Attributes) error {
6969
return nil
7070
}
7171

72-
// SetInternalRestaurantInformerFactory gets Lister from SharedInformerFactory.
72+
// SetRestaurantInformerFactory gets Lister from SharedInformerFactory.
7373
// The lister knows how to lists Toppings.
74-
func (d *PizzaToppingsPlugin) SetInternalRestaurantInformerFactory(f informers.SharedInformerFactory) {
75-
d.toppingLister = f.Restaurant().InternalVersion().Toppings().Lister()
76-
d.SetReadyFunc(f.Restaurant().InternalVersion().Toppings().Informer().HasSynced)
74+
func (d *PizzaToppingsPlugin) SetRestaurantInformerFactory(f informers.SharedInformerFactory) {
75+
d.toppingLister = f.Restaurant().V1alpha1().Toppings().Lister()
76+
d.SetReadyFunc(f.Restaurant().V1alpha1().Toppings().Informer().HasSynced)
7777
}
7878

7979
// ValidaValidateInitializationte checks whether the plugin was correctly initialized.

0 commit comments

Comments
 (0)