Skip to content

Commit e391e80

Browse files
committed
Devfile Cabal Feedback 2 - Var Warning
Signed-off-by: Maysun J Faisal <[email protected]>
1 parent 03ef74b commit e391e80

33 files changed

+658
-228
lines changed

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -7422,14 +7422,14 @@ spec:
74227422
variables:
74237423
additionalProperties:
74247424
type: string
7425-
description: Map of string variables. Variable values can be referenced
7426-
throughout the devfile in string type fields in the form {{variable-key}}
7427-
except for schemaVersion, metadata, parent source. Exception
7428-
to the string field also include element's key identifiers (command
7429-
id, component name, endpoint name, project name, etc.) and their
7430-
references(events, command's component, container's volume mount
7431-
name, etc.) and string enums(command group kind, endpoint exposure,
7432-
etc.)
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"
74337433
type: object
74347434
type: object
74357435
required:

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -7427,14 +7427,14 @@ spec:
74277427
variables:
74287428
additionalProperties:
74297429
type: string
7430-
description: Map of string variables. Variable values can be referenced
7431-
throughout the devfile in string type fields in the form {{variable-key}}
7432-
except for schemaVersion, metadata, parent source. Exception
7433-
to the string field also include element's key identifiers (command
7434-
id, component name, endpoint name, project name, etc.) and their
7435-
references(events, command's component, container's volume mount
7436-
name, etc.) and string enums(command group kind, endpoint exposure,
7437-
etc.)
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"
74387438
type: object
74397439
type: object
74407440
required:

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -7073,14 +7073,14 @@ spec:
70737073
variables:
70747074
additionalProperties:
70757075
type: string
7076-
description: Map of string variables. Variable values can be referenced
7077-
throughout the devfile in string type fields in the form {{variable-key}}
7078-
except for schemaVersion, metadata, parent source. Exception to
7079-
the string field also include element's key identifiers (command
7080-
id, component name, endpoint name, project name, etc.) and their
7081-
references(events, command's component, container's volume mount
7082-
name, etc.) and string enums(command group kind, endpoint exposure,
7083-
etc.)
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"
70847084
type: object
70857085
type: object
70867086
type: object

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -7078,14 +7078,14 @@ spec:
70787078
variables:
70797079
additionalProperties:
70807080
type: string
7081-
description: Map of string variables. Variable values can be referenced
7082-
throughout the devfile in string type fields in the form {{variable-key}}
7083-
except for schemaVersion, metadata, parent source. Exception to
7084-
the string field also include element's key identifiers (command
7085-
id, component name, endpoint name, project name, etc.) and their
7086-
references(events, command's component, container's volume mount
7087-
name, etc.) and string enums(command group kind, endpoint exposure,
7088-
etc.)
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"
70897089
type: object
70907090
type: object
70917091
type: object

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ type DevWorkspaceTemplateSpec struct {
1414

1515
// +devfile:overrides:generate
1616
type DevWorkspaceTemplateSpecContent struct {
17-
// Map of string variables.
18-
// Variable values can be referenced throughout the devfile in string type fields in the form {{variable-key}}
19-
// except for schemaVersion, metadata, parent source. Exception to the string field also include element's key identifiers
20-
// (command id, component name, endpoint name, project name, etc.) and their references(events, command's component, container's
21-
// volume mount name, etc.) and string enums(command group kind, endpoint exposure, etc.)
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
2224
// +optional
2325
// +patchStrategy=merge
2426
// +devfile:overrides:include:omitInPlugin=true,description=Overrides of variables encapsulated in a parent devfile.

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. Deprecated, use the global attributes instead.
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func checkKeys(doCheck checkFn, toplevelListContainers ...dw.TopLevelListContain
5454
k := mapIter.Key()
5555
v := mapIter.Value()
5656
if k.Kind() != reflect.String || v.Kind() != reflect.String {
57-
return fmt.Errorf("unable to fetch Global Variables, Global Variables should be map of strings")
57+
return fmt.Errorf("unable to fetch top-level Variables, top-level Variables should be map of strings")
5858
}
5959
variableKeys = append(variableKeys, k.String())
6060
}
@@ -64,7 +64,7 @@ func checkKeys(doCheck checkFn, toplevelListContainers ...dw.TopLevelListContain
6464
if attributeValue.IsValid() && attributeValue.CanInterface() {
6565
attributes, ok := attributeValue.Interface().(attributesPkg.Attributes)
6666
if !ok {
67-
return fmt.Errorf("unable to fetch Global Attributes from the devfile data")
67+
return fmt.Errorf("unable to fetch top-level Attributes from the devfile data")
6868
}
6969
var attributeKeys []string
7070
for k := range attributes {

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ func MergeDevWorkspaceTemplateSpec(
122122
result.Attributes = attributes.Attributes{}
123123
}
124124
for k, v := range content.Attributes {
125-
result.Attributes.FromMap(map[string]interface{}{
126-
k: v,
127-
}, &err)
125+
result.Attributes.Put(k, v, &err)
128126
if err != nil {
129127
return nil, err
130128
}

Diff for: pkg/validation/variables/errors.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package variables
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
// InvalidKeysError returns an error for the invalid keys
9+
type InvalidKeysError struct {
10+
Keys []string
11+
}
12+
13+
func (e *InvalidKeysError) Error() string {
14+
return fmt.Sprintf("invalid variable references - %s", strings.Join(e.Keys, ","))
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
variables:
2+
devnull: /dev/null
3+
projects:
4+
- name: project1
5+
clonePath: "{{path}}"
6+
sparseCheckoutDirs:
7+
- xyz
8+
- "{{dir}}"
9+
git:
10+
checkoutFrom:
11+
revision: "{{tag}}"
12+
remotes:
13+
"{{dir}}": "{{version1}}/dev/null-/dev/null"
14+
"{{version}}": "test"
15+
- name: project2
16+
zip:
17+
location: "{{tag}}"
18+
starterProjects:
19+
- name: starterproject1
20+
description: "{{desc}}"
21+
subDir: "{{dir}}"
22+
git:
23+
checkoutFrom:
24+
revision: "{{tag}}"
25+
remotes:
26+
"{{tag}}": "/dev/null"
27+
"{{dir}}": "test"
28+
- name: starterproject2
29+
zip:
30+
location: "{{tag}}"
31+
components:
32+
- name: component1
33+
container:
34+
image: "{{a}}"
35+
env:
36+
- name: BAR
37+
value: "{{b}}"
38+
- name: "{{c}}"
39+
value: "{{bar}}"
40+
command:
41+
- tail
42+
- -f
43+
- "{{b}}"
44+
- "{{c}}"
45+
- name: component2
46+
kubernetes:
47+
inlined: "{{foo}}"
48+
endpoints:
49+
- name: endpoint1
50+
exposure: "public"
51+
protocol: "https"
52+
path : "/{{x}}}"
53+
targetPort: 9998
54+
- name: endpoint2
55+
path : "{{bar}}"
56+
targetPort: 9999
57+
- name: component3
58+
volume:
59+
size: "{{xyz}}"
60+
- name: component4
61+
openshift:
62+
uri: "{{foo}}"
63+
commands:
64+
- id: command1
65+
exec:
66+
commandLine: "test-{{tag}}"
67+
env:
68+
- name: tag
69+
value: "{{tag}}"
70+
- name: FOO
71+
value: "{{BAR}}"
72+
- id: command2
73+
composite:
74+
commands:
75+
- xyz
76+
- command1
77+
label: "{{abc}}"
78+
- id: command3
79+
apply:
80+
label: "{{abc}}"
+70-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,80 @@
11
variables:
22
devnull: /dev/null
3+
projects:
4+
- name: project1
5+
clonePath: "{{path}}"
6+
sparseCheckoutDirs:
7+
- xyz
8+
- "{{dir}}"
9+
git:
10+
checkoutFrom:
11+
revision: "{{tag}}"
12+
remotes:
13+
"{{dir}}": "{{version1}}{{devnull}}-{{devnull}}"
14+
"{{version}}": "test"
15+
- name: project2
16+
zip:
17+
location: "{{tag}}"
18+
starterProjects:
19+
- name: starterproject1
20+
description: "{{desc}}"
21+
subDir: "{{dir}}"
22+
git:
23+
checkoutFrom:
24+
revision: "{{tag}}"
25+
remotes:
26+
"{{tag}}": "{{devnull}}"
27+
"{{dir}}": "test"
28+
- name: starterproject2
29+
zip:
30+
location: "{{tag}}"
331
components:
432
- name: component1
533
container:
6-
image: image
34+
image: "{{a}}"
735
env:
836
- name: BAR
9-
value: "{{foo}}"
37+
value: "{{b}}"
38+
- name: "{{c}}"
39+
value: "{{bar}}"
1040
command:
1141
- tail
1242
- -f
13-
- "{{devnull}}"
43+
- "{{b}}"
44+
- "{{c}}"
45+
- name: component2
46+
kubernetes:
47+
inlined: "{{foo}}"
48+
endpoints:
49+
- name: endpoint1
50+
exposure: "public"
51+
protocol: "https"
52+
path : "/{{x}}}"
53+
targetPort: 9998
54+
- name: endpoint2
55+
path : "{{bar}}"
56+
targetPort: 9999
57+
- name: component3
58+
volume:
59+
size: "{{xyz}}"
60+
- name: component4
61+
openshift:
62+
uri: "{{foo}}"
63+
commands:
64+
- id: command1
65+
exec:
66+
commandLine: "test-{{tag}}"
67+
env:
68+
- name: tag
69+
value: "{{tag}}"
70+
- name: FOO
71+
value: "{{BAR}}"
72+
- id: command2
73+
composite:
74+
commands:
75+
- xyz
76+
- command1
77+
label: "{{abc}}"
78+
- id: command3
79+
apply:
80+
label: "{{abc}}"
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
zip:
2-
location: "/FOO"
2+
location: "/FOOBAR"
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Variables are defined in test-fixtures/variables/variables-referenced.yaml
22
zip:
3-
location: "/{{foo}}"
3+
location: "/{{foo}}{{bar}}"

Diff for: pkg/validation/variables/utils.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package variables
2+
3+
// checkForInvalidError checks for InvalidKeysError and stores the key in the map
4+
func checkForInvalidError(invalidKeys map[string]bool, err error) {
5+
if verr, ok := err.(*InvalidKeysError); ok {
6+
for _, key := range verr.Keys {
7+
invalidKeys[key] = true
8+
}
9+
}
10+
}
11+
12+
// processInvalidKeys processes the invalid keys and return InvalidKeysError if present
13+
func processInvalidKeys(invalidKeys map[string]bool) error {
14+
var invalidKeysArr []string
15+
for key := range invalidKeys {
16+
invalidKeysArr = append(invalidKeysArr, key)
17+
}
18+
19+
if len(invalidKeysArr) > 0 {
20+
return &InvalidKeysError{Keys: invalidKeysArr}
21+
}
22+
23+
return nil
24+
}

0 commit comments

Comments
 (0)