Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup & Update metadata func #62

Merged
merged 2 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/g

// To get all the components from the devfile
components, err := devfile.Data.GetComponents(DevfileOptions{})

// To get all the components from the devfile with attributes tagged - tool: console-import & import: {strategy: Dockerfile}
components, err := devfile.Data.GetComponents(DevfileOptions{
Filter: map[string]interface{}{
"tool": "console-import",
"import": map[string]interface{}{
"strategy": "Dockerfile",
},
},
})
```
2. To get the Kubernetes objects from the devfile, visit pkg/devfile/generator/generators.go
```
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/devfile/library
go 1.13

require (
github.com/devfile/api/v2 v2.0.0-20210211160219-33a78aec06af
github.com/devfile/api/v2 v2.0.0-20210219185433-585f5fe35835
github.com/fatih/color v1.7.0
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/gobwas/glob v0.2.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/devfile/api/v2 v2.0.0-20210211160219-33a78aec06af h1:egbFAAS/CWJMAqa4zIm8Cik3+iCqTAfLPfCj6PLEG5Y=
github.com/devfile/api/v2 v2.0.0-20210211160219-33a78aec06af/go.mod h1:Cot4snybn3qhIh48oIFi9McocnIx7zY5fFbjfrIpPvg=
github.com/devfile/api/v2 v2.0.0-20210219185433-585f5fe35835 h1:PalHtpqhvX/yu5DKFqwTWa1h7UJBd0H7+veJStur/wg=
github.com/devfile/api/v2 v2.0.0-20210219185433-585f5fe35835/go.mod h1:Cot4snybn3qhIh48oIFi9McocnIx7zY5fFbjfrIpPvg=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
Expand Down
30 changes: 28 additions & 2 deletions pkg/devfile/generator/generators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"reflect"
"testing"

"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/api/v2/pkg/attributes"
"github.com/devfile/library/pkg/devfile/parser"
v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"github.com/devfile/library/pkg/testingutil"

Expand All @@ -25,6 +27,21 @@ func TestGetContainers(t *testing.T) {
containerImages := []string{"image1", "image2"}
trueMountSources := true
falseMountSources := false

project := v1alpha2.Project{
ClonePath: "test-project/",
Name: "project0",
ProjectSource: v1.ProjectSource{
Git: &v1.GitProjectSource{
GitLikeProjectSource: v1.GitLikeProjectSource{
Remotes: map[string]string{
"origin": "repo",
},
},
},
},
}

tests := []struct {
name string
containerComponents []v1.Component
Expand Down Expand Up @@ -167,8 +184,17 @@ func TestGetContainers(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {

devObj := parser.DevfileObj{
Data: &testingutil.TestDevfileData{
Components: tt.containerComponents,
Data: &v2.DevfileV2{
Devfile: v1.Devfile{
DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{
DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{
Components: tt.containerComponents,
Projects: []v1alpha2.Project{
project,
},
},
},
},
},
}

Expand Down
22 changes: 18 additions & 4 deletions pkg/devfile/generator/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/devfile/api/v2/pkg/attributes"
"github.com/devfile/library/pkg/devfile/parser"
v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
"github.com/devfile/library/pkg/testingutil"
buildv1 "github.com/openshift/api/build/v1"
Expand Down Expand Up @@ -747,8 +748,14 @@ func TestGetServiceSpec(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {

devObj := parser.DevfileObj{
Data: &testingutil.TestDevfileData{
Components: tt.containerComponents,
Data: &v2.DevfileV2{
Devfile: v1.Devfile{
DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{
DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{
Components: tt.containerComponents,
},
},
},
},
}

Expand Down Expand Up @@ -1076,10 +1083,17 @@ func TestGetPortExposure(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
devObj := parser.DevfileObj{
Data: &testingutil.TestDevfileData{
Components: tt.containerComponents,
Data: &v2.DevfileV2{
Devfile: v1.Devfile{
DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{
DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{
Components: tt.containerComponents,
},
},
},
},
}

mapCreated, err := getPortExposure(devObj, tt.filterOptions)
if !tt.wantErr && err != nil {
t.Errorf("TestGetPortExposure unexpected error: %v", err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/devfile/parser/configurables.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const (
// SetMetadataName set metadata name in a devfile
func (d DevfileObj) SetMetadataName(name string) error {
metadata := d.Data.GetMetadata()
d.Data.SetMetadata(name, metadata.Version)
metadata.Name = name
d.Data.SetMetadata(metadata)
return d.WriteYamlDevfile()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/devfile/parser/data/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type DevfileData interface {
GetSchemaVersion() string
SetSchemaVersion(version string)
GetMetadata() devfilepkg.DevfileMetadata
SetMetadata(name, version string)
SetMetadata(metadata devfilepkg.DevfileMetadata)

// parent related methods
GetParent() *v1.Parent
Expand Down
Loading