Skip to content

Commit c175e96

Browse files
authoredFeb 22, 2021
Merge pull request #62 from maysunfaisal/350-1
Cleanup & Update metadata func
2 parents 3066a89 + b0a5637 commit c175e96

14 files changed

+138
-735
lines changed
 

‎README.md

+10
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ The function documentation can be accessed via [pkg.go.dev](https://pkg.go.dev/g
1616
1717
// To get all the components from the devfile
1818
components, err := devfile.Data.GetComponents(DevfileOptions{})
19+
20+
// To get all the components from the devfile with attributes tagged - tool: console-import & import: {strategy: Dockerfile}
21+
components, err := devfile.Data.GetComponents(DevfileOptions{
22+
Filter: map[string]interface{}{
23+
"tool": "console-import",
24+
"import": map[string]interface{}{
25+
"strategy": "Dockerfile",
26+
},
27+
},
28+
})
1929
```
2030
2. To get the Kubernetes objects from the devfile, visit pkg/devfile/generator/generators.go
2131
```

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/devfile/library
33
go 1.13
44

55
require (
6-
github.com/devfile/api/v2 v2.0.0-20210211160219-33a78aec06af
6+
github.com/devfile/api/v2 v2.0.0-20210219185433-585f5fe35835
77
github.com/fatih/color v1.7.0
88
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
99
github.com/gobwas/glob v0.2.3

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
4444
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4545
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4646
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
47-
github.com/devfile/api/v2 v2.0.0-20210211160219-33a78aec06af h1:egbFAAS/CWJMAqa4zIm8Cik3+iCqTAfLPfCj6PLEG5Y=
48-
github.com/devfile/api/v2 v2.0.0-20210211160219-33a78aec06af/go.mod h1:Cot4snybn3qhIh48oIFi9McocnIx7zY5fFbjfrIpPvg=
47+
github.com/devfile/api/v2 v2.0.0-20210219185433-585f5fe35835 h1:PalHtpqhvX/yu5DKFqwTWa1h7UJBd0H7+veJStur/wg=
48+
github.com/devfile/api/v2 v2.0.0-20210219185433-585f5fe35835/go.mod h1:Cot4snybn3qhIh48oIFi9McocnIx7zY5fFbjfrIpPvg=
4949
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
5050
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
5151
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=

‎pkg/devfile/generator/generators_test.go

+28-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import (
44
"reflect"
55
"testing"
66

7+
"github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
78
v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
89
"github.com/devfile/api/v2/pkg/attributes"
910
"github.com/devfile/library/pkg/devfile/parser"
11+
v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
1012
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
1113
"github.com/devfile/library/pkg/testingutil"
1214

@@ -25,6 +27,21 @@ func TestGetContainers(t *testing.T) {
2527
containerImages := []string{"image1", "image2"}
2628
trueMountSources := true
2729
falseMountSources := false
30+
31+
project := v1alpha2.Project{
32+
ClonePath: "test-project/",
33+
Name: "project0",
34+
ProjectSource: v1.ProjectSource{
35+
Git: &v1.GitProjectSource{
36+
GitLikeProjectSource: v1.GitLikeProjectSource{
37+
Remotes: map[string]string{
38+
"origin": "repo",
39+
},
40+
},
41+
},
42+
},
43+
}
44+
2845
tests := []struct {
2946
name string
3047
containerComponents []v1.Component
@@ -167,8 +184,17 @@ func TestGetContainers(t *testing.T) {
167184
t.Run(tt.name, func(t *testing.T) {
168185

169186
devObj := parser.DevfileObj{
170-
Data: &testingutil.TestDevfileData{
171-
Components: tt.containerComponents,
187+
Data: &v2.DevfileV2{
188+
Devfile: v1.Devfile{
189+
DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{
190+
DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{
191+
Components: tt.containerComponents,
192+
Projects: []v1alpha2.Project{
193+
project,
194+
},
195+
},
196+
},
197+
},
172198
},
173199
}
174200

‎pkg/devfile/generator/utils_test.go

+18-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/devfile/api/v2/pkg/attributes"
1010
"github.com/devfile/library/pkg/devfile/parser"
11+
v2 "github.com/devfile/library/pkg/devfile/parser/data/v2"
1112
"github.com/devfile/library/pkg/devfile/parser/data/v2/common"
1213
"github.com/devfile/library/pkg/testingutil"
1314
buildv1 "github.com/openshift/api/build/v1"
@@ -747,8 +748,14 @@ func TestGetServiceSpec(t *testing.T) {
747748
t.Run(tt.name, func(t *testing.T) {
748749

749750
devObj := parser.DevfileObj{
750-
Data: &testingutil.TestDevfileData{
751-
Components: tt.containerComponents,
751+
Data: &v2.DevfileV2{
752+
Devfile: v1.Devfile{
753+
DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{
754+
DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{
755+
Components: tt.containerComponents,
756+
},
757+
},
758+
},
752759
},
753760
}
754761

@@ -1076,10 +1083,17 @@ func TestGetPortExposure(t *testing.T) {
10761083
for _, tt := range tests {
10771084
t.Run(tt.name, func(t *testing.T) {
10781085
devObj := parser.DevfileObj{
1079-
Data: &testingutil.TestDevfileData{
1080-
Components: tt.containerComponents,
1086+
Data: &v2.DevfileV2{
1087+
Devfile: v1.Devfile{
1088+
DevWorkspaceTemplateSpec: v1.DevWorkspaceTemplateSpec{
1089+
DevWorkspaceTemplateSpecContent: v1.DevWorkspaceTemplateSpecContent{
1090+
Components: tt.containerComponents,
1091+
},
1092+
},
1093+
},
10811094
},
10821095
}
1096+
10831097
mapCreated, err := getPortExposure(devObj, tt.filterOptions)
10841098
if !tt.wantErr && err != nil {
10851099
t.Errorf("TestGetPortExposure unexpected error: %v", err)

‎pkg/devfile/parser/configurables.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ const (
2222
// SetMetadataName set metadata name in a devfile
2323
func (d DevfileObj) SetMetadataName(name string) error {
2424
metadata := d.Data.GetMetadata()
25-
d.Data.SetMetadata(name, metadata.Version)
25+
metadata.Name = name
26+
d.Data.SetMetadata(metadata)
2627
return d.WriteYamlDevfile()
2728
}
2829

‎pkg/devfile/parser/data/interface.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type DevfileData interface {
1111
GetSchemaVersion() string
1212
SetSchemaVersion(version string)
1313
GetMetadata() devfilepkg.DevfileMetadata
14-
SetMetadata(name, version string)
14+
SetMetadata(metadata devfilepkg.DevfileMetadata)
1515

1616
// parent related methods
1717
GetParent() *v1.Parent

0 commit comments

Comments
 (0)