Skip to content

Commit b7fb9ed

Browse files
committed
Address Global Attribute Feedback
Signed-off-by: Maysun J Faisal <[email protected]>
1 parent 695dc4f commit b7fb9ed

File tree

63 files changed

+689
-963
lines changed

Some content is hidden

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

63 files changed

+689
-963
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -4144,10 +4144,10 @@ spec:
41444144
description: Map of implementation-dependant free-form YAML attributes.
41454145
Attribute values can be referenced throughout the devfile in
41464146
string type fields in the form {{attribute-key}} except for
4147-
schemaVersion and metadata. Exception to the string field include
4148-
element's key identifiers(command id, component name, endpoint
4149-
name, project name, etc.) and string enums(command group kind,
4150-
endpoint exposure, etc.)
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.)
41514151
type: object
41524152
x-kubernetes-preserve-unknown-fields: true
41534153
commands:

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -4142,10 +4142,10 @@ spec:
41424142
description: Map of implementation-dependant free-form YAML attributes.
41434143
Attribute values can be referenced throughout the devfile in
41444144
string type fields in the form {{attribute-key}} except for
4145-
schemaVersion and metadata. Exception to the string field include
4146-
element's key identifiers(command id, component name, endpoint
4147-
name, project name, etc.) and string enums(command group kind,
4148-
endpoint exposure, etc.)
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.)
41494149
type: object
41504150
x-kubernetes-preserve-unknown-fields: true
41514151
commands:

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -3917,10 +3917,11 @@ spec:
39173917
attributes:
39183918
description: Map of implementation-dependant free-form YAML attributes.
39193919
Attribute values can be referenced throughout the devfile in string
3920-
type fields in the form {{attribute-key}} except for schemaVersion
3921-
and metadata. Exception to the string field include element's key
3922-
identifiers(command id, component name, endpoint name, project name,
3923-
etc.) and string enums(command group kind, endpoint exposure, etc.)
3920+
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.)
39243925
type: object
39253926
x-kubernetes-preserve-unknown-fields: true
39263927
commands:

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -3915,10 +3915,11 @@ spec:
39153915
attributes:
39163916
description: Map of implementation-dependant free-form YAML attributes.
39173917
Attribute values can be referenced throughout the devfile in string
3918-
type fields in the form {{attribute-key}} except for schemaVersion
3919-
and metadata. Exception to the string field include element's key
3920-
identifiers(command id, component name, endpoint name, project name,
3921-
etc.) and string enums(command group kind, endpoint exposure, etc.)
3918+
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.)
39223923
type: object
39233924
x-kubernetes-preserve-unknown-fields: true
39243925
commands:

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type DevWorkspaceTemplateSpec struct {
1616
type DevWorkspaceTemplateSpecContent struct {
1717
// Map of implementation-dependant free-form YAML attributes.
1818
// Attribute values can be referenced throughout the devfile in string type fields in the form {{attribute-key}}
19-
// except for schemaVersion and metadata. Exception to the string field include element's key identifiers(command id,
19+
// except for schemaVersion, metadata and events. Exception to the string field include element's key identifiers(command id,
2020
// component name, endpoint name, project name, etc.) and string enums(command group kind, endpoint exposure, etc.)
2121
// +optional
2222
// +patchStrategy=merge

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

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

33
import (
4+
"fmt"
45
"reflect"
56

67
workspaces "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
@@ -42,7 +43,10 @@ func checkKeys(doCheck checkFn, toplevelListContainers ...workspaces.TopLevelLis
4243
}
4344

4445
if attributeValue.IsValid() && attributeValue.CanInterface() {
45-
attributes := attributeValue.Interface().(attributesPkg.Attributes)
46+
attributes, ok := attributeValue.Interface().(attributesPkg.Attributes)
47+
if !ok {
48+
return fmt.Errorf("unable to fetch Attributes from the devfile data")
49+
}
4650
var attributeKeys []string
4751
for k := range attributes {
4852
attributeKeys = append(attributeKeys, k)

Diff for: pkg/validation/attributes/attributes.go

+11-16
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,37 @@ import (
88
apiAttributes "github.com/devfile/api/v2/pkg/attributes"
99
)
1010

11-
// ValidateGlobalAttribute validates the workspace template spec data for global attribute references
12-
func ValidateGlobalAttribute(workspaceTemplateSpec *v1alpha2.DevWorkspaceTemplateSpec) error {
11+
// ValidateAndReplaceGlobalAttribute validates the workspace template spec data for global attribute references and replaces them with the attribute value
12+
func ValidateAndReplaceGlobalAttribute(workspaceTemplateSpec *v1alpha2.DevWorkspaceTemplateSpec) error {
1313

1414
var err error
1515

1616
if workspaceTemplateSpec != nil {
17-
// Validate the components
18-
if err = ValidateComponents(workspaceTemplateSpec.Attributes, &workspaceTemplateSpec.Components); err != nil {
17+
// Validate the components and replace for global attribute
18+
if err = ValidateAndReplaceForComponents(workspaceTemplateSpec.Attributes, workspaceTemplateSpec.Components); err != nil {
1919
return err
2020
}
2121

22-
// Validate the commands
23-
if err = ValidateCommands(workspaceTemplateSpec.Attributes, &workspaceTemplateSpec.Commands); err != nil {
22+
// Validate the commands and replace for global attribute
23+
if err = ValidateAndReplaceForCommands(workspaceTemplateSpec.Attributes, workspaceTemplateSpec.Commands); err != nil {
2424
return err
2525
}
2626

27-
// Validate the events
28-
if err = ValidateEvents(workspaceTemplateSpec.Attributes, workspaceTemplateSpec.Events); err != nil {
27+
// Validate the projects and replace for global attribute
28+
if err = ValidateAndReplaceForProjects(workspaceTemplateSpec.Attributes, workspaceTemplateSpec.Projects); err != nil {
2929
return err
3030
}
3131

32-
// Validate the projects
33-
if err = ValidateProjects(workspaceTemplateSpec.Attributes, &workspaceTemplateSpec.Projects); err != nil {
34-
return err
35-
}
36-
37-
// Validate the starter projects
38-
if err = ValidateStarterProjects(workspaceTemplateSpec.Attributes, &workspaceTemplateSpec.StarterProjects); err != nil {
32+
// Validate the starter projects and replace for global attribute
33+
if err = ValidateAndReplaceForStarterProjects(workspaceTemplateSpec.Attributes, workspaceTemplateSpec.StarterProjects); err != nil {
3934
return err
4035
}
4136
}
4237

4338
return nil
4439
}
4540

46-
var globalAttributeRegex = regexp.MustCompile(`\{{2}(.*?)\}{2}`)
41+
var globalAttributeRegex = regexp.MustCompile(`\{\{(.*?)\}\}`)
4742

4843
// validateAndReplaceDataWithAttribute validates the string for a global attribute and replaces it. An error
4944
// is returned if the string references an invalid global attribute key

Diff for: pkg/validation/attributes/attributes_command.go

+26-28
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,34 @@ import (
55
apiAttributes "github.com/devfile/api/v2/pkg/attributes"
66
)
77

8-
// ValidateCommands validates the commands data for a global attribute
9-
func ValidateCommands(attributes apiAttributes.Attributes, commands *[]v1alpha2.Command) error {
10-
11-
if commands != nil {
12-
for i := range *commands {
13-
var err error
14-
15-
// Validate various command types
16-
switch {
17-
case (*commands)[i].Exec != nil:
18-
if err = validateExecCommand(attributes, (*commands)[i].Exec); err != nil {
19-
return err
20-
}
21-
case (*commands)[i].Composite != nil:
22-
if err = validateCompositeCommand(attributes, (*commands)[i].Composite); err != nil {
23-
return err
24-
}
25-
case (*commands)[i].Apply != nil:
26-
if err = validateApplyCommand(attributes, (*commands)[i].Apply); err != nil {
27-
return err
28-
}
8+
// ValidateAndReplaceForCommands validates the commands data for global attribute references and replaces them with the attribute value
9+
func ValidateAndReplaceForCommands(attributes apiAttributes.Attributes, commands []v1alpha2.Command) error {
10+
11+
for i := range commands {
12+
var err error
13+
14+
// Validate various command types
15+
switch {
16+
case commands[i].Exec != nil:
17+
if err = validateAndReplaceForExecCommand(attributes, commands[i].Exec); err != nil {
18+
return err
19+
}
20+
case commands[i].Composite != nil:
21+
if err = validateAndReplaceForCompositeCommand(attributes, commands[i].Composite); err != nil {
22+
return err
23+
}
24+
case commands[i].Apply != nil:
25+
if err = validateAndReplaceForApplyCommand(attributes, commands[i].Apply); err != nil {
26+
return err
2927
}
3028
}
3129
}
3230

3331
return nil
3432
}
3533

36-
// validateExecCommand validates the exec command data for a global attribute
37-
func validateExecCommand(attributes apiAttributes.Attributes, exec *v1alpha2.ExecCommand) error {
34+
// validateAndReplaceForExecCommand validates the exec command data for global attribute references and replaces them with the attribute value
35+
func validateAndReplaceForExecCommand(attributes apiAttributes.Attributes, exec *v1alpha2.ExecCommand) error {
3836
var err error
3937

4038
if exec != nil {
@@ -60,7 +58,7 @@ func validateExecCommand(attributes apiAttributes.Attributes, exec *v1alpha2.Exe
6058

6159
// Validate exec env
6260
if len(exec.Env) > 0 {
63-
if err = validateEnv(attributes, &exec.Env); err != nil {
61+
if err = validateAndReplaceForEnv(attributes, exec.Env); err != nil {
6462
return err
6563
}
6664
}
@@ -69,8 +67,8 @@ func validateExecCommand(attributes apiAttributes.Attributes, exec *v1alpha2.Exe
6967
return nil
7068
}
7169

72-
// validateExecCommand validates the composite command data for a global attribute
73-
func validateCompositeCommand(attributes apiAttributes.Attributes, composite *v1alpha2.CompositeCommand) error {
70+
// validateAndReplaceForCompositeCommand validates the composite command data for global attribute references and replaces them with the attribute value
71+
func validateAndReplaceForCompositeCommand(attributes apiAttributes.Attributes, composite *v1alpha2.CompositeCommand) error {
7472
var err error
7573

7674
if composite != nil {
@@ -90,8 +88,8 @@ func validateCompositeCommand(attributes apiAttributes.Attributes, composite *v1
9088
return nil
9189
}
9290

93-
// validateApplyCommand validates the apply command data for a global attribute
94-
func validateApplyCommand(attributes apiAttributes.Attributes, apply *v1alpha2.ApplyCommand) error {
91+
// validateAndReplaceForApplyCommand validates the apply command data for global attribute references and replaces them with the attribute value
92+
func validateAndReplaceForApplyCommand(attributes apiAttributes.Attributes, apply *v1alpha2.ApplyCommand) error {
9593
var err error
9694

9795
if apply != nil {

0 commit comments

Comments
 (0)