Skip to content

Commit

Permalink
Merge pull request #2059 from acpana/acpana/fix-direct-test
Browse files Browse the repository at this point in the history
fix: guard against nil model
  • Loading branch information
google-oss-prow[bot] authored Jun 20, 2024
2 parents 0ce0cde + 89f4b9b commit 30b7d89
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/controller/direct/directbase/directbase_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func AddController(mgr manager.Manager, gvk schema.GroupVersionKind, model Model
immediateReconcileRequests := make(chan event.GenericEvent, k8s.ImmediateReconcileRequestsBufferSize)
resourceWatcherRoutines := semaphore.NewWeighted(k8s.MaxNumResourceWatcherRoutines)

if model == nil {
return fmt.Errorf("model is nil for gvk %s", gvk)
}

reconciler, err := NewReconciler(mgr, immediateReconcileRequests, resourceWatcherRoutines, gvk, model, deps.JitterGenerator)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/direct/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type ModelFactoryFunc func(ctx context.Context, config *config.ControllerConfig)

func GetModel(gk schema.GroupKind) (directbase.Model, error) {
registration := singleton.registrations[gk]
if registration == nil {
if registration == nil || registration.model == nil {
return nil, fmt.Errorf("no model registered for %s", gk)
}
return registration.model, nil
Expand Down
9 changes: 9 additions & 0 deletions pkg/test/controller/reconciler/testreconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"
"time"

"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/config"
dclcontroller "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/dcl"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/directbase"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/direct/registry"
Expand Down Expand Up @@ -95,6 +96,14 @@ func NewTestReconciler(t *testing.T, mgr manager.Manager, provider *tfschema.Pro
}
serviceMetaLoader := metadata.New()
dclConverter := conversion.New(dclSchemaLoader, serviceMetaLoader)

// Initialize direct controllers
if err := registry.Init(context.TODO(), &config.ControllerConfig{
HTTPClient: httpClient,
}); err != nil {
log.Fatalf("error intializing direct registry: %v", err)
}

return &TestReconciler{
mgr: mgr,
t: t,
Expand Down

0 comments on commit 30b7d89

Please sign in to comment.