Skip to content

Commit adaa1b4

Browse files
authored
Switch to use parser library (#4188)
* cleanup git history Signed-off-by: Stephanie <[email protected]> * format files Signed-off-by: Stephanie <[email protected]> * add epl-2.0 into license whitelist Signed-off-by: Stephanie <[email protected]> * remove componentType and commandType in convert.go Signed-off-by: Stephanie <[email protected]> * pull in latest library change Signed-off-by: Stephanie <[email protected]> * add --project to app list test Signed-off-by: Stephanie <[email protected]> * fix integration test Signed-off-by: Stephanie <[email protected]> * revert change to public doc * move the testdevfileobj to testingutil Signed-off-by: Stephanie <[email protected]>
1 parent 2e8304e commit adaa1b4

File tree

203 files changed

+13929
-11856
lines changed

Some content is hidden

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

203 files changed

+13929
-11856
lines changed

.wwhrd.yml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ whitelist:
1313
- BSD-3-Clause
1414
- BSD-2-Clause
1515
- MPL-2.0-no-copyleft-exception
16+
- EPL-2.0
1617

1718
exceptions:
1819
# wwhrd currently does not detect ISC which is compatible with Odo so, add it under exceptions to avoid errors due to it being not recognised

go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ require (
88
github.com/Netflix/go-expect v0.0.0-20200312175327-da48e75238e2
99
github.com/blang/semver v3.5.1+incompatible
1010
github.com/containerd/containerd v1.3.3 // indirect
11+
github.com/devfile/api v0.0.0-20201103130402-29b8738e196e
12+
github.com/devfile/library v0.0.0-20201112211805-e68d67cf4204
1113
github.com/docker/docker v17.12.0-ce-rc1.0.20200309214505-aa6a9891b09c+incompatible
1214
github.com/docker/go-connections v0.4.1-0.20200120150455-7dc0a2d6ddce
1315
github.com/fatih/color v1.7.0
@@ -42,7 +44,6 @@ require (
4244
github.com/spf13/cobra v0.0.5
4345
github.com/spf13/pflag v1.0.5
4446
github.com/stretchr/testify v1.6.1
45-
github.com/xeipuuv/gojsonschema v1.2.0
4647
github.com/zalando/go-keyring v0.1.0
4748
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
4849
gopkg.in/AlecAivazis/survey.v1 v1.8.0
@@ -53,7 +54,6 @@ require (
5354
k8s.io/client-go v12.0.0+incompatible
5455
k8s.io/klog v1.0.0
5556
k8s.io/kubectl v0.0.0
56-
sigs.k8s.io/controller-runtime v0.6.0 // indirect
5757
sigs.k8s.io/yaml v1.2.0
5858
)
5959

go.sum

+17
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
217217
github.com/daviddengcn/go-colortext v0.0.0-20160507010035-511bcaf42ccd/go.mod h1:dv4zxwHi5C/8AeI+4gX4dCWOIvNi7I6JCSX0HvlKPgE=
218218
github.com/deislabs/oras v0.7.0/go.mod h1:sqMKPG3tMyIX9xwXUBRLhZ24o+uT4y6jgBD2RzUTKDM=
219219
github.com/denisenkom/go-mssqldb v0.0.0-20190515213511-eb9f6a1743f3/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
220+
github.com/devfile/api v0.0.0-20201103130402-29b8738e196e h1:Ha6wyKs7VWqQTz2Fm1o4PAYpKX6SIiYjgWmGzNW8cBE=
221+
github.com/devfile/api v0.0.0-20201103130402-29b8738e196e/go.mod h1:hp5Lmob7ESmtSZXZ7xRN9o8vemsen9111+ASi2YuXs4=
222+
github.com/devfile/library v0.0.0-20201112211805-e68d67cf4204 h1:rWcsIrGErsVIYRUopre3XkZ/ko+o+LYqs9YZzn+UpvY=
223+
github.com/devfile/library v0.0.0-20201112211805-e68d67cf4204/go.mod h1:jQTcvSRQuAofQPuVuC//B04v+ay4ttwqE4NVZp/p+uQ=
220224
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
221225
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
222226
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
@@ -550,6 +554,8 @@ github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/U
550554
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
551555
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
552556
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
557+
github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI=
558+
github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA=
553559
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
554560
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
555561
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
@@ -596,6 +602,8 @@ github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCV
596602
github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
597603
github.com/json-iterator/go v1.1.8 h1:QiWkFLKq0T7mpzwOTu6BzNDbfTE8OLrYhVKYMLF46Ok=
598604
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
605+
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
606+
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
599607
github.com/jsonnet-bundler/jsonnet-bundler v0.1.0/go.mod h1:YKsSFc9VFhhLITkJS3X2PrRqWG9u2Jq99udTdDjQLfM=
600608
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
601609
github.com/jteeuwen/go-bindata v3.0.8-0.20151023091102-a0ff2567cfb7+incompatible/go.mod h1:JVvhzYOiGBnFSYRyV00iY8q7/0PThjIYav1p9h5dmKs=
@@ -672,6 +680,7 @@ github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx
672680
github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
673681
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
674682
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
683+
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
675684
github.com/mattn/go-isatty v0.0.13-0.20200128103942-cb30d6282491 h1:jygFUAtCyqjM5JGFNAWcXLqlXArQqxDZ3DqQer1BIik=
676685
github.com/mattn/go-isatty v0.0.13-0.20200128103942-cb30d6282491/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
677686
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
@@ -709,6 +718,7 @@ github.com/mitchellh/hashstructure v1.0.0/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1D
709718
github.com/mitchellh/mapstructure v0.0.0-20180220230111-00c29f56e238/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
710719
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
711720
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
721+
github.com/mitchellh/reflectwalk v1.0.1/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
712722
github.com/moby/buildkit v0.0.0-20181107081847-c3a857e3fca0/go.mod h1:nnELdKPRkUAQR6pAB3mRU3+IlbqL3SSaAWqQL8k/K+4=
713723
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
714724
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
@@ -1105,7 +1115,9 @@ golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271/go.mod h1:z5CRVTTTmAJ677TzLL
11051115
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
11061116
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
11071117
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
1118+
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
11081119
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
1120+
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
11091121
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7 h1:AeiKBIuRw3UomYXSbLy0Mc2dDLfdtbT/IVn4keq83P0=
11101122
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
11111123
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -1160,15 +1172,18 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w
11601172
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11611173
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11621174
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1175+
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11631176
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11641177
golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11651178
golang.org/x/sys v0.0.0-20191028164358-195ce5e7f934/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11661179
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11671180
golang.org/x/sys v0.0.0-20191210023423-ac6580df4449/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11681181
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
11691182
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1183+
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11701184
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11711185
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
1186+
golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11721187
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
11731188
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
11741189
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -1323,6 +1338,7 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
13231338
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
13241339
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
13251340
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
1341+
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
13261342
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
13271343
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
13281344
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
@@ -1412,6 +1428,7 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
14121428
rsc.io/letsencrypt v0.0.1/go.mod h1:buyQKZ6IXrRnB7TdkHP0RyEybLx18HHyOSoTyoOLqNY=
14131429
sigs.k8s.io/controller-runtime v0.1.10/go.mod h1:HFAYoOh6XMV+jKF1UjFwrknPbowfyHEHHRdJMf2jMX8=
14141430
sigs.k8s.io/controller-runtime v0.4.0/go.mod h1:ApC79lpY3PHW9xj/w9pj+lYkLgwAAUZwfXkME1Lajns=
1431+
sigs.k8s.io/controller-runtime v0.5.2/go.mod h1:JZUwSMVbxDupo0lTJSSFP5pimEyxGynROImSsqIOx1A=
14151432
sigs.k8s.io/controller-runtime v0.6.0 h1:Fzna3DY7c4BIP6KwfSlrfnj20DJ+SeMBK8HSFvOk9NM=
14161433
sigs.k8s.io/controller-runtime v0.6.0/go.mod h1:CpYf5pdNY/B352A1TFLAS2JVSlnGQ5O2cftPHndTroo=
14171434
sigs.k8s.io/controller-tools v0.1.10/go.mod h1:6g08p9m9G/So3sBc1AOQifHfhxH/mb6Sc4z0LMI8XMw=

pkg/component/component.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ import (
1414

1515
v1 "k8s.io/api/apps/v1"
1616

17-
devfileParser "github.com/openshift/odo/pkg/devfile/parser"
17+
devfileParser "github.com/devfile/library/pkg/devfile/parser"
1818

19+
"github.com/devfile/library/pkg/devfile/parser"
1920
"github.com/openshift/odo/pkg/devfile/adapters/common"
20-
"github.com/openshift/odo/pkg/devfile/parser"
2121
"github.com/openshift/odo/pkg/kclient"
2222

2323
"github.com/openshift/odo/pkg/envinfo"
2424

2525
"github.com/pkg/errors"
2626
"k8s.io/klog"
2727

28+
devfilev1 "github.com/devfile/api/pkg/apis/workspaces/v1alpha2"
2829
applabels "github.com/openshift/odo/pkg/application/labels"
2930
"github.com/openshift/odo/pkg/catalog"
3031
componentlabels "github.com/openshift/odo/pkg/component/labels"
3132
"github.com/openshift/odo/pkg/config"
32-
parsercommon "github.com/openshift/odo/pkg/devfile/parser/data/common"
3333
"github.com/openshift/odo/pkg/log"
3434
"github.com/openshift/odo/pkg/occlient"
3535
"github.com/openshift/odo/pkg/odo/util/validation"
@@ -587,7 +587,7 @@ func ensureAndLogProperResourceUsage(resourceMin, resourceMax *string, resourceN
587587
// isS2I: Legacy option. Set as true if you want to use the old S2I method as it differentiates slightly.
588588
// Returns:
589589
// err: Errors if any else nil
590-
func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConfig config.LocalConfigInfo, envSpecificInfo envinfo.EnvSpecificInfo, stdout io.Writer, cmpExist bool, containerComponents []parsercommon.DevfileComponent, isS2I bool) (err error) {
590+
func ApplyConfig(client *occlient.Client, kClient *kclient.Client, componentConfig config.LocalConfigInfo, envSpecificInfo envinfo.EnvSpecificInfo, stdout io.Writer, cmpExist bool, containerComponents []devfilev1.Component, isS2I bool) (err error) {
591591

592592
if client == nil {
593593
var err error

pkg/component/component_full_description.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"fmt"
66
"strings"
77

8-
devfileParser "github.com/openshift/odo/pkg/devfile/parser"
9-
"github.com/openshift/odo/pkg/devfile/parser/data/common"
8+
devfilev1 "github.com/devfile/api/pkg/apis/workspaces/v1alpha2"
9+
devfileParser "github.com/devfile/library/pkg/devfile/parser"
1010
"github.com/openshift/odo/pkg/envinfo"
1111
"github.com/openshift/odo/pkg/kclient"
1212
"github.com/openshift/odo/pkg/kclient/generator"
@@ -156,7 +156,7 @@ func NewComponentFullDescriptionFromClientAndLocalConfig(client *occlient.Client
156156
if e != nil {
157157
return cfd, e
158158
}
159-
var components []common.DevfileComponent
159+
var components []devfilev1.Component
160160
var configProvider envinfo.LocalConfigProvider = localConfigInfo
161161
if envInfo != nil {
162162
configProvider = envInfo

pkg/component/devfile_repr.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package component
22

33
import (
4+
"github.com/devfile/library/pkg/devfile/parser"
45
"github.com/openshift/odo/pkg/config"
5-
"github.com/openshift/odo/pkg/devfile/parser"
66
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
77
)
88

@@ -69,6 +69,6 @@ type ContainerRepr struct {
6969

7070
type PortRepr struct {
7171
Name string `yaml:"Name" json:"Name"`
72-
ExposedPort int32 `yaml:"ExposedPort" json:"ExposedPort"`
72+
ExposedPort int `yaml:"ExposedPort" json:"ExposedPort"`
7373
Protocol string `yaml:"Protocol" json:"Protocol"`
7474
}

pkg/config/config.go

+85-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package config
22

33
import (
44
"fmt"
5-
"github.com/openshift/odo/pkg/envinfo"
65
"io"
76
"net/url"
87
"os"
98
"path/filepath"
109
"strconv"
1110
"strings"
1211

12+
"github.com/openshift/odo/pkg/envinfo"
13+
14+
"github.com/devfile/library/pkg/devfile/parser"
1315
"github.com/openshift/odo/pkg/testingutil/filesystem"
1416

1517
"github.com/pkg/errors"
@@ -602,6 +604,15 @@ var (
602604
lowerCaseLocalParameters = util.GetLowerCaseParameters(GetLocallySupportedParameters())
603605
)
604606

607+
var (
608+
supportedDevfileParameterDescriptions = map[string]string{
609+
Name: NameDescription,
610+
Ports: PortsDescription,
611+
Memory: MemoryDescription,
612+
}
613+
lowerCaseDevfileParameters = util.GetLowerCaseParameters(GetDevfileSupportedParameters())
614+
)
615+
605616
// FormatLocallySupportedParameters outputs supported parameters and their description
606617
func FormatLocallySupportedParameters() (result string) {
607618
for _, v := range GetLocallySupportedParameters() {
@@ -610,6 +621,18 @@ func FormatLocallySupportedParameters() (result string) {
610621
return "\nAvailable Parameters for s2i Components:\n" + result
611622
}
612623

624+
// FormatDevfileSupportedParameters outputs supported parameters and their description
625+
func FormatDevfileSupportedParameters() (result string) {
626+
for _, v := range GetDevfileSupportedParameters() {
627+
result = result + " " + v + " - " + supportedDevfileParameterDescriptions[v] + "\n"
628+
}
629+
return "\nAvailable Parameters for Devfile Components:\n" + result
630+
}
631+
632+
func GetDevfileSupportedParameters() []string {
633+
return util.GetSortedKeys(supportedDevfileParameterDescriptions)
634+
}
635+
613636
// AsLocallySupportedParameter returns the parameter in lower case and a boolean indicating if it is a supported parameter
614637
func AsLocallySupportedParameter(param string) (string, bool) {
615638
lower := strings.ToLower(param)
@@ -621,6 +644,67 @@ func GetLocallySupportedParameters() []string {
621644
return util.GetSortedKeys(supportedLocalParameterDescriptions)
622645
}
623646

647+
// AsDevfileSupportedParameter returns the parameter in lower case and a boolean indicating if it is a supported parameter
648+
func AsDevfileSupportedParameter(param string) (string, bool) {
649+
lower := strings.ToLower(param)
650+
return lower, lowerCaseDevfileParameters[lower]
651+
}
652+
653+
// SetDevfileConfiguration allows setting all the parameters that are configurable in a devfile
654+
func SetDevfileConfiguration(d parser.DevfileObj, parameter string, value interface{}) error {
655+
656+
// we are ignoring this error becase a developer is usually aware of the type of value that is
657+
// being passed. So consider this a shortcut, if you know its a string value use this strValue
658+
// else parse it inside the switch case.
659+
strValue, _ := value.(string)
660+
if parameter, ok := AsDevfileSupportedParameter(parameter); ok {
661+
switch parameter {
662+
case "name":
663+
return d.SetMetadataName(strValue)
664+
case "ports":
665+
arrValue := strings.Split(strValue, ",")
666+
return d.SetPorts(arrValue...)
667+
case "memory":
668+
return d.SetMemory(strValue)
669+
}
670+
671+
}
672+
return errors.Errorf("unknown parameter :'%s' is not a configurable parameter in the devfile", parameter)
673+
674+
}
675+
676+
// DeleteConfiguration allows deleting the parameters that are configurable in a devfile
677+
func DeleteDevfileConfiguration(d parser.DevfileObj, parameter string) error {
678+
if parameter, ok := AsDevfileSupportedParameter(parameter); ok {
679+
switch parameter {
680+
case "name":
681+
return d.SetMetadataName("")
682+
case "ports":
683+
return d.RemovePorts()
684+
case "memory":
685+
return d.SetMemory("")
686+
}
687+
}
688+
return errors.Errorf("unknown parameter :'%s' is not a configurable parameter in the devfile", parameter)
689+
}
690+
691+
// IsSet checks if a parameter is set in the devfile
692+
func IsSetInDevfile(d parser.DevfileObj, parameter string) bool {
693+
694+
if parameter, ok := AsDevfileSupportedParameter(parameter); ok {
695+
switch parameter {
696+
case "name":
697+
return d.GetMetadataName() != ""
698+
case "ports":
699+
return d.HasPorts()
700+
case "memory":
701+
return d.GetMemory() != ""
702+
}
703+
}
704+
return false
705+
706+
}
707+
624708
// SrcType is an enum to indicate the type of source of component -- local source/binary or git for the generation of app/component names
625709
type SrcType string
626710

0 commit comments

Comments
 (0)