Skip to content

Commit 694c2c8

Browse files
committed
feat: spread container env to initContianers
1 parent e3f2714 commit 694c2c8

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
coreapi "github.com/inftyai/llmaz/api/core/v1alpha1"
2323
"github.com/inftyai/llmaz/test/util"
2424
"github.com/inftyai/llmaz/test/util/wrapper"
25+
"github.com/stretchr/testify/assert"
26+
corev1 "k8s.io/api/core/v1"
2527
)
2628

2729
func Test_ModelSourceProvider(t *testing.T) {
@@ -69,3 +71,64 @@ func Test_ModelSourceProvider(t *testing.T) {
6971
})
7072
}
7173
}
74+
75+
func TestEnvInjectModelLoader(t *testing.T) {
76+
tests := []struct {
77+
name string
78+
provider ModelSourceProvider
79+
template *corev1.PodTemplateSpec
80+
}{
81+
{
82+
name: "Spread conatiner env to initContiner using modelhub",
83+
provider: &ModelHubProvider{
84+
modelName: "test-model",
85+
},
86+
template: &corev1.PodTemplateSpec{
87+
Spec: corev1.PodSpec{
88+
Containers: []corev1.Container{
89+
{
90+
Name: "model-runner",
91+
Image: "vllm:test",
92+
Env: []corev1.EnvVar{
93+
{Name: "http_proxy", Value: "1.1.1.1:1234"},
94+
{Name: "https_proxy", Value: "1.1.1.1:1234"},
95+
},
96+
},
97+
},
98+
},
99+
},
100+
},
101+
{
102+
name: "Spread conatiner env to initContiner using objstores",
103+
provider: &URIProvider{
104+
modelName: "test-model",
105+
},
106+
template: &corev1.PodTemplateSpec{
107+
Spec: corev1.PodSpec{
108+
Containers: []corev1.Container{
109+
{
110+
Name: "model-runner",
111+
Image: "vllm:test",
112+
Env: []corev1.EnvVar{
113+
{Name: "http_proxy", Value: "1.1.1.1:1234"},
114+
{Name: "https_proxy", Value: "1.1.1.1:1234"},
115+
},
116+
},
117+
},
118+
},
119+
},
120+
},
121+
}
122+
123+
for _, tt := range tests {
124+
t.Run(tt.name, func(t *testing.T) {
125+
tt.provider.InjectModelLoader(tt.template, 0)
126+
initContainer := tt.template.Spec.InitContainers[0]
127+
// assert.Equal(t, tt.expectedInitEnvVars, initContainer.Env[:len(tt.expectedInitEnvVars)])
128+
// for env := range tt.template.Spec.Containers[0].Env {
129+
assert.Subset(t, initContainer.Env, tt.template.Spec.Containers[0].Env)
130+
131+
// assert.Equal(t, tt.expectedVolumes, template.Spec.Volumes)
132+
})
133+
}
134+
}

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)