Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: patch for volumeMounts #546

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions pkg/controllers/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
return c.garbageCollectWorkspace(ctx, wObj)
}

func (c *WorkspaceReconciler) updateControllerRevision(ctx context.Context, wObj *kaitov1alpha1.Workspace) error {
func (c *WorkspaceReconciler) updateControllerRevision(ctx context.Context, wObj *kaitov1alpha1.Workspace) error { // TODO: Move non-updateControllerRevision related logic to separate functions
currentHash := computeHash(wObj)
annotations := wObj.GetAnnotations()

Expand Down Expand Up @@ -267,6 +267,10 @@
Data: runtime.RawExtension{Raw: jsonData},
}

if annotations == nil {
annotations = make(map[string]string)

Check warning on line 271 in pkg/controllers/workspace_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controllers/workspace_controller.go#L271

Added line #L271 was not covered by tests
} // nil checking.

annotations[WorkspaceRevisionAnnotation] = currentHash
wObj.SetAnnotations(annotations)
deployment := &appsv1.Deployment{}
Expand All @@ -287,11 +291,29 @@

if hash, exists := deployment.Annotations[WorkspaceRevisionAnnotation]; !exists || (hash != currentHash) {

initContainers, envs := resources.GenerateInitContainers(wObj)
var volumes []corev1.Volume
var volumeMounts []corev1.VolumeMount
shmVolume, shmVolumeMount := utils.ConfigSHMVolume(*wObj.Resource.Count)
if shmVolume.Name != "" {
volumes = append(volumes, shmVolume)

Check warning on line 298 in pkg/controllers/workspace_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controllers/workspace_controller.go#L298

Added line #L298 was not covered by tests
}
if shmVolumeMount.Name != "" {
volumeMounts = append(volumeMounts, shmVolumeMount)

Check warning on line 301 in pkg/controllers/workspace_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controllers/workspace_controller.go#L301

Added line #L301 was not covered by tests
}

if len(wObj.Inference.Adapters) > 0 {
adapterVolume, adapterVolumeMount := utils.ConfigAdapterVolume()
volumes = append(volumes, adapterVolume)
volumeMounts = append(volumeMounts, adapterVolumeMount)
}

initContainers, envs := resources.GenerateInitContainers(wObj, volumeMounts)
spec := &deployment.Spec
spec.Template.Spec.InitContainers = initContainers
spec.Template.Spec.Containers[0].Env = envs
spec.Template.Spec.Containers[0].VolumeMounts = volumeMounts
deployment.Annotations[WorkspaceRevisionAnnotation] = currentHash
spec.Template.Spec.Volumes = volumes

if err := c.Update(ctx, deployment); err != nil {
return fmt.Errorf("failed to update deployment: %w", err)
Expand Down
10 changes: 5 additions & 5 deletions pkg/resources/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@
initContainers := []corev1.Container{}
envs := []corev1.EnvVar{}
if len(workspaceObj.Inference.Adapters) > 0 {
initContainers, envs = GenerateInitContainers(workspaceObj)
initContainers, envs = GenerateInitContainers(workspaceObj, volumeMount)

Check warning on line 278 in pkg/resources/manifests.go

View check run for this annotation

Codecov / codecov/patch

pkg/resources/manifests.go#L278

Added line #L278 was not covered by tests
}

return &appsv1.Deployment{
Expand Down Expand Up @@ -334,16 +334,16 @@
}
}

func GenerateInitContainers(wObj *kaitov1alpha1.Workspace) ([]corev1.Container, []corev1.EnvVar) {
initContainers := []corev1.Container{}
envs := []corev1.EnvVar{}
func GenerateInitContainers(wObj *kaitov1alpha1.Workspace, volumeMount []corev1.VolumeMount) ([]corev1.Container, []corev1.EnvVar) {
var initContainers []corev1.Container
var envs []corev1.EnvVar

Check warning on line 339 in pkg/resources/manifests.go

View check run for this annotation

Codecov / codecov/patch

pkg/resources/manifests.go#L337-L339

Added lines #L337 - L339 were not covered by tests
if len(wObj.Inference.Adapters) > 0 {
for _, adapter := range wObj.Inference.Adapters {
initContainer := corev1.Container{
Name: adapter.Source.Name,
Image: adapter.Source.Image,
Command: []string{"/bin/sh", "-c", fmt.Sprintf("mkdir -p /mnt/adapter/%s && cp -r /data/* /mnt/adapter/%s", adapter.Source.Name, adapter.Source.Name)},
VolumeMounts: []corev1.VolumeMount{},
VolumeMounts: volumeMount,

Check warning on line 346 in pkg/resources/manifests.go

View check run for this annotation

Codecov / codecov/patch

pkg/resources/manifests.go#L346

Added line #L346 was not covered by tests
ImagePullPolicy: corev1.PullAlways,
}
initContainers = append(initContainers, initContainer)
Expand Down
Loading