From 0c9cffb322ddc16a9c8f2b9d72e1e991f2a2bc54 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Thu, 21 Nov 2024 14:04:06 -0500 Subject: [PATCH 1/2] feat(service): add part-of, instance selector labels and appProtocol --- internal/controllers/services.go | 12 +++++-- internal/test/resources.go | 62 ++++++++++++++++++++++---------- 2 files changed, 53 insertions(+), 21 deletions(-) diff --git a/internal/controllers/services.go b/internal/controllers/services.go index 58ec16f5..4f402e83 100644 --- a/internal/controllers/services.go +++ b/internal/controllers/services.go @@ -47,11 +47,13 @@ func (r *Reconciler) reconcileCoreService(ctx context.Context, cr *model.Cryosta "app": cr.Name, "component": "cryostat", } + appProtocol := "http" svc.Spec.Ports = []corev1.ServicePort{ { - Name: "http", - Port: *config.HTTPPort, - TargetPort: intstr.IntOrString{IntVal: constants.AuthProxyHttpContainerPort}, + Name: "http", + Port: *config.HTTPPort, + TargetPort: intstr.IntOrString{IntVal: constants.AuthProxyHttpContainerPort}, + AppProtocol: &appProtocol, }, } return nil @@ -214,6 +216,10 @@ func configureService(config *operatorv1beta2.ServiceConfig, appLabel string, co // Add required labels, overriding any user-specified labels with the same keys config.Labels["app"] = appLabel config.Labels["component"] = componentLabel + config.Labels["app.kubernetes.io/name"] = "cryostat" + config.Labels["app.kubernetes.io/instance"] = appLabel + config.Labels["app.kubernetes.io/component"] = componentLabel + config.Labels["app.kubernetes.io/part-of"] = "cryostat" } func (r *Reconciler) createOrUpdateService(ctx context.Context, svc *corev1.Service, owner metav1.Object, diff --git a/internal/test/resources.go b/internal/test/resources.go index 0e804e80..015dd385 100644 --- a/internal/test/resources.go +++ b/internal/test/resources.go @@ -760,13 +760,18 @@ func (r *TestResources) NewCryostatWithAdditionalMetadata() *model.CryostatInsta } func (r *TestResources) NewCryostatService() *corev1.Service { + appProtocol := "http" return &corev1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: r.Name, Namespace: r.Namespace, Labels: map[string]string{ - "app": r.Name, - "component": "cryostat", + "app": r.Name, + "component": "cryostat", + "app.kubernetes.io/name": "cryostat", + "app.kubernetes.io/instance": r.Name, + "app.kubernetes.io/component": "cryostat", + "app.kubernetes.io/part-of": "cryostat", }, }, Spec: corev1.ServiceSpec{ @@ -777,9 +782,10 @@ func (r *TestResources) NewCryostatService() *corev1.Service { }, Ports: []corev1.ServicePort{ { - Name: "http", - Port: 4180, - TargetPort: intstr.FromInt(4180), + Name: "http", + Port: 4180, + TargetPort: intstr.FromInt(4180), + AppProtocol: &appProtocol, }, }, }, @@ -792,8 +798,12 @@ func (r *TestResources) NewReportsService() *corev1.Service { Name: r.Name + "-reports", Namespace: r.Namespace, Labels: map[string]string{ - "app": r.Name, - "component": "reports", + "app": r.Name, + "component": "reports", + "app.kubernetes.io/name": "cryostat", + "app.kubernetes.io/instance": r.Name, + "app.kubernetes.io/component": "reports", + "app.kubernetes.io/part-of": "cryostat", }, }, Spec: corev1.ServiceSpec{ @@ -819,8 +829,12 @@ func (r *TestResources) NewAgentProxyService() *corev1.Service { Name: r.Name + "-agent", Namespace: r.Namespace, Labels: map[string]string{ - "app": r.Name, - "component": "cryostat", + "app": r.Name, + "component": "cryostat", + "app.kubernetes.io/name": "cryostat", + "app.kubernetes.io/instance": r.Name, + "app.kubernetes.io/component": "cryostat", + "app.kubernetes.io/part-of": "cryostat", }, }, Spec: corev1.ServiceSpec{ @@ -848,9 +862,13 @@ func (r *TestResources) NewCustomizedCoreService() *corev1.Service { "my/custom": "annotation", } svc.Labels = map[string]string{ - "app": r.Name, - "component": "cryostat", - "my": "label", + "app": r.Name, + "component": "cryostat", + "my": "label", + "app.kubernetes.io/name": "cryostat", + "app.kubernetes.io/instance": r.Name, + "app.kubernetes.io/component": "cryostat", + "app.kubernetes.io/part-of": "cryostat", } return svc } @@ -863,9 +881,13 @@ func (r *TestResources) NewCustomizedReportsService() *corev1.Service { "my/custom": "annotation", } svc.Labels = map[string]string{ - "app": r.Name, - "component": "reports", - "my": "label", + "app": r.Name, + "component": "reports", + "my": "label", + "app.kubernetes.io/name": "cryostat", + "app.kubernetes.io/instance": r.Name, + "app.kubernetes.io/component": "reports", + "app.kubernetes.io/part-of": "cryostat", } return svc } @@ -878,9 +900,13 @@ func (r *TestResources) NewCustomizedAgentService() *corev1.Service { "my/custom": "annotation", } svc.Labels = map[string]string{ - "app": r.Name, - "component": "cryostat", - "my": "label", + "app": r.Name, + "component": "cryostat", + "my": "label", + "app.kubernetes.io/name": "cryostat", + "app.kubernetes.io/instance": r.Name, + "app.kubernetes.io/component": "cryostat", + "app.kubernetes.io/part-of": "cryostat", } return svc } From 55e723feebefe7392390736a85e4e36776df4dac Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Thu, 28 Nov 2024 16:08:58 -0500 Subject: [PATCH 2/2] relabel service to remove ambiguity --- internal/controllers/services.go | 2 +- internal/test/resources.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/controllers/services.go b/internal/controllers/services.go index 4f402e83..5be4c1ac 100644 --- a/internal/controllers/services.go +++ b/internal/controllers/services.go @@ -190,7 +190,7 @@ func configureAgentService(cr *model.CryostatInstance) *operatorv1beta2.AgentSer } // Apply common service defaults - configureService(&config.ServiceConfig, cr.Name, "cryostat") + configureService(&config.ServiceConfig, cr.Name, "cryostat-agent-gateway") // Apply default HTTP port if not provided if config.HTTPPort == nil { diff --git a/internal/test/resources.go b/internal/test/resources.go index 015dd385..bc74bc9f 100644 --- a/internal/test/resources.go +++ b/internal/test/resources.go @@ -830,10 +830,10 @@ func (r *TestResources) NewAgentProxyService() *corev1.Service { Namespace: r.Namespace, Labels: map[string]string{ "app": r.Name, - "component": "cryostat", + "component": "cryostat-agent-gateway", "app.kubernetes.io/name": "cryostat", "app.kubernetes.io/instance": r.Name, - "app.kubernetes.io/component": "cryostat", + "app.kubernetes.io/component": "cryostat-agent-gateway", "app.kubernetes.io/part-of": "cryostat", }, }, @@ -901,11 +901,11 @@ func (r *TestResources) NewCustomizedAgentService() *corev1.Service { } svc.Labels = map[string]string{ "app": r.Name, - "component": "cryostat", + "component": "cryostat-agent-gateway", "my": "label", "app.kubernetes.io/name": "cryostat", "app.kubernetes.io/instance": r.Name, - "app.kubernetes.io/component": "cryostat", + "app.kubernetes.io/component": "cryostat-agent-gateway", "app.kubernetes.io/part-of": "cryostat", } return svc