Is your feature request related to a problem? Please describe.
I'm not sure if this is an actual problem, as I'm not 100% sure whether in Kubernetes, a Deployment must have a ports entry (with a containerPort) that matches up with a corresponding Service targetPort.
In any case, if this scenario is applied, Score does not create an entry in the related Deployment when a corresponding Service targetPort has been defined in the workload specification.
Describe the solution you'd like
I see this could go a couple of ways:
- If it can be determined whether Kubernetes requires that any associated Service(s) need to have a port definition added to a Deployment
ports section, a solution should be developed so that when score-k8s generates manifests, this missing YAML is written.
- Alternatively, this logic could be embodied in a patch template, available in the community.
Describe alternatives you've considered
I have written a patch template that (so far) is making the appropriate addition(s) to the Deployments when the use case described exists. I'm just learning Go templating, so there may be better ways to do what I present here. I leave it to the discretion of those who know this tech better to adjust as they see fit.
Here is my template:
{{/* Get a reference to manifests before looping through workload definitions. */}}
{{ $manifests := .Manifests }}
{{ range $w_name, $w_spec := .Workloads }} {{/* start: workloads loop */}}
{{ range $mi, $mf := $manifests }} {{/* start: manifests loop */}}
{{/* Check for Deployment manifest that matches this workload name. */}}
{{ if and (eq $mf.kind "Deployment") (eq $mf.metadata.name $w_name) }}
{{ range $ci, $ct := $mf.spec.template.spec.containers }} {{/* start: containers loop */}}
{{/* Check if workload service exists. */}}
{{ if $w_spec.service }}
{{ range $p_name, $p_spec := $w_spec.service.ports }} {{/* start: service ports loop */}}
- op: set
description: Add service target port definition to Deployment ports.
path: {{ $mi }}.spec.template.spec.containers.{{ $ci }}.ports.-1
value:
name: {{ $p_name }}
containerPort: {{ $p_spec.targetPort }}
protocol: TCP
{{ end }} {{/* end: service ports loop */}}
{{ end }}
{{ end }} {{/* end: containers loop */}}
{{ end }} {{/* kind: Deployment */}}
{{ end }} {{/* end: manifests loop */}}
{{ end }} {{/* end: workloads loop */}}
Is your feature request related to a problem? Please describe.
I'm not sure if this is an actual problem, as I'm not 100% sure whether in Kubernetes, a Deployment must have a
portsentry (with acontainerPort) that matches up with a corresponding ServicetargetPort.In any case, if this scenario is applied, Score does not create an entry in the related Deployment when a corresponding Service
targetPorthas been defined in the workload specification.Describe the solution you'd like
I see this could go a couple of ways:
portssection, a solution should be developed so that when score-k8s generates manifests, this missing YAML is written.Describe alternatives you've considered
I have written a patch template that (so far) is making the appropriate addition(s) to the Deployments when the use case described exists. I'm just learning Go templating, so there may be better ways to do what I present here. I leave it to the discretion of those who know this tech better to adjust as they see fit.
Here is my template: