template.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. Copyright 2026 LocoStack.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package litellm
  14. import (
  15. "fmt"
  16. "github.com/LocoStack/loco-operator/api/v1alpha1"
  17. corev1 "k8s.io/api/core/v1"
  18. )
  19. const (
  20. LITELLM_MASTER_KEY_ENV_NAME = "MASTER_KEY"
  21. LITELLM_AUTH_SECRET_KEY = "key"
  22. LITELLM_CONFIG_KEY = "config.yaml"
  23. // MCPAuthHeaderName is the header litellm's MCP gateway expects the caller's
  24. // key in, per https://docs.litellm.ai/docs/mcp_control#method-1-url-based-namespacing.
  25. MCPAuthHeaderName = "x-litellm-api-key"
  26. )
  27. // MasterKeySecretName returns the name of the Secret holding a gateway component's
  28. // litellm master key, as created by ReconcileKey(ctx, "litellm", LITELLM_AUTH_SECRET_KEY, ...).
  29. func MasterKeySecretName(gatewayComponentName string) string {
  30. return gatewayComponentName + "-litellm"
  31. }
  32. var LiteLLMTemplate = v1alpha1.Template{
  33. Name: "litellm",
  34. Spec: v1alpha1.TemplateSpec{
  35. Runtime: v1alpha1.RuntimeSpec{
  36. Name: "litellm",
  37. Image: "ghcr.io/berriai/litellm:v1.87.1",
  38. Command: []string{"litellm"},
  39. Args: []string{"--port", "$(spec.runtime.port)"},
  40. Env: []corev1.EnvVar{
  41. {Name: "CONFIG_FILE_PATH", Value: fmt.Sprintf("/etc/litellm/%s", LITELLM_CONFIG_KEY)},
  42. {Name: LITELLM_MASTER_KEY_ENV_NAME, ValueFrom: &corev1.EnvVarSource{
  43. SecretKeyRef: &corev1.SecretKeySelector{
  44. LocalObjectReference: corev1.LocalObjectReference{Name: "$(metadata.name)-litellm"},
  45. Key: LITELLM_AUTH_SECRET_KEY,
  46. },
  47. }},
  48. },
  49. VolumeMounts: []corev1.VolumeMount{
  50. {
  51. Name: "config",
  52. MountPath: "/etc/litellm",
  53. ReadOnly: true,
  54. },
  55. },
  56. Port: 4000,
  57. },
  58. Volumes: []corev1.Volume{
  59. {
  60. Name: "config",
  61. VolumeSource: corev1.VolumeSource{
  62. ConfigMap: &corev1.ConfigMapVolumeSource{
  63. LocalObjectReference: corev1.LocalObjectReference{Name: "$(metadata.name)-config"},
  64. },
  65. },
  66. },
  67. },
  68. },
  69. }