Skip to content

Commit ba39985

Browse files
authored
Merge pull request devfile#106 from yangcao77/762-create-endpoints-for-v2index
762 create endpoints for v2index
2 parents a663cf6 + 9ea85c5 commit ba39985

File tree

23 files changed

+1851
-113
lines changed

23 files changed

+1851
-113
lines changed

index/generator/go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,8 @@ github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ
8484
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8585
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
8686
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
87-
github.com/devfile/api/v2 v2.0.0-20210917193329-089a48011460 h1:cmd+3poyUwevcWchYdvE02YT1nQU4SJpA5/wrdLrpWE=
88-
github.com/devfile/api/v2 v2.0.0-20210917193329-089a48011460/go.mod h1:kLX/nW93gigOHXK3NLeJL2fSS/sgEe+OHu8bo3aoOi4=
8987
github.com/devfile/api/v2 v2.0.0-20211021164004-dabee4e633ed h1:OXF9l+MlJrirXAqKN6EZUVaHB0FKm7nh0EjpktwnBig=
9088
github.com/devfile/api/v2 v2.0.0-20211021164004-dabee4e633ed/go.mod h1:d99eTN6QxgzihOOFyOZA+VpUyD4Q1pYRYHZ/ci9J96Q=
91-
github.com/devfile/library v1.2.0 h1:OT1Irwg5EZhlCpsAFkjIzd3bqyzbLG0JmFPMHeE1e7M=
92-
github.com/devfile/library v1.2.0/go.mod h1:gyiQS+ZImnM4/d+wFUl3gJmIozOSXMenl0WX8cx4zu4=
9389
github.com/devfile/library v1.2.1-0.20211104222135-49d635cb492f h1:kKsBWkFiD7tSIpzwfmz7TH89U1U3yRxSJ9UPOo2OH1s=
9490
github.com/devfile/library v1.2.1-0.20211104222135-49d635cb492f/go.mod h1:uFZZdTuRqA68FVe/JoJHP92CgINyQkyWnM2Qyiim+50=
9591
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=

index/generator/library/library.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818
devfile = "devfile.yaml"
1919
devfileHidden = ".devfile.yaml"
2020
extraDevfileEntries = "extraDevfileEntries.yaml"
21-
stackYaml = "stack.yaml"
21+
stackYaml = "stack.yaml"
2222
)
2323

2424
// MissingArchError is an error if the architecture list is empty
@@ -103,7 +103,7 @@ func validateIndexComponent(indexComponent schema.Schema, componentType schema.D
103103
if version.Links == nil || len(version.Links) == 0 {
104104
return fmt.Errorf("index component version %s: links are empty", version.Version)
105105
}
106-
if version.Resources == nil || len(version.Resources) == 0 {
106+
if version.Resources == nil || len(version.Resources) == 0 {
107107
return fmt.Errorf("index component version %s: resources are empty", version.Version)
108108
}
109109
if version.Default {
@@ -119,7 +119,7 @@ func validateIndexComponent(indexComponent schema.Schema, componentType schema.D
119119
}
120120
}
121121
} else if componentType == schema.SampleDevfileType {
122-
if indexComponent.Versions != nil && len(indexComponent.Versions) > 0 {
122+
if indexComponent.Versions != nil && len(indexComponent.Versions) > 0 {
123123
defaultFound := false
124124
for _, version := range indexComponent.Versions {
125125
if version.Version == "" {
@@ -176,8 +176,8 @@ func fileExists(filepath string) bool {
176176

177177
func dirExists(dirpath string) error {
178178
dir, err := os.Stat(dirpath)
179-
if os.IsNotExist(err){
180-
return fmt.Errorf("path: %s does not exist: %w",dirpath, err)
179+
if os.IsNotExist(err) {
180+
return fmt.Errorf("path: %s does not exist: %w", dirpath, err)
181181
}
182182
if !dir.IsDir() {
183183
return fmt.Errorf("%s is not a directory", dirpath)
@@ -213,7 +213,7 @@ func parseDevfileRegistry(registryDirPath string, force bool) ([]schema.Schema,
213213
}
214214
}
215215

216-
i:= 0
216+
i := 0
217217
for i < len(indexComponent.Versions) {
218218
versionComponent := indexComponent.Versions[i]
219219
if versionComponent.Git != nil {
@@ -231,6 +231,14 @@ func parseDevfileRegistry(registryDirPath string, force bool) ([]schema.Schema,
231231
indexComponent.Versions[i] = versionComponent
232232
i++
233233
}
234+
235+
for _, version := range indexComponent.Versions {
236+
// if a particular version supports all architectures, the top architecture List should be empty (support all) as well
237+
if version.Architectures == nil || len(version.Architectures) == 0 {
238+
indexComponent.Architectures = nil
239+
break
240+
}
241+
}
234242
} else { // if stack.yaml not exist, old stack repo struct, directly lookfor & parse devfile.yaml
235243
versionComponent := schema.Version{}
236244
err := parseStackDevfile(stackFolderPath, stackFolderDir.Name(), force, &versionComponent, &indexComponent)
@@ -276,7 +284,7 @@ func parseStackDevfile(devfileDirPath string, stackName string, force bool, vers
276284

277285
if !force {
278286
// Devfile validation
279-
devfileObj,_, err := devfileParser.ParseDevfileAndValidate(parser.ParserArgs{Path: devfilePath})
287+
devfileObj, _, err := devfileParser.ParseDevfileAndValidate(parser.ParserArgs{Path: devfilePath})
280288
if err != nil {
281289
return fmt.Errorf("%s devfile is not valid: %v", devfileDirPath, err)
282290
}
@@ -292,7 +300,6 @@ func parseStackDevfile(devfileDirPath string, stackName string, force bool, vers
292300
return fmt.Errorf("failed to read %s: %v", devfilePath, err)
293301
}
294302

295-
296303
var devfile schema.Devfile
297304
err = yaml.Unmarshal(bytes, &devfile)
298305
if err != nil {
@@ -412,7 +419,7 @@ func parseExtraDevfileEntries(registryDirPath string, force bool) ([]schema.Sche
412419
// Can't handle during registry build since we don't have access to devfile library/parser
413420
if indexComponent.Type == schema.SampleDevfileType && validateSamples {
414421
if indexComponent.Versions != nil && len(indexComponent.Versions) > 0 {
415-
for _, version := range indexComponent.Versions{
422+
for _, version := range indexComponent.Versions {
416423
sampleVersonDirPath := filepath.Join(samplesDir, devfileEntry.Name, version.Version)
417424
devfilePath := filepath.Join(sampleVersonDirPath, "devfile.yaml")
418425
_, err := os.Stat(filepath.Join(devfilePath))
@@ -497,7 +504,7 @@ func checkForRequiredMetadata(devfileObj parser.DevfileObj) []error {
497504
return metadataErrors
498505
}
499506

500-
func validateStackInfo (stackInfo schema.Schema, stackfolderDir string) []error {
507+
func validateStackInfo(stackInfo schema.Schema, stackfolderDir string) []error {
501508
var errors []error
502509

503510
if stackInfo.Name == "" {
@@ -537,7 +544,6 @@ func validateStackInfo (stackInfo schema.Schema, stackfolderDir string) []error
537544
return errors
538545
}
539546

540-
541547
// In checks if the value is in the array
542548
func inArray(arr []string, value string) bool {
543549
for _, item := range arr {
@@ -546,4 +552,4 @@ func inArray(arr []string, value string) bool {
546552
}
547553
}
548554
return false
549-
}
555+
}

index/generator/library/library_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestValidateIndexComponent(t *testing.T) {
5656
Name: "nodejs",
5757
Versions: []schema.Version{
5858
{
59-
Version: "1.0.0",
59+
Version: "1.0.0",
6060
SchemaVersion: "2.0.0",
6161
Resources: []string{
6262
"devfile.yaml",
@@ -73,7 +73,7 @@ func TestValidateIndexComponent(t *testing.T) {
7373
Name: "nodejs",
7474
Versions: []schema.Version{
7575
{
76-
Version: "1.0.0",
76+
Version: "1.0.0",
7777
SchemaVersion: "2.0.0",
7878
Links: map[string]string{
7979
"self": "devfile-catalog/java-maven:latest",
@@ -103,18 +103,18 @@ func TestValidateIndexComponent(t *testing.T) {
103103
SupportUrl: "http://testurl/support.md",
104104
Versions: []schema.Version{
105105
{
106-
Version: "1.0.0",
106+
Version: "1.0.0",
107107
SchemaVersion: "2.0.0",
108-
Default: true,
108+
Default: true,
109109
Links: map[string]string{
110-
"self": "devfile-catalog/java-maven:1.0.0",
110+
"self": "devfile-catalog/java-maven:1.0.0",
111111
},
112112
Resources: []string{
113113
"devfile.yaml",
114114
},
115115
},
116116
{
117-
Version: "1.1.0",
117+
Version: "1.1.0",
118118
SchemaVersion: "2.1.0",
119119
Links: map[string]string{
120120
"self": "devfile-catalog/java-maven:2.1.0",
@@ -181,9 +181,9 @@ func TestValidateIndexComponent(t *testing.T) {
181181
Name: "nodejs",
182182
Versions: []schema.Version{
183183
{
184-
Version: "1.0.0",
184+
Version: "1.0.0",
185185
SchemaVersion: "2.0.0",
186-
Default: true,
186+
Default: true,
187187
Links: map[string]string{
188188
"self": "devfile-catalog/java-maven:latest",
189189
},
@@ -206,9 +206,9 @@ func TestValidateIndexComponent(t *testing.T) {
206206
Name: "nodejs",
207207
Versions: []schema.Version{
208208
{
209-
Version: "1.0.0",
209+
Version: "1.0.0",
210210
SchemaVersion: "2.0.0",
211-
Default: true,
211+
Default: true,
212212
Links: map[string]string{
213213
"self": "devfile-catalog/java-maven:latest",
214214
},
@@ -228,7 +228,7 @@ func TestValidateIndexComponent(t *testing.T) {
228228
{
229229
"Case 11: empty version list",
230230
schema.Schema{
231-
Name: "nodejs",
231+
Name: "nodejs",
232232
Versions: []schema.Version{},
233233
},
234234
schema.StackDevfileType,
@@ -245,7 +245,7 @@ func TestValidateIndexComponent(t *testing.T) {
245245
SupportUrl: "http://testurl/support.md",
246246
Versions: []schema.Version{
247247
{
248-
Version: "1.0.0",
248+
Version: "1.0.0",
249249
SchemaVersion: "2.0.0",
250250
Links: map[string]string{
251251
"self": "devfile-catalog/java-maven:latest",
@@ -308,9 +308,9 @@ func TestValidateIndexComponent(t *testing.T) {
308308
SupportUrl: "http://testurl/support.md",
309309
Versions: []schema.Version{
310310
{
311-
Version: "1.0.0",
311+
Version: "1.0.0",
312312
SchemaVersion: "2.0.0",
313-
Default: true,
313+
Default: true,
314314
Links: map[string]string{
315315
"self": "devfile-catalog/java-maven:1.0.0",
316316
},
@@ -319,9 +319,9 @@ func TestValidateIndexComponent(t *testing.T) {
319319
},
320320
},
321321
{
322-
Version: "1.1.0",
322+
Version: "1.1.0",
323323
SchemaVersion: "2.1.0",
324-
Default: true,
324+
Default: true,
325325
Links: map[string]string{
326326
"self": "devfile-catalog/java-maven:1.1.0",
327327
},
@@ -340,17 +340,17 @@ func TestValidateIndexComponent(t *testing.T) {
340340
Name: "nodejs",
341341
Versions: []schema.Version{
342342
{
343-
Version: "1.0.0",
343+
Version: "1.0.0",
344344
SchemaVersion: "2.0.0",
345-
Default: true,
345+
Default: true,
346346
Git: &schema.Git{
347347
Remotes: map[string]string{
348348
"origin": "https://github.com/redhat-developer/devfile-sample/nodejs",
349349
},
350350
},
351351
},
352352
{
353-
Version: "1.1.0",
353+
Version: "1.1.0",
354354
SchemaVersion: "2.1.0",
355355
Git: &schema.Git{
356356
Remotes: map[string]string{
@@ -379,7 +379,7 @@ func TestValidateIndexComponent(t *testing.T) {
379379
SupportUrl: "http://testurl/support.md",
380380
Versions: []schema.Version{
381381
{
382-
Version: "1.0.0",
382+
Version: "1.0.0",
383383
SchemaVersion: "2.0.0",
384384
Git: &schema.Git{
385385
Remotes: map[string]string{
@@ -439,19 +439,19 @@ func TestValidateIndexComponent(t *testing.T) {
439439
SupportUrl: "http://testurl/support.md",
440440
Versions: []schema.Version{
441441
{
442-
Version: "1.0.0",
442+
Version: "1.0.0",
443443
SchemaVersion: "2.0.0",
444-
Default: true,
444+
Default: true,
445445
Git: &schema.Git{
446446
Remotes: map[string]string{
447447
"origin": "https://github.com/redhat-developer/devfile-sample/nodejs",
448448
},
449449
},
450450
},
451451
{
452-
Version: "1.1.0",
452+
Version: "1.1.0",
453453
SchemaVersion: "2.1.0",
454-
Default: true,
454+
Default: true,
455455
Git: &schema.Git{
456456
Remotes: map[string]string{
457457
"origin": "https://github.com/redhat-developer/devfile-sample/nodejs-2.1.0",

index/generator/schema/schema.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ type StarterProject struct {
157157
type Devfile struct {
158158
Meta Schema `yaml:"metadata,omitempty" json:"metadata,omitempty"`
159159
StarterProjects []StarterProject `yaml:"starterProjects,omitempty" json:"starterProjects,omitempty"`
160-
SchemaVersion string `yaml:"schemaVersion,omitempty" json:"schemaVersion,omitempty"`
160+
SchemaVersion string `yaml:"schemaVersion,omitempty" json:"schemaVersion,omitempty"`
161161
}
162162

163163
// Git stores the information of remote repositories
164164
type Git struct {
165-
Remotes map[string]string `yaml:"remotes,omitempty" json:"remotes,omitempty"`
166-
Url string `yaml:"url,omitempty" json:"url,omitempty"`
167-
RemoteName string `yaml:"remoteName,omitempty" json:"remoteName,omitempty"`
168-
SubDir string `yaml:"subDir,omitempty" json:"subDir,omitempty"`
169-
Revision string `yaml:"revision,omitempty" json:"revision,omitempty"`
165+
Remotes map[string]string `yaml:"remotes,omitempty" json:"remotes,omitempty"`
166+
Url string `yaml:"url,omitempty" json:"url,omitempty"`
167+
RemoteName string `yaml:"remoteName,omitempty" json:"remoteName,omitempty"`
168+
SubDir string `yaml:"subDir,omitempty" json:"subDir,omitempty"`
169+
Revision string `yaml:"revision,omitempty" json:"revision,omitempty"`
170170
}
171171

172172
// ExtraDevfileEntries is the extraDevfileEntries structure that is used by index component
@@ -177,24 +177,24 @@ type ExtraDevfileEntries struct {
177177

178178
// Version stores the top-level stack information defined within stack.yaml
179179
type StackInfo struct {
180-
Name string `yaml:"name,omitempty" json:"name,omitempty"`
181-
DisplayName string `yaml:"displayName,omitempty" json:"displayName,omitempty"`
182-
Description string `yaml:"description,omitempty" json:"description,omitempty"`
183-
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
184-
Versions []Version `yaml:"versions,omitempty" json:"versions,omitempty"`
180+
Name string `yaml:"name,omitempty" json:"name,omitempty"`
181+
DisplayName string `yaml:"displayName,omitempty" json:"displayName,omitempty"`
182+
Description string `yaml:"description,omitempty" json:"description,omitempty"`
183+
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
184+
Versions []Version `yaml:"versions,omitempty" json:"versions,omitempty"`
185185
}
186186

187187
// Version stores the information for each stack version
188188
type Version struct {
189-
Version string `yaml:"version,omitempty" json:"version,omitempty"`
190-
SchemaVersion string `yaml:"schemaVersion,omitempty" json:"schemaVersion,omitempty"`
191-
Default bool `yaml:"default,omitempty" json:"default,omitempty"`
192-
Git *Git `yaml:"git,omitempty" json:"git,omitempty"`
193-
Description string `yaml:"description,omitempty" json:"description,omitempty"`
194-
Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"`
195-
Architectures []string `yaml:"architectures,omitempty" json:"architectures,omitempty"`
196-
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
197-
Links map[string]string `yaml:"links,omitempty" json:"links,omitempty"`
198-
Resources []string `yaml:"resources,omitempty" json:"resources,omitempty"`
199-
StarterProjects []string `yaml:"starterProjects,omitempty" json:"starterProjects,omitempty"`
200-
}
189+
Version string `yaml:"version,omitempty" json:"version,omitempty"`
190+
SchemaVersion string `yaml:"schemaVersion,omitempty" json:"schemaVersion,omitempty"`
191+
Default bool `yaml:"default,omitempty" json:"default,omitempty"`
192+
Git *Git `yaml:"git,omitempty" json:"git,omitempty"`
193+
Description string `yaml:"description,omitempty" json:"description,omitempty"`
194+
Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"`
195+
Architectures []string `yaml:"architectures,omitempty" json:"architectures,omitempty"`
196+
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
197+
Links map[string]string `yaml:"links,omitempty" json:"links,omitempty"`
198+
Resources []string `yaml:"resources,omitempty" json:"resources,omitempty"`
199+
StarterProjects []string `yaml:"starterProjects,omitempty" json:"starterProjects,omitempty"`
200+
}

index/server/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/devfile/registry-support/index/generator v0.0.0-20220222194908-7a90a4214f3e
1010
github.com/gin-gonic/gin v1.6.3
1111
github.com/gorilla/mux v1.7.3 // indirect
12+
github.com/hashicorp/go-version v1.4.0
1213
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
1314
github.com/opencontainers/image-spec v1.0.1
1415
github.com/prometheus/client_golang v1.11.0

0 commit comments

Comments
 (0)