File tree Expand file tree Collapse file tree 3 files changed +7
-45
lines changed
pkg/reconciler/customresourcesgate Expand file tree Collapse file tree 3 files changed +7
-45
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,6 @@ package customresourcesgate
2020
2121import (
2222 "context"
23- "reflect"
24-
2523 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2624 "k8s.io/apimachinery/pkg/runtime/schema"
2725 ctrl "sigs.k8s.io/controller-runtime"
@@ -39,12 +37,6 @@ type Reconciler struct {
3937
4038// Reconcile reconciles CustomResourceDefinitions and reports ready and unready GVKs to the gate.
4139func (r * Reconciler ) Reconcile (_ context.Context , crd * apiextensionsv1.CustomResourceDefinition ) (ctrl.Result , error ) {
42- // If there is no gate, then we don't need to do work.
43- if r .gate == nil || reflect .ValueOf (r .gate ).IsNil () {
44- r .log .Debug ("Gate is not set, skipping reconciliation" )
45- return ctrl.Result {}, nil
46- }
47-
4840 established := isEstablished (crd )
4941 gkvs := toGVKs (crd )
5042
Original file line number Diff line number Diff line change @@ -317,43 +317,6 @@ func TestReconcile(t *testing.T) {
317317 args args
318318 want want
319319 }{
320- "NilGateSkipsReconciliation" : {
321- reason : "Should skip reconciliation when gate is nil" ,
322- fields : fields {
323- gate : nil ,
324- },
325- args : args {
326- ctx : context .Background (),
327- crd : & apiextensionsv1.CustomResourceDefinition {
328- ObjectMeta : metav1.ObjectMeta {
329- Name : "testresources.example.com" ,
330- },
331- Spec : apiextensionsv1.CustomResourceDefinitionSpec {
332- Group : "example.com" ,
333- Names : apiextensionsv1.CustomResourceDefinitionNames {
334- Kind : "TestResource" ,
335- },
336- Versions : []apiextensionsv1.CustomResourceDefinitionVersion {
337- {Name : "v1" , Served : true },
338- },
339- },
340- Status : apiextensionsv1.CustomResourceDefinitionStatus {
341- Conditions : []apiextensionsv1.CustomResourceDefinitionCondition {
342- {
343- Type : apiextensionsv1 .Established ,
344- Status : apiextensionsv1 .ConditionTrue ,
345- },
346- },
347- },
348- },
349- },
350- want : want {
351- result : ctrl.Result {},
352- err : nil ,
353- trueCalls : []schema.GroupVersionKind {},
354- falseCalls : []schema.GroupVersionKind {},
355- },
356- },
357320 "EstablishedCRDCallsGateTrue" : {
358321 reason : "Should call gate.True for all GVKs when CRD is established" ,
359322 fields : fields {
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ limitations under the License.
1717package customresourcesgate
1818
1919import (
20+ "errors"
21+ "reflect"
22+
2023 apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2124 ctrl "sigs.k8s.io/controller-runtime"
2225 "sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -27,6 +30,10 @@ import (
2730// Setup adds a controller that reconciles CustomResourceDefinitions to support delayed start of controllers.
2831// o.Gate is expected to be something like *gate.Gate[schema.GroupVersionKind].
2932func Setup (mgr ctrl.Manager , o controller.Options ) error {
33+ if o .Gate == nil || reflect .ValueOf (o .Gate ).IsNil () {
34+ return errors .New ("gate is required" )
35+ }
36+
3037 r := & Reconciler {
3138 log : o .Logger ,
3239 gate : o .Gate ,
You can’t perform that action at this time.
0 commit comments