Skip to content

Commit 9815e74

Browse files
committed
feat: spread container env to initContianers
1 parent e3f2714 commit 9815e74

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/onsi/ginkgo/v2 v2.22.2
88
github.com/onsi/gomega v1.36.2
99
github.com/open-policy-agent/cert-controller v0.12.0
10+
github.com/stretchr/testify v1.9.0
1011
k8s.io/api v0.32.2
1112
k8s.io/apiextensions-apiserver v0.32.2
1213
k8s.io/apimachinery v0.32.2
@@ -49,6 +50,7 @@ require (
4950
github.com/modern-go/reflect2 v1.0.2 // indirect
5051
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
5152
github.com/pkg/errors v0.9.1 // indirect
53+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
5254
github.com/prometheus/client_golang v1.20.2 // indirect
5355
github.com/prometheus/client_model v0.6.1 // indirect
5456
github.com/prometheus/common v0.55.0 // indirect

pkg/controller_helper/modelsource/modelhub.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ func (p *ModelHubProvider) InjectModelLoader(template *corev1.PodTemplateSpec, i
7575
},
7676
}
7777

78+
// We have exactly one container in the template.Spec.Containers.
79+
spreadEnvToInitContainer(template.Spec.Containers[0].Env, initContainer)
80+
7881
// This is related to the model loader logics which will read the environment when loading models weights.
7982
initContainer.Env = append(
8083
initContainer.Env,
@@ -157,3 +160,7 @@ func (p *ModelHubProvider) InjectModelLoader(template *corev1.PodTemplateSpec, i
157160
},
158161
})
159162
}
163+
164+
func spreadEnvToInitContainer(containerEnv []corev1.EnvVar, initContainer *corev1.Container) {
165+
initContainer.Env = append(initContainer.Env, containerEnv...)
166+
}

pkg/controller_helper/modelsource/modelsource_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ package modelSource
1919
import (
2020
"testing"
2121

22+
"github.com/stretchr/testify/assert"
23+
corev1 "k8s.io/api/core/v1"
24+
2225
coreapi "github.com/inftyai/llmaz/api/core/v1alpha1"
2326
"github.com/inftyai/llmaz/test/util"
2427
"github.com/inftyai/llmaz/test/util/wrapper"
@@ -69,3 +72,60 @@ func Test_ModelSourceProvider(t *testing.T) {
6972
})
7073
}
7174
}
75+
76+
func TestEnvInjectModelLoader(t *testing.T) {
77+
tests := []struct {
78+
name string
79+
provider ModelSourceProvider
80+
template *corev1.PodTemplateSpec
81+
}{
82+
{
83+
name: "Spread container env to initContiner using modelhub",
84+
provider: &ModelHubProvider{
85+
modelName: "test-model",
86+
},
87+
template: &corev1.PodTemplateSpec{
88+
Spec: corev1.PodSpec{
89+
Containers: []corev1.Container{
90+
{
91+
Name: "model-runner",
92+
Image: "vllm:test",
93+
Env: []corev1.EnvVar{
94+
{Name: "http_proxy", Value: "1.1.1.1:1234"},
95+
{Name: "https_proxy", Value: "1.1.1.1:1234"},
96+
},
97+
},
98+
},
99+
},
100+
},
101+
},
102+
{
103+
name: "Spread container env to initContiner using objstores",
104+
provider: &URIProvider{
105+
modelName: "test-model",
106+
},
107+
template: &corev1.PodTemplateSpec{
108+
Spec: corev1.PodSpec{
109+
Containers: []corev1.Container{
110+
{
111+
Name: "model-runner",
112+
Image: "vllm:test",
113+
Env: []corev1.EnvVar{
114+
{Name: "http_proxy", Value: "1.1.1.1:1234"},
115+
{Name: "https_proxy", Value: "1.1.1.1:1234"},
116+
},
117+
},
118+
},
119+
},
120+
},
121+
},
122+
}
123+
124+
for _, tt := range tests {
125+
t.Run(tt.name, func(t *testing.T) {
126+
tt.provider.InjectModelLoader(tt.template, 0)
127+
initContainer := tt.template.Spec.InitContainers[0]
128+
assert.Subset(t, initContainer.Env, tt.template.Spec.Containers[0].Env)
129+
})
130+
}
131+
}

pkg/controller_helper/modelsource/uri.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ func (p *URIProvider) InjectModelLoader(template *corev1.PodTemplateSpec, index
120120
},
121121
}
122122

123+
// We have exactly one container in the template.Spec.Containers.
124+
spreadEnvToInitContainer(template.Spec.Containers[0].Env, initContainer)
125+
123126
switch p.protocol {
124127
case OSS:
125128
initContainer.Env = append(

0 commit comments

Comments
 (0)