diff --git a/klt-cert-manager/pkg/fake/manager_mock.go b/klt-cert-manager/pkg/fake/manager_mock.go index d136251930c..323cf33ad07 100644 --- a/klt-cert-manager/pkg/fake/manager_mock.go +++ b/klt-cert-manager/pkg/fake/manager_mock.go @@ -13,7 +13,7 @@ import ( "net/http" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" + "sigs.k8s.io/controller-runtime/pkg/config" "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/manager" "sigs.k8s.io/controller-runtime/pkg/webhook" @@ -53,7 +53,7 @@ import ( // GetConfigFunc: func() *rest.Config { // panic("mock out the GetConfig method") // }, -// GetControllerOptionsFunc: func() v1alpha1.ControllerConfigurationSpec { +// GetControllerOptionsFunc: func() config.Controller { // panic("mock out the GetControllerOptions method") // }, // GetEventRecorderForFunc: func(name string) record.EventRecorder { @@ -62,6 +62,9 @@ import ( // GetFieldIndexerFunc: func() client.FieldIndexer { // panic("mock out the GetFieldIndexer method") // }, +// GetHTTPClientFunc: func() *http.Client { +// panic("mock out the GetHTTPClient method") +// }, // GetLoggerFunc: func() logr.Logger { // panic("mock out the GetLogger method") // }, @@ -71,12 +74,9 @@ import ( // GetSchemeFunc: func() *runtime.Scheme { // panic("mock out the GetScheme method") // }, -// GetWebhookServerFunc: func() *webhook.Server { +// GetWebhookServerFunc: func() webhook.Server { // panic("mock out the GetWebhookServer method") // }, -// SetFieldsFunc: func(ifaceVal interface{}) error { -// panic("mock out the SetFields method") -// }, // StartFunc: func(ctx context.Context) error { // panic("mock out the Start method") // }, @@ -115,7 +115,7 @@ type MockManager struct { GetConfigFunc func() *rest.Config // GetControllerOptionsFunc mocks the GetControllerOptions method. - GetControllerOptionsFunc func() v1alpha1.ControllerConfigurationSpec + GetControllerOptionsFunc func() config.Controller // GetEventRecorderForFunc mocks the GetEventRecorderFor method. GetEventRecorderForFunc func(name string) record.EventRecorder @@ -123,6 +123,9 @@ type MockManager struct { // GetFieldIndexerFunc mocks the GetFieldIndexer method. GetFieldIndexerFunc func() client.FieldIndexer + // GetHTTPClientFunc mocks the GetHTTPClient method. + GetHTTPClientFunc func() *http.Client + // GetLoggerFunc mocks the GetLogger method. GetLoggerFunc func() logr.Logger @@ -133,10 +136,7 @@ type MockManager struct { GetSchemeFunc func() *runtime.Scheme // GetWebhookServerFunc mocks the GetWebhookServer method. - GetWebhookServerFunc func() *webhook.Server - - // SetFieldsFunc mocks the SetFields method. - SetFieldsFunc func(ifaceVal interface{}) error + GetWebhookServerFunc func() webhook.Server // StartFunc mocks the Start method. StartFunc func(ctx context.Context) error @@ -195,6 +195,9 @@ type MockManager struct { // GetFieldIndexer holds details about calls to the GetFieldIndexer method. GetFieldIndexer []struct { } + // GetHTTPClient holds details about calls to the GetHTTPClient method. + GetHTTPClient []struct { + } // GetLogger holds details about calls to the GetLogger method. GetLogger []struct { } @@ -207,11 +210,6 @@ type MockManager struct { // GetWebhookServer holds details about calls to the GetWebhookServer method. GetWebhookServer []struct { } - // SetFields holds details about calls to the SetFields method. - SetFields []struct { - // IfaceVal is the ifaceVal argument value. - IfaceVal interface{} - } // Start holds details about calls to the Start method. Start []struct { // Ctx is the ctx argument value. @@ -230,11 +228,11 @@ type MockManager struct { lockGetControllerOptions sync.RWMutex lockGetEventRecorderFor sync.RWMutex lockGetFieldIndexer sync.RWMutex + lockGetHTTPClient sync.RWMutex lockGetLogger sync.RWMutex lockGetRESTMapper sync.RWMutex lockGetScheme sync.RWMutex lockGetWebhookServer sync.RWMutex - lockSetFields sync.RWMutex lockStart sync.RWMutex } @@ -514,7 +512,7 @@ func (mock *MockManager) GetConfigCalls() []struct { } // GetControllerOptions calls GetControllerOptionsFunc. -func (mock *MockManager) GetControllerOptions() v1alpha1.ControllerConfigurationSpec { +func (mock *MockManager) GetControllerOptions() config.Controller { if mock.GetControllerOptionsFunc == nil { panic("MockManager.GetControllerOptionsFunc: method is nil but IManager.GetControllerOptions was just called") } @@ -599,6 +597,33 @@ func (mock *MockManager) GetFieldIndexerCalls() []struct { return calls } +// GetHTTPClient calls GetHTTPClientFunc. +func (mock *MockManager) GetHTTPClient() *http.Client { + if mock.GetHTTPClientFunc == nil { + panic("MockManager.GetHTTPClientFunc: method is nil but IManager.GetHTTPClient was just called") + } + callInfo := struct { + }{} + mock.lockGetHTTPClient.Lock() + mock.calls.GetHTTPClient = append(mock.calls.GetHTTPClient, callInfo) + mock.lockGetHTTPClient.Unlock() + return mock.GetHTTPClientFunc() +} + +// GetHTTPClientCalls gets all the calls that were made to GetHTTPClient. +// Check the length with: +// +// len(mockedIManager.GetHTTPClientCalls()) +func (mock *MockManager) GetHTTPClientCalls() []struct { +} { + var calls []struct { + } + mock.lockGetHTTPClient.RLock() + calls = mock.calls.GetHTTPClient + mock.lockGetHTTPClient.RUnlock() + return calls +} + // GetLogger calls GetLoggerFunc. func (mock *MockManager) GetLogger() logr.Logger { if mock.GetLoggerFunc == nil { @@ -681,7 +706,7 @@ func (mock *MockManager) GetSchemeCalls() []struct { } // GetWebhookServer calls GetWebhookServerFunc. -func (mock *MockManager) GetWebhookServer() *webhook.Server { +func (mock *MockManager) GetWebhookServer() webhook.Server { if mock.GetWebhookServerFunc == nil { panic("MockManager.GetWebhookServerFunc: method is nil but IManager.GetWebhookServer was just called") } @@ -707,38 +732,6 @@ func (mock *MockManager) GetWebhookServerCalls() []struct { return calls } -// SetFields calls SetFieldsFunc. -func (mock *MockManager) SetFields(ifaceVal interface{}) error { - if mock.SetFieldsFunc == nil { - panic("MockManager.SetFieldsFunc: method is nil but IManager.SetFields was just called") - } - callInfo := struct { - IfaceVal interface{} - }{ - IfaceVal: ifaceVal, - } - mock.lockSetFields.Lock() - mock.calls.SetFields = append(mock.calls.SetFields, callInfo) - mock.lockSetFields.Unlock() - return mock.SetFieldsFunc(ifaceVal) -} - -// SetFieldsCalls gets all the calls that were made to SetFields. -// Check the length with: -// -// len(mockedIManager.SetFieldsCalls()) -func (mock *MockManager) SetFieldsCalls() []struct { - IfaceVal interface{} -} { - var calls []struct { - IfaceVal interface{} - } - mock.lockSetFields.RLock() - calls = mock.calls.SetFields - mock.lockSetFields.RUnlock() - return calls -} - // Start calls StartFunc. func (mock *MockManager) Start(ctx context.Context) error { if mock.StartFunc == nil { diff --git a/klt-cert-manager/pkg/webhook/builder_test.go b/klt-cert-manager/pkg/webhook/builder_test.go index ed1223d8591..a9952b3c140 100644 --- a/klt-cert-manager/pkg/webhook/builder_test.go +++ b/klt-cert-manager/pkg/webhook/builder_test.go @@ -45,8 +45,8 @@ func TestBuilder_Run(t *testing.T) { mockManager.GetAPIReaderFunc = func() client.Reader { return newFakeClient() } - webhookServer := &webhook.Server{} - mockManager.GetWebhookServerFunc = func() *webhook.Server { + webhookServer := webhook.NewServer(webhook.Options{}) + mockManager.GetWebhookServerFunc = func() webhook.Server { return webhookServer } diff --git a/klt-cert-manager/pkg/webhook/manager.go b/klt-cert-manager/pkg/webhook/manager.go index 704584333ae..612dfac5b4f 100644 --- a/klt-cert-manager/pkg/webhook/manager.go +++ b/klt-cert-manager/pkg/webhook/manager.go @@ -4,6 +4,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/manager" + "sigs.k8s.io/controller-runtime/pkg/webhook" ) const ( @@ -43,9 +44,10 @@ func (provider WebhookProvider) createOptions(scheme *runtime.Scheme, namespace } func (provider WebhookProvider) SetupWebhookServer(mgr manager.Manager) { + webhookServer := mgr.GetWebhookServer() - webhookServer.CertDir = provider.certificateDirectory - webhookServer.KeyName = provider.keyFileName - webhookServer.CertName = provider.certificateFileName + webhookServer.(*webhook.DefaultServer).Options.CertDir = provider.certificateDirectory + webhookServer.(*webhook.DefaultServer).Options.KeyName = provider.keyFileName + webhookServer.(*webhook.DefaultServer).Options.CertName = provider.certificateFileName } diff --git a/klt-cert-manager/pkg/webhook/manager_test.go b/klt-cert-manager/pkg/webhook/manager_test.go index 97c39ee172d..83bc9139580 100644 --- a/klt-cert-manager/pkg/webhook/manager_test.go +++ b/klt-cert-manager/pkg/webhook/manager_test.go @@ -31,23 +31,23 @@ func TestCreateOptions(t *testing.T) { }) t.Run("configures webhooks server", func(t *testing.T) { provider := NewWebhookManagerProvider("certs-dir", "key-file", "cert-file") - expectedWebhookServer := &webhook.Server{} + expectedWebhookServer := webhook.NewServer(webhook.Options{}) mgr := &fake.MockManager{ - GetWebhookServerFunc: func() *webhook.Server { + GetWebhookServerFunc: func() webhook.Server { return expectedWebhookServer }, } provider.SetupWebhookServer(mgr) - assert.Equal(t, "certs-dir", expectedWebhookServer.CertDir) - assert.Equal(t, "key-file", expectedWebhookServer.KeyName) - assert.Equal(t, "cert-file", expectedWebhookServer.CertName) + assert.Equal(t, "certs-dir", expectedWebhookServer.(*webhook.DefaultServer).Options.CertDir) + assert.Equal(t, "key-file", expectedWebhookServer.(*webhook.DefaultServer).Options.KeyName) + assert.Equal(t, "cert-file", expectedWebhookServer.(*webhook.DefaultServer).Options.CertName) mgrWebhookServer := mgr.GetWebhookServer() - assert.Equal(t, "certs-dir", mgrWebhookServer.CertDir) - assert.Equal(t, "key-file", mgrWebhookServer.KeyName) - assert.Equal(t, "cert-file", mgrWebhookServer.CertName) + assert.Equal(t, "certs-dir", mgrWebhookServer.(*webhook.DefaultServer).Options.CertDir) + assert.Equal(t, "key-file", mgrWebhookServer.(*webhook.DefaultServer).Options.KeyName) + assert.Equal(t, "cert-file", mgrWebhookServer.(*webhook.DefaultServer).Options.CertName) }) }