Skip to content

Commit a2940cb

Browse files
committed
Address global attribute PR feedback
Signed-off-by: Maysun J Faisal <[email protected]>
1 parent fb6e078 commit a2940cb

File tree

65 files changed

+233
-384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+233
-384
lines changed

Diff for: crds/workspace.devfile.io_devworkspaces.v1beta1.yaml

+9-6
Original file line numberDiff line numberDiff line change
@@ -4141,15 +4141,17 @@ spec:
41414141
of a workspace template.
41424142
properties:
41434143
attributes:
4144+
additionalProperties:
4145+
type: string
41444146
description: Map of implementation-dependant free-form YAML attributes.
41454147
Attribute values can be referenced throughout the devfile in
41464148
string type fields in the form {{attribute-key}} except for
4147-
schemaVersion, metadata and events. Exception to the string
4148-
field include element's key identifiers(command id, component
4149-
name, endpoint name, project name, etc.) and string enums(command
4150-
group kind, endpoint exposure, etc.)
4149+
schemaVersion, metadata, parent source. Exception to the string
4150+
field also include element's key identifiers (command id, component
4151+
name, endpoint name, project name, etc.) and their references(events,
4152+
command's component, container's volume mount name, etc.) and
4153+
string enums(command group kind, endpoint exposure, etc.)
41514154
type: object
4152-
x-kubernetes-preserve-unknown-fields: true
41534155
commands:
41544156
description: Predefined, ready-to-use, workspace-related commands
41554157
items:
@@ -5572,11 +5574,12 @@ spec:
55725574
- kubernetes
55735575
properties:
55745576
attributes:
5577+
additionalProperties:
5578+
type: string
55755579
description: Overrides of attributes encapsulated in a parent
55765580
devfile. Overriding is done according to K8S strategic merge
55775581
patch standard rules.
55785582
type: object
5579-
x-kubernetes-preserve-unknown-fields: true
55805583
commands:
55815584
description: Overrides of commands encapsulated in a parent
55825585
devfile or a plugin. Overriding is done according to K8S

Diff for: crds/workspace.devfile.io_devworkspaces.yaml

+9-6
Original file line numberDiff line numberDiff line change
@@ -4139,15 +4139,17 @@ spec:
41394139
of a workspace template.
41404140
properties:
41414141
attributes:
4142+
additionalProperties:
4143+
type: string
41424144
description: Map of implementation-dependant free-form YAML attributes.
41434145
Attribute values can be referenced throughout the devfile in
41444146
string type fields in the form {{attribute-key}} except for
4145-
schemaVersion, metadata and events. Exception to the string
4146-
field include element's key identifiers(command id, component
4147-
name, endpoint name, project name, etc.) and string enums(command
4148-
group kind, endpoint exposure, etc.)
4147+
schemaVersion, metadata, parent source. Exception to the string
4148+
field also include element's key identifiers (command id, component
4149+
name, endpoint name, project name, etc.) and their references(events,
4150+
command's component, container's volume mount name, etc.) and
4151+
string enums(command group kind, endpoint exposure, etc.)
41494152
type: object
4150-
x-kubernetes-preserve-unknown-fields: true
41514153
commands:
41524154
description: Predefined, ready-to-use, workspace-related commands
41534155
items:
@@ -5577,11 +5579,12 @@ spec:
55775579
- kubernetes
55785580
properties:
55795581
attributes:
5582+
additionalProperties:
5583+
type: string
55805584
description: Overrides of attributes encapsulated in a parent
55815585
devfile. Overriding is done according to K8S strategic merge
55825586
patch standard rules.
55835587
type: object
5584-
x-kubernetes-preserve-unknown-fields: true
55855588
commands:
55865589
description: Overrides of commands encapsulated in a parent
55875590
devfile or a plugin. Overriding is done according to K8S

Diff for: crds/workspace.devfile.io_devworkspacetemplates.v1beta1.yaml

+9-6
Original file line numberDiff line numberDiff line change
@@ -3915,15 +3915,17 @@ spec:
39153915
of a workspace template.
39163916
properties:
39173917
attributes:
3918+
additionalProperties:
3919+
type: string
39183920
description: Map of implementation-dependant free-form YAML attributes.
39193921
Attribute values can be referenced throughout the devfile in string
39203922
type fields in the form {{attribute-key}} except for schemaVersion,
3921-
metadata and events. Exception to the string field include element's
3922-
key identifiers(command id, component name, endpoint name, project
3923-
name, etc.) and string enums(command group kind, endpoint exposure,
3924-
etc.)
3923+
metadata, parent source. Exception to the string field also include
3924+
element's key identifiers (command id, component name, endpoint
3925+
name, project name, etc.) and their references(events, command's
3926+
component, container's volume mount name, etc.) and string enums(command
3927+
group kind, endpoint exposure, etc.)
39253928
type: object
3926-
x-kubernetes-preserve-unknown-fields: true
39273929
commands:
39283930
description: Predefined, ready-to-use, workspace-related commands
39293931
items:
@@ -5294,11 +5296,12 @@ spec:
52945296
- kubernetes
52955297
properties:
52965298
attributes:
5299+
additionalProperties:
5300+
type: string
52975301
description: Overrides of attributes encapsulated in a parent
52985302
devfile. Overriding is done according to K8S strategic merge
52995303
patch standard rules.
53005304
type: object
5301-
x-kubernetes-preserve-unknown-fields: true
53025305
commands:
53035306
description: Overrides of commands encapsulated in a parent devfile
53045307
or a plugin. Overriding is done according to K8S strategic merge

Diff for: crds/workspace.devfile.io_devworkspacetemplates.yaml

+9-6
Original file line numberDiff line numberDiff line change
@@ -3913,15 +3913,17 @@ spec:
39133913
of a workspace template.
39143914
properties:
39153915
attributes:
3916+
additionalProperties:
3917+
type: string
39163918
description: Map of implementation-dependant free-form YAML attributes.
39173919
Attribute values can be referenced throughout the devfile in string
39183920
type fields in the form {{attribute-key}} except for schemaVersion,
3919-
metadata and events. Exception to the string field include element's
3920-
key identifiers(command id, component name, endpoint name, project
3921-
name, etc.) and string enums(command group kind, endpoint exposure,
3922-
etc.)
3921+
metadata, parent source. Exception to the string field also include
3922+
element's key identifiers (command id, component name, endpoint
3923+
name, project name, etc.) and their references(events, command's
3924+
component, container's volume mount name, etc.) and string enums(command
3925+
group kind, endpoint exposure, etc.)
39233926
type: object
3924-
x-kubernetes-preserve-unknown-fields: true
39253927
commands:
39263928
description: Predefined, ready-to-use, workspace-related commands
39273929
items:
@@ -5299,11 +5301,12 @@ spec:
52995301
- kubernetes
53005302
properties:
53015303
attributes:
5304+
additionalProperties:
5305+
type: string
53025306
description: Overrides of attributes encapsulated in a parent
53035307
devfile. Overriding is done according to K8S strategic merge
53045308
patch standard rules.
53055309
type: object
5306-
x-kubernetes-preserve-unknown-fields: true
53075310
commands:
53085311
description: Overrides of commands encapsulated in a parent devfile
53095312
or a plugin. Overriding is done according to K8S strategic merge

Diff for: pkg/apis/workspaces/v1alpha2/devworkspaceTemplateSpec.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package v1alpha2
22

3-
import attributes "github.com/devfile/api/v2/pkg/attributes"
4-
53
// Structure of the workspace. This is also the specification of a workspace template.
64
// +devfile:jsonschema:generate
75
type DevWorkspaceTemplateSpec struct {
@@ -16,12 +14,13 @@ type DevWorkspaceTemplateSpec struct {
1614
type DevWorkspaceTemplateSpecContent struct {
1715
// Map of implementation-dependant free-form YAML attributes.
1816
// Attribute values can be referenced throughout the devfile in string type fields in the form {{attribute-key}}
19-
// except for schemaVersion, metadata and events. Exception to the string field include element's key identifiers(command id,
20-
// component name, endpoint name, project name, etc.) and string enums(command group kind, endpoint exposure, etc.)
17+
// except for schemaVersion, metadata, parent source. Exception to the string field also include element's key identifiers
18+
// (command id, component name, endpoint name, project name, etc.) and their references(events, command's component, container's
19+
// volume mount name, etc.) and string enums(command group kind, endpoint exposure, etc.)
2120
// +optional
2221
// +patchStrategy=merge
2322
// +devfile:overrides:include:omitInPlugin=true,description=Overrides of attributes encapsulated in a parent devfile.
24-
Attributes attributes.Attributes `json:"attributes,omitempty" patchStrategy:"merge"`
23+
Attributes map[string]string `json:"attributes,omitempty" patchStrategy:"merge"`
2524

2625
// List of the workspace components, such as editor and plugins,
2726
// user-provided containers, or other types of components

Diff for: pkg/apis/workspaces/v1alpha2/zz_generated.deepcopy.go

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/apis/workspaces/v1alpha2/zz_generated.parent_overrides.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/utils/overriding/keys.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"reflect"
66

77
workspaces "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
8-
attributesPkg "github.com/devfile/api/v2/pkg/attributes"
98
"github.com/hashicorp/go-multierror"
109
"k8s.io/apimachinery/pkg/util/sets"
1110
)
@@ -42,14 +41,17 @@ func checkKeys(doCheck checkFn, toplevelListContainers ...workspaces.TopLevelLis
4241
attributeValue = value.FieldByName("Attributes")
4342
}
4443

45-
if attributeValue.IsValid() && attributeValue.CanInterface() {
46-
attributes, ok := attributeValue.Interface().(attributesPkg.Attributes)
47-
if !ok {
48-
return fmt.Errorf("unable to fetch Attributes from the devfile data")
49-
}
44+
if attributeValue.IsValid() && attributeValue.Kind() == reflect.Map {
45+
mapIter := attributeValue.MapRange()
46+
5047
var attributeKeys []string
51-
for k := range attributes {
52-
attributeKeys = append(attributeKeys, k)
48+
for mapIter.Next() {
49+
k := mapIter.Key()
50+
v := mapIter.Value()
51+
if k.Kind() != reflect.String || v.Kind() != reflect.String {
52+
return fmt.Errorf("unable to fetch Global Attributes, Global Attributes should be map of strings")
53+
}
54+
attributeKeys = append(attributeKeys, k.String())
5355
}
5456
listTypeToKeys["Attributes"] = append(listTypeToKeys["Attributes"], sets.NewString(attributeKeys...))
5557
}

Diff for: pkg/utils/overriding/merging.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"strings"
77

88
workspaces "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
9-
"github.com/devfile/api/v2/pkg/attributes"
109
"k8s.io/apimachinery/pkg/util/json"
1110
"k8s.io/apimachinery/pkg/util/sets"
1211
"k8s.io/apimachinery/pkg/util/yaml"
@@ -107,18 +106,12 @@ func MergeDevWorkspaceTemplateSpec(
107106
postStopCommands = postStopCommands.Union(sets.NewString(content.Events.PostStop...))
108107
}
109108

110-
var err error
111109
if len(content.Attributes) > 0 {
112110
if len(result.Attributes) == 0 {
113-
result.Attributes = attributes.Attributes{}
111+
result.Attributes = make(map[string]string)
114112
}
115113
for k, v := range content.Attributes {
116-
result.Attributes.FromMap(map[string]interface{}{
117-
k: v,
118-
}, &err)
119-
if err != nil {
120-
return nil, err
121-
}
114+
result.Attributes[k] = v
122115
}
123116
}
124117
}

Diff for: pkg/utils/overriding/merging_test.go

+12-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
workspaces "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
10-
attributesPkg "github.com/devfile/api/v2/pkg/attributes"
1110
"github.com/stretchr/testify/assert"
1211
"k8s.io/apimachinery/pkg/util/json"
1312
yamlMachinery "k8s.io/apimachinery/pkg/util/yaml"
@@ -27,9 +26,9 @@ func TestBasicMerging(t *testing.T) {
2726
{
2827
name: "Basic Merging",
2928
mainContent: &workspaces.DevWorkspaceTemplateSpecContent{
30-
Attributes: attributesPkg.Attributes{}.FromMap(map[string]interface{}{
31-
"main": true,
32-
}, nil),
29+
Attributes: map[string]string{
30+
"version1": "main",
31+
},
3332
Commands: []workspaces.Command{
3433
{
3534
Id: "mainCommand",
@@ -72,9 +71,9 @@ func TestBasicMerging(t *testing.T) {
7271
},
7372
pluginFlattenedContents: []*workspaces.DevWorkspaceTemplateSpecContent{
7473
{
75-
Attributes: attributesPkg.Attributes{}.FromMap(map[string]interface{}{
74+
Attributes: map[string]string{
7675
"version2": "plugin",
77-
}, nil),
76+
},
7877
Commands: []workspaces.Command{
7978
{
8079
Id: "pluginCommand",
@@ -105,9 +104,9 @@ func TestBasicMerging(t *testing.T) {
105104
},
106105
},
107106
parentFlattenedContent: &workspaces.DevWorkspaceTemplateSpecContent{
108-
Attributes: attributesPkg.Attributes{}.FromMap(map[string]interface{}{
109-
"version": "parent",
110-
}, nil),
107+
Attributes: map[string]string{
108+
"version3": "parent",
109+
},
111110
Commands: []workspaces.Command{
112111
{
113112
Id: "parentCommand",
@@ -138,11 +137,11 @@ func TestBasicMerging(t *testing.T) {
138137
},
139138
},
140139
expected: &workspaces.DevWorkspaceTemplateSpecContent{
141-
Attributes: attributesPkg.Attributes{}.FromMap(map[string]interface{}{
142-
"version": "parent",
140+
Attributes: map[string]string{
141+
"version3": "parent",
143142
"version2": "plugin",
144-
"main": true,
145-
}, nil),
143+
"version1": "main",
144+
},
146145
Commands: []workspaces.Command{
147146
{
148147
Id: "parentCommand",

Diff for: pkg/utils/overriding/overriding_test.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"testing"
99

1010
workspaces "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
11-
attributesPkg "github.com/devfile/api/v2/pkg/attributes"
1211
"github.com/stretchr/testify/assert"
1312
"k8s.io/apimachinery/pkg/util/json"
1413
yamlMachinery "k8s.io/apimachinery/pkg/util/yaml"
@@ -52,10 +51,10 @@ func TestBasicToplevelOverriding(t *testing.T) {
5251
},
5352
},
5453
},
55-
Attributes: attributesPkg.Attributes{}.FromMap(map[string]interface{}{
54+
Attributes: map[string]string{
5655
"version": "main",
5756
"xyz": "xyz",
58-
}, nil),
57+
},
5958
}
6059

6160
patch := workspaces.ParentOverrides{
@@ -86,9 +85,9 @@ func TestBasicToplevelOverriding(t *testing.T) {
8685
},
8786
},
8887
},
89-
Attributes: attributesPkg.Attributes{}.FromMap(map[string]interface{}{
88+
Attributes: map[string]string{
9089
"version": "patch",
91-
}, nil),
90+
},
9291
}
9392

9493
expected := &workspaces.DevWorkspaceTemplateSpecContent{
@@ -133,10 +132,10 @@ func TestBasicToplevelOverriding(t *testing.T) {
133132
},
134133
},
135134
},
136-
Attributes: attributesPkg.Attributes{}.FromMap(map[string]interface{}{
135+
Attributes: map[string]string{
137136
"version": "patch",
138137
"xyz": "xyz",
139-
}, nil),
138+
},
140139
}
141140

142141
result, err := OverrideDevWorkspaceTemplateSpec(&original, &patch)

Diff for: pkg/utils/overriding/test-fixtures/merges/duplicate-with-parent/main.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
parent:
22
uri: "anyParent"
33
attributes:
4-
objectAttribute:
5-
attributeField: 9.9
4+
objectAttribute: mainValue
65
components:
76
- container:
87
image: "aDifferentValue"

Diff for: pkg/utils/overriding/test-fixtures/merges/duplicate-with-parent/parent.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
attributes:
2-
objectAttribute:
3-
attributeField: 10.10
2+
objectAttribute: parentValue
43
components:
54
- container:
65
image: "aValue"

0 commit comments

Comments
 (0)