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 committed Nov 21, 2024
1 parent 0ec9a84 commit 3effe86
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 21 deletions.
12 changes: 9 additions & 3 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 @@ -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",
"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 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",
"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 Down

0 comments on commit 3effe86

Please sign in to comment.