Skip to content

Commit ff3c01b

Browse files
authored
Add Global Attributes, Global Variable & Substitution and Deprecate Metadata.Attributes (#352)
* Add Global Attribute and Substitution Signed-off-by: Maysun J Faisal <[email protected]> * Remove global attribute support for vs commands Signed-off-by: Maysun J Faisal <[email protected]> * Remove global attributes from plugin overrides Signed-off-by: Maysun J Faisal <[email protected]> * Address Global Attribute Feedback Signed-off-by: Maysun J Faisal <[email protected]> * Update Cabal Feedback - 1 Signed-off-by: Maysun J Faisal <[email protected]> * Devfile Cabal Feedback 2 - Var Warning Signed-off-by: Maysun J Faisal <[email protected]> * Update dw merging tests for main branch dw rename Signed-off-by: Maysun J Faisal <[email protected]> * PR feedback tests - 1 Signed-off-by: Maysun J Faisal <[email protected]> * PR feedback test - 1.1 Signed-off-by: Maysun J Faisal <[email protected]> * Update merging and overriding tests Signed-off-by: Maysun J Faisal <[email protected]>
1 parent a313872 commit ff3c01b

File tree

78 files changed

+2582
-166
lines changed

Some content is hidden

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

78 files changed

+2582
-166
lines changed

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

+29
Original file line numberDiff line numberDiff line change
@@ -4140,6 +4140,10 @@ spec:
41404140
description: Structure of the devworkspace. This is also the specification
41414141
of a devworkspace template.
41424142
properties:
4143+
attributes:
4144+
description: Map of implementation-dependant free-form YAML attributes.
4145+
type: object
4146+
x-kubernetes-preserve-unknown-fields: true
41434147
commands:
41444148
description: Predefined, ready-to-use, devworkspace-related commands
41454149
items:
@@ -5561,6 +5565,12 @@ spec:
55615565
- required:
55625566
- kubernetes
55635567
properties:
5568+
attributes:
5569+
description: Overrides of attributes encapsulated in a parent
5570+
devfile. Overriding is done according to K8S strategic merge
5571+
patch standard rules.
5572+
type: object
5573+
x-kubernetes-preserve-unknown-fields: true
55645574
commands:
55655575
description: Overrides of commands encapsulated in a parent
55665576
devfile or a plugin. Overriding is done according to K8S
@@ -7148,6 +7158,13 @@ spec:
71487158
uri:
71497159
description: Uri of a Devfile yaml file
71507160
type: string
7161+
variables:
7162+
additionalProperties:
7163+
type: string
7164+
description: Overrides of variables encapsulated in a parent
7165+
devfile. Overriding is done according to K8S strategic merge
7166+
patch standard rules.
7167+
type: object
71517168
type: object
71527169
projects:
71537170
description: Projects worked on in the devworkspace, containing
@@ -7402,6 +7419,18 @@ spec:
74027419
- name
74037420
type: object
74047421
type: array
7422+
variables:
7423+
additionalProperties:
7424+
type: string
7425+
description: "Map of key-value variables used for string replacement
7426+
in the devfile. Values can can be referenced via {{variable-key}}
7427+
to replace the corresponding value in string fields in the devfile.
7428+
Replacement cannot be used for \n - schemaVersion, metadata,
7429+
parent source - element identifiers, e.g. command id, component
7430+
name, endpoint name, project name - references to identifiers,
7431+
e.g. in events, a command's component, container's volume mount
7432+
name - string enums, e.g. command group kind, endpoint exposure"
7433+
type: object
74057434
type: object
74067435
required:
74077436
- started

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

+29
Original file line numberDiff line numberDiff line change
@@ -4138,6 +4138,10 @@ spec:
41384138
description: Structure of the devworkspace. This is also the specification
41394139
of a devworkspace template.
41404140
properties:
4141+
attributes:
4142+
description: Map of implementation-dependant free-form YAML attributes.
4143+
type: object
4144+
x-kubernetes-preserve-unknown-fields: true
41414145
commands:
41424146
description: Predefined, ready-to-use, devworkspace-related commands
41434147
items:
@@ -5566,6 +5570,12 @@ spec:
55665570
- required:
55675571
- kubernetes
55685572
properties:
5573+
attributes:
5574+
description: Overrides of attributes encapsulated in a parent
5575+
devfile. Overriding is done according to K8S strategic merge
5576+
patch standard rules.
5577+
type: object
5578+
x-kubernetes-preserve-unknown-fields: true
55695579
commands:
55705580
description: Overrides of commands encapsulated in a parent
55715581
devfile or a plugin. Overriding is done according to K8S
@@ -7153,6 +7163,13 @@ spec:
71537163
uri:
71547164
description: Uri of a Devfile yaml file
71557165
type: string
7166+
variables:
7167+
additionalProperties:
7168+
type: string
7169+
description: Overrides of variables encapsulated in a parent
7170+
devfile. Overriding is done according to K8S strategic merge
7171+
patch standard rules.
7172+
type: object
71567173
type: object
71577174
projects:
71587175
description: Projects worked on in the devworkspace, containing
@@ -7407,6 +7424,18 @@ spec:
74077424
- name
74087425
type: object
74097426
type: array
7427+
variables:
7428+
additionalProperties:
7429+
type: string
7430+
description: "Map of key-value variables used for string replacement
7431+
in the devfile. Values can can be referenced via {{variable-key}}
7432+
to replace the corresponding value in string fields in the devfile.
7433+
Replacement cannot be used for \n - schemaVersion, metadata,
7434+
parent source - element identifiers, e.g. command id, component
7435+
name, endpoint name, project name - references to identifiers,
7436+
e.g. in events, a command's component, container's volume mount
7437+
name - string enums, e.g. command group kind, endpoint exposure"
7438+
type: object
74107439
type: object
74117440
required:
74127441
- started

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

+29
Original file line numberDiff line numberDiff line change
@@ -3914,6 +3914,10 @@ spec:
39143914
description: Structure of the devworkspace. This is also the specification
39153915
of a devworkspace template.
39163916
properties:
3917+
attributes:
3918+
description: Map of implementation-dependant free-form YAML attributes.
3919+
type: object
3920+
x-kubernetes-preserve-unknown-fields: true
39173921
commands:
39183922
description: Predefined, ready-to-use, devworkspace-related commands
39193923
items:
@@ -5284,6 +5288,12 @@ spec:
52845288
- required:
52855289
- kubernetes
52865290
properties:
5291+
attributes:
5292+
description: Overrides of attributes encapsulated in a parent
5293+
devfile. Overriding is done according to K8S strategic merge
5294+
patch standard rules.
5295+
type: object
5296+
x-kubernetes-preserve-unknown-fields: true
52875297
commands:
52885298
description: Overrides of commands encapsulated in a parent devfile
52895299
or a plugin. Overriding is done according to K8S strategic merge
@@ -6813,6 +6823,13 @@ spec:
68136823
uri:
68146824
description: Uri of a Devfile yaml file
68156825
type: string
6826+
variables:
6827+
additionalProperties:
6828+
type: string
6829+
description: Overrides of variables encapsulated in a parent devfile.
6830+
Overriding is done according to K8S strategic merge patch standard
6831+
rules.
6832+
type: object
68166833
type: object
68176834
projects:
68186835
description: Projects worked on in the devworkspace, containing names
@@ -7053,6 +7070,18 @@ spec:
70537070
- name
70547071
type: object
70557072
type: array
7073+
variables:
7074+
additionalProperties:
7075+
type: string
7076+
description: "Map of key-value variables used for string replacement
7077+
in the devfile. Values can can be referenced via {{variable-key}}
7078+
to replace the corresponding value in string fields in the devfile.
7079+
Replacement cannot be used for \n - schemaVersion, metadata, parent
7080+
source - element identifiers, e.g. command id, component name,
7081+
endpoint name, project name - references to identifiers, e.g. in
7082+
events, a command's component, container's volume mount name -
7083+
string enums, e.g. command group kind, endpoint exposure"
7084+
type: object
70567085
type: object
70577086
type: object
70587087
served: true

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

+29
Original file line numberDiff line numberDiff line change
@@ -3912,6 +3912,10 @@ spec:
39123912
description: Structure of the devworkspace. This is also the specification
39133913
of a devworkspace template.
39143914
properties:
3915+
attributes:
3916+
description: Map of implementation-dependant free-form YAML attributes.
3917+
type: object
3918+
x-kubernetes-preserve-unknown-fields: true
39153919
commands:
39163920
description: Predefined, ready-to-use, devworkspace-related commands
39173921
items:
@@ -5289,6 +5293,12 @@ spec:
52895293
- required:
52905294
- kubernetes
52915295
properties:
5296+
attributes:
5297+
description: Overrides of attributes encapsulated in a parent
5298+
devfile. Overriding is done according to K8S strategic merge
5299+
patch standard rules.
5300+
type: object
5301+
x-kubernetes-preserve-unknown-fields: true
52925302
commands:
52935303
description: Overrides of commands encapsulated in a parent devfile
52945304
or a plugin. Overriding is done according to K8S strategic merge
@@ -6818,6 +6828,13 @@ spec:
68186828
uri:
68196829
description: Uri of a Devfile yaml file
68206830
type: string
6831+
variables:
6832+
additionalProperties:
6833+
type: string
6834+
description: Overrides of variables encapsulated in a parent devfile.
6835+
Overriding is done according to K8S strategic merge patch standard
6836+
rules.
6837+
type: object
68216838
type: object
68226839
projects:
68236840
description: Projects worked on in the devworkspace, containing names
@@ -7058,6 +7075,18 @@ spec:
70587075
- name
70597076
type: object
70607077
type: array
7078+
variables:
7079+
additionalProperties:
7080+
type: string
7081+
description: "Map of key-value variables used for string replacement
7082+
in the devfile. Values can can be referenced via {{variable-key}}
7083+
to replace the corresponding value in string fields in the devfile.
7084+
Replacement cannot be used for \n - schemaVersion, metadata, parent
7085+
source - element identifiers, e.g. command id, component name,
7086+
endpoint name, project name - references to identifiers, e.g. in
7087+
events, a command's component, container's volume mount name -
7088+
string enums, e.g. command group kind, endpoint exposure"
7089+
type: object
70617090
type: object
70627091
type: object
70637092
served: true

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

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

3+
import attributes "github.com/devfile/api/v2/pkg/attributes"
4+
35
// Structure of the devworkspace. This is also the specification of a devworkspace template.
46
// +devfile:jsonschema:generate
57
type DevWorkspaceTemplateSpec struct {
@@ -12,6 +14,24 @@ type DevWorkspaceTemplateSpec struct {
1214

1315
// +devfile:overrides:generate
1416
type DevWorkspaceTemplateSpecContent struct {
17+
// Map of key-value variables used for string replacement in the devfile. Values can can be referenced via {{variable-key}}
18+
// to replace the corresponding value in string fields in the devfile. Replacement cannot be used for
19+
//
20+
// - schemaVersion, metadata, parent source
21+
// - element identifiers, e.g. command id, component name, endpoint name, project name
22+
// - references to identifiers, e.g. in events, a command's component, container's volume mount name
23+
// - string enums, e.g. command group kind, endpoint exposure
24+
// +optional
25+
// +patchStrategy=merge
26+
// +devfile:overrides:include:omitInPlugin=true,description=Overrides of variables encapsulated in a parent devfile.
27+
Variables map[string]string `json:"variables,omitempty" patchStrategy:"merge"`
28+
29+
// Map of implementation-dependant free-form YAML attributes.
30+
// +optional
31+
// +patchStrategy=merge
32+
// +devfile:overrides:include:omitInPlugin=true,description=Overrides of attributes encapsulated in a parent devfile.
33+
Attributes attributes.Attributes `json:"attributes,omitempty" patchStrategy:"merge"`
34+
1535
// List of the devworkspace components, such as editor and plugins,
1636
// user-provided containers, or other types of components
1737
// +optional

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

+28
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

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

Diff for: pkg/devfile/header.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type DevfileMetadata struct {
2727
// +kubebuilder:validation:Pattern=^([0-9]+)\.([0-9]+)\.([0-9]+)(\-[0-9a-z-]+(\.[0-9a-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$
2828
Version string `json:"version,omitempty"`
2929

30-
// Map of implementation-dependant free-form YAML attributes.
30+
// Map of implementation-dependant free-form YAML attributes. Deprecated, use the top-level attributes field instead.
3131
// +optional
3232
Attributes attributes.Attributes `json:"attributes,omitempty"`
3333

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

+46
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package overriding
22

33
import (
4+
"fmt"
5+
"reflect"
6+
47
dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
8+
attributesPkg "github.com/devfile/api/v2/pkg/attributes"
59
"github.com/hashicorp/go-multierror"
610
"k8s.io/apimachinery/pkg/util/sets"
711
)
@@ -27,7 +31,49 @@ func checkKeys(doCheck checkFn, toplevelListContainers ...dw.TopLevelListContain
2731
for listType, listElem := range topLevelList {
2832
listTypeToKeys[listType] = append(listTypeToKeys[listType], sets.NewString(listElem.GetKeys()...))
2933
}
34+
35+
value := reflect.ValueOf(topLevelListContainer)
36+
37+
var variableValue reflect.Value
38+
var attributeValue reflect.Value
39+
40+
// toplevelListContainers can contain either a pointer or a struct and needs to be safeguarded when using reflect
41+
if value.Kind() == reflect.Ptr {
42+
variableValue = value.Elem().FieldByName("Variables")
43+
attributeValue = value.Elem().FieldByName("Attributes")
44+
} else {
45+
variableValue = value.FieldByName("Variables")
46+
attributeValue = value.FieldByName("Attributes")
47+
}
48+
49+
if variableValue.IsValid() && variableValue.Kind() == reflect.Map {
50+
mapIter := variableValue.MapRange()
51+
52+
var variableKeys []string
53+
for mapIter.Next() {
54+
k := mapIter.Key()
55+
v := mapIter.Value()
56+
if k.Kind() != reflect.String || v.Kind() != reflect.String {
57+
return fmt.Errorf("unable to fetch top-level Variables, top-level Variables should be map of strings")
58+
}
59+
variableKeys = append(variableKeys, k.String())
60+
}
61+
listTypeToKeys["Variables"] = append(listTypeToKeys["Variables"], sets.NewString(variableKeys...))
62+
}
63+
64+
if attributeValue.IsValid() && attributeValue.CanInterface() {
65+
attributes, ok := attributeValue.Interface().(attributesPkg.Attributes)
66+
if !ok {
67+
return fmt.Errorf("unable to fetch top-level Attributes from the devfile data")
68+
}
69+
var attributeKeys []string
70+
for k := range attributes {
71+
attributeKeys = append(attributeKeys, k)
72+
}
73+
listTypeToKeys["Attributes"] = append(listTypeToKeys["Attributes"], sets.NewString(attributeKeys...))
74+
}
3075
}
76+
3177
for listType, keySets := range listTypeToKeys {
3278
errors = multierror.Append(errors, doCheck(listType, keySets)...)
3379
}

0 commit comments

Comments
 (0)