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

Add devfile registry on preferences init when ODO_EXPERIMENTAL=true #3845

Closed
Closed
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
2 changes: 1 addition & 1 deletion pkg/odo/cli/registry/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (o *ListOptions) Run() (err error) {
}

registryList := cfg.OdoSettings.RegistryList
if len(*registryList) == 0 {
if registryList == nil || len(*registryList) == 0 {
return fmt.Errorf("No devfile registries added to the configuration. Refer `odo registry add -h` to add one")
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/preference/preference.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ func NewPreferenceInfo() (*PreferenceInfo, error) {

// If the preference file doesn't exist then we return with default preference
if _, err = os.Stat(preferenceFile); os.IsNotExist(err) {
// Add the default devfile registry if "ODO_EXPERIMENTAL" env variable is true
// We specifically need to check for the experimental mode env, as `odo preferences set experimental true` already properly
// initializes the default devfile registries.
experimentalEnvStr, _ := os.LookupEnv("ODO_EXPERIMENTAL")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this check? Should we even bother checking if we're in experimental mode? I have applied your patch to my PR here: #3705 which doesn't include looking up experimental and I have all tests passing.

Just out of curiosity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdrage This test https://github.com/openshift/odo/blob/master/tests/integration/component.go#L293 was failing without this check, as devfile components were getting listed without experimental mode being on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like your branch modifies the test to remove that check (which makes sense, as devfile is being moved out of experimental mode), but that explains why the test isn't failing on your branch

if experimentalEnvStr == "true" {
defaultRegistryList := []Registry{
{
Name: DefaultDevfileRegistryName,
URL: DefaultDevfileRegistryURL,
Secure: false,
},
}
c.OdoSettings.RegistryList = &defaultRegistryList
}
return &c, nil
}

Expand Down
18 changes: 17 additions & 1 deletion tests/helper/helper_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,40 @@ func runningCmd(cmd *exec.Cmd) string {
return fmt.Sprintf("Running %s with args %v", prog, cmd.Args)
}

func CmdRunner(program string, args ...string) *gexec.Session {
// CmdRunnerWithEnv runs the specified program and args, and sets the given env variables
func CmdRunnerWithEnv(env []string, program string, args ...string) *gexec.Session {
//prefix ginkgo verbose output with program name
prefix := fmt.Sprintf("[%s] ", filepath.Base(program))
prefixWriter := gexec.NewPrefixedWriter(prefix, GinkgoWriter)
command := exec.Command(program, args...)
command.Env = env
fmt.Fprintln(GinkgoWriter, runningCmd(command))
session, err := gexec.Start(command, prefixWriter, prefixWriter)
Expect(err).NotTo(HaveOccurred())
return session
}

// CmdRunner runs the specified program and args
func CmdRunner(program string, args ...string) *gexec.Session {
// Re-use the CmdRunnerWithEnv function since the logic is the same
// By passing in nil as the env, we default to the system env
return CmdRunnerWithEnv(nil, program, args...)
}

// CmdShouldPass returns stdout if command succeeds
func CmdShouldPass(program string, args ...string) string {
session := CmdRunner(program, args...)
Eventually(session).Should(gexec.Exit(0), runningCmd(session.Command))
return string(session.Wait().Out.Contents())
}

// CmdShouldPassWithEnv returns stdout if command succeeds
func CmdShouldPassWithEnv(env []string, program string, args ...string) string {
session := CmdRunnerWithEnv(env, program, args...)
Eventually(session).Should(gexec.Exit(0), runningCmd(session.Command))
return string(session.Wait().Out.Contents())
}

// CmdShouldRunWithTimeout waits for a certain duration and then returns stdout
func CmdShouldRunWithTimeout(timeout time.Duration, program string, args ...string) string {
session := CmdRunner(program, args...)
Expand Down
11 changes: 10 additions & 1 deletion tests/integration/devfile/cmd_devfile_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var _ = Describe("odo devfile registry command tests", func() {
// Using program commmand according to cliRunner in devfile
cliRunner := helper.GetCliRunner()

// This is run after every Spec (It)
// This is run before every Spec (It)
var _ = BeforeEach(func() {
SetDefaultEventuallyTimeout(10 * time.Minute)
context = helper.CreateNewContext()
Expand Down Expand Up @@ -59,6 +59,15 @@ var _ = Describe("odo devfile registry command tests", func() {
helper.MatchAllInOutput(output, []string{"No devfile registries added to the configuration. Refer `odo registry add -h` to add one"})

})

It("Should list all default registries when experimental mode is set via env", func() {
// Point to an alternative global odo config for this test case (want to test without any preferences file)
// And set experimental mode via env
fakeConfig := filepath.Join(context, "fakeconfig.yaml")
env := []string{"GLOBALODOCONFIG=" + fakeConfig, "ODO_EXPERIMENTAL=true"}
output := helper.CmdShouldPassWithEnv(env, "odo", "registry", "list")
helper.MatchAllInOutput(output, []string{"DefaultDevfileRegistry"})
})
})

Context("When executing registry commands with the registry is not present", func() {
Expand Down