Skip to content

Commit

Permalink
Add pod annotations from DWOC & podAdditions to devworkspace pod
Browse files Browse the repository at this point in the history
Signed-off-by: dkwon17 <[email protected]>
  • Loading branch information
dkwon17 committed Jun 11, 2024
1 parent 4b71cdd commit f7efbb5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions controllers/workspace/devworkspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,9 @@ func (r *DevWorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request
allPodAdditions = append(allPodAdditions, *routingPodAdditions)
}

annotationAdditions := controllerv1alpha1.PodAdditions{Annotations: workspace.Config.Workspace.PodAnnotations}
allPodAdditions = append(allPodAdditions, annotationAdditions)

// Step five: Prepare workspace ServiceAccount
var serviceAcctName string
if *workspace.Config.Workspace.ServiceAccount.DisableCreation {
Expand Down
12 changes: 12 additions & 0 deletions pkg/config/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,15 @@ func mergeConfig(from, to *controller.OperatorConfiguration) {
}
to.Workspace.DefaultContainerResources = mergeResources(from.Workspace.DefaultContainerResources, to.Workspace.DefaultContainerResources)
}

if from.Workspace.PodAnnotations != nil {
if to.Workspace.PodAnnotations == nil {
to.Workspace.PodAnnotations = make(map[string]string)
}
for key, value := range from.Workspace.PodAnnotations {
to.Workspace.PodAnnotations[key] = value
}
}
}
}

Expand Down Expand Up @@ -586,6 +595,9 @@ func GetCurrentConfigString(currConfig *controller.OperatorConfiguration) string
if !reflect.DeepEqual(workspace.DefaultContainerResources, defaultConfig.Workspace.DefaultContainerResources) {
config = append(config, "workspace.defaultContainerResources is set")
}
if !reflect.DeepEqual(workspace.PodAnnotations, defaultConfig.Workspace.PodAnnotations) {
config = append(config, "workspace.podAnnotations is set")
}
}
if currConfig.EnableExperimentalFeatures != nil && *currConfig.EnableExperimentalFeatures {
config = append(config, "enableExperimentalFeatures=true")
Expand Down
7 changes: 7 additions & 0 deletions pkg/provision/workspace/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func getSpecDeployment(
constants.DevWorkspaceIDLabel: workspace.Status.DevWorkspaceId,
constants.DevWorkspaceNameLabel: workspace.Name,
},
Annotations: podAdditions.Annotations,
},
Spec: corev1.PodSpec{
InitContainers: podAdditions.InitContainers,
Expand Down Expand Up @@ -300,9 +301,15 @@ func mergePodAdditions(toMerge []v1alpha1.PodAdditions) (*v1alpha1.PodAdditions,
pullSecretNames := map[string]bool{}
for _, additions := range toMerge {
for annotKey, annotVal := range additions.Annotations {
if podAdditions.Annotations == nil {
podAdditions.Annotations = map[string]string{}
}
podAdditions.Annotations[annotKey] = annotVal
}
for labelKey, labelVal := range additions.Labels {
if podAdditions.Labels == nil {
podAdditions.Labels = map[string]string{}
}
podAdditions.Labels[labelKey] = labelVal
}
for _, container := range additions.Containers {
Expand Down

0 comments on commit f7efbb5

Please sign in to comment.