Skip to content

Commit 47ba388

Browse files
feat(image-builder): Add mechanism to pass api server env vars to kaniko build jobs (caraml-dev#398)
* Add mechanism to pass api server env vars to kaniko build jobs * Fix lint comments * Fix inline comments
1 parent be214e9 commit 47ba388

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

api/turing/config/config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ type KanikoConfig struct {
208208
ImageVersion string `validate:"required"`
209209
// AdditionalArgs allows platform-level additional arguments to be configured for Kaniko jobs
210210
AdditionalArgs []string
211+
// APIServerEnvVars allows extra API-server environment variables to be passed to Kaniko jobs
212+
APIServerEnvVars []string
211213
// Kaniko kubernetes service account
212214
ServiceAccount string
213215
// ResourceRequestsLimits is the resources required by Kaniko executor.
@@ -439,8 +441,11 @@ type MlflowConfig struct {
439441
// Note that the Kaniko image builder needs to be configured correctly to have the necessary credentials to download
440442
// the artifacts from the blob storage tool depending on the artifact service type selected (gcs/s3). For gcs, the
441443
// credentials can be provided via a k8s service account or a secret but for s3, the credentials can be provided via
442-
// additional arguments in the config KanikoConfig.AdditionalArgs e.g.
444+
// 1) additional arguments in the config KanikoConfig.AdditionalArgs e.g.
443445
// --build-arg=[AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY/AWS_DEFAULT_REGION/AWS_ENDPOINT_URL]=xxx
446+
// OR
447+
// 2) additional arguments in the config KanikoConfig.APIServerEnvVars, which will pass the specified environment
448+
// variables PRESENT within the Turing API server's container to the image builder as build arguments
444449
ArtifactServiceType string `validate:"required,oneof=nop gcs s3"`
445450
}
446451

api/turing/imagebuilder/imagebuilder.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"net/http"
7+
"os"
78
"sort"
89
"strings"
910
"time"
@@ -320,6 +321,11 @@ func (ib *imageBuilder) createKanikoJob(
320321
volumes, volumeMounts = ib.configureVolumesAndVolumeMountsToAddCredentials(volumes, volumeMounts)
321322
envVars = ib.configureEnvVarsToAddCredentials(envVars)
322323

324+
// Add all other env vars that are propagated from the API server as build args
325+
for _, envVar := range ib.imageBuildingConfig.KanikoConfig.APIServerEnvVars {
326+
kanikoArgs = append(kanikoArgs, fmt.Sprintf("--build-arg=%s=%s", envVar, os.Getenv(envVar)))
327+
}
328+
323329
job := cluster.Job{
324330
Name: kanikoJobName,
325331
Namespace: ib.imageBuildingConfig.BuildNamespace,

0 commit comments

Comments
 (0)