score-spec/score-helm

[bug] Only 1 service is generated

bobbydeveaux opened this issue · 2 comments

Describe the bug
When running score-helm run -f score.yaml -o manifest.yaml, it generates a file that is used by the 'score-helm-charts/workload' helm chart. However, despite my score.yaml file containing 2 services, the helm-chart creates a service in k8s as 1 service with 2 pods.

To Reproduce

apiVersion: score.dev/v1b1

metadata:
  name: both

containers:
  backend:
    image: be:1.0.0

  frontend:
    image: fe:1.0.0

service:
  ports:
    frontend:
      port: 8080
      targetPort: 8080
    backend:
      port: 8000
      targetPort: 8000

resources:
  env:
    type: environment

  my-be-dns:
    type: dns

  my-fe-dns:
    type: dns

  bobby-bucket:
    type: s3

  backend-route:
    type: route
    params:
      path: /api
      port: 8000
      host: ${resources.my-be-dns.host}

  frontend-route:
    type: route
    params:
      path: /
      port: 8080
      host: ${resources.my-fe-dns.host}

score-helm run -f score.yaml -o manifest.yaml

helm install test-app score-helm-charts/workload --values ./manifest.yaml

Expected behavior
Would expect an 2 deployments within k8s - and 2 services running.

Just looking at the output quickly I can see the manifest looks like

$ go run github.com/score-spec/score-helm/cmd/score-helm@latest run score.yaml
go: downloading github.com/score-spec/score-helm v0.0.0-20240105083034-d29b2dfdefe6
go: downloading github.com/score-spec/score-go v0.0.0-20230905115428-131acdd2f5cf
containers:
  backend:
    image:
      name: be:1.0.0
  frontend:
    image:
      name: fe:1.0.0
service:
  ports:
    - name: backend
      port: 8000
      targetPort: 8000
    - name: frontend
      port: 8080
      targetPort: 8080
  type: ClusterIP

And the helm output looks like

$ helm template demo score-helm-charts/workload --values manifest.yaml
---
# Source: workload/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: demo
  labels:
    helm.sh/chart: workload-0.4.0
    app.kubernetes.io/name: demo
    app.kubernetes.io/instance: demo
    app.kubernetes.io/version: "0.4.0"
    app.kubernetes.io/managed-by: Helm
spec:
  type: ClusterIP
  selector:
    app.kubernetes.io/name: demo
    app.kubernetes.io/instance: demo
  ports:
    - name: backend
      port: 8000
      targetPort: 8000
    - name: frontend
      port: 8080
      targetPort: 8080
---
# Source: workload/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo
  labels:
    helm.sh/chart: workload-0.4.0
    app.kubernetes.io/name: demo
    app.kubernetes.io/instance: demo
    app.kubernetes.io/version: "0.4.0"
    app.kubernetes.io/managed-by: Helm
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: demo
      app.kubernetes.io/instance: demo
  template:
    metadata:
      labels:
        app.kubernetes.io/name: demo
        app.kubernetes.io/instance: demo
    spec:
      containers:
        - name: backend
          image: "be:1.0.0"
        - name: frontend
          image: "fe:1.0.0"

So the service has both ports on it.

Unfortunately @bobbydeveaux this is expected behavior, Score is a workload spec and generates 2 containers in the same pod (the same workload).

If you're looking for 2 services (backed by different deployments) you should be looking at 2 separate Score files.