Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Adding metrics container port in tilt-prepare only if it's missing #9308

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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