Skip to content

Commit

Permalink
Merge pull request #34 from score-spec/svc-name
Browse files Browse the repository at this point in the history
Default `Service` name now as the `Workload`, removing the `-svc` suffix + new annotation to override it `k8s.score.dev/service-name`
  • Loading branch information
mathieu-benoit authored Sep 7, 2024
2 parents 4d196ce + 94d5000 commit ed404d0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
5 changes: 3 additions & 2 deletions internal/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
)

const (
AnnotationPrefix = "k8s.score.dev/"
WorkloadKindAnnotation = AnnotationPrefix + "kind"
AnnotationPrefix = "k8s.score.dev/"
WorkloadKindAnnotation = AnnotationPrefix + "kind"
WorkloadServiceNameAnnotation = AnnotationPrefix + "service-name"
)

func ListAnnotations(metadata map[string]interface{}) []string {
Expand Down
9 changes: 6 additions & 3 deletions internal/convert/workloads.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func ConvertWorkload(state *project.State, workloadName string) ([]machineryMeta
manifests = append(manifests, &coreV1.Service{
TypeMeta: machineryMeta.TypeMeta{Kind: "Service", APIVersion: "v1"},
ObjectMeta: machineryMeta.ObjectMeta{
Name: WorkloadServiceName(workloadName),
Name: WorkloadServiceName(workloadName, spec.Metadata),
Annotations: topLevelAnnotations,
Labels: commonLabels,
},
Expand Down Expand Up @@ -279,8 +279,11 @@ func ConvertWorkload(state *project.State, workloadName string) ([]machineryMeta
return manifests, nil
}

func WorkloadServiceName(workloadName string) string {
return fmt.Sprintf("%s-svc", workloadName)
func WorkloadServiceName(workloadName string, specMetadata map[string]interface{}) string {
if d, ok := internal.FindAnnotation(specMetadata, internal.WorkloadServiceNameAnnotation); ok {
return d
}
return workloadName
}

func buildProbe(input scoretypes.HttpProbe) coreV1.ProbeHandler {
Expand Down
2 changes: 1 addition & 1 deletion internal/convert/workloads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ metadata:
app.kubernetes.io/instance: example-abcdef
app.kubernetes.io/managed-by: score-k8s
app.kubernetes.io/name: example
name: example-svc
name: example
spec:
ports:
- name: web
Expand Down
2 changes: 1 addition & 1 deletion internal/provisioners/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func buildWorkloadServices(state *project.State) map[string]NetworkService {
out := make(map[string]NetworkService, len(state.Workloads))
for workloadName, workloadState := range state.Workloads {
ns := NetworkService{
ServiceName: convert.WorkloadServiceName(workloadName),
ServiceName: convert.WorkloadServiceName(workloadName, state.Workloads[workloadName].Spec.Metadata),
Ports: make(map[string]ServicePort),
}
if workloadState.Spec.Service != nil {
Expand Down

0 comments on commit ed404d0

Please sign in to comment.