Skip to content

Commit

Permalink
Replace 'default' service name with 'api'
Browse files Browse the repository at this point in the history
The default service represents the logstash API, so this commit updates
the service name and associated methods to reflect that.

This should also be more intuitive for users who wish to change the
settings for the service.
  • Loading branch information
robbavey committed Feb 28, 2023
1 parent 7b063e2 commit 1a06bb6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions pkg/apis/logstash/v1alpha1/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/logstash/v1alpha1/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
)

func TestDefaultService(t *testing.T) {
func TestAPIService(t *testing.T) {
type args struct {
logstashName string
}
Expand All @@ -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)
}
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/logstash/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions pkg/controller/logstash/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/test/logstash/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/test/logstash/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 1a06bb6

Please sign in to comment.