diff --git a/pkg/apis/logstash/v1alpha1/name.go b/pkg/apis/logstash/v1alpha1/name.go index a2a32d47ed3..4ea4a789c4d 100644 --- a/pkg/apis/logstash/v1alpha1/name.go +++ b/pkg/apis/logstash/v1alpha1/name.go @@ -9,8 +9,8 @@ import ( ) const ( - defaultServiceSuffix = "default" - configSuffix = "config" + apiServiceSuffix = "api" + configSuffix = "config" ) // Namer is a Namer that is configured with the defaults for resources related to a Logstash resource. @@ -30,9 +30,9 @@ func Name(name string) string { return Namer.Suffix(name) } -// DefaultServiceName returns the name of the HTTP service for a given Logstash name. -func DefaultServiceName(name string) string { - return Namer.Suffix(name, defaultServiceSuffix) +// APIServiceName returns the name of the HTTP service for a given Logstash name. +func APIServiceName(name string) string { + return Namer.Suffix(name, apiServiceSuffix) } func UserServiceName(deployName string, name string) string { diff --git a/pkg/apis/logstash/v1alpha1/name_test.go b/pkg/apis/logstash/v1alpha1/name_test.go index a7704be84d3..21f767af222 100644 --- a/pkg/apis/logstash/v1alpha1/name_test.go +++ b/pkg/apis/logstash/v1alpha1/name_test.go @@ -8,7 +8,7 @@ import ( "testing" ) -func TestDefaultService(t *testing.T) { +func TestAPIService(t *testing.T) { type args struct { logstashName string } @@ -20,12 +20,12 @@ func TestDefaultService(t *testing.T) { { name: "sample", args: args{logstashName: "sample"}, - want: "sample-ls-default", + want: "sample-ls-api", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := DefaultServiceName(tt.args.logstashName); got != tt.want { + if got := APIServiceName(tt.args.logstashName); got != tt.want { t.Errorf("DefaultService() = %v, want %v", got, tt.want) } }) diff --git a/pkg/controller/logstash/reconcile.go b/pkg/controller/logstash/reconcile.go index c21e8a3d3c0..89819f13c8c 100644 --- a/pkg/controller/logstash/reconcile.go +++ b/pkg/controller/logstash/reconcile.go @@ -31,7 +31,7 @@ func reconcileStatefulSet(params Params, podTemplate corev1.PodTemplateSpec) (*r s := sset.New(sset.Params{ Name: logstashv1alpha1.Name(params.Logstash.Name), Namespace: params.Logstash.Namespace, - ServiceName: logstashv1alpha1.DefaultServiceName(params.Logstash.Name), + ServiceName: logstashv1alpha1.APIServiceName(params.Logstash.Name), Selector: params.Logstash.GetIdentityLabels(), Labels: params.Logstash.GetIdentityLabels(), PodTemplateSpec: podTemplate, diff --git a/pkg/controller/logstash/service.go b/pkg/controller/logstash/service.go index a5a61c81111..b72b7ea85f8 100644 --- a/pkg/controller/logstash/service.go +++ b/pkg/controller/logstash/service.go @@ -19,15 +19,15 @@ import ( // When a service is defined that matches the API service name, then that service is used to define // the service for the logstash API. If not, then a default service is created for the API service func reconcileServices(params Params) ([]corev1.Service, error) { - createdApiService := false + createdAPIService := false - var svcs []corev1.Service + svcs := make([]corev1.Service, 0) for _, service := range params.Logstash.Spec.Services { var svc *corev1.Service logstash := params.Logstash - if logstashv1alpha1.UserServiceName(logstash.Name, service.Name) == logstashv1alpha1.DefaultServiceName(logstash.Name) { - svc = newDefaultService(params.Logstash) - createdApiService = true + if logstashv1alpha1.UserServiceName(logstash.Name, service.Name) == logstashv1alpha1.APIServiceName(logstash.Name) { + svc = newAPIService(params.Logstash) + createdAPIService = true } else { svc = newService(service, params.Logstash) } @@ -36,8 +36,8 @@ func reconcileServices(params Params) ([]corev1.Service, error) { } svcs = append(svcs, *svc) } - if !createdApiService { - svc := newDefaultService(params.Logstash) + if !createdAPIService { + svc := newAPIService(params.Logstash) if err := reconcileService(params, svc); err != nil { return []corev1.Service{}, err } @@ -75,14 +75,14 @@ func newService(service logstashv1alpha1.LogstashService, logstash logstashv1alp return &svc } -func newDefaultService(logstash logstashv1alpha1.Logstash) *corev1.Service { +func newAPIService(logstash logstashv1alpha1.Logstash) *corev1.Service { svc := corev1.Service{ ObjectMeta: metav1.ObjectMeta{}, Spec: corev1.ServiceSpec{ClusterIP: "None"}, } svc.ObjectMeta.Namespace = logstash.Namespace - svc.ObjectMeta.Name = logstashv1alpha1.DefaultServiceName(logstash.Name) + svc.ObjectMeta.Name = logstashv1alpha1.APIServiceName(logstash.Name) labels := NewLabels(logstash) ports := []corev1.ServicePort{ diff --git a/test/e2e/test/logstash/builder.go b/test/e2e/test/logstash/builder.go index 0aead87d493..2e7385f2d76 100644 --- a/test/e2e/test/logstash/builder.go +++ b/test/e2e/test/logstash/builder.go @@ -127,7 +127,7 @@ func (b Builder) Count() int32 { } func (b Builder) ServiceName() string { - return b.Logstash.Name + "-ls-default" + return b.Logstash.Name + "-ls-api" } func (b Builder) ListOptions() []client.ListOption { diff --git a/test/e2e/test/logstash/http_client.go b/test/e2e/test/logstash/http_client.go index 8c0235a1648..b9456d01539 100644 --- a/test/e2e/test/logstash/http_client.go +++ b/test/e2e/test/logstash/http_client.go @@ -33,7 +33,7 @@ func NewLogstashClient(logstash v1alpha1.Logstash, k *test.K8sClient) (*http.Cli func DoRequest(client *http.Client, logstash v1alpha1.Logstash, method, path string) ([]byte, error) { scheme := "http" - url, err := url.Parse(fmt.Sprintf("%s://%s.%s.svc:9600%s", scheme, v1alpha1.DefaultServiceName(logstash.Name), logstash.Namespace, path)) + url, err := url.Parse(fmt.Sprintf("%s://%s.%s.svc:9600%s", scheme, v1alpha1.APIServiceName(logstash.Name), logstash.Namespace, path)) if err != nil { return nil, fmt.Errorf("while parsing URL: %w", err) }