Skip to content

Commit 990e45c

Browse files
committed
check for nil gates in setup, not reconcile.
Signed-off-by: Scott Nichols <[email protected]>
1 parent 066eac1 commit 990e45c

File tree

3 files changed

+7
-45
lines changed

3 files changed

+7
-45
lines changed

pkg/reconciler/customresourcesgate/reconciler.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ package customresourcesgate
2020

2121
import (
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.
4139
func (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

pkg/reconciler/customresourcesgate/reconciler_test.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff 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{

pkg/reconciler/customresourcesgate/setup.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ limitations under the License.
1717
package customresourcesgate
1818

1919
import (
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].
2932
func 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,

0 commit comments

Comments
 (0)