Skip to content

Commit

Permalink
Move registry to preference
Browse files Browse the repository at this point in the history
<!--
Thank you for opening a PR! Here are some things you need to know before submitting:

1. Please read our developer guideline: https://github.com/redhat-developer/odo/wiki/Developer-Guidelines
2. Label this PR accordingly with the '/kind' line
3. Ensure you have written and ran the appropriate tests: https://github.com/redhat-developer/odo/wiki/Writing-and-running-tests
4. Read how we approve and LGTM each PR: https://github.com/redhat-developer/odo/wiki/PR-Review

Documentation:

If you are pushing a change to documentation, please read: https://github.com/redhat-developer/odo/wiki/Contributing-to-Docs
-->

**What type of PR is this:**

<!--
Add one of the following kinds:
/kind bug
/kind cleanup
/kind tests
/kind documentation

Feel free to use other [labels](https://github.com/redhat-developer/odo/labels) as needed. However one of the above labels must be present or the PR will not be reviewed. This instruction is for reviewers as well.
-->
/kind feature

**What does this PR do / why we need it:**

This PR does the following:
- Moves "registry" to preference
- Gets rid of unused preference configuration options
- Reorders the parameters for preference for the usage in --help

**Which issue(s) this PR fixes:**
<!--
Specifying the issue will automatically close it when this PR is merged
-->

#5402

**PR acceptance criteria:**

- [X] Unit test

- [X] Integration test

- [X] Documentation

**How to test changes / Special notes to the reviewer:**
  • Loading branch information
cdrage committed Feb 7, 2022
1 parent 6d8f6ce commit c6eae3e
Show file tree
Hide file tree
Showing 34 changed files with 143 additions and 324 deletions.
2 changes: 1 addition & 1 deletion USAGE_DATA.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ The following table describes the additional information collected by odo comman
| | **Cluster Type** | Openshift 4 / Kubernetes |
|**Project Create**| Cluster Type |Openshift 4 / Kubernetes |
|**Project Set**| Cluster Type |Openshift 4 / Kubernetes |
|**Preference Change** | Preference Key| UpdateNotification/NamePrefix/Timeout/BuildTimeout/PushTimeout/Ephemeral/ConsentTelemetry |
|**Preference Change** | Preference Key| UpdateNotification/Timeout/PushTimeout/RegistryCacheTime/Ephemeral/ConsentTelemetry |


21 changes: 10 additions & 11 deletions docs/website/docs/getting-started/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ Example:
$ odo preference view
PARAMETER CURRENT_VALUE
UpdateNotification
NamePrefix
Timeout
BuildTimeout
PushTimeout
RegistryCacheTime
Ephemeral
ConsentTelemetry
```
Expand Down Expand Up @@ -94,12 +93,12 @@ Unsetting a preference key sets it to an empty value in the preference file. odo

### Preference Key Table

| Preference | Description | Default |
| --------------------- | ------------------------------------------------------------------------- | ------------------------- |
| UpdateNotification | Control whether a notification to update odo is shown | True |
| NamePrefix | Set a default name prefix for an odo resource (component, storage, etc) | Current directory name |
| Timeout | Timeout for OpenShift server connection check | 1 second |
| BuildTimeout | Timeout for waiting for a build of the git component to complete | 300 seconds |
| PushTimeout | Timeout for waiting for a component to start | 240 seconds |
| Ephemeral | Control whether odo should create a emptyDir volume to store source code | True |
| ConsentTelemetry | Control whether odo can collect telemetry for the user's odo usage | False |
| Preference | Description | Default |
|--------------------|--------------------------------------------------------------------------------|------------------------|
| UpdateNotification | Control whether a notification to update odo is shown | True |
| NamePrefix | Set a default name prefix for an odo resource (component, storage, etc) | Current directory name |
| Timeout | Timeout for Kubernetes server connection check | 1 second |
| PushTimeout | Timeout for waiting for a component to start | 240 seconds |
| RegistryCacheTime | For how long (in minutes) odo will cache information from the Devfile registry | 4 Minutes |
| Ephemeral | Control whether odo should create a emptyDir volume to store source code | True |
| ConsentTelemetry | Control whether odo can collect telemetry for the user's odo usage | False |
23 changes: 0 additions & 23 deletions docs/website/docs/tutorials/deploying-java-app-with-database.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,6 @@ In this example we will use odo to manage a sample [Java JPA MicroService applic
```shell
odo push --show-log
```
**Troubleshooting**:
The Open Liberty image used by this application is relatively large(~850 MB), and depending on your internet connection, it might fail to download within the BuildTimeout set by odo; default timeout is 300 seconds.
```shell
$ odo push
Validation
✓ Validating the devfile [45508ns]
Updating services
✓ Services and Links are in sync with the cluster, no changes are required
Creating Kubernetes resources for component mysboproj
✗ Waiting for component to start [5m]
✗ Failed to start component with name "mysboproj". Error: Failed to create the component: error while waiting for deployment rollout: timeout while waiting for mysboproj-app deployment roll out
```
In case this step fails due to a timeout, consider increasing the Build Timeout:
```shell
odo preference set BuildTimeout 600
```
Deploy the application to the cluster again:
```shell
odo push --show-log -f
```
5. The application is now deployed to the cluster - you can view the status of the cluster, and the application test results by streaming the cluster logs of the component that we pushed to the cluster in the previous step.
```shell
odo log --follow
Expand Down
2 changes: 1 addition & 1 deletion pkg/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/redhat-developer/odo/pkg/devfile"
"github.com/redhat-developer/odo/pkg/kclient"
"github.com/redhat-developer/odo/pkg/log"
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/registry/util"
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/preference/registry/util"
"github.com/redhat-developer/odo/pkg/preference"
"github.com/redhat-developer/odo/pkg/segment"
"github.com/redhat-developer/odo/pkg/testingutil/filesystem"
Expand Down
21 changes: 11 additions & 10 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,18 @@ func GetDefaultComponentName(cfg preference.Client, componentPath string, compon
existingComponentNames = append(existingComponentNames, component.Name)
}

// If there's no prefix in config file, or its value is empty string use safe default - the current directory along with component type
if cfg.NamePrefix() == nil || *cfg.NamePrefix() == "" {
prefix, err = GetComponentDir(componentPath)
if err != nil {
return "", errors.Wrap(err, "unable to generate random component name")
}
prefix = util.TruncateString(prefix, componentRandomNamePartsMaxLen)
} else {
// Set the required prefix into componentName
prefix = *cfg.NamePrefix()
// V2 Change -> V3
// We have removed the cfg.NamePrefix() from odo preference NamePrefix, we will instead create a random component name.
// if cfg.NamePrefix() == nil || *cfg.NamePrefix() == "" {
prefix, err = GetComponentDir(componentPath)
if err != nil {
return "", errors.Wrap(err, "unable to generate random component name")
}
prefix = util.TruncateString(prefix, componentRandomNamePartsMaxLen)
// } else {
// Set the required prefix into componentName
// prefix = *cfg.NamePrefix()
//}

// Generate unique name for the component using prefix and unique random suffix
componentName, err := util.GetRandomName(
Expand Down
1 change: 0 additions & 1 deletion pkg/component/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ func TestGetDefaultComponentName(t *testing.T) {
t.Run(tt.testName, func(t *testing.T) {
ctrl := gomock.NewController(t)
cfg := preference.NewMockClient(ctrl)
cfg.EXPECT().NamePrefix().Return(nil)

name, err := GetDefaultComponentName(cfg, tt.componentPath, tt.componentType, tt.existingComponents)
if (err != nil) != tt.wantErr {
Expand Down
2 changes: 1 addition & 1 deletion pkg/component/starter_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/redhat-developer/odo/pkg/devfile/location"
"github.com/redhat-developer/odo/pkg/log"
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/registry/util"
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/preference/registry/util"
"github.com/redhat-developer/odo/pkg/util"

"github.com/pkg/errors"
Expand Down
2 changes: 1 addition & 1 deletion pkg/odo/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/redhat-developer/odo/pkg/odo/cli/logout"
"github.com/redhat-developer/odo/pkg/odo/cli/plugins"
"github.com/redhat-developer/odo/pkg/odo/cli/preference"
"github.com/redhat-developer/odo/pkg/odo/cli/preference/registry"
"github.com/redhat-developer/odo/pkg/odo/cli/project"
"github.com/redhat-developer/odo/pkg/odo/cli/registry"
"github.com/redhat-developer/odo/pkg/odo/cli/telemetry"
"github.com/redhat-developer/odo/pkg/odo/cli/url"
"github.com/redhat-developer/odo/pkg/odo/cli/utils"
Expand Down
2 changes: 1 addition & 1 deletion pkg/odo/cli/component/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

"github.com/redhat-developer/odo/pkg/kclient"
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/registry/util"
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/preference/registry/util"
"github.com/redhat-developer/odo/pkg/odo/cmdline"
"github.com/redhat-developer/odo/pkg/preference"
"github.com/redhat-developer/odo/pkg/project"
Expand Down
2 changes: 1 addition & 1 deletion pkg/odo/cli/component/create_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/redhat-developer/odo/pkg/catalog"
"github.com/redhat-developer/odo/pkg/component"
"github.com/redhat-developer/odo/pkg/log"
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/registry/util"
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/preference/registry/util"
"github.com/redhat-developer/odo/pkg/preference"
"github.com/redhat-developer/odo/pkg/util"
"github.com/zalando/go-keyring"
Expand Down
10 changes: 10 additions & 0 deletions pkg/odo/cli/preference/preference.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package preference
import (
"fmt"

"github.com/redhat-developer/odo/pkg/odo/cli/preference/registry"
"github.com/redhat-developer/odo/pkg/odo/util"
"github.com/redhat-developer/odo/pkg/preference"

Expand All @@ -19,9 +20,16 @@ var preferenceLongDesc = ktemplates.LongDesc(`Modifies odo specific configuratio

// NewCmdPreference implements the utils config odo command
func NewCmdPreference(name, fullName string) *cobra.Command {

// Main Commands
preferenceViewCmd := NewCmdView(viewCommandName, util.GetFullName(fullName, viewCommandName))
preferenceSetCmd := NewCmdSet(setCommandName, util.GetFullName(fullName, setCommandName))
preferenceUnsetCmd := NewCmdUnset(unsetCommandName, util.GetFullName(fullName, unsetCommandName))
registryCmd := registry.NewCmdRegistry(registry.RecommendedCommandName, util.GetFullName(fullName, registry.RecommendedCommandName))

// Subcommands

// Set the examples
preferenceCmd := &cobra.Command{
Use: name,
Short: "Modifies preference settings",
Expand All @@ -33,8 +41,10 @@ func NewCmdPreference(name, fullName string) *cobra.Command {
),
}

// Add the commands, help, usage and annotations
preferenceCmd.AddCommand(preferenceViewCmd, preferenceSetCmd)
preferenceCmd.AddCommand(preferenceUnsetCmd)
preferenceCmd.AddCommand(registryCmd)
preferenceCmd.SetUsageTemplate(util.CmdUsageTemplate)
preferenceCmd.Annotations = map[string]string{"command": "main"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
// Built-in packages
"fmt"

util2 "github.com/redhat-developer/odo/pkg/odo/cli/registry/util"
util2 "github.com/redhat-developer/odo/pkg/odo/cli/preference/registry/util"
"github.com/redhat-developer/odo/pkg/odo/cmdline"

// Third-party packages
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
ktemplates "k8s.io/kubectl/pkg/util/templates"

// odo packages
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/registry/util"
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/preference/registry/util"
"github.com/redhat-developer/odo/pkg/odo/cmdline"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
ktemplates "k8s.io/kubectl/pkg/util/templates"

// odo packages
util "github.com/redhat-developer/odo/pkg/odo/cli/registry/util"
util "github.com/redhat-developer/odo/pkg/odo/cli/preference/registry/util"
"github.com/redhat-developer/odo/pkg/odo/cmdline"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
ktemplates "k8s.io/kubectl/pkg/util/templates"

// odo packages
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/registry/util"
registryUtil "github.com/redhat-developer/odo/pkg/odo/cli/preference/registry/util"
"github.com/redhat-developer/odo/pkg/odo/cmdline"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions"
odoutil "github.com/redhat-developer/odo/pkg/odo/util"
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions pkg/odo/cli/preference/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import (
const setCommandName = "set"

var (
setLongDesc = ktemplates.LongDesc(`Set an individual value in the odo preference file.
setLongDesc = ktemplates.LongDesc(`Set an individual value in the odo preference file.
%[1]s`)
setExample = ktemplates.Examples(`
# Set a preference value in the global preference`)
# All available preference values you can set`)
)

// SetOptions encapsulates the options for the command
Expand Down Expand Up @@ -89,7 +88,7 @@ func NewCmdSet(name, fullName string) *cobra.Command {
o := NewSetOptions(prefClient)
preferenceSetCmd := &cobra.Command{
Use: name,
Short: "Set a value in odo config file",
Short: "Set a value in the odo preference file",
Long: fmt.Sprintf(setLongDesc, preference.FormatSupportedParameters()),
Example: func(exampleString, fullName string) string {
properties := prefClient.NewPreferenceList()
Expand Down
9 changes: 6 additions & 3 deletions pkg/odo/cli/preference/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ func NewCmdUnset(name, fullName string) *cobra.Command {
Short: "Unset a value in odo preference file",
Long: fmt.Sprintf(unsetLongDesc, preference.FormatSupportedParameters()),
Example: func(exampleString, fullName string) string {
for _, property := range preference.GetSupportedParameters() {
exampleString += fmt.Sprintf("\n %s %s", fullName, property)
}
// For now, the --help page is too large listing all unset values too.
// Just show one example of how to unset a value.
//for _, property := range preference.GetSupportedParameters() {
//exampleString += fmt.Sprintf("\n %s %s", fullName, property)
//}
exampleString += fmt.Sprintf("\n %s %s", fullName, preference.GetSupportedParameters()[0])
return "\n" + exampleString
}(unsetExample, fullName),
Args: func(cmd *cobra.Command, args []string) error {
Expand Down
5 changes: 2 additions & 3 deletions pkg/odo/cli/preference/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

const viewCommandName = "view"

var viewExample = ktemplates.Examples(`# For viewing the current preference value
var viewExample = ktemplates.Examples(`# View all set preference values
%[1]s
`)

Expand Down Expand Up @@ -57,10 +57,9 @@ func (o *ViewOptions) Run() (err error) {
w := tabwriter.NewWriter(os.Stdout, 5, 2, 2, ' ', tabwriter.TabIndent)
fmt.Fprintln(w, "PARAMETER", "\t", "CURRENT_VALUE")
fmt.Fprintln(w, "UpdateNotification", "\t", showBlankIfNil(o.prefClient.UpdateNotification()))
fmt.Fprintln(w, "NamePrefix", "\t", showBlankIfNil(o.prefClient.NamePrefix()))
fmt.Fprintln(w, "Timeout", "\t", showBlankIfNil(o.prefClient.Timeout()))
fmt.Fprintln(w, "BuildTimeout", "\t", showBlankIfNil(o.prefClient.BuildTimeout()))
fmt.Fprintln(w, "PushTimeout", "\t", showBlankIfNil(o.prefClient.PushTimeout()))
fmt.Fprintln(w, "RegistryCacheTime", "\t", showBlankIfNil(o.prefClient.RegistryCacheTime()))
fmt.Fprintln(w, "Ephemeral", "\t", showBlankIfNil(o.prefClient.EphemeralSourceVolume()))
fmt.Fprintln(w, "ConsentTelemetry", "\t", showBlankIfNil(o.prefClient.ConsentTelemetry()))

Expand Down
3 changes: 1 addition & 2 deletions pkg/odo/cli/preference/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ func TestView(t *testing.T) {
}

prefClient.EXPECT().UpdateNotification().Return(pointer.Bool(false))
prefClient.EXPECT().NamePrefix().Return(pointer.String("aprefix"))
prefClient.EXPECT().Timeout().Return(pointer.Int(10))
prefClient.EXPECT().BuildTimeout().Return(pointer.Int(10))
prefClient.EXPECT().RegistryCacheTime().Return(pointer.Int(240))
prefClient.EXPECT().PushTimeout().Return(pointer.Int(10))
prefClient.EXPECT().EphemeralSourceVolume().Return(pointer.Bool(false))
prefClient.EXPECT().ConsentTelemetry().Return(pointer.Bool(false))
Expand Down
Loading

0 comments on commit c6eae3e

Please sign in to comment.