Skip to content

Commit 6126245

Browse files
Adding HF token env var when using multi llm NIM without caching (#698)
* Adding HF token env var when using multi llm NIM without caching Signed-off-by: Vishesh Tanksale <[email protected]> * Adddressing review comments Signed-off-by: Vishesh Tanksale <[email protected]> * Adddressing lint fixes Signed-off-by: Vishesh Tanksale <[email protected]> --------- Signed-off-by: Vishesh Tanksale <[email protected]>
1 parent 6c1bc14 commit 6126245

File tree

7 files changed

+35
-34
lines changed

7 files changed

+35
-34
lines changed

api/apps/v1alpha1/nimcache_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type NIMCacheSpec struct {
4848
GroupID *int64 `json:"groupID,omitempty"`
4949
// CertConfig is the name of the ConfigMap containing the custom certificates.
5050
// for secure communication.
51+
//
5152
// Deprecated: use `Proxy` instead to configure custom certificates for using proxy.
5253
// +optional
5354
CertConfig *CertConfig `json:"certConfig,omitempty"`

api/apps/v1alpha1/nimservice_types.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -275,17 +275,6 @@ func (n *NIMService) GetStandardEnv() []corev1.EnvVar {
275275
Name: "NIM_CACHE_PATH",
276276
Value: utils.DefaultModelStorePath,
277277
},
278-
{
279-
Name: "NGC_API_KEY",
280-
ValueFrom: &corev1.EnvVarSource{
281-
SecretKeyRef: &corev1.SecretKeySelector{
282-
LocalObjectReference: corev1.LocalObjectReference{
283-
Name: n.Spec.AuthSecret,
284-
},
285-
Key: "NGC_API_KEY",
286-
},
287-
},
288-
},
289278
{
290279
Name: "OUTLINES_CACHE_DIR",
291280
Value: "/tmp/outlines",
@@ -362,6 +351,11 @@ func (n *NIMService) getLWSCommonEnv() []corev1.EnvVar {
362351
return env
363352
}
364353

354+
// GetLWSLeaderEnvFrom returns the env from sources for the leader worker set.
355+
func (n *NIMService) GetLWSCommonEnvFrom() []corev1.EnvFromSource {
356+
return n.GetEnvFrom()
357+
}
358+
365359
func (n *NIMService) GetLWSLeaderEnv() []corev1.EnvVar {
366360
env := n.getLWSCommonEnv()
367361

@@ -566,6 +560,23 @@ func (n *NIMService) GetEnv() []corev1.EnvVar {
566560
return envVarList
567561
}
568562

563+
// GetEnvFrom returns merged slice of standard and user specified env from sources.
564+
func (n *NIMService) GetEnvFrom() []corev1.EnvFromSource {
565+
if n.Spec.AuthSecret != "" {
566+
return []corev1.EnvFromSource{
567+
{
568+
SecretRef: &corev1.SecretEnvSource{
569+
LocalObjectReference: corev1.LocalObjectReference{
570+
Name: n.Spec.AuthSecret,
571+
},
572+
},
573+
},
574+
}
575+
}
576+
// no secrets to source the env variables
577+
return []corev1.EnvFromSource{}
578+
}
579+
569580
// GetImage returns container image for the NIMService.
570581
func (n *NIMService) GetImage() string {
571582
return fmt.Sprintf("%s:%s", n.Spec.Image.Repository, n.Spec.Image.Tag)
@@ -1047,6 +1058,7 @@ func (n *NIMService) GetDeploymentParams() *rendertypes.DeploymentParams {
10471058
// Set container spec
10481059
params.ContainerName = n.GetContainerName()
10491060
params.Env = n.GetEnv()
1061+
params.EnvFrom = n.GetEnvFrom()
10501062
params.Args = n.GetArgs()
10511063
params.Command = n.GetCommand()
10521064
params.Resources = n.GetResources()
@@ -1118,6 +1130,8 @@ func (n *NIMService) GetLWSParams() *rendertypes.LeaderWorkerSetParams {
11181130
params.Command = n.GetCommand()
11191131
params.LeaderEnvs = n.GetLWSLeaderEnv()
11201132
params.WorkerEnvs = n.GetLWSWorkerEnv()
1133+
params.LeaderEnvFrom = n.GetLWSCommonEnvFrom()
1134+
params.WorkerEnvFrom = n.GetLWSCommonEnvFrom()
11211135
params.UserID = n.GetUserID()
11221136
params.GroupID = n.GetGroupID()
11231137
params.Image = n.GetImage()

config/crd/bases/apps.nvidia.com_nimcaches.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ spec:
5454
description: |-
5555
CertConfig is the name of the ConfigMap containing the custom certificates.
5656
for secure communication.
57+
5758
Deprecated: use `Proxy` instead to configure custom certificates for using proxy.
5859
properties:
5960
mountPath:

internal/controller/nimcache_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ func (r *NIMCacheReconciler) constructJob(ctx context.Context, nimCache *appsv1a
12581258
job.Spec.Template.Spec.Containers[0].Env = utils.MergeEnvVars(job.Spec.Template.Spec.Containers[0].Env, nimCache.Spec.Env)
12591259

12601260
// Inject custom CA certificates when running in a proxy envronment
1261-
if nimCache.Spec.CertConfig != nil {
1261+
if nimCache.Spec.CertConfig != nil { //nolint:staticcheck // checking for deprecated field
12621262
err := errors.NewBadRequest("Deprecated field 'CertConfig' is used. Please migrate to 'Proxy' field on NIMCache.\"")
12631263
logger.Error(err, err.Error())
12641264
return nil, err

internal/controller/platform/standalone/nimservice_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,17 +1107,6 @@ var _ = Describe("NIMServiceReconciler for a standalone platform", func() {
11071107
Name: "NIM_CACHE_PATH",
11081108
Value: "/model-store",
11091109
},
1110-
{
1111-
Name: "NGC_API_KEY",
1112-
ValueFrom: &corev1.EnvVarSource{
1113-
SecretKeyRef: &corev1.SecretKeySelector{
1114-
LocalObjectReference: corev1.LocalObjectReference{
1115-
Name: "",
1116-
},
1117-
Key: "NGC_API_KEY",
1118-
},
1119-
},
1120-
},
11211110
{
11221111
Name: "OUTLINES_CACHE_DIR",
11231112
Value: "/tmp/outlines",
@@ -1209,17 +1198,6 @@ var _ = Describe("NIMServiceReconciler for a standalone platform", func() {
12091198
Name: "NIM_CACHE_PATH",
12101199
Value: "/model-store",
12111200
},
1212-
{
1213-
Name: "NGC_API_KEY",
1214-
ValueFrom: &corev1.EnvVarSource{
1215-
SecretKeyRef: &corev1.SecretKeySelector{
1216-
LocalObjectReference: corev1.LocalObjectReference{
1217-
Name: "",
1218-
},
1219-
Key: "NGC_API_KEY",
1220-
},
1221-
},
1222-
},
12231201
{
12241202
Name: "OUTLINES_CACHE_DIR",
12251203
Value: "/tmp/outlines",

internal/render/types/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type DeploymentParams struct {
7171
Volumes []corev1.Volume
7272
VolumeMounts []corev1.VolumeMount
7373
Env []corev1.EnvVar
74+
EnvFrom []corev1.EnvFromSource
7475
Resources *corev1.ResourceRequirements
7576
NodeSelector map[string]string
7677
Tolerations []corev1.Toleration
@@ -112,6 +113,8 @@ type LeaderWorkerSetParams struct {
112113
LeaderVolumeMounts []corev1.VolumeMount
113114
WorkerEnvs []corev1.EnvVar
114115
LeaderEnvs []corev1.EnvVar
116+
WorkerEnvFrom []corev1.EnvFromSource
117+
LeaderEnvFrom []corev1.EnvFromSource
115118
Resources *corev1.ResourceRequirements
116119
NodeSelector map[string]string
117120
Tolerations []corev1.Toleration

manifests/deployment.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ spec:
9898
{{- if .Env }}
9999
{{- .Env | yaml | nindent 10 }}
100100
{{- end }}
101+
envFrom:
102+
{{- if .EnvFrom }}
103+
{{- .EnvFrom | yaml | nindent 10 }}
104+
{{- end }}
101105
{{- with .Resources }}
102106
resources:
103107
{{ . | yaml | nindent 10 }}

0 commit comments

Comments
 (0)