Skip to content

Commit 3f437aa

Browse files
committed
Update deployment annotation handling to match devfile/api
Adapt handling of additional annotations on the workspace Deployment to match what is expected from the devfile API (Annotations field on container components). As part of supporting this, removes support for specifying additional annotations/labels via attributes. Signed-off-by: Angel Misevski <amisevsk@redhat.com>
1 parent 118252e commit 3f437aa

File tree

3 files changed

+21
-49
lines changed

3 files changed

+21
-49
lines changed

docs/additional-configuration.md

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,6 @@ data:
122122

123123
Note: As for automatically mounting secrets, it is necessary to apply the `controller.devfile.io/watch-secret` label to git credentials secrets
124124

125-
## Applying labels and annotations to the workspace deployment
126-
In some cases, it is useful to apply additional labels or annotations to the deployment that is created for a DevWorkspace. This is supported by setting attributes `controller.devfile.io/deployment-labels` and `controller.devfile.io/deployment-annotations` in the DevWorkspace's attributes field. The value of these attributes should be specified as a string map, as it is for regular metadata labels and annotations. For example:
127-
```
128-
kind: DevWorkspace
129-
apiVersion: workspace.devfile.io/v1alpha2
130-
metadata:
131-
name: my-workspace
132-
spec:
133-
template:
134-
attributes:
135-
controller.devfile.io/deployment-labels:
136-
my-label: foo
137-
my-other-label: bar
138-
controller.devfile.io/deployment-annotations:
139-
my-attribute: foo
140-
my-other-attribute: bar
141-
```
142-
143125
## Debugging a failing workspace
144126
Normally, when a workspace fails to start, the deployment will be scaled down and the workspace will be stopped in a `Failed` state. This can make it difficult to debug misconfiguration errors, so the annotation `controller.devfile.io/debug-start: "true"` can be applied to DevWorkspaces to leave resources for failed workspaces on the cluster. This allows viewing logs from workspace containers.
145127

pkg/constants/attributes.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,6 @@ const (
6565
// will not be cloned into the workspace on start.
6666
ProjectCloneAttribute = "controller.devfile.io/project-clone"
6767

68-
// DeployLabelsAttribute is an DevWorkspace attribute used in .spec.attributes that defines additional labels
69-
// that should be applied to the workspace deployment. Value should be a map[string]string
70-
DeployLabelsAttribute = "controller.devfile.io/deployment-labels"
71-
72-
// DeployAnnotationsAttribute is an DevWorkspace attribute used in .spec.attributes that defines additional annotations
73-
// that should be applied to the workspace deployment. Value should be a map[string]string
74-
DeployAnnotationsAttribute = "controller.devfile.io/deployment-annotations"
75-
7668
// PluginSourceAttribute is an attribute added to components, commands, and projects in a flattened
7769
// DevWorkspace representation to signify where the respective component came from (i.e. which plugin
7870
// or parent imported it)

pkg/provision/workspace/deployment.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,12 @@ func getSpecDeployment(
239239
podAdditions.InitContainers[idx].VolumeMounts = append(podAdditions.InitContainers[idx].VolumeMounts, podAdditions.VolumeMounts...)
240240
}
241241

242-
labels, annotations, err := getAdditionalLabelsAndAttributes(workspace)
243-
if err != nil {
244-
return nil, err
245-
}
242+
labels := map[string]string{}
246243
labels[constants.DevWorkspaceIDLabel] = workspace.Status.DevWorkspaceId
247244
labels[constants.DevWorkspaceNameLabel] = workspace.Name
248245

246+
annotations, err := getAdditionalAnnotations(workspace)
247+
249248
deployment := &appsv1.Deployment{
250249
ObjectMeta: metav1.ObjectMeta{
251250
Name: common.DeploymentName(workspace.Status.DevWorkspaceId),
@@ -460,6 +459,24 @@ func needsPVCWorkaround(podAdditions *v1alpha1.PodAdditions) (needs bool, pvcNam
460459
return false, ""
461460
}
462461

462+
func getAdditionalAnnotations(workspace *dw.DevWorkspace) (map[string]string, error) {
463+
annotations := map[string]string{}
464+
465+
for _, component := range workspace.Spec.Template.Components {
466+
if component.Container == nil || component.Container.Annotation == nil || component.Container.Annotation.Deployment == nil {
467+
continue
468+
}
469+
for k, v := range component.Container.Annotation.Deployment {
470+
if currValue, exists := annotations[k]; exists && v != currValue {
471+
return nil, fmt.Errorf("conflicting annotations found on container components for key %s", k)
472+
}
473+
annotations[k] = v
474+
}
475+
}
476+
477+
return annotations, nil
478+
}
479+
463480
func checkPodEvents(pod *corev1.Pod, workspaceID string, clusterAPI sync.ClusterAPI) (msg string, err error) {
464481
evs := &corev1.EventList{}
465482
selector, err := fields.ParseSelector(fmt.Sprintf("involvedObject.name=%s", pod.Name))
@@ -516,22 +533,3 @@ func checkIfUnrecoverableEventIgnored(reason string) (ignored bool) {
516533
}
517534
return false
518535
}
519-
520-
// getAdditionalLabelsAndAttributes reads attributes on the DevWorkspace and returns the additional labels and
521-
// attributes that should be applied to the DevWorkspace. Returns an error if attributes cannot be deserialized
522-
// into a map[string]string. If attributes are not defined, returns an empty map.
523-
func getAdditionalLabelsAndAttributes(workspace *dw.DevWorkspace) (labels, annotations map[string]string, err error) {
524-
labels = map[string]string{}
525-
annotations = map[string]string{}
526-
if workspace.Spec.Template.Attributes.Exists(constants.DeployLabelsAttribute) {
527-
if err := workspace.Spec.Template.Attributes.GetInto(constants.DeployLabelsAttribute, &labels); err != nil {
528-
return nil, nil, fmt.Errorf("failed to process %s attribute: %w", constants.DeployLabelsAttribute, err)
529-
}
530-
}
531-
if workspace.Spec.Template.Attributes.Exists(constants.DeployAnnotationsAttribute) {
532-
if err := workspace.Spec.Template.Attributes.GetInto(constants.DeployAnnotationsAttribute, &annotations); err != nil {
533-
return nil, nil, fmt.Errorf("failed to process %s attribute: %w", constants.DeployAnnotationsAttribute, err)
534-
}
535-
}
536-
return labels, annotations, nil
537-
}

0 commit comments

Comments
 (0)