Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/v1/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ const (
// The portal uses this label to discover available templates for a dropdown.
// Values: "gitlab" (extensible to other CI systems in the future).
CITemplateLabel = "app.edp.epam.com/ci-template"

// GitServerLabel is a label used to store the name of the GitServer in related resources.
GitServerLabel = "app.edp.epam.com/gitServer"
)
39 changes: 15 additions & 24 deletions controllers/gitserver/create_event_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ import (
"github.com/epam/edp-codebase-operator/v2/pkg/tektoncd"
)

const errGetDNSWildcard = "failed to get dnsWildcard: %w"

type CreateEventListener struct {
k8sClient client.Client
}

func generateEventListenerHost(gitServer *codebaseApi.GitServer, dnsWildcard string) string {
return fmt.Sprintf("el-%s-%s.%s", gitServer.Name, gitServer.Namespace, dnsWildcard)
}

func NewCreateEventListener(k8sClient client.Client) *CreateEventListener {
return &CreateEventListener{k8sClient: k8sClient}
}
Expand Down Expand Up @@ -70,7 +76,7 @@ func (h *CreateEventListener) createEventListener(ctx context.Context, gitServer
el.SetName(elName)
el.SetNamespace(gitServer.Namespace)
el.SetLabels(map[string]string{
"app.edp.epam.com/gitServer": gitServer.Name,
codebaseApi.GitServerLabel: gitServer.Name,
})

el.Object["spec"] = map[string]interface{}{
Expand Down Expand Up @@ -163,7 +169,7 @@ func (h *CreateEventListener) createIngress(ctx context.Context, gitServer *code

config, err := platform.GetKrciConfig(ctx, h.k8sClient, gitServer.Namespace)
if err != nil {
return fmt.Errorf("failed to get dnsWildcard: %w", err)
return fmt.Errorf(errGetDNSWildcard, err)
}

// This port is hardcoded in Tekton Triggers.
Expand All @@ -175,18 +181,13 @@ func (h *CreateEventListener) createIngress(ctx context.Context, gitServer *code
Name: name,
Namespace: gitServer.Namespace,
Labels: map[string]string{
"app.edp.epam.com/gitServer": gitServer.Name,
codebaseApi.GitServerLabel: gitServer.Name,
},
},
Spec: networkingv1.IngressSpec{
Rules: []networkingv1.IngressRule{
{
Host: fmt.Sprintf(
"el-%s-%s.%s",
gitServer.Name,
gitServer.Namespace,
config.DnsWildcard,
),
Host: generateEventListenerHost(gitServer, config.DnsWildcard),
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{
Expand Down Expand Up @@ -253,7 +254,7 @@ func (h *CreateEventListener) createHTTPRoute(ctx context.Context, gitServer *co

config, err := platform.GetKrciConfig(ctx, h.k8sClient, gitServer.Namespace)
if err != nil {
return fmt.Errorf("failed to get dnsWildcard: %w", err)
return fmt.Errorf(errGetDNSWildcard, err)
}

// This port is hardcoded in Tekton Triggers.
Expand All @@ -265,7 +266,7 @@ func (h *CreateEventListener) createHTTPRoute(ctx context.Context, gitServer *co
Name: name,
Namespace: gitServer.Namespace,
Labels: map[string]string{
"app.edp.epam.com/gitServer": gitServer.Name,
codebaseApi.GitServerLabel: gitServer.Name,
},
},
Spec: gatewayv1.HTTPRouteSpec{
Expand All @@ -278,12 +279,7 @@ func (h *CreateEventListener) createHTTPRoute(ctx context.Context, gitServer *co
},
},
Hostnames: []gatewayv1.Hostname{
gatewayv1.Hostname(fmt.Sprintf(
"el-%s-%s.%s",
gitServer.Name,
gitServer.Namespace,
config.DnsWildcard,
)),
gatewayv1.Hostname(generateEventListenerHost(gitServer, config.DnsWildcard)),
},
Rules: []gatewayv1.HTTPRouteRule{
{
Expand Down Expand Up @@ -346,7 +342,7 @@ func (h *CreateEventListener) createRoute(ctx context.Context, gitServer *codeba

config, err := platform.GetKrciConfig(ctx, h.k8sClient, gitServer.Namespace)
if err != nil {
return fmt.Errorf("failed to get dnsWildcard: %w", err)
return fmt.Errorf(errGetDNSWildcard, err)
}

const routeWeight = int32(100)
Expand All @@ -357,12 +353,7 @@ func (h *CreateEventListener) createRoute(ctx context.Context, gitServer *codeba
Namespace: gitServer.Namespace,
},
Spec: routeApi.RouteSpec{
Host: fmt.Sprintf(
"el-%s-%s.%s",
gitServer.Name,
gitServer.Namespace,
config.DnsWildcard,
),
Host: generateEventListenerHost(gitServer, config.DnsWildcard),
TLS: &routeApi.TLSConfig{
InsecureEdgeTerminationPolicy: routeApi.InsecureEdgeTerminationPolicyRedirect,
Termination: routeApi.TLSTerminationEdge,
Expand Down
Loading