Skip to content

Check for Architecture during Registry Build #66

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

Merged
merged 3 commits into from
Jul 8, 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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# OSX related files
.DS_Store

# IDE related files
.idea
1 change: 1 addition & 0 deletions index/generator/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
gopkg.in/yaml.v2 v2.3.0
k8s.io/apiextensions-apiserver v0.18.6
)
9 changes: 2 additions & 7 deletions index/generator/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLi
github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
Expand Down Expand Up @@ -373,7 +372,6 @@ github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIK
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
github.com/spf13/afero v1.2.2 h1:5jhuqJyZCZf2JRofRvN/nIFgIWNzPa3/Vz8mYylgbWc=
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
Expand All @@ -387,7 +385,6 @@ github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
Expand All @@ -401,8 +398,9 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
Expand Down Expand Up @@ -523,7 +521,6 @@ golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0 h1:HyfiK1WMnHj5FXFXatD+Qs1A/xC2Run6RzeW1SyHxpc=
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -538,7 +535,6 @@ golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down Expand Up @@ -633,7 +629,6 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
Expand Down
23 changes: 21 additions & 2 deletions index/generator/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ const (
extraDevfileEntries = "extraDevfileEntries.yaml"
)

// MissingArchError is an error if the architecture list is empty
type MissingArchError struct {
devfile string
}

func (e *MissingArchError) Error() string {
return fmt.Sprintf("the %s devfile has no architecture(s) mentioned\n", e.devfile)
}

// GenerateIndexStruct parses registry then generates index struct according to the schema
func GenerateIndexStruct(registryDirPath string, force bool) ([]schema.Schema, error) {
// Parse devfile registry then populate index struct
Expand Down Expand Up @@ -75,6 +84,10 @@ func validateIndexComponent(indexComponent schema.Schema, componentType schema.D
}
}

if len(indexComponent.Architectures) == 0 {
return &MissingArchError{devfile: indexComponent.Name}
}

return nil
}

Expand Down Expand Up @@ -150,7 +163,10 @@ func parseDevfileRegistry(registryDirPath string, force bool) ([]schema.Schema,
if !force {
// Index component validation
err := validateIndexComponent(indexComponent, schema.StackDevfileType)
if err != nil {
if _, ok := err.(*MissingArchError); ok {
// log to the console as FYI if the devfile has no architectures
fmt.Printf("%s", err.Error())
} else if err != nil {
return nil, fmt.Errorf("%s index component is not valid: %v", devfileDir.Name(), err)
}
}
Expand Down Expand Up @@ -213,7 +229,10 @@ func parseExtraDevfileEntries(registryDirPath string, force bool) ([]schema.Sche

// Index component validation
err := validateIndexComponent(indexComponent, devfileType)
if err != nil {
if _, ok := err.(*MissingArchError); ok {
// log to the console as FYI if the devfile has no architectures
fmt.Printf("%s", err.Error())
} else if err != nil {
return nil, fmt.Errorf("%s index component is not valid: %v", indexComponent.Name, err)
}
}
Expand Down
54 changes: 40 additions & 14 deletions index/generator/library/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ import (
"testing"

"github.com/devfile/registry-support/index/generator/schema"
"github.com/stretchr/testify/assert"
)

func TestValidateIndexComponent(t *testing.T) {

nameNotInitErr := ".*name is not initialized.*"
linkEmptyErr := ".*links are empty.*"
resourcesEmptyErr := ".*resources are empty.*"
gitEmptyErr := ".*git is empty.*"
multipleRemotesErr := ".*has multiple remotes.*"
noArchErr := ".*has no architecture.*"

tests := []struct {
name string
indexComponent schema.Schema
componentType schema.DevfileType
wantErr bool
wantErr *string
}{
{
"Case 1: test index component is not initialized for stack component",
Expand All @@ -27,7 +36,7 @@ func TestValidateIndexComponent(t *testing.T) {
},
},
schema.StackDevfileType,
true,
&nameNotInitErr,
},
{
"Case 2: test index component links are empty for stack component",
Expand All @@ -38,7 +47,7 @@ func TestValidateIndexComponent(t *testing.T) {
},
},
schema.StackDevfileType,
true,
&linkEmptyErr,
},
{
"Case 3: test index component resources are empty for stack component",
Expand All @@ -49,15 +58,15 @@ func TestValidateIndexComponent(t *testing.T) {
},
},
schema.StackDevfileType,
true,
&resourcesEmptyErr,
},
{
"Case 4: test index component git is empty for sample component",
schema.Schema{
Name: "nodejs",
},
schema.SampleDevfileType,
true,
&gitEmptyErr,
},
{
"Case 5: test happy path for for stack component",
Expand All @@ -69,9 +78,12 @@ func TestValidateIndexComponent(t *testing.T) {
Resources: []string{
"devfile.yaml",
},
Architectures: []string{
"amd64",
},
},
schema.StackDevfileType,
false,
nil,
},
{
"Case 6: test happy path for for sample component",
Expand All @@ -82,9 +94,12 @@ func TestValidateIndexComponent(t *testing.T) {
"origin": "https://github.com/redhat-developer/devfile-sample",
},
},
Architectures: []string{
"amd64",
},
},
schema.SampleDevfileType,
false,
nil,
},
{
"Case 7: test index component git has multiple remotes",
Expand All @@ -98,19 +113,30 @@ func TestValidateIndexComponent(t *testing.T) {
},
},
schema.SampleDevfileType,
true,
&multipleRemotesErr,
},
{
"Case 8: check for missing arch",
schema.Schema{
Name: "nodejs",
Git: &schema.Git{
Remotes: map[string]string{
"origin": "https://github.com/redhat-developer/devfile-sample",
},
},
},
schema.SampleDevfileType,
&noArchErr,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotErr := false
err := validateIndexComponent(tt.indexComponent, tt.componentType)
if err != nil {
gotErr = true
}
if gotErr != tt.wantErr {
t.Errorf("Got error: %t, want error: %t, function return error: %v", gotErr, tt.wantErr, err)
if tt.wantErr != nil && assert.Error(t, err) {
assert.Regexp(t, *tt.wantErr, err.Error(), "Error message should match")
} else {
assert.NoError(t, err, "Expected error to be nil")
}
})
}
Expand Down
1 change: 1 addition & 0 deletions index/generator/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type Schema struct {
Description string `yaml:"description,omitempty" json:"description,omitempty"`
Type DevfileType `yaml:"type,omitempty" json:"type,omitempty"`
Tags []string `yaml:"tags,omitempty" json:"tags,omitempty"`
Architectures []string `yaml:"architectures,omitempty" json:"architectures,omitempty"`
Icon string `yaml:"icon,omitempty" json:"icon,omitempty"`
GlobalMemoryLimit string `yaml:"globalMemoryLimit,omitempty" json:"globalMemoryLimit,omitempty"`
ProjectType string `yaml:"projectType,omitempty" json:"projectType,omitempty"`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading