Skip to content

Commit 648740e

Browse files
fix: enable GCP deployments (#1474)
1 parent 281a69e commit 648740e

File tree

6 files changed

+268
-48
lines changed

6 files changed

+268
-48
lines changed

deploy/cloud/operator/internal/consts/consts.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,7 @@ const (
6969
KubeAnnotationDynamoComponentStorageNS = "nvidia.com/dynamo-storage-namespace"
7070

7171
DynamoDeploymentConfigEnvVar = "DYN_DEPLOYMENT_CONFIG"
72+
73+
DockerConfigVolumeName = "docker-config"
74+
DockerConfigVolumeMountPath = "/docker-config/.docker"
7275
)

deploy/cloud/operator/internal/controller/common.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,10 @@ func getIngressHost(ingressSpec v1alpha1.IngressSpec) string {
6767
func getK8sName(value string) string {
6868
return strings.ReplaceAll(value, ":", "--")
6969
}
70+
71+
func isGoogleRegistry(host string) bool {
72+
return host == "gcr.io" ||
73+
strings.HasSuffix(host, ".gcr.io") ||
74+
strings.HasSuffix(host, ".pkg.dev") ||
75+
strings.HasSuffix(host, ".google.com")
76+
}

deploy/cloud/operator/internal/controller/dynamocomponent_controller.go

Lines changed: 64 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -852,11 +852,15 @@ func (r *DynamoComponentReconciler) generateImageBuilderPodTemplateSpec(ctx cont
852852
Name: "workspace",
853853
MountPath: "/workspace",
854854
},
855+
{
856+
Name: consts.DockerConfigVolumeName,
857+
MountPath: consts.DockerConfigVolumeMountPath,
858+
},
855859
}
856860

857861
if dockerConfigJSONSecretName != "" {
858862
volumes = append(volumes, corev1.Volume{
859-
Name: dockerConfigJSONSecretName,
863+
Name: consts.DockerConfigVolumeName,
860864
VolumeSource: corev1.VolumeSource{
861865
Secret: &corev1.SecretVolumeSource{
862866
SecretName: dockerConfigJSONSecretName,
@@ -869,9 +873,12 @@ func (r *DynamoComponentReconciler) generateImageBuilderPodTemplateSpec(ctx cont
869873
},
870874
},
871875
})
872-
volumeMounts = append(volumeMounts, corev1.VolumeMount{
873-
Name: dockerConfigJSONSecretName,
874-
MountPath: "/kaniko/.docker/",
876+
} else {
877+
volumes = append(volumes, corev1.Volume{
878+
Name: consts.DockerConfigVolumeName,
879+
VolumeSource: corev1.VolumeSource{
880+
EmptyDir: &corev1.EmptyDirVolumeSource{},
881+
},
875882
})
876883
}
877884

@@ -921,8 +928,6 @@ func (r *DynamoComponentReconciler) generateImageBuilderPodTemplateSpec(ctx cont
921928

922929
buildEngine := getDynamoComponentImageBuildEngine()
923930

924-
privileged := buildEngine != DynamoComponentImageBuildEngineBuildkitRootless
925-
926931
dynamoComponentDownloadCommandTemplate, err := template.New("downloadCommand").Parse(`
927932
set -e
928933
@@ -943,10 +948,6 @@ echo "Extracting dynamoComponent tar file..."
943948
tar -xvf /tmp/downloaded.tar
944949
echo "Removing dynamoComponent tar file..."
945950
rm /tmp/downloaded.tar
946-
{{if not .Privileged}}
947-
echo "Changing directory permission..."
948-
chown -R 1000:1000 /workspace
949-
{{end}}
950951
echo "Done"
951952
`)
952953

@@ -961,7 +962,6 @@ echo "Done"
961962
"DynamoComponentDownloadURL": dynamoComponentDownloadURL,
962963
"DynamoComponentRepositoryName": dynamoComponentRepositoryName,
963964
"DynamoComponentVersion": dynamoComponentVersion,
964-
"Privileged": privileged,
965965
})
966966
if err != nil {
967967
err = errors.Wrap(err, "failed to execute download command template")
@@ -1004,6 +1004,44 @@ echo "Done"
10041004
},
10051005
}
10061006

1007+
if dockerConfigJSONSecretName == "" {
1008+
// if no explicit docker config is provided, we need to provide the docker config to the image builder
1009+
var ref name.Reference
1010+
ref, err = name.ParseReference(imageName)
1011+
if err != nil {
1012+
err = errors.Wrap(err, "failed to parse reference")
1013+
return
1014+
}
1015+
dockerRegistry := ref.Context().RegistryStr()
1016+
if isGoogleRegistry(dockerRegistry) {
1017+
// for GCP, we use the google cloud sdk to get the docker config.
1018+
initContainers = append(initContainers, corev1.Container{
1019+
Name: "gcp-init-docker-config",
1020+
Image: "google/cloud-sdk:slim",
1021+
Command: []string{
1022+
"/bin/bash",
1023+
"-c",
1024+
fmt.Sprintf(`set -e
1025+
gcloud --quiet config get-value account
1026+
TOKEN=$(gcloud --quiet auth print-access-token)
1027+
cat > %s/config.json <<EOL
1028+
{
1029+
"auths": {
1030+
"%s": {
1031+
"auth": "$(echo -n "oauth2accesstoken:${TOKEN}" | base64 -w 0)"
1032+
}
1033+
}
1034+
}
1035+
EOL
1036+
echo 'Docker config.json created successfully'`, consts.DockerConfigVolumeMountPath, dockerRegistry),
1037+
},
1038+
Resources: downloaderContainerResources,
1039+
EnvFrom: downloaderContainerEnvFrom,
1040+
VolumeMounts: volumeMounts,
1041+
})
1042+
}
1043+
}
1044+
10071045
containers := make([]corev1.Container, 0)
10081046

10091047
var globalExtraPodMetadata *dynamoCommon.ExtraPodMetadata
@@ -1111,13 +1149,10 @@ echo "Done"
11111149
Name: "IFS",
11121150
Value: "''",
11131151
},
1114-
}
1115-
1116-
if dockerConfigJSONSecretName != "" {
1117-
builderContainerEnvs = append(builderContainerEnvs, corev1.EnvVar{
1152+
{
11181153
Name: "DOCKER_CONFIG",
1119-
Value: "/kaniko/.docker/",
1120-
})
1154+
Value: consts.DockerConfigVolumeMountPath,
1155+
},
11211156
}
11221157

11231158
kanikoCacheRepo := os.Getenv("KANIKO_CACHE_REPO")
@@ -1174,9 +1209,6 @@ echo "Done"
11741209
if isBuildkit {
11751210
output := fmt.Sprintf("type=image,name=%s,push=true,registry.insecure=%v", imageName, dockerRegistryInsecure)
11761211
buildkitdFlags := []string{}
1177-
if !privileged {
1178-
buildkitdFlags = append(buildkitdFlags, "--oci-worker-no-process-sandbox")
1179-
}
11801212
if isEstargzEnabled() {
11811213
buildkitdFlags = append(buildkitdFlags, "--oci-worker-snapshotter=stargz")
11821214
output += ",oci-mediatypes=true,compression=estargz,force-compression=true"
@@ -1215,23 +1247,6 @@ echo "Done"
12151247
}
12161248
}
12171249

1218-
var builderContainerSecurityContext *corev1.SecurityContext
1219-
1220-
if buildEngine == DynamoComponentImageBuildEngineBuildkit {
1221-
builderContainerSecurityContext = &corev1.SecurityContext{
1222-
Privileged: ptr.To(true),
1223-
}
1224-
} else if buildEngine == DynamoComponentImageBuildEngineBuildkitRootless {
1225-
kubeAnnotations["container.apparmor.security.beta.kubernetes.io/builder"] = "unconfined"
1226-
builderContainerSecurityContext = &corev1.SecurityContext{
1227-
SeccompProfile: &corev1.SeccompProfile{
1228-
Type: corev1.SeccompProfileTypeUnconfined,
1229-
},
1230-
RunAsUser: ptr.To(int64(1000)),
1231-
RunAsGroup: ptr.To(int64(1000)),
1232-
}
1233-
}
1234-
12351250
// add build args to pass via --build-arg
12361251
for _, buildArg := range buildArgs {
12371252
quotedBuildArg := unix.SingleQuote.Quote(buildArg)
@@ -1261,7 +1276,13 @@ echo "Done"
12611276
EnvFrom: builderContainerEnvFrom,
12621277
TTY: true,
12631278
Stdin: true,
1264-
SecurityContext: builderContainerSecurityContext,
1279+
}
1280+
1281+
if buildEngine == DynamoComponentImageBuildEngineKaniko {
1282+
// we need to run as root when using kaniko
1283+
container.SecurityContext = &corev1.SecurityContext{
1284+
RunAsUser: ptr.To(int64(0)),
1285+
}
12651286
}
12661287

12671288
if globalDefaultImageBuilderContainerResources != nil {
@@ -1284,6 +1305,11 @@ echo "Done"
12841305
Volumes: volumes,
12851306
InitContainers: initContainers,
12861307
Containers: containers,
1308+
SecurityContext: &corev1.PodSecurityContext{
1309+
RunAsUser: ptr.To(int64(1000)),
1310+
RunAsGroup: ptr.To(int64(1000)),
1311+
FSGroup: ptr.To(int64(1000)),
1312+
},
12871313
},
12881314
}
12891315

deploy/cloud/operator/internal/controller/dynamocomponentdeployment_controller.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,21 +1000,23 @@ func (r *DynamoComponentDeploymentReconciler) createOrUpdateOrDeleteServices(ctx
10001000
return
10011001
}
10021002

1003-
func (r *DynamoComponentDeploymentReconciler) createOrUpdateOrDeleteIngress(ctx context.Context, opt generateResourceOption) (modified bool, err error) {
1004-
modified, _, err = commonController.SyncResource(ctx, r, opt.dynamoComponentDeployment, func(ctx context.Context) (*networkingv1.Ingress, bool, error) {
1003+
func (r *DynamoComponentDeploymentReconciler) createOrUpdateOrDeleteIngress(ctx context.Context, opt generateResourceOption) (bool, error) {
1004+
modified, _, err := commonController.SyncResource(ctx, r, opt.dynamoComponentDeployment, func(ctx context.Context) (*networkingv1.Ingress, bool, error) {
10051005
return r.generateIngress(ctx, opt)
10061006
})
10071007
if err != nil {
1008-
return
1008+
return false, err
10091009
}
1010-
modified_, _, err := commonController.SyncResource(ctx, r, opt.dynamoComponentDeployment, func(ctx context.Context) (*networkingv1beta1.VirtualService, bool, error) {
1011-
return r.generateVirtualService(ctx, opt)
1012-
})
1013-
if err != nil {
1014-
return
1010+
if r.UseVirtualService {
1011+
modified_, _, err := commonController.SyncResource(ctx, r, opt.dynamoComponentDeployment, func(ctx context.Context) (*networkingv1beta1.VirtualService, bool, error) {
1012+
return r.generateVirtualService(ctx, opt)
1013+
})
1014+
if err != nil {
1015+
return false, err
1016+
}
1017+
return modified || modified_, nil
10151018
}
1016-
modified = modified || modified_
1017-
return
1019+
return modified, nil
10181020
}
10191021

10201022
func (r *DynamoComponentDeploymentReconciler) generateIngress(ctx context.Context, opt generateResourceOption) (*networkingv1.Ingress, bool, error) {

docs/guides/dynamo_deploy/dynamo_cloud.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ kubectl get storageclass
100100
# standard (default) kubernetes.io/gce-pd Delete Immediate true 1d
101101
```
102102

103+
### Cloud Provider-Specific deployment
104+
105+
#### Google Kubernetes Engine (GKE) deployment
106+
107+
You can find detailed instructions for deployment in GKE [here](../dynamo_deploy/gke_setup.md)
108+
103109
### Installation
104110

105111
1. Set the required environment variables:

0 commit comments

Comments
 (0)