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

Odo v3: Move odo registry to odo preference registry, remove unused pref. settings #5428

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
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
15 changes: 5 additions & 10 deletions pkg/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,12 @@ 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()
// Create a random generated name for the component to use within Kubernetes
prefix, err = GetComponentDir(componentPath)
if err != nil {
return "", errors.Wrap(err, "unable to generate random component name")
}
prefix = util.TruncateString(prefix, componentRandomNamePartsMaxLen)

// 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 @@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"

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/clientset"
"github.com/zalando/go-keyring"
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"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"

Expand Down
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"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
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"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
Expand Down
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"
"github.com/redhat-developer/odo/pkg/odo/genericclioptions/clientset"
Expand Down
7 changes: 3 additions & 4 deletions pkg/odo/cli/preference/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,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 @@ -88,7 +87,7 @@ func NewCmdSet(name, fullName string) *cobra.Command {
o := NewSetOptions()
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 {
prefClient, err := preference.NewClient()
Expand Down
5 changes: 2 additions & 3 deletions pkg/odo/cli/preference/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ 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)
}
// Just show one example of how to unset a value.
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 @@ -17,7 +17,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 @@ -58,10 +58,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.clientset.PreferenceClient.UpdateNotification()))
fmt.Fprintln(w, "NamePrefix", "\t", showBlankIfNil(o.clientset.PreferenceClient.NamePrefix()))
fmt.Fprintln(w, "Timeout", "\t", showBlankIfNil(o.clientset.PreferenceClient.Timeout()))
fmt.Fprintln(w, "BuildTimeout", "\t", showBlankIfNil(o.clientset.PreferenceClient.BuildTimeout()))
fmt.Fprintln(w, "PushTimeout", "\t", showBlankIfNil(o.clientset.PreferenceClient.PushTimeout()))
fmt.Fprintln(w, "RegistryCacheTime", "\t", showBlankIfNil(o.clientset.PreferenceClient.RegistryCacheTime()))
fmt.Fprintln(w, "Ephemeral", "\t", showBlankIfNil(o.clientset.PreferenceClient.EphemeralSourceVolume()))
fmt.Fprintln(w, "ConsentTelemetry", "\t", showBlankIfNil(o.clientset.PreferenceClient.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 @@ -36,9 +36,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
53 changes: 14 additions & 39 deletions pkg/preference/implem.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ type odoSettings struct {
// Controls if an update notification is shown or not
UpdateNotification *bool `yaml:"UpdateNotification,omitempty"`

// Holds the prefix part of generated random application name
NamePrefix *string `yaml:"NamePrefix,omitempty"`

// Timeout for OpenShift server connection check
Timeout *int `yaml:"Timeout,omitempty"`

// BuildTimeout for OpenShift build timeout check
BuildTimeout *int `yaml:"BuildTimeout,omitempty"`

// PushTimeout for OpenShift pod timeout check
PushTimeout *int `yaml:"PushTimeout,omitempty"`

Expand Down Expand Up @@ -266,16 +260,6 @@ func (c *preferenceInfo) SetConfiguration(parameter string, value string) error
}
c.OdoSettings.Timeout = &typedval

case "buildtimeout":
typedval, err := strconv.Atoi(value)
if err != nil {
return errors.Errorf("unable to set %q to %q, value must be an integer", parameter, value)
}
if typedval < 0 {
return errors.Errorf("cannot set timeout to less than 0")
}
c.OdoSettings.BuildTimeout = &typedval

case "pushtimeout":
typedval, err := strconv.Atoi(value)
if err != nil {
Expand Down Expand Up @@ -303,10 +287,6 @@ func (c *preferenceInfo) SetConfiguration(parameter string, value string) error
}
c.OdoSettings.UpdateNotification = &val

// TODO: should we add a validator here? What is the use of nameprefix?
case "nameprefix":
c.OdoSettings.NamePrefix = &value

case "ephemeral":
val, err := strconv.ParseBool(strings.ToLower(value))
if err != nil {
Expand Down Expand Up @@ -363,12 +343,6 @@ func (c *preferenceInfo) GetTimeout() int {
return util.GetIntOrDefault(c.OdoSettings.Timeout, DefaultTimeout)
}

// GetBuildTimeout gets the value set by BuildTimeout
func (c *preferenceInfo) GetBuildTimeout() int {
// default timeout value is 300
return util.GetIntOrDefault(c.OdoSettings.BuildTimeout, DefaultBuildTimeout)
}

// GetPushTimeout gets the value set by PushTimeout
func (c *preferenceInfo) GetPushTimeout() int {
// default timeout value is 1
Expand All @@ -389,13 +363,7 @@ func (c *preferenceInfo) GetUpdateNotification() bool {
// GetEphemeralSourceVolume returns the value of ephemeral from preferences
// and if absent then returns default
func (c *preferenceInfo) GetEphemeralSourceVolume() bool {
return util.GetBoolOrDefault(c.OdoSettings.Ephemeral, DefaultEphemeralSettings)
}

// GetNamePrefix returns the value of Prefix from preferences
// and if absent then returns default
func (c *preferenceInfo) GetNamePrefix() string {
return util.GetStringOrEmpty(c.OdoSettings.NamePrefix)
return util.GetBoolOrDefault(c.OdoSettings.Ephemeral, DefaultEphemeralSetting)
}

// GetConsentTelemetry returns the value of ConsentTelemetry from preferences
Expand All @@ -405,26 +373,33 @@ func (c *preferenceInfo) GetConsentTelemetry() bool {
return util.GetBoolOrDefault(c.OdoSettings.ConsentTelemetry, DefaultConsentTelemetrySetting)
}

// GetEphemeral returns the value of Ephemeral from preferences
// and if absent then returns default
// default value: true, ephemeral is enabled by default
func (c *preferenceInfo) GetEphemeral() bool {
return util.GetBoolOrDefault(c.OdoSettings.Ephemeral, DefaultEphemeralSetting)
}

func (c *preferenceInfo) UpdateNotification() *bool {
return c.OdoSettings.UpdateNotification
}

func (c *preferenceInfo) NamePrefix() *string {
return c.OdoSettings.NamePrefix
func (c *preferenceInfo) Ephemeral() *bool {
return c.OdoSettings.Ephemeral
}

func (c *preferenceInfo) Timeout() *int {
return c.OdoSettings.Timeout
}

func (c *preferenceInfo) BuildTimeout() *int {
return c.OdoSettings.BuildTimeout
}

func (c *preferenceInfo) PushTimeout() *int {
return c.OdoSettings.PushTimeout
}

func (c *preferenceInfo) RegistryCacheTime() *int {
return c.OdoSettings.RegistryCacheTime
}

func (c *preferenceInfo) EphemeralSourceVolume() *bool {
return c.OdoSettings.Ephemeral
}
Expand Down
Loading