Skip to content

Commit

Permalink
feat(service): add part-of, instance selector labels and appProtocol (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores authored Dec 17, 2024
1 parent 85d6445 commit 75b7a81
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 22 deletions.
14 changes: 10 additions & 4 deletions internal/controllers/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -188,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 {
Expand All @@ -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,
Expand Down
62 changes: 44 additions & 18 deletions internal/test/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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,
},
},
},
Expand All @@ -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{
Expand All @@ -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-agent-gateway",
"app.kubernetes.io/name": "cryostat",
"app.kubernetes.io/instance": r.Name,
"app.kubernetes.io/component": "cryostat-agent-gateway",
"app.kubernetes.io/part-of": "cryostat",
},
},
Spec: corev1.ServiceSpec{
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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-agent-gateway",
"my": "label",
"app.kubernetes.io/name": "cryostat",
"app.kubernetes.io/instance": r.Name,
"app.kubernetes.io/component": "cryostat-agent-gateway",
"app.kubernetes.io/part-of": "cryostat",
}
return svc
}
Expand Down

0 comments on commit 75b7a81

Please sign in to comment.