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

Fix multiple registry related issues #3341

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 3 additions & 5 deletions pkg/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,9 @@ func ListDevfileComponents(registryName string) (DevfileComponentTypeList, error
// Load the devfile registry index.json
registry := reg // needed to prevent the lambda from capturing the value
retrieveRegistryIndices.Add(util.ConcurrentTask{ToRun: func(errChannel chan error) {
indexEntries, e := getDevfileIndexEntries(registry)
if e != nil {
log.Warningf("Registry %s is not set up properly with error: %v", registryName, err)
errChannel <- e
GeekArthur marked this conversation as resolved.
Show resolved Hide resolved
indexEntries, err := getDevfileIndexEntries(registry)
if err != nil {
log.Warningf("Registry %s is not set up properly with error: %v", registry.Name, err)
return
}

Expand Down Expand Up @@ -204,7 +203,6 @@ func ListDevfileComponents(registryName string) (DevfileComponentTypeList, error
devfile, err := GetDevfile(link)
if err != nil {
log.Warningf("Registry %s is not set up properly with error: %v", devfileIndex.Registry.Name, err)
errChannel <- err
return
}

Expand Down
46 changes: 36 additions & 10 deletions pkg/odo/cli/component/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,16 @@ func (co *CreateOptions) Complete(name string, cmd *cobra.Command, args []string

// Validate user specify registry
if co.devfileMetadata.devfileRegistry.Name != "" {
// TODO: We should add more validations here to validate registry existence and correctness
if co.devfileMetadata.devfilePath.value != "" {
return errors.New("You can specify registry via --registry if you want to use the devfile that is specified via --devfile")
return errors.New("You can't specify registry via --registry if you want to use the devfile that is specified via --devfile")
}

registryList, err := catalog.GetDevfileRegistries(co.devfileMetadata.devfileRegistry.Name)
if err != nil {
return errors.Wrap(err, "Failed to get registry")
}
if len(registryList) == 0 {
return errors.Errorf("Registry %s doesn't exist, please specify a valid registry via --registry", co.devfileMetadata.devfileRegistry.Name)
}
}

Expand Down Expand Up @@ -513,16 +520,29 @@ func (co *CreateOptions) Complete(name string, cmd *cobra.Command, args []string
// Since we need to support both devfile and s2i, so we have to check if the component type is
// supported by devfile, if it is supported we return and will download the corresponding devfile later,
// if it is not supported we still need to run all the codes related with s2i after devfile compatibility check
spinner := log.Spinner("Checking devfile compatibility")

hasComponent := false

for _, devfileComponent := range catalogDevfileList.Items {
if co.devfileMetadata.componentType == devfileComponent.Name && devfileComponent.Support {
co.devfileMetadata.devfileSupport = true
co.devfileMetadata.devfileLink = devfileComponent.Link
co.devfileMetadata.devfileRegistry = devfileComponent.Registry
if co.devfileMetadata.componentType == devfileComponent.Name {
hasComponent = true
if devfileComponent.Support {
co.devfileMetadata.devfileSupport = true
co.devfileMetadata.devfileLink = devfileComponent.Link
co.devfileMetadata.devfileRegistry = devfileComponent.Registry
break
}
}
}

existSpinner := log.Spinner("Checking devfile existence")
if hasComponent {
existSpinner.End(true)
} else {
existSpinner.End(false)
}

supportSpinner := log.Spinner("Checking devfile compatibility")
if co.devfileMetadata.devfileSupport {
registrySpinner := log.Spinnerf("Creating a devfile component from registry: %s", co.devfileMetadata.devfileRegistry.Name)

Expand All @@ -532,13 +552,19 @@ func (co *CreateOptions) Complete(name string, cmd *cobra.Command, args []string
return err
}

spinner.End(true)
supportSpinner.End(true)
registrySpinner.End(true)
return nil
}
supportSpinner.End(false)

spinner.End(false)
log.Warning("\nDevfile component type is not supported, please run `odo catalog list components` for a list of supported devfile component types")
// Currently only devfile component supports --registry flag, so if user specifies --registry when creating devfile component,
// we should error out instead of running s2i componet code and throw warning message
if co.devfileMetadata.devfileRegistry.Name != "" {
return errors.Errorf("Devfile component type %s is not supported, please run `odo catalog list components` for a list of supported devfile component types", co.devfileMetadata.componentType)
} else {
log.Warningf("Devfile component type %s is not supported, please run `odo catalog list components` for a list of supported devfile component types", co.devfileMetadata.componentType)
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions tests/integration/devfile/cmd_devfile_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,18 @@ var _ = Describe("odo devfile catalog command tests", func() {
helper.MatchAllInOutput(output, wantOutput)
})
})

Context("When executing catalog list components with registry that is not set up properly", func() {
GeekArthur marked this conversation as resolved.
Show resolved Hide resolved
It("should list components from valid registry", func() {
helper.CmdShouldPass("odo", "registry", "add", "fake", "http://fake")
output := helper.CmdShouldPass("odo", "catalog", "list", "components")
wantOutput := []string{
GeekArthur marked this conversation as resolved.
Show resolved Hide resolved
"Odo Devfile Components",
"java-spring-boot",
"quarkus",
}
helper.MatchAllInOutput(output, wantOutput)
helper.CmdShouldPass("odo", "registry", "delete", "fake", "-f")
})
})
})
8 changes: 7 additions & 1 deletion tests/integration/devfile/cmd_devfile_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,16 @@ var _ = Describe("odo devfile create command tests", func() {
})

Context("When executing odo create with devfile component type argument and --registry flag", func() {
It("should successfully create the devfile component", func() {
It("should successfully create the devfile component if specified registry is valid", func() {
componentRegistry := "DefaultDevfileRegistry"
helper.CmdShouldPass("odo", "create", "java-openliberty", "--registry", componentRegistry)
})

It("should fail to create the devfile component if specified registry is invalid", func() {
GeekArthur marked this conversation as resolved.
Show resolved Hide resolved
componentRegistry := "fake"
output := helper.CmdShouldFail("odo", "create", "java-openliberty", "--registry", componentRegistry)
helper.MatchAllInOutput(output, []string{"Registry fake doesn't exist, please specify a valid registry via --registry"})
})
})

Context("When executing odo create with devfile component type argument and --context flag", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,18 @@ var _ = Describe("odo docker devfile catalog command tests", func() {
helper.MatchAllInOutput(output, wantOutput)
})
})

Context("When executing catalog list components with registry that is not set up properly", func() {
It("should list components from valid registry", func() {
helper.CmdShouldPass("odo", "registry", "add", "fake", "http://fake")
output := helper.CmdShouldPass("odo", "catalog", "list", "components")
wantOutput := []string{
GeekArthur marked this conversation as resolved.
Show resolved Hide resolved
"Odo Devfile Components",
"java-spring-boot",
"quarkus",
}
helper.MatchAllInOutput(output, wantOutput)
helper.CmdShouldPass("odo", "registry", "delete", "fake", "-f")
})
})
})