Skip to content

Commit 4353bcc

Browse files
davidfestalDavid Festalamisevsk
authored
Implementation of parent and plugin overriding (#98)
* Prepare GO model for overriding * Keyed interface and union normalizing implementation * Gather all union definitions in a single file. In the future these definitions could be generated automatically from the api source code. * Basic union normalizing tests * Implement overriding logic * Add overriding tests. The test yaml files provide useful hints about how the overriding works according to strategic merge patch rules * Add a schema for overrides and enhance markdown support to support code blocks. * Add missing required fields: `targetPort` in `Kubernetes`-like components * Generate files (crds,go and schemas) * Add schemas for yaml files of overriding tests * Add directives * Add additional vendors * Add a command to run tests * Support the case when no `.theia` folder exists * Only override in parent or plugin scope and add new elements only in the main devfile body. * Add the merge of events. * Remove the Events from the Overrides struct * Generate CRDs and schemas * Accommodate repo renaming Signed-off-by: David Festal <[email protected]> * Run go fmt on changes * Run go mod tidy * Minor code cleanups and formatting * Regenerate schemas after rebasing to fix PR check Signed-off-by: Angel Misevski <[email protected]> Co-authored-by: David Festal <[email protected]> Co-authored-by: Angel Misevski <[email protected]>
1 parent 002d129 commit 4353bcc

File tree

83 files changed

+9221
-1448
lines changed

Some content is hidden

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

83 files changed

+9221
-1448
lines changed

.theia/settings.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
"go.lintFlags": ["--fast"],
44
"go.useLanguageServer": true,
55
"yaml.schemas": {
6-
"./schemas/devfile.json": "devfile-support/samples/*devfile.yaml",
7-
"./schemas/devworkspace.json": "samples/*devworkspace.yaml"
8-
}
6+
"./schemas/devfile.json": "devfile-support/samples/*devfile.yaml",
7+
"./schemas/devworkspace.json": "samples/*devworkspace.yaml",
8+
"./schemas/devworkspace-template.json": "samples/*devworkspacetemplate.yaml",
9+
"./schemas/devworkspace-template-spec.json": [ "pkg/utils/overriding/test-fixtures/patches/original.yaml", "pkg/utils/overriding/test-fixtures/merges/*.yaml", "pkg/overriding/test-fixtures/**/result.yaml" ],
10+
"./schemas/override-spec.json": "pkg/utils/overriding/test-fixtures/**/patch.yaml"
11+
}
912
}

build.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,16 @@ onError() {
9494
}
9595
trap 'onError' ERR
9696

97-
sed -i -e '/"description":/s/ \\n - /\\n- /g' -e '/"description":/s/ \\n \([^-]\)/\\n\\n\1/g' "${BASE_DIR}/schemas/devworkspace-template.json" "${BASE_DIR}/schemas/devworkspace.json"
97+
sed -i -e '/"description":/s/ \\t/\\n/g' -e '/"description":/s/ \\n - /\\n- /g' -e '/"description":/s/ \\n \([^-]\)/\\n\\n\1/g' "${BASE_DIR}/schemas/devworkspace-template.json" "${BASE_DIR}/schemas/devworkspace.json"
9898

9999
transform "devworkspace" "${BASE_DIR}/schemas/devworkspace-template.json" ""
100100
transform "devworkspace" "${BASE_DIR}/schemas/devworkspace.json" 's#"path" *: *"/properties/spec/#"path": "/properties/spec/properties/template/#'
101101

102102
jq ".properties.spec" "${BASE_DIR}/schemas/devworkspace-template.json" > "${BASE_DIR}/schemas/devworkspace-template-spec.json"
103103

104+
jq ".properties.parent" "${BASE_DIR}/schemas/devworkspace-template-spec.json" > "${BASE_DIR}/schemas/override-spec.json"
105+
transform "override" "${BASE_DIR}/schemas/override-spec.json" ''
106+
104107
cp "${BASE_DIR}/schemas/devworkspace-template-spec.json" "${BASE_DIR}/schemas/devfile.json"
105108

106109
transform "devfile" "${BASE_DIR}/schemas/devfile.json" ""

deploy/crds/workspace.devfile.io_devworkspaces_crd.yaml

+27-152
Large diffs are not rendered by default.

deploy/crds/workspace.devfile.io_devworkspacetemplates_crd.yaml

+26-152
Original file line numberDiff line numberDiff line change
@@ -735,8 +735,9 @@ spec:
735735
Kubernetes Custom Resources"
736736
properties:
737737
commands:
738-
description: Overrides of commands encapsulated in a plugin.
739-
Overriding is done using a strategic merge
738+
description: Overrides of commands encapsulated in a parent
739+
devfile or a plugin. Overriding is done using a strategic
740+
merge patch
740741
items:
741742
properties:
742743
apply:
@@ -1108,11 +1109,12 @@ spec:
11081109
type: array
11091110
components:
11101111
description: Overrides of components encapsulated in a plugin.
1111-
Overriding is done using a strategic merge
1112+
Overriding is done using a strategic merge patch. A plugin
1113+
cannot override embedded plugin components.
11121114
items:
11131115
properties:
11141116
componentType:
1115-
description: Type of component override
1117+
description: Type of component override for a plugin
11161118
enum:
11171119
- Container
11181120
- Kubernetes
@@ -1121,7 +1123,7 @@ spec:
11211123
type: string
11221124
container:
11231125
description: Configuration overriding for a Container
1124-
component
1126+
component in a plugin
11251127
properties:
11261128
args:
11271129
description: "The arguments to supply to the command
@@ -1275,7 +1277,7 @@ spec:
12751277
type: object
12761278
kubernetes:
12771279
description: Configuration overriding for a Kubernetes
1278-
component
1280+
component in a plugin
12791281
properties:
12801282
endpoints:
12811283
items:
@@ -1368,7 +1370,7 @@ spec:
13681370
type: object
13691371
openshift:
13701372
description: Configuration overriding for an OpenShift
1371-
component
1373+
component in a plugin
13721374
properties:
13731375
endpoints:
13741376
items:
@@ -1461,6 +1463,7 @@ spec:
14611463
type: object
14621464
volume:
14631465
description: Configuration overriding for a Volume component
1466+
in a plugin
14641467
properties:
14651468
name:
14661469
description: Mandatory name that allows referencing
@@ -1561,7 +1564,8 @@ spec:
15611564
description: Parent workspace template
15621565
properties:
15631566
commands:
1564-
description: Predefined, ready-to-use, workspace-related commands
1567+
description: Overrides of commands encapsulated in a parent devfile
1568+
or a plugin. Overriding is done using a strategic merge patch
15651569
items:
15661570
properties:
15671571
apply:
@@ -1911,8 +1915,8 @@ spec:
19111915
type: object
19121916
type: array
19131917
components:
1914-
description: List of the workspace components, such as editor and
1915-
plugins, user-provided containers, or other types of components
1918+
description: Overrides of components encapsulated in a parent devfile.
1919+
Overriding is done using a strategic merge patch
19161920
items:
19171921
properties:
19181922
componentType:
@@ -2287,8 +2291,9 @@ spec:
22872291
Kubernetes Custom Resources"
22882292
properties:
22892293
commands:
2290-
description: Overrides of commands encapsulated in a plugin.
2291-
Overriding is done using a strategic merge
2294+
description: Overrides of commands encapsulated in a parent
2295+
devfile or a plugin. Overriding is done using a strategic
2296+
merge patch
22922297
items:
22932298
properties:
22942299
apply:
@@ -2664,11 +2669,12 @@ spec:
26642669
type: array
26652670
components:
26662671
description: Overrides of components encapsulated in a
2667-
plugin. Overriding is done using a strategic merge
2672+
plugin. Overriding is done using a strategic merge patch.
2673+
A plugin cannot override embedded plugin components.
26682674
items:
26692675
properties:
26702676
componentType:
2671-
description: Type of component override
2677+
description: Type of component override for a plugin
26722678
enum:
26732679
- Container
26742680
- Kubernetes
@@ -2677,7 +2683,7 @@ spec:
26772683
type: string
26782684
container:
26792685
description: Configuration overriding for a Container
2680-
component
2686+
component in a plugin
26812687
properties:
26822688
args:
26832689
description: "The arguments to supply to the
@@ -2836,7 +2842,7 @@ spec:
28362842
type: object
28372843
kubernetes:
28382844
description: Configuration overriding for a Kubernetes
2839-
component
2845+
component in a plugin
28402846
properties:
28412847
endpoints:
28422848
items:
@@ -2934,7 +2940,7 @@ spec:
29342940
type: object
29352941
openshift:
29362942
description: Configuration overriding for an OpenShift
2937-
component
2943+
component in a plugin
29382944
properties:
29392945
endpoints:
29402946
items:
@@ -3032,7 +3038,7 @@ spec:
30323038
type: object
30333039
volume:
30343040
description: Configuration overriding for a Volume
3035-
component
3041+
component in a plugin
30363042
properties:
30373043
name:
30383044
description: Mandatory name that allows referencing
@@ -3097,41 +3103,6 @@ spec:
30973103
type: object
30983104
type: object
30993105
type: array
3100-
events:
3101-
description: Bindings of commands to events. Each command is referred-to
3102-
by its name.
3103-
properties:
3104-
postStart:
3105-
description: Names of commands that should be executed after
3106-
the workspace is completely started. In the case of Che-Theia,
3107-
these commands should be executed after all plugins and extensions
3108-
have started, including project cloning. This means that those
3109-
commands are not triggered until the user opens the IDE in
3110-
his browser.
3111-
items:
3112-
type: string
3113-
type: array
3114-
postStop:
3115-
description: Names of commands that should be executed after
3116-
stopping the workspace.
3117-
items:
3118-
type: string
3119-
type: array
3120-
preStart:
3121-
description: Names of commands that should be executed before
3122-
the workspace start. Kubernetes-wise, these commands would
3123-
typically be executed in init containers of the workspace
3124-
POD.
3125-
items:
3126-
type: string
3127-
type: array
3128-
preStop:
3129-
description: Names of commands that should be executed before
3130-
stopping the workspace.
3131-
items:
3132-
type: string
3133-
type: array
3134-
type: object
31353106
id:
31363107
description: Id in a registry that contains a Devfile yaml file
31373108
type: string
@@ -3154,8 +3125,8 @@ spec:
31543125
- name
31553126
type: object
31563127
projects:
3157-
description: Projects worked on in the workspace, containing names
3158-
and sources locations
3128+
description: Overrides of projects encapsulated in a parent devfile.
3129+
Overriding is done using a strategic merge patch.
31593130
items:
31603131
properties:
31613132
clonePath:
@@ -3249,103 +3220,6 @@ spec:
32493220
type: array
32503221
registryUrl:
32513222
type: string
3252-
starterProjects:
3253-
description: StarterProjects is a project that can be used as a
3254-
starting point when bootstrapping new projects
3255-
items:
3256-
properties:
3257-
clonePath:
3258-
description: Path relative to the root of the projects to
3259-
which this project should be cloned into. This is a unix-style
3260-
relative path (i.e. uses forward slashes). The path is invalid
3261-
if it is absolute or tries to escape the project root through
3262-
the usage of '..'. If not specified, defaults to the project
3263-
name.
3264-
type: string
3265-
custom:
3266-
description: Project's Custom source
3267-
properties:
3268-
embeddedResource:
3269-
type: object
3270-
x-kubernetes-embedded-resource: true
3271-
x-kubernetes-preserve-unknown-fields: true
3272-
projectSourceClass:
3273-
type: string
3274-
required:
3275-
- embeddedResource
3276-
- projectSourceClass
3277-
type: object
3278-
description:
3279-
description: Description of a starter project
3280-
type: string
3281-
git:
3282-
description: Project's Git source
3283-
properties:
3284-
branch:
3285-
description: The branch to check
3286-
type: string
3287-
location:
3288-
description: Project's source location address. Should
3289-
be URL for git and github located projects, or; file://
3290-
for zip
3291-
type: string
3292-
sparseCheckoutDir:
3293-
description: Part of project to populate in the working
3294-
directory.
3295-
type: string
3296-
startPoint:
3297-
description: The tag or commit id to reset the checked
3298-
out branch to
3299-
type: string
3300-
type: object
3301-
github:
3302-
description: Project's GitHub source
3303-
properties:
3304-
branch:
3305-
description: The branch to check
3306-
type: string
3307-
location:
3308-
description: Project's source location address. Should
3309-
be URL for git and github located projects, or; file://
3310-
for zip
3311-
type: string
3312-
sparseCheckoutDir:
3313-
description: Part of project to populate in the working
3314-
directory.
3315-
type: string
3316-
startPoint:
3317-
description: The tag or commit id to reset the checked
3318-
out branch to
3319-
type: string
3320-
type: object
3321-
name:
3322-
description: Project name
3323-
type: string
3324-
sourceType:
3325-
description: Type of project source
3326-
enum:
3327-
- Git
3328-
- Github
3329-
- Zip
3330-
- Custom
3331-
type: string
3332-
zip:
3333-
description: Project's Zip source
3334-
properties:
3335-
location:
3336-
description: Project's source location address. Should
3337-
be URL for git and github located projects, or; file://
3338-
for zip
3339-
type: string
3340-
sparseCheckoutDir:
3341-
description: Part of project to populate in the working
3342-
directory.
3343-
type: string
3344-
type: object
3345-
required:
3346-
- name
3347-
type: object
3348-
type: array
33493223
uri:
33503224
description: Uri of a Devfile yaml file
33513225
type: string

devfile-support/samples/spring-boot-http-booster-devfile.yaml.devfile-1.0.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ commands:
9191
- workdir: '${PROJECTS_ROOT}/spring-boot-http-booster'
9292
type: exec
9393
command: 'mvn fabric8:deploy -Popenshift -DskipTests'
94-
component: maven
94+
component: maven

devfile.kubernetes-api.code-workspace

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
"go.autocompleteUnimportedPackages": true,
2626
"yaml.schemas": {
2727
"./schemas/devfile.json": "devfile-support/samples/*devfile.yaml",
28-
"./schemas/devworkspace.json": [ "samples/*devworkspace.yaml", "deploy/crds/*_devworkspace_cr.yaml"],
29-
"./schemas/devworkspace-template.json": [ "samples/*devworkspacetemplate.yaml", "deploy/crds/*_devworkspacetemplate_cr.yaml" ]
28+
"./schemas/devworkspace.json": "samples/*devworkspace.yaml",
29+
"./schemas/devworkspace-template.json": "samples/*devworkspacetemplate.yaml",
30+
"./schemas/devworkspace-template-spec.json": [ "pkg/utils/overriding/test-fixtures/patches/original.yaml", "pkg/utils/overriding/test-fixtures/merges/*.yaml", "pkg/overriding/test-fixtures/**/result.yaml" ],
31+
"./schemas/override-spec.json": "pkg/utils/overriding/test-fixtures/**/patch.yaml"
3032
}
3133
}
3234
}

devfile.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ components:
2727
]; do echo "Waiting for the clone end" ; sleep 2; done; sleep 2 ; grep
2828
-e '/src/github.com/devfile/api/schemas/'
2929
${CHE_PROJECTS_ROOT}/.theia/settings.json > /dev/null ; if [ $? -ne 0 ];
30-
then echo "Updating the yaml schema bindings" ; sed -e
30+
then echo "Updating the yaml schema bindings" ; mkdir -p ${CHE_PROJECTS_ROOT}/.theia ; sed -e
3131
's:/schemas/:/src/github.com/devfile/api/schemas/:g'
3232
${CHE_PROJECTS_ROOT}/src/github.com/devfile/api/.theia/settings.json
3333
> ${CHE_PROJECTS_ROOT}/.theia/settings.json; fi; sleep infinity
@@ -54,3 +54,9 @@ commands:
5454
type: exec
5555
command: go mod vendor
5656
component: tools
57+
- name: Run tests
58+
actions:
59+
- workdir: '${CHE_PROJECTS_ROOT}/src/github.com/devfile/api'
60+
type: exec
61+
command: go test -v ./...
62+
component: tools

go.mod

+4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ module github.com/devfile/api
33
go 1.13
44

55
require (
6+
github.com/hashicorp/go-multierror v1.1.0
7+
github.com/mitchellh/reflectwalk v1.0.1
68
github.com/operator-framework/operator-sdk v0.17.0
79
github.com/spf13/pflag v1.0.5
10+
github.com/stretchr/testify v1.4.0
811
k8s.io/api v0.17.4
912
k8s.io/apimachinery v0.17.4
1013
k8s.io/client-go v12.0.0+incompatible
1114
sigs.k8s.io/controller-runtime v0.5.2
15+
sigs.k8s.io/yaml v1.1.0
1216
)
1317

1418
replace (

0 commit comments

Comments
 (0)