Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80d5f9a

Browse files
committedJul 22, 2024·
fix service monitors
1 parent adb850c commit 80d5f9a

30 files changed

+152
-114
lines changed
 

‎bundle/manifests/rhtas.redhat.com_rekors.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ spec:
150150
x-kubernetes-validations:
151151
- message: Feature cannot be disabled
152152
rule: (self || !oldSelf)
153+
host:
154+
description: Set hostname for your Ingress/Route.
155+
type: string
153156
required:
154157
- enabled
155158
type: object

‎bundle/manifests/rhtas.redhat.com_securesigns.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ spec:
512512
x-kubernetes-validations:
513513
- message: Feature cannot be disabled
514514
rule: (self || !oldSelf)
515+
host:
516+
description: Set hostname for your Ingress/Route.
517+
type: string
515518
required:
516519
- enabled
517520
type: object

‎internal/clidownload/component.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (c *Component) Start(ctx context.Context) error {
5858

5959
obj = append(obj, ns)
6060
obj = append(obj, c.createDeployment(ns.Name, labels))
61-
svc := kubernetes.CreateService(ns.Name, cliServerName, cliServerPortName, cliServerPort, labels)
61+
svc := kubernetes.CreateService(ns.Name, cliServerName, cliServerPortName, cliServerPort, cliServerPort, labels)
6262
obj = append(obj, svc)
6363
ingress, err := kubernetes.CreateIngress(ctx, c.Client, *svc, rhtasv1alpha1.ExternalAccess{Host: CliHostName}, cliServerPortName, labels)
6464
if err != nil {

‎internal/controller/common/utils/kubernetes/service.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"k8s.io/apimachinery/pkg/util/intstr"
1313
)
1414

15-
func CreateService(namespace string, name string, portName string, port int, labels map[string]string) *corev1.Service {
15+
func CreateService(namespace string, name string, portName string, port int, targetPort int32, labels map[string]string) *corev1.Service {
1616
return &corev1.Service{
1717
ObjectMeta: metav1.ObjectMeta{
1818
Name: name,
@@ -26,7 +26,7 @@ func CreateService(namespace string, name string, portName string, port int, lab
2626
Name: portName,
2727
Protocol: corev1.ProtocolTCP,
2828
Port: int32(port),
29-
TargetPort: intstr.FromInt(port),
29+
TargetPort: intstr.FromInt32(targetPort),
3030
},
3131
},
3232
},

‎internal/controller/ctlog/actions/constants.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ const (
66
RBACName = "ctlog"
77
MonitoringRoleName = "prometheus-k8s-ctlog"
88

9-
CertCondition = "FulcioCertAvailable"
10-
MetricsPortName = "metrics"
11-
MetricsPort = 6963
9+
CertCondition = "FulcioCertAvailable"
10+
ServerPortName = "80-tcp"
11+
ServerPort = 80
12+
ServerTargetPort = 6962
13+
MetricsPortName = "metrics"
14+
MetricsPort = 6963
1215
)

‎internal/controller/ctlog/actions/deployment.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package actions
33
import (
44
"context"
55
"fmt"
6+
67
cutils "github.com/securesign/operator/internal/controller/common/utils"
78

89
rhtasv1alpha1 "github.com/securesign/operator/api/v1alpha1"
@@ -39,17 +40,15 @@ func (i deployAction) Handle(ctx context.Context, instance *rhtasv1alpha1.CTlog)
3940

4041
labels := constants.LabelsFor(ComponentName, DeploymentName, instance.Name)
4142

42-
dp, err := utils.CreateDeployment(instance, DeploymentName, RBACName, labels)
43+
dp, err := utils.CreateDeployment(instance, DeploymentName, RBACName, labels, ServerTargetPort, MetricsPort)
4344
if err != nil {
44-
if err != nil {
45-
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
46-
Type: constants.Ready,
47-
Status: metav1.ConditionFalse,
48-
Reason: constants.Failure,
49-
Message: err.Error(),
50-
})
51-
return i.FailedWithStatusUpdate(ctx, fmt.Errorf("could create server Deployment: %w", err), instance)
52-
}
45+
meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{
46+
Type: constants.Ready,
47+
Status: metav1.ConditionFalse,
48+
Reason: constants.Failure,
49+
Message: err.Error(),
50+
})
51+
return i.FailedWithStatusUpdate(ctx, fmt.Errorf("could create server Deployment: %w", err), instance)
5352
}
5453
err = cutils.SetTrustedCA(&dp.Spec.Template, cutils.TrustedCAAnnotationToReference(instance.Annotations))
5554
if err != nil {

‎internal/controller/ctlog/actions/monitoring.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (i monitoringAction) Handle(ctx context.Context, instance *rhtasv1alpha1.CT
100100
[]monitoringv1.Endpoint{
101101
{
102102
Interval: monitoringv1.Duration("30s"),
103-
Port: ComponentName,
103+
Port: MetricsPortName,
104104
Scheme: "http",
105105
},
106106
},

‎internal/controller/ctlog/actions/service.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ func (i serviceAction) Handle(ctx context.Context, instance *rhtasv1alpha1.CTlog
4040

4141
labels := constants.LabelsFor(ComponentName, ComponentName, instance.Name)
4242

43-
svc := kubernetes.CreateService(instance.Namespace, ComponentName, MetricsPortName, MetricsPort, labels)
44-
svc.Spec.Ports = append(svc.Spec.Ports, corev1.ServicePort{
45-
Name: "80-tcp",
46-
Protocol: corev1.ProtocolTCP,
47-
Port: 80,
48-
TargetPort: intstr.FromInt32(6962),
49-
})
43+
svc := kubernetes.CreateService(instance.Namespace, ComponentName, ServerPortName, ServerPort, ServerTargetPort, labels)
44+
if instance.Spec.Monitoring.Enabled {
45+
svc.Spec.Ports = append(svc.Spec.Ports, corev1.ServicePort{
46+
Name: MetricsPortName,
47+
Protocol: corev1.ProtocolTCP,
48+
Port: MetricsPort,
49+
TargetPort: intstr.FromInt32(MetricsPort),
50+
})
51+
}
5052
if err = controllerutil.SetControllerReference(instance, svc, i.Client.Scheme()); err != nil {
5153
return i.Failed(fmt.Errorf("could not set controller reference for Service: %w", err))
5254
}

‎internal/controller/ctlog/ctlog_controller_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ var _ = Describe("CTlog controller", func() {
123123
}).Should(Equal(constants.Pending))
124124

125125
By("Creating trillian service")
126-
Expect(k8sClient.Create(ctx, kubernetes.CreateService(Namespace, trillian.LogserverDeploymentName, trillian.ServerPortName, trillian.ServerPort, constants.LabelsForComponent(trillian.LogServerComponentName, instance.Name)))).To(Succeed())
126+
Expect(k8sClient.Create(ctx, kubernetes.CreateService(Namespace, trillian.LogserverDeploymentName, trillian.ServerPortName, trillian.ServerPort, trillian.ServerPort, constants.LabelsForComponent(trillian.LogServerComponentName, instance.Name)))).To(Succeed())
127127
Eventually(func(g Gomega) string {
128128
found := &v1alpha1.CTlog{}
129129
g.Expect(k8sClient.Get(ctx, typeNamespaceName, found)).Should(Succeed())
@@ -163,8 +163,7 @@ var _ = Describe("CTlog controller", func() {
163163
Eventually(func() error {
164164
return k8sClient.Get(ctx, types.NamespacedName{Name: actions.ComponentName, Namespace: Namespace}, service)
165165
}).Should(Succeed())
166-
Expect(service.Spec.Ports[0].Port).Should(Equal(int32(6963)))
167-
Expect(service.Spec.Ports[1].Port).Should(Equal(int32(80)))
166+
Expect(service.Spec.Ports[0].Port).Should(Equal(int32(80)))
168167

169168
By("Move to Ready phase")
170169
// Workaround to succeed condition for Ready phase

‎internal/controller/ctlog/ctlog_hot_update_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ var _ = Describe("CTlog update test", func() {
111111
}).Should(Succeed())
112112

113113
By("Creating trillian service")
114-
Expect(k8sClient.Create(ctx, kubernetes.CreateService(Namespace, trillian.LogserverDeploymentName, trillian.ServerPortName, trillian.ServerPort, constants.LabelsForComponent(trillian.LogServerComponentName, instance.Name)))).To(Succeed())
114+
Expect(k8sClient.Create(ctx, kubernetes.CreateService(Namespace, trillian.LogserverDeploymentName, trillian.ServerPortName, trillian.ServerPort, trillian.ServerPort, constants.LabelsForComponent(trillian.LogServerComponentName, instance.Name)))).To(Succeed())
115115

116116
By("Creating fulcio root cert")
117117
fulcioCa := kubernetes.CreateSecret("test", Namespace,

‎internal/controller/ctlog/utils/ctlog_deployment.go

+28-19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package utils
22

33
import (
44
"errors"
5+
"strconv"
56

67
"github.com/securesign/operator/api/v1alpha1"
78
"github.com/securesign/operator/internal/controller/common/utils"
@@ -12,12 +13,34 @@ import (
1213
"k8s.io/apimachinery/pkg/util/intstr"
1314
)
1415

15-
func CreateDeployment(instance *v1alpha1.CTlog, deploymentName string, sa string, labels map[string]string) (*appsv1.Deployment, error) {
16+
func CreateDeployment(instance *v1alpha1.CTlog, deploymentName string, sa string, labels map[string]string, serverPort, metricsPort int32) (*appsv1.Deployment, error) {
1617
if instance.Status.ServerConfigRef == nil {
1718
return nil, errors.New("server config name not specified")
1819
}
1920
replicas := int32(1)
2021
// Define a new Deployment object
22+
23+
containerPorts := []corev1.ContainerPort{
24+
{
25+
ContainerPort: serverPort,
26+
Protocol: corev1.ProtocolTCP,
27+
},
28+
}
29+
30+
appArgs := []string{
31+
"--http_endpoint=0.0.0.0:" + strconv.Itoa(int(serverPort)),
32+
"--log_config=/ctfe-keys/config",
33+
"--alsologtostderr",
34+
}
35+
36+
if instance.Spec.Monitoring.Enabled {
37+
appArgs = append(appArgs, "--metrics_endpoint=0.0.0.0:"+strconv.Itoa(int(metricsPort)))
38+
containerPorts = append(containerPorts, corev1.ContainerPort{
39+
ContainerPort: metricsPort,
40+
Protocol: corev1.ProtocolTCP,
41+
})
42+
}
43+
2144
dep := &appsv1.Deployment{
2245
ObjectMeta: metav1.ObjectMeta{
2346
Name: deploymentName,
@@ -39,17 +62,12 @@ func CreateDeployment(instance *v1alpha1.CTlog, deploymentName string, sa string
3962
{
4063
Name: "ctlog",
4164
Image: constants.CTLogImage,
42-
Args: []string{
43-
"--http_endpoint=0.0.0.0:6962",
44-
"--metrics_endpoint=0.0.0.0:6963",
45-
"--log_config=/ctfe-keys/config",
46-
"--alsologtostderr",
47-
},
65+
Args: appArgs,
4866
LivenessProbe: &corev1.Probe{
4967
ProbeHandler: corev1.ProbeHandler{
5068
HTTPGet: &corev1.HTTPGetAction{
5169
Path: "/healthz",
52-
Port: intstr.FromInt32(6962),
70+
Port: intstr.FromInt32(serverPort),
5371
},
5472
},
5573
InitialDelaySeconds: 10,
@@ -62,7 +80,7 @@ func CreateDeployment(instance *v1alpha1.CTlog, deploymentName string, sa string
6280
ProbeHandler: corev1.ProbeHandler{
6381
HTTPGet: &corev1.HTTPGetAction{
6482
Path: "/healthz",
65-
Port: intstr.FromInt32(6962),
83+
Port: intstr.FromInt32(serverPort),
6684
},
6785
},
6886
InitialDelaySeconds: 10,
@@ -78,16 +96,7 @@ func CreateDeployment(instance *v1alpha1.CTlog, deploymentName string, sa string
7896
ReadOnly: true,
7997
},
8098
},
81-
Ports: []corev1.ContainerPort{
82-
{
83-
ContainerPort: 6962,
84-
Protocol: corev1.ProtocolTCP,
85-
},
86-
{
87-
ContainerPort: 6963,
88-
Protocol: corev1.ProtocolTCP,
89-
},
90-
},
99+
Ports: containerPorts,
91100
},
92101
},
93102
Volumes: []corev1.Volume{

‎internal/controller/fulcio/actions/constants.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ const (
99

1010
CertCondition = "FulcioCertAvailable"
1111

12-
PortName = "metrics"
13-
Port = 2112
12+
ServerPortName = "80-tcp"
13+
ServerPort = 80
14+
TargetServerPort = 5555
15+
GRPCPortName = "5554-tcp"
16+
GRPCPort = 5554
17+
MetricsPortName = "metrics"
18+
MetricsPort = 2112
1419
)

‎internal/controller/fulcio/actions/ingress.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (i ingressAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Fulci
4343
return i.Failed(fmt.Errorf("could not find service for ingress: %w", err))
4444
}
4545

46-
ingress, err := kubernetes.CreateIngress(ctx, i.Client, *svc, instance.Spec.ExternalAccess, "80-tcp", labels)
46+
ingress, err := kubernetes.CreateIngress(ctx, i.Client, *svc, instance.Spec.ExternalAccess, ServerPortName, labels)
4747
if err != nil {
4848
return i.Failed(fmt.Errorf("could not create ingress object: %w", err))
4949
}

‎internal/controller/fulcio/actions/monitoring.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (i monitoringAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Fu
100100
[]monitoringv1.Endpoint{
101101
{
102102
Interval: monitoringv1.Duration("30s"),
103-
Port: "fulcio-server",
103+
Port: MetricsPortName,
104104
Scheme: "http",
105105
},
106106
},

‎internal/controller/fulcio/actions/service.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,23 @@ func (i serviceAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Fulci
4040

4141
labels := constants.LabelsFor(ComponentName, DeploymentName, instance.Name)
4242

43-
svc := kubernetes.CreateService(instance.Namespace, DeploymentName, PortName, Port, labels)
43+
svc := kubernetes.CreateService(instance.Namespace, DeploymentName, ServerPortName, ServerPort, TargetServerPort, labels)
4444
svc.Spec.Ports = append(svc.Spec.Ports, corev1.ServicePort{
45-
Name: "5554-tcp",
45+
Name: GRPCPortName,
4646
Protocol: corev1.ProtocolTCP,
47-
Port: 5554,
48-
TargetPort: intstr.FromInt32(5554),
49-
})
50-
svc.Spec.Ports = append(svc.Spec.Ports, corev1.ServicePort{
51-
Name: "80-tcp",
52-
Protocol: corev1.ProtocolTCP,
53-
Port: 80,
54-
TargetPort: intstr.FromInt32(5555),
47+
Port: GRPCPort,
48+
TargetPort: intstr.FromInt32(GRPCPort),
5549
})
50+
51+
if instance.Spec.Monitoring.Enabled {
52+
svc.Spec.Ports = append(svc.Spec.Ports, corev1.ServicePort{
53+
Name: MetricsPortName,
54+
Protocol: corev1.ProtocolTCP,
55+
Port: MetricsPort,
56+
TargetPort: intstr.FromInt32(MetricsPort),
57+
})
58+
}
59+
5660
if err = controllerutil.SetControllerReference(instance, svc, i.Client.Scheme()); err != nil {
5761
return i.Failed(fmt.Errorf("could not set controller reference for Service: %w", err))
5862
}

‎internal/controller/fulcio/fulcio_controller_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,8 @@ var _ = Describe("Fulcio controller", func() {
209209
Eventually(func() error {
210210
return k8sClient.Get(ctx, types.NamespacedName{Name: actions.DeploymentName, Namespace: Namespace}, service)
211211
}).Should(Succeed())
212-
Expect(service.Spec.Ports[0].Port).Should(Equal(int32(2112)))
212+
Expect(service.Spec.Ports[0].Port).Should(Equal(int32(80)))
213213
Expect(service.Spec.Ports[1].Port).Should(Equal(int32(5554)))
214-
Expect(service.Spec.Ports[2].Port).Should(Equal(int32(80)))
215214

216215
By("Checking if Ingress was successfully created in the reconciliation")
217216
ingress := &v1.Ingress{}
@@ -220,7 +219,7 @@ var _ = Describe("Fulcio controller", func() {
220219
}).Should(Succeed())
221220
Expect(ingress.Spec.Rules[0].Host).Should(Equal("fulcio.localhost"))
222221
Expect(ingress.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend.Service.Name).Should(Equal(service.Name))
223-
Expect(ingress.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend.Service.Port.Name).Should(Equal("80-tcp"))
222+
Expect(ingress.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend.Service.Port.Name).Should(Equal(actions.ServerPortName))
224223

225224
By("Checking if controller will return deployment to desired state")
226225
deployment = &appsv1.Deployment{}

‎internal/controller/fulcio/utils/fulcio_deployment.go

+19-14
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ func CreateDeployment(instance *v1alpha1.Fulcio, deploymentName string, sa strin
2929
return nil, errors.New("CA secret is not specified")
3030
}
3131

32+
containerPorts := []corev1.ContainerPort{
33+
{
34+
Protocol: corev1.ProtocolTCP,
35+
ContainerPort: 5555,
36+
},
37+
{
38+
Protocol: corev1.ProtocolTCP,
39+
ContainerPort: 5554,
40+
},
41+
}
42+
43+
if instance.Spec.Monitoring.Enabled {
44+
containerPorts = append(containerPorts, corev1.ContainerPort{
45+
Protocol: corev1.ProtocolTCP,
46+
ContainerPort: 2112,
47+
})
48+
}
49+
3250
args := []string{
3351
"serve",
3452
"--port=5555",
@@ -95,20 +113,7 @@ func CreateDeployment(instance *v1alpha1.Fulcio, deploymentName string, sa strin
95113
Image: constants.FulcioServerImage,
96114
Args: args,
97115
Env: env,
98-
Ports: []corev1.ContainerPort{
99-
{
100-
Protocol: corev1.ProtocolTCP,
101-
ContainerPort: 5555,
102-
},
103-
{
104-
Protocol: corev1.ProtocolTCP,
105-
ContainerPort: 5554,
106-
},
107-
{
108-
Protocol: corev1.ProtocolTCP,
109-
ContainerPort: 2112,
110-
},
111-
},
116+
Ports: containerPorts,
112117
LivenessProbe: &corev1.Probe{
113118
ProbeHandler: corev1.ProbeHandler{
114119
HTTPGet: &corev1.HTTPGetAction{

‎internal/controller/rekor/actions/constants.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package actions
22

33
const (
44
ServerDeploymentName = "rekor-server"
5-
ServerDeploymentPortName = "metrics"
6-
ServerDeploymentPort = 2112
5+
ServerDeploymentPortName = "80-tcp"
6+
ServerDeploymentPort = 80
7+
ServerTargetDeploymentPort = 3000
8+
MetricsPortName = "metrics"
9+
MetricsPort = 2112
710
RedisDeploymentName = "rekor-redis"
811
RedisDeploymentPortName = "resp"
912
RedisDeploymentPort = 6379

‎internal/controller/rekor/actions/redis/svc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (i createServiceAction) Handle(ctx context.Context, instance *rhtasv1alpha1
4040
)
4141

4242
labels := constants.LabelsFor(actions.RedisComponentName, actions.RedisDeploymentName, instance.Name)
43-
svc := k8sutils.CreateService(instance.Namespace, actions.RedisDeploymentName, actions.RedisDeploymentPortName, actions.RedisDeploymentPort, labels)
43+
svc := k8sutils.CreateService(instance.Namespace, actions.RedisDeploymentName, actions.RedisDeploymentPortName, actions.RedisDeploymentPort, actions.RedisDeploymentPort, labels)
4444

4545
if err = controllerutil.SetControllerReference(instance, svc, i.Client.Scheme()); err != nil {
4646
return i.Failed(fmt.Errorf("could not set controller reference for Redis service: %w", err))

‎internal/controller/rekor/actions/server/ingress.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (i ingressAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Rekor
4444
return i.Failed(fmt.Errorf("could not find service for ingress: %w", err))
4545
}
4646

47-
ingress, err := kubernetes.CreateIngress(ctx, i.Client, *svc, instance.Spec.ExternalAccess, "80-tcp", labels)
47+
ingress, err := kubernetes.CreateIngress(ctx, i.Client, *svc, instance.Spec.ExternalAccess, actions.ServerDeploymentPortName, labels)
4848
if err != nil {
4949
return i.Failed(fmt.Errorf("could not create ingress object: %w", err))
5050
}

‎internal/controller/rekor/actions/server/monitoring.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (i monitoringAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Re
113113
[]monitoringv1.Endpoint{
114114
{
115115
Interval: monitoringv1.Duration("30s"),
116-
Port: "rekor-server",
116+
Port: actions.MetricsPortName,
117117
Scheme: "http",
118118
},
119119
},

‎internal/controller/rekor/actions/server/svc.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ func (i createServiceAction) Handle(ctx context.Context, instance *rhtasv1alpha1
4242
)
4343

4444
labels := constants.LabelsFor(actions.ServerComponentName, actions.ServerDeploymentName, instance.Name)
45-
svc := k8sutils.CreateService(instance.Namespace, actions.ServerDeploymentName, actions.ServerDeploymentPortName, actions.ServerDeploymentPort, labels)
46-
svc.Spec.Ports = append(svc.Spec.Ports, corev1.ServicePort{
47-
Name: "80-tcp",
48-
Protocol: corev1.ProtocolTCP,
49-
Port: 80,
50-
TargetPort: intstr.FromInt(3000),
51-
})
45+
svc := k8sutils.CreateService(instance.Namespace, actions.ServerDeploymentName, actions.ServerDeploymentPortName, actions.ServerDeploymentPort, actions.ServerTargetDeploymentPort, labels)
46+
47+
if instance.Spec.Monitoring.Enabled {
48+
svc.Spec.Ports = append(svc.Spec.Ports, corev1.ServicePort{
49+
Name: actions.MetricsPortName,
50+
Protocol: corev1.ProtocolTCP,
51+
Port: actions.MetricsPort,
52+
TargetPort: intstr.FromInt(actions.MetricsPort),
53+
})
54+
}
5255

5356
if err = controllerutil.SetControllerReference(instance, svc, i.Client.Scheme()); err != nil {
5457
return i.Failed(fmt.Errorf("could not set controller reference for service: %w", err))

‎internal/controller/rekor/actions/ui/svc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (i createServiceAction) Handle(ctx context.Context, instance *rhtasv1alpha1
4141
)
4242

4343
labels := constants.LabelsFor(actions.UIComponentName, actions.SearchUiDeploymentName, instance.Name)
44-
svc := k8sutils.CreateService(instance.Namespace, actions.SearchUiDeploymentName, actions.SearchUiDeploymentPortName, actions.SearchUiDeploymentPort, labels)
44+
svc := k8sutils.CreateService(instance.Namespace, actions.SearchUiDeploymentName, actions.SearchUiDeploymentPortName, actions.SearchUiDeploymentPort, actions.SearchUiDeploymentPort, labels)
4545
svc.Spec.Ports[0].Port = 80
4646

4747
if err = controllerutil.SetControllerReference(instance, svc, i.Client.Scheme()); err != nil {

‎internal/controller/rekor/utils/rekor_deployment.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ func CreateRekorDeployment(instance *v1alpha1.Rekor, dpName string, sa string, l
7171
},
7272
}
7373

74+
containerPorts := []core.ContainerPort{
75+
{
76+
ContainerPort: 3000,
77+
Name: "rekor-server",
78+
},
79+
}
80+
81+
if instance.Spec.Monitoring.Enabled {
82+
containerPorts = append(containerPorts, core.ContainerPort{
83+
ContainerPort: 2112,
84+
Protocol: "TCP",
85+
})
86+
}
87+
7488
// KMS memory
7589
if instance.Spec.Signer.KMS == "memory" {
7690
appArgs = append(appArgs, "--rekor_server.signer=memory")
@@ -145,18 +159,9 @@ func CreateRekorDeployment(instance *v1alpha1.Rekor, dpName string, sa string, l
145159
Volumes: volumes,
146160
Containers: []core.Container{
147161
{
148-
Name: dpName,
149-
Image: constants.RekorServerImage,
150-
Ports: []core.ContainerPort{
151-
{
152-
ContainerPort: 3000,
153-
Name: "rekor-server",
154-
},
155-
{
156-
ContainerPort: 2112,
157-
Protocol: "TCP",
158-
},
159-
},
162+
Name: dpName,
163+
Image: constants.RekorServerImage,
164+
Ports: containerPorts,
160165
Env: env,
161166
Args: appArgs,
162167
VolumeMounts: volumeMounts,

‎internal/controller/trillian/actions/db/svc.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (i createServiceAction) Handle(ctx context.Context, instance *rhtasv1alpha1
4242
)
4343

4444
labels := constants.LabelsFor(actions.DbComponentName, actions.DbDeploymentName, instance.Name)
45-
mysql := k8sutils.CreateService(instance.Namespace, host, host, port, labels)
45+
mysql := k8sutils.CreateService(instance.Namespace, host, host, port, port, labels)
4646

4747
if err = controllerutil.SetControllerReference(instance, mysql, i.Client.Scheme()); err != nil {
4848
return i.Failed(fmt.Errorf("could not set controller reference for DB service: %w", err))

‎internal/controller/trillian/actions/logserver/monitoring.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (i monitoringAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Tr
112112
[]monitoringv1.Endpoint{
113113
{
114114
Interval: monitoringv1.Duration("30s"),
115-
Port: actions.LogServerMonitoringName,
115+
Port: actions.MonitoringPortName,
116116
Scheme: "http",
117117
},
118118
},

‎internal/controller/trillian/actions/logserver/service.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ func (i createServiceAction) Handle(ctx context.Context, instance *rhtasv1alpha1
4242
)
4343

4444
labels := constants.LabelsFor(actions.LogServerComponentName, actions.LogserverDeploymentName, instance.Name)
45-
logserverService := k8sutils.CreateService(instance.Namespace, actions.LogserverDeploymentName, actions.ServerPortName, actions.ServerPort, labels)
45+
logserverService := k8sutils.CreateService(instance.Namespace, actions.LogserverDeploymentName, actions.ServerPortName, actions.ServerPort, actions.ServerPort, labels)
4646

4747
if instance.Spec.Monitoring.Enabled {
4848
logserverService.Spec.Ports = append(logserverService.Spec.Ports, corev1.ServicePort{
49-
Name: actions.LogServerMonitoringName,
49+
Name: actions.MonitoringPortName,
5050
Protocol: corev1.ProtocolTCP,
5151
Port: int32(actions.MonitoringPort),
5252
TargetPort: intstr.FromInt(actions.MonitoringPort),

‎internal/controller/trillian/actions/logsigner/monitoring.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (i monitoringAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Tr
112112
[]monitoringv1.Endpoint{
113113
{
114114
Interval: monitoringv1.Duration("30s"),
115-
Port: actions.LogSignerComponentName,
115+
Port: actions.MonitoringPortName,
116116
Scheme: "http",
117117
},
118118
},

‎internal/controller/trillian/actions/logsigner/service.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ import (
1515
rhtasv1alpha1 "github.com/securesign/operator/api/v1alpha1"
1616
)
1717

18-
const (
19-
monitoringPort = 8090
20-
)
21-
2218
func NewCreateServiceAction() action.Action[*rhtasv1alpha1.Trillian] {
2319
return &createServiceAction{}
2420
}
@@ -44,7 +40,7 @@ func (i createServiceAction) Handle(ctx context.Context, instance *rhtasv1alpha1
4440
)
4541

4642
labels := constants.LabelsFor(actions.LogSignerComponentName, actions.LogsignerDeploymentName, instance.Name)
47-
logsignerService := k8sutils.CreateService(instance.Namespace, actions.LogsignerDeploymentName, actions.MonitoringPortName, actions.MonitoringPort, labels)
43+
logsignerService := k8sutils.CreateService(instance.Namespace, actions.LogsignerDeploymentName, actions.MonitoringPortName, actions.MonitoringPort, actions.MonitoringPort, labels)
4844

4945
if err = controllerutil.SetControllerReference(instance, logsignerService, i.Client.Scheme()); err != nil {
5046
return i.Failed(fmt.Errorf("could not set controller reference for logsigner Service: %w", err))

‎internal/controller/tuf/actions/servise.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (i serviceAction) Handle(ctx context.Context, instance *rhtasv1alpha1.Tuf)
3838

3939
labels := constants.LabelsFor(ComponentName, DeploymentName, instance.Name)
4040

41-
svc := kubernetes.CreateService(instance.Namespace, DeploymentName, PortName, Port, labels)
41+
svc := kubernetes.CreateService(instance.Namespace, DeploymentName, PortName, Port, Port, labels)
4242
//patch the pregenerated service
4343
svc.Spec.Ports[0].Port = instance.Spec.Port
4444
if err = controllerutil.SetControllerReference(instance, svc, i.Client.Scheme()); err != nil {

0 commit comments

Comments
 (0)
Please sign in to comment.