Skip to content

Commit

Permalink
Merge pull request #9308 from prometherion/issues/9306
Browse files Browse the repository at this point in the history
🐛 Adding metrics container port in tilt-prepare only if it's missing
  • Loading branch information
k8s-ci-robot authored Aug 25, 2023
2 parents a723462 + be68373 commit fd60888
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions hack/tools/internal/tilt-prepare/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,12 +834,15 @@ func prepareWorkload(name, prefix, binaryName, containerName string, objs []unst
}
finalArgs = append(finalArgs, a)
}

container.Ports = append(container.Ports, corev1.ContainerPort{
Name: "metrics",
ContainerPort: 8080,
Protocol: "TCP",
})
// tilt-prepare should add the metrics port if and only if it's missing:
// as best practices with controller-runtime, it's named metrics and listening on port 8080.
if !containerHasMetricsPort(container.Ports) {
container.Ports = append(container.Ports, corev1.ContainerPort{
Name: "metrics",
ContainerPort: 8080,
Protocol: corev1.ProtocolTCP,
})
}

container.Command = cmd
container.Args = finalArgs
Expand All @@ -848,6 +851,16 @@ func prepareWorkload(name, prefix, binaryName, containerName string, objs []unst
})
}

func containerHasMetricsPort(ports []corev1.ContainerPort) bool {
for _, port := range ports {
if port.ContainerPort == 8080 {
return true
}
}

return false
}

type updateDeploymentFunction func(deployment *appsv1.Deployment)

// updateDeployment passes all (typed) deployments to the updateDeploymentFunction
Expand Down

0 comments on commit fd60888

Please sign in to comment.