Skip to content

Commit

Permalink
Add deprecated stacks filtering to registry-library (#232)
Browse files Browse the repository at this point in the history
* Add filtering for deprecated stacks

Signed-off-by: thepetk <thepetk@gmail.com>

* Add test cases for deprecated stacks filtering

Signed-off-by: thepetk <thepetk@gmail.com>

* Update documentation

Signed-off-by: thepetk <thepetk@gmail.com>

* Update library with const values

Signed-off-by: thepetk <thepetk@gmail.com>

* Fix type for DeprecatedFilter

Signed-off-by: thepetk <thepetk@gmail.com>

* Update registry-library/README.md

Co-authored-by: Michael Valdron <michael.valdron@gmail.com>
Signed-off-by: thepetk <thepetk@gmail.com>

* Update registry-library/library/library_test.go

Co-authored-by: Michael Valdron <michael.valdron@gmail.com>
Signed-off-by: thepetk <thepetk@gmail.com>

* Fix icon for test resource

Signed-off-by: thepetk <thepetk@gmail.com>

* Replace broken icon

Signed-off-by: thepetk <thepetk@gmail.com>

---------

Signed-off-by: thepetk <thepetk@gmail.com>
Co-authored-by: Michael Valdron <michael.valdron@gmail.com>
  • Loading branch information
thepetk and michael-valdron committed Apr 15, 2024
1 parent b950a06 commit 4f92146
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 22 deletions.
4 changes: 2 additions & 2 deletions index/generator/tests/registry/index_main.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"description": "Spring Boot® using Java",
"type": "stack",
"tags": ["Java", "Spring"],
"icon": "https://www.eclipse.org/che/images/logo-eclipseche.svg",
"icon": "https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg",
"projectType": "spring",
"language": "java",
"versions": [
Expand All @@ -163,7 +163,7 @@
"schemaVersion": "2.2.0",
"default": true,
"description": "Spring Boot® using Java",
"icon": "https://www.eclipse.org/che/images/logo-eclipseche.svg",
"icon": "https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg",
"tags": ["Java", "Spring"],
"links": {
"self": "devfile-catalog/java-springboot:1.1.0"
Expand Down
4 changes: 2 additions & 2 deletions index/generator/tests/registry/index_registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
"description": "Spring Boot® using Java",
"type": "stack",
"tags": ["Java", "Spring"],
"icon": "https://www.eclipse.org/che/images/logo-eclipseche.svg",
"icon": "https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg",
"projectType": "spring",
"language": "java",
"versions": [
Expand All @@ -164,7 +164,7 @@
"default": true,
"description": "Spring Boot® using Java",
"tags": ["Java", "Spring"],
"icon": "https://www.eclipse.org/che/images/logo-eclipseche.svg",
"icon": "https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg",
"links": {
"self": "devfile-catalog/java-springboot:1.1.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
description: Spring Boot® using Java
tags: ["Java", "Spring"]
globalMemoryLimit: 2674Mi
icon: https://www.eclipse.org/che/images/logo-eclipseche.svg
icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg
projectType: "spring"
language: "java"
starterProjects:
Expand Down
2 changes: 1 addition & 1 deletion index/server/pkg/util/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"Java",
"Spring"
],
"icon": "https://www.eclipse.org/che/images/logo-eclipseche.svg",
"icon": "https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg",
"projectType": "spring",
"language": "java",
"links": {
Expand Down
4 changes: 2 additions & 2 deletions index/server/registry-REST-API.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ curl http://devfile-registry.192.168.1.1.nip.io/index
"Java",
"Spring"
],
"icon": "https://www.eclipse.org/che/images/logo-eclipseche.svg",
"icon": "https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg",
"globalMemoryLimit": "2674Mi",
"projectType": "spring",
"language": "java",
Expand Down Expand Up @@ -801,7 +801,7 @@ curl http://devfile-registry.192.168.1.1.nip.io/index/all
"Java",
"Spring"
],
"icon": "https://www.eclipse.org/che/images/logo-eclipseche.svg",
"icon": "https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg",
"globalMemoryLimit": "2674Mi",
"projectType": "spring",
"language": "java",
Expand Down
4 changes: 2 additions & 2 deletions index/server/tests/registry/index_main.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"Java",
"Spring"
],
"icon": "https://www.eclipse.org/che/images/logo-eclipseche.svg",
"icon": "https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg",
"projectType": "spring",
"language": "java",
"versions": [
Expand All @@ -171,7 +171,7 @@
"schemaVersion": "2.2.0",
"default": true,
"description": "Spring Boot® using Java",
"icon": "https://www.eclipse.org/che/images/logo-eclipseche.svg",
"icon": "https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg",
"tags": [
"Java",
"Spring"
Expand Down
4 changes: 2 additions & 2 deletions index/server/tests/registry/index_registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"Java",
"Spring"
],
"icon": "https://www.eclipse.org/che/images/logo-eclipseche.svg",
"icon": "https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg",
"projectType": "spring",
"language": "java",
"versions": [
Expand All @@ -171,7 +171,7 @@
"schemaVersion": "2.2.0",
"default": true,
"description": "Spring Boot® using Java",
"icon": "https://www.eclipse.org/che/images/logo-eclipseche.svg",
"icon": "https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg",
"tags": [
"Java",
"Spring"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
description: Spring Boot® using Java
tags: ["Java", "Spring"]
globalMemoryLimit: 2674Mi
icon: https://www.eclipse.org/che/images/logo-eclipseche.svg
icon: https://raw.githubusercontent.com/devfile-samples/devfile-stack-icons/main/spring.svg
projectType: "spring"
language: "java"
starterProjects:
Expand Down
16 changes: 16 additions & 0 deletions registry-library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ Supported devfile media types can be found in the latest version of [library.go]
HTTPTimeout: &customTimeout
}
```
7. Filter *only deprecated* Devfiles based on the [lifecycle process for the devfiles project](https://github.com/devfile/registry/blob/main/LIFECYCLE.md)
```go
options := registryLibrary.RegistryOptions{
Filter: registryLibrary.RegistryFilter{
Deprecated: registryLibrary.DeprecatedFilterTrue,
},
}
```
8. Filter *only non deprecated* Devfiles based on the [lifecycle process for the devfiles project](https://github.com/devfile/registry/blob/main/LIFECYCLE.md)
```go
options := registryLibrary.RegistryOptions{
Filter: registryLibrary.RegistryFilter{
Deprecated: registryLibrary.DeprecatedFilterFalse,
},
}
```

#### Download the starter project

Expand Down
31 changes: 22 additions & 9 deletions registry-library/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ const (
DevfilePNGLogoMediaType = "image/png"
DevfileArchiveMediaType = "application/x-tar"

OwnersFile = "OWNERS"
registryLibrary = "registry-library" //constant to indicate that function is called by the library
httpRequestResponseTimeout = 30 * time.Second // httpRequestTimeout configures timeout of all HTTP requests
OwnersFile = "OWNERS"
registryLibrary = "registry-library" //constant to indicate that function is called by the library
httpRequestResponseTimeout = 30 * time.Second // httpRequestTimeout configures timeout of all HTTP requests
DeprecatedFilterTrue DeprecatedFilter = "true"
DeprecatedFilterFalse DeprecatedFilter = "false"
)

var (
Expand All @@ -65,6 +67,9 @@ type Registry struct {
err error
}

// DeprecatedFilter to manage the deprecated filter values
type DeprecatedFilter string

// TelemetryData structure to pass in client telemetry information
// The User and Locale fields should be passed in by clients if telemetry opt-in is enabled
// the generic Client name will be passed in regardless of opt-in/out choice. The value
Expand Down Expand Up @@ -103,6 +108,10 @@ type RegistryFilter struct {
// only major version and minor version are required. e.g. 2.1, 2.2 ect. service version should not be provided.
// will only be applied if `NewIndexSchema=true`
MaxSchemaVersion string
// Deprecated is set to filter devfile index for stacks having the "Deprecated" tag inside their default set of tags
// or not. the only acceptable values are "true"/"false". in case the value is "true" it will only include only
// deprecated stacks, if is "false" only non deprecated. will only be applied if `NewIndexSchema=true`
Deprecated DeprecatedFilter
}

// GetRegistryIndex returns the list of index schema structured stacks and/or samples from a specified devfile registry.
Expand Down Expand Up @@ -152,13 +161,17 @@ func GetRegistryIndex(registryURL string, options RegistryOptions, devfileTypes
q.Add("arch", arch)
}
}

if options.NewIndexSchema && (options.Filter.MaxSchemaVersion != "" || options.Filter.MinSchemaVersion != "") {
if options.Filter.MinSchemaVersion != "" {
q.Add("minSchemaVersion", options.Filter.MinSchemaVersion)
if options.NewIndexSchema {
if options.Filter.MaxSchemaVersion != "" || options.Filter.MinSchemaVersion != "" {
if options.Filter.MinSchemaVersion != "" {
q.Add("minSchemaVersion", options.Filter.MinSchemaVersion)
}
if options.Filter.MaxSchemaVersion != "" {
q.Add("maxSchemaVersion", options.Filter.MaxSchemaVersion)
}
}
if options.Filter.MaxSchemaVersion != "" {
q.Add("maxSchemaVersion", options.Filter.MaxSchemaVersion)
if options.Filter.Deprecated == DeprecatedFilterTrue || options.Filter.Deprecated == DeprecatedFilterFalse {
q.Add("deprecated", string(options.Filter.Deprecated))
}
}
urlObj.RawQuery = q.Encode()
Expand Down
41 changes: 41 additions & 0 deletions registry-library/library/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ var (
},
}

deprecatedFilteredIndex = []indexSchema.Schema{
{
Name: "deprecatedindex1",
Tags: []string{"Deprecated, arm64"},
},
}

nonDeprecatedFilteredIndex = []indexSchema.Schema{
{
Name: "deprecatedindex2",
},
}

schemaVersionFilteredIndex = []indexSchema.Schema{
{
Name: "indexSchema2.1",
Expand Down Expand Up @@ -206,6 +219,10 @@ func setUpIndexHandle(indexUrl *url.URL) []indexSchema.Schema {

if strings.Contains(indexUrl.String(), "arch=amd64&arch=arm64") {
data = archFilteredIndex
} else if strings.Contains(indexUrl.String(), "deprecated=true") {
data = deprecatedFilteredIndex
} else if strings.Contains(indexUrl.String(), "deprecated=false") {
data = nonDeprecatedFilteredIndex
} else if strings.Contains(indexUrl.String(), "maxSchemaVersion=2.2") && strings.Contains(indexUrl.String(), "minSchemaVersion=2.1") {
data = schemaVersionFilteredIndex
} else if indexUrl.Path == "/index/sample" {
Expand Down Expand Up @@ -315,6 +332,30 @@ func TestGetRegistryIndex(t *testing.T) {
devfileTypes: []indexSchema.DevfileType{indexSchema.StackDevfileType},
wantSchemas: schemaVersionFilteredIndex,
},
{
name: "Get Deprecated Filtered Index",
url: "http://" + serverIP,
options: RegistryOptions{
NewIndexSchema: true,
Filter: RegistryFilter{
Deprecated: DeprecatedFilterTrue,
},
},
devfileTypes: []indexSchema.DevfileType{indexSchema.StackDevfileType},
wantSchemas: deprecatedFilteredIndex,
},
{
name: "Get Non Deprecated Filtered Index",
url: "http://" + serverIP,
options: RegistryOptions{
NewIndexSchema: true,
Filter: RegistryFilter{
Deprecated: DeprecatedFilterFalse,
},
},
devfileTypes: []indexSchema.DevfileType{indexSchema.StackDevfileType},
wantSchemas: nonDeprecatedFilteredIndex,
},
{
name: "Get Arch Filtered Index",
url: "http://" + serverIP,
Expand Down

0 comments on commit 4f92146

Please sign in to comment.