From 4a041182b51d64ce0a4cc4f9016c634daaf105db Mon Sep 17 00:00:00 2001 From: Steve Wagner Date: Tue, 25 Apr 2023 13:27:14 -0700 Subject: [PATCH] Rename to NGINX terms (#48) --- internal/application/application_constants.go | 8 ++++---- internal/application/border_client.go | 8 ++++---- internal/application/border_client_test.go | 10 +++++----- internal/application/doc.go | 4 ++-- internal/application/nginx_client_interface.go | 8 ++++---- ...r_client.go => nginx_http_border_client.go} | 14 +++++++------- ...est.go => nginx_http_border_client_test.go} | 18 +++++++++--------- ...client.go => nginx_stream_border_client.go} | 14 +++++++------- ...t.go => nginx_stream_border_client_test.go} | 18 +++++++++--------- internal/translation/translator.go | 4 ++-- 10 files changed, 53 insertions(+), 53 deletions(-) rename internal/application/{http_border_client.go => nginx_http_border_client.go} (79%) rename internal/application/{http_border_client_test.go => nginx_http_border_client_test.go} (78%) rename internal/application/{tcp_border_client.go => nginx_stream_border_client.go} (77%) rename internal/application/{tcp_border_client_test.go => nginx_stream_border_client_test.go} (77%) diff --git a/internal/application/application_constants.go b/internal/application/application_constants.go index 5f213d4..ae43477 100644 --- a/internal/application/application_constants.go +++ b/internal/application/application_constants.go @@ -20,9 +20,9 @@ package application // 3. Update the NewBorderClient factory method in border_client.go that returns the client; const ( - // ClientTypeTcp creates a TcpBorderClient that uses the Stream* methods of the NGINX Plus client. - ClientTypeTcp = "tcp" + // ClientTypeNginxStream creates a NginxStreamBorderClient that uses the Stream* methods of the NGINX Plus client. + ClientTypeNginxStream = "stream" - // ClientTypeHttp creates an HttpBorderClient that uses the HTTP* methods of the NGINX Plus client. - ClientTypeHttp = "http" + // ClientTypeNginxHttp creates an NginxHttpBorderClient that uses the HTTP* methods of the NGINX Plus client. + ClientTypeNginxHttp = "http" ) diff --git a/internal/application/border_client.go b/internal/application/border_client.go index bae7eab..a5cc93e 100644 --- a/internal/application/border_client.go +++ b/internal/application/border_client.go @@ -31,11 +31,11 @@ func NewBorderClient(clientType string, borderClient interface{}) (Interface, er logrus.Debugf(`NewBorderClient for type: %s`, clientType) switch clientType { - case ClientTypeTcp: - return NewTcpBorderClient(borderClient) + case ClientTypeNginxStream: + return NewNginxStreamBorderClient(borderClient) - case ClientTypeHttp: - return NewHttpBorderClient(borderClient) + case ClientTypeNginxHttp: + return NewNginxHttpBorderClient(borderClient) default: borderClient, _ := NewNullBorderClient() diff --git a/internal/application/border_client_test.go b/internal/application/border_client_test.go index 6d5ab50..0b8105e 100644 --- a/internal/application/border_client_test.go +++ b/internal/application/border_client_test.go @@ -17,20 +17,20 @@ func TestBorderClient_CreatesHttpBorderClient(t *testing.T) { t.Errorf(`error creating border client: %v`, err) } - if _, ok := client.(*HttpBorderClient); !ok { - t.Errorf(`expected client to be of type HttpBorderClient`) + if _, ok := client.(*NginxHttpBorderClient); !ok { + t.Errorf(`expected client to be of type NginxHttpBorderClient`) } } func TestBorderClient_CreatesTcpBorderClient(t *testing.T) { borderClient := mocks.MockNginxClient{} - client, err := NewBorderClient("tcp", borderClient) + client, err := NewBorderClient("stream", borderClient) if err != nil { t.Errorf(`error creating border client: %v`, err) } - if _, ok := client.(*TcpBorderClient); !ok { - t.Errorf(`expected client to be of type TcpBorderClient`) + if _, ok := client.(*NginxStreamBorderClient); !ok { + t.Errorf(`expected client to be of type NginxStreamBorderClient`) } } diff --git a/internal/application/doc.go b/internal/application/doc.go index 0395d6b..4d24fab 100644 --- a/internal/application/doc.go +++ b/internal/application/doc.go @@ -17,8 +17,8 @@ To add a Border Server client... At this time the only supported Border Servers are NGINX Plus servers. The two Border Server clients for NGINX Plus are: -- HttpBorderClient: updates NGINX Plus servers using HTTP Upstream methods on the NGINX Plus API. -- TcpBorderClient: updates NGINX Plus servers using Stream Upstream methods on the NGINX Plus API. +- NginxHttpBorderClient: updates NGINX Plus servers using HTTP Upstream methods on the NGINX Plus API. +- NginxStreamBorderClient: updates NGINX Plus servers using Stream Upstream methods on the NGINX Plus API. Both of these implementations use the NGINX Plus client module to communicate with the NGINX Plus server. diff --git a/internal/application/nginx_client_interface.go b/internal/application/nginx_client_interface.go index 516d6e1..728db1e 100644 --- a/internal/application/nginx_client_interface.go +++ b/internal/application/nginx_client_interface.go @@ -9,15 +9,15 @@ import nginxClient "github.com/nginxinc/nginx-plus-go-client/client" // NginxClientInterface defines the functions used on the NGINX Plus client, abstracting away the full details of that client. type NginxClientInterface interface { - // DeleteStreamServer is used by the TcpBorderClient. + // DeleteStreamServer is used by the NginxStreamBorderClient. DeleteStreamServer(upstream string, server string) error - // UpdateStreamServers is used by the TcpBorderClient. + // UpdateStreamServers is used by the NginxStreamBorderClient. UpdateStreamServers(upstream string, servers []nginxClient.StreamUpstreamServer) ([]nginxClient.StreamUpstreamServer, []nginxClient.StreamUpstreamServer, []nginxClient.StreamUpstreamServer, error) - // DeleteHTTPServer is used by the HttpBorderClient. + // DeleteHTTPServer is used by the NginxHttpBorderClient. DeleteHTTPServer(upstream string, server string) error - // UpdateHTTPServers is used by the HttpBorderClient. + // UpdateHTTPServers is used by the NginxHttpBorderClient. UpdateHTTPServers(upstream string, servers []nginxClient.UpstreamServer) ([]nginxClient.UpstreamServer, []nginxClient.UpstreamServer, []nginxClient.UpstreamServer, error) } diff --git a/internal/application/http_border_client.go b/internal/application/nginx_http_border_client.go similarity index 79% rename from internal/application/http_border_client.go rename to internal/application/nginx_http_border_client.go index a306141..b7657c5 100644 --- a/internal/application/http_border_client.go +++ b/internal/application/nginx_http_border_client.go @@ -11,26 +11,26 @@ import ( nginxClient "github.com/nginxinc/nginx-plus-go-client/client" ) -// HttpBorderClient implements the BorderClient interface for HTTP upstreams. -type HttpBorderClient struct { +// NginxHttpBorderClient implements the BorderClient interface for HTTP upstreams. +type NginxHttpBorderClient struct { BorderClient nginxClient NginxClientInterface } -// NewHttpBorderClient is the Factory function for creating an HttpBorderClient. -func NewHttpBorderClient(client interface{}) (Interface, error) { +// NewNginxHttpBorderClient is the Factory function for creating an NginxHttpBorderClient. +func NewNginxHttpBorderClient(client interface{}) (Interface, error) { ngxClient, ok := client.(NginxClientInterface) if !ok { return nil, fmt.Errorf(`expected a NginxClientInterface, got a %v`, client) } - return &HttpBorderClient{ + return &NginxHttpBorderClient{ nginxClient: ngxClient, }, nil } // Update manages the Upstream servers for the Upstream Name given in the ServerUpdateEvent. -func (hbc *HttpBorderClient) Update(event *core.ServerUpdateEvent) error { +func (hbc *NginxHttpBorderClient) Update(event *core.ServerUpdateEvent) error { httpUpstreamServers := asNginxHttpUpstreamServers(event.UpstreamServers) _, _, _, err := hbc.nginxClient.UpdateHTTPServers(event.UpstreamName, httpUpstreamServers) if err != nil { @@ -41,7 +41,7 @@ func (hbc *HttpBorderClient) Update(event *core.ServerUpdateEvent) error { } // Delete deletes the Upstream server for the Upstream Name given in the ServerUpdateEvent. -func (hbc *HttpBorderClient) Delete(event *core.ServerUpdateEvent) error { +func (hbc *NginxHttpBorderClient) Delete(event *core.ServerUpdateEvent) error { err := hbc.nginxClient.DeleteHTTPServer(event.UpstreamName, event.UpstreamServers[0].Host) if err != nil { return fmt.Errorf(`error occurred deleting the nginx+ upstream server: %w`, err) diff --git a/internal/application/http_border_client_test.go b/internal/application/nginx_http_border_client_test.go similarity index 78% rename from internal/application/http_border_client_test.go rename to internal/application/nginx_http_border_client_test.go index 40a5fe1..defc2ef 100644 --- a/internal/application/http_border_client_test.go +++ b/internal/application/nginx_http_border_client_test.go @@ -10,8 +10,8 @@ import ( ) func TestHttpBorderClient_Delete(t *testing.T) { - event := buildServerUpdateEvent(deletedEventType, ClientTypeHttp) - borderClient, nginxClient, err := buildBorderClient(ClientTypeHttp) + event := buildServerUpdateEvent(deletedEventType, ClientTypeNginxHttp) + borderClient, nginxClient, err := buildBorderClient(ClientTypeNginxHttp) if err != nil { t.Fatalf(`error occurred creating a new border client: %v`, err) } @@ -27,8 +27,8 @@ func TestHttpBorderClient_Delete(t *testing.T) { } func TestHttpBorderClient_Update(t *testing.T) { - event := buildServerUpdateEvent(createEventType, ClientTypeHttp) - borderClient, nginxClient, err := buildBorderClient(ClientTypeHttp) + event := buildServerUpdateEvent(createEventType, ClientTypeNginxHttp) + borderClient, nginxClient, err := buildBorderClient(ClientTypeNginxHttp) if err != nil { t.Fatalf(`error occurred creating a new border client: %v`, err) } @@ -45,15 +45,15 @@ func TestHttpBorderClient_Update(t *testing.T) { func TestHttpBorderClient_BadNginxClient(t *testing.T) { var emptyInterface interface{} - _, err := NewBorderClient(ClientTypeHttp, emptyInterface) + _, err := NewBorderClient(ClientTypeNginxHttp, emptyInterface) if err == nil { t.Fatalf(`expected an error to occur when creating a new border client`) } } func TestHttpBorderClient_DeleteReturnsError(t *testing.T) { - event := buildServerUpdateEvent(deletedEventType, ClientTypeHttp) - borderClient, _, err := buildTerrorizingBorderClient(ClientTypeHttp) + event := buildServerUpdateEvent(deletedEventType, ClientTypeNginxHttp) + borderClient, _, err := buildTerrorizingBorderClient(ClientTypeNginxHttp) if err != nil { t.Fatalf(`error occurred creating a new border client: %v`, err) } @@ -66,8 +66,8 @@ func TestHttpBorderClient_DeleteReturnsError(t *testing.T) { } func TestHttpBorderClient_UpdateReturnsError(t *testing.T) { - event := buildServerUpdateEvent(createEventType, ClientTypeHttp) - borderClient, _, err := buildTerrorizingBorderClient(ClientTypeHttp) + event := buildServerUpdateEvent(createEventType, ClientTypeNginxHttp) + borderClient, _, err := buildTerrorizingBorderClient(ClientTypeNginxHttp) if err != nil { t.Fatalf(`error occurred creating a new border client: %v`, err) } diff --git a/internal/application/tcp_border_client.go b/internal/application/nginx_stream_border_client.go similarity index 77% rename from internal/application/tcp_border_client.go rename to internal/application/nginx_stream_border_client.go index 822110b..46cd498 100644 --- a/internal/application/tcp_border_client.go +++ b/internal/application/nginx_stream_border_client.go @@ -11,26 +11,26 @@ import ( nginxClient "github.com/nginxinc/nginx-plus-go-client/client" ) -// TcpBorderClient implements the BorderClient interface for TCP upstreams. -type TcpBorderClient struct { +// NginxStreamBorderClient implements the BorderClient interface for stream upstreams. +type NginxStreamBorderClient struct { BorderClient nginxClient NginxClientInterface } -// NewTcpBorderClient is the Factory function for creating an TcpBorderClient. -func NewTcpBorderClient(client interface{}) (Interface, error) { +// NewNginxStreamBorderClient is the Factory function for creating an NginxStreamBorderClient. +func NewNginxStreamBorderClient(client interface{}) (Interface, error) { ngxClient, ok := client.(NginxClientInterface) if !ok { return nil, fmt.Errorf(`expected a NginxClientInterface, got a %v`, client) } - return &TcpBorderClient{ + return &NginxStreamBorderClient{ nginxClient: ngxClient, }, nil } // Update manages the Upstream servers for the Upstream Name given in the ServerUpdateEvent. -func (tbc *TcpBorderClient) Update(event *core.ServerUpdateEvent) error { +func (tbc *NginxStreamBorderClient) Update(event *core.ServerUpdateEvent) error { streamUpstreamServers := asNginxStreamUpstreamServers(event.UpstreamServers) _, _, _, err := tbc.nginxClient.UpdateStreamServers(event.UpstreamName, streamUpstreamServers) if err != nil { @@ -41,7 +41,7 @@ func (tbc *TcpBorderClient) Update(event *core.ServerUpdateEvent) error { } // Delete deletes the Upstream server for the Upstream Name given in the ServerUpdateEvent. -func (tbc *TcpBorderClient) Delete(event *core.ServerUpdateEvent) error { +func (tbc *NginxStreamBorderClient) Delete(event *core.ServerUpdateEvent) error { err := tbc.nginxClient.DeleteStreamServer(event.UpstreamName, event.UpstreamServers[0].Host) if err != nil { return fmt.Errorf(`error occurred deleting the nginx+ upstream server: %w`, err) diff --git a/internal/application/tcp_border_client_test.go b/internal/application/nginx_stream_border_client_test.go similarity index 77% rename from internal/application/tcp_border_client_test.go rename to internal/application/nginx_stream_border_client_test.go index 69087e5..ddcb346 100644 --- a/internal/application/tcp_border_client_test.go +++ b/internal/application/nginx_stream_border_client_test.go @@ -10,8 +10,8 @@ import ( ) func TestTcpBorderClient_Delete(t *testing.T) { - event := buildServerUpdateEvent(deletedEventType, ClientTypeTcp) - borderClient, nginxClient, err := buildBorderClient(ClientTypeTcp) + event := buildServerUpdateEvent(deletedEventType, ClientTypeNginxStream) + borderClient, nginxClient, err := buildBorderClient(ClientTypeNginxStream) if err != nil { t.Fatalf(`error occurred creating a new border client: %v`, err) } @@ -27,8 +27,8 @@ func TestTcpBorderClient_Delete(t *testing.T) { } func TestTcpBorderClient_Update(t *testing.T) { - event := buildServerUpdateEvent(createEventType, ClientTypeTcp) - borderClient, nginxClient, err := buildBorderClient(ClientTypeTcp) + event := buildServerUpdateEvent(createEventType, ClientTypeNginxStream) + borderClient, nginxClient, err := buildBorderClient(ClientTypeNginxStream) if err != nil { t.Fatalf(`error occurred creating a new border client: %v`, err) } @@ -45,15 +45,15 @@ func TestTcpBorderClient_Update(t *testing.T) { func TestTcpBorderClient_BadNginxClient(t *testing.T) { var emptyInterface interface{} - _, err := NewBorderClient(ClientTypeTcp, emptyInterface) + _, err := NewBorderClient(ClientTypeNginxStream, emptyInterface) if err == nil { t.Fatalf(`expected an error to occur when creating a new border client`) } } func TestTcpBorderClient_DeleteReturnsError(t *testing.T) { - event := buildServerUpdateEvent(deletedEventType, ClientTypeTcp) - borderClient, _, err := buildTerrorizingBorderClient(ClientTypeTcp) + event := buildServerUpdateEvent(deletedEventType, ClientTypeNginxStream) + borderClient, _, err := buildTerrorizingBorderClient(ClientTypeNginxStream) if err != nil { t.Fatalf(`error occurred creating a new border client: %v`, err) } @@ -66,8 +66,8 @@ func TestTcpBorderClient_DeleteReturnsError(t *testing.T) { } func TestTcpBorderClient_UpdateReturnsError(t *testing.T) { - event := buildServerUpdateEvent(createEventType, ClientTypeTcp) - borderClient, _, err := buildTerrorizingBorderClient(ClientTypeTcp) + event := buildServerUpdateEvent(createEventType, ClientTypeNginxStream) + borderClient, _, err := buildTerrorizingBorderClient(ClientTypeNginxStream) if err != nil { t.Fatalf(`error occurred creating a new border client: %v`, err) } diff --git a/internal/translation/translator.go b/internal/translation/translator.go index 55d7c29..a858cad 100644 --- a/internal/translation/translator.go +++ b/internal/translation/translator.go @@ -89,7 +89,7 @@ func fixIngressName(name string) string { return name[4:] } -// getClientType returns the client type for the port, defaults to ClientTypeHttp if no Annotation is found. +// getClientType returns the client type for the port, defaults to ClientTypeNginxHttp if no Annotation is found. func getClientType(portName string, annotations map[string]string) string { key := fmt.Sprintf("%s/%s", configuration.PortAnnotationPrefix, portName) logrus.Infof("getClientType: key=%s", key) @@ -99,5 +99,5 @@ func getClientType(portName string, annotations map[string]string) string { } } - return application.ClientTypeHttp + return application.ClientTypeNginxHttp }