From d72ddb7a659bf89f47a42057aa52ddd199993ed6 Mon Sep 17 00:00:00 2001 From: Charlie Drage Date: Fri, 7 Aug 2020 11:27:10 -0400 Subject: [PATCH] Make Devfile the default deployment mechanism for odo (#3691) * Update to 1.1.5 image (#3688) **What type of PR is this?** > Uncomment only one ` /kind` line, and delete the rest. > For example, `> /kind bug` would simply become: `/kind bug` /kind feature **What does does this PR do / why we need it**: Updates to 1.1.5 odo-init-image. **Which issue(s) this PR fixes**: N/A **PR acceptance criteria**: N/A **How to test changes / Special notes to the reviewer**: N/A Signed-off-by: Charlie Drage * Release 1.2.5 (#3689) **What type of PR is this?** > Uncomment only one ` /kind` line, and delete the rest. > For example, `> /kind bug` would simply become: `/kind bug` /kind feature **What does does this PR do / why we need it**: Release 1.2.5 of odo **Which issue(s) this PR fixes**: N/A **PR acceptance criteria**: N/A **How to test changes / Special notes to the reviewer**: N/A Signed-off-by: Charlie Drage * added --s2i flag for `odo create` command * corrected error messages * Corrected flag description and validation * added --s2i flag for `odo create` command * Make Devfile the default deployment mechanism for odo **What type of PR is this?** > Uncomment only one ` /kind` line, and delete the rest. > For example, `> /kind bug` would simply become: `/kind bug` /kind feature **What does does this PR do / why we need it**: Makes Devfile the default deployment mechanism, removing S2I in favour of Devfile deployment. **Which issue(s) this PR fixes**: Closes https://github.com/openshift/odo/issues/3550 **How to test changes / Special notes to the reviewer**: Run: ```sh odo preference set experimental false odo create --starter nodejs odo push ``` Co-authored-by: Devang Gaur --- pkg/component/component_full_description.go | 4 +-- pkg/odo/cli/component/create.go | 34 +++++++++++++++------ pkg/odo/cli/component/delete.go | 9 ++---- pkg/odo/cli/service/create.go | 2 +- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/pkg/component/component_full_description.go b/pkg/component/component_full_description.go index 65f8e49a9f1..926a8cdbe83 100644 --- a/pkg/component/component_full_description.go +++ b/pkg/component/component_full_description.go @@ -189,8 +189,8 @@ func (cfd *ComponentFullDescription) Print(client *occlient.Client) error { if len(cfd.Spec.URL.Items) > 0 { var output string - // For S2I Only.. - // if the component is not pushed + // FOR S2I ONLY. + // This part *needs* to be edited before merge.. This will still try to output S2I info for i, componentURL := range cfd.Spec.URL.Items { if componentURL.Status.State == urlpkg.StateTypePushed { output += fmt.Sprintf(" ยท %v exposed via %v\n", urlpkg.GetURLString(componentURL.Spec.Protocol, componentURL.Spec.Host, "", true), componentURL.Spec.Port) diff --git a/pkg/odo/cli/component/create.go b/pkg/odo/cli/component/create.go index c5379eb22c2..09c53c273bc 100644 --- a/pkg/odo/cli/component/create.go +++ b/pkg/odo/cli/component/create.go @@ -391,6 +391,9 @@ func (co *CreateOptions) Complete(name string, cmd *cobra.Command, args []string // Validate user specify devfile path if co.devfileMetadata.devfilePath.value != "" { + if co.forceS2i { + return errors.New("You can't set --s2i flag as true if you want to use the devfile that is specified via --devfile") + } fileErr := util.ValidateFile(co.devfileMetadata.devfilePath.value) urlErr := util.ValidateURL(co.devfileMetadata.devfilePath.value) if fileErr != nil && urlErr != nil { @@ -405,6 +408,10 @@ func (co *CreateOptions) Complete(name string, cmd *cobra.Command, args []string // Validate user specify registry if co.devfileMetadata.devfileRegistry.Name != "" { + if co.forceS2i { + return errors.New("You can't specify registry via --registry if you want to force the S2I build with --s2i") + } + if co.devfileMetadata.devfilePath.value != "" { return errors.New("you can't specify registry via --registry if you want to use the devfile that is specified via --devfile") } @@ -1019,6 +1026,23 @@ func (co *CreateOptions) Run() (err error) { } } + if !util.CheckPathExists(DevfilePath) { + // Download devfile from registry + params := util.DownloadParams{ + Request: util.HTTPRequestParams{ + URL: co.devfileMetadata.devfileRegistry.URL + co.devfileMetadata.devfileLink, + }, + Filepath: DevfilePath, + } + if registryUtil.IsSecure(co.devfileMetadata.devfileRegistry.Name) { + token, err := keyring.Get(util.CredentialPrefix+co.devfileMetadata.devfileRegistry.Name, "default") + if err != nil { + return errors.Wrap(err, "unable to get secure registry credential from keyring") + } + params.Request.Token = token + } + } + if !util.CheckPathExists(DevfilePath) { // Download devfile from registry params := util.DownloadParams{ @@ -1067,11 +1091,6 @@ func (co *CreateOptions) Run() (err error) { return err } - err = util.AddFileToIgnoreFile(ignoreFile, filepath.Join(co.componentContext, envDir)) - if err != nil { - return err - } - log.Italic("\nPlease use `odo push` command to create the component with source deployed") return nil } @@ -1162,11 +1181,6 @@ func NewCmdCreate(name, fullName string) *cobra.Command { componentCreateCmd.Flags().StringSliceVarP(&co.componentPorts, "port", "p", []string{}, "Ports to be used when the component is created (ex. 8080,8100/tcp,9100/udp)") componentCreateCmd.Flags().StringSliceVar(&co.componentEnvVars, "env", []string{}, "Environmental variables for the component. For example --env VariableName=Value") - componentCreateCmd.Flags().StringVar(&co.devfileMetadata.starter, "starter", "", "Download a project specified in the devfile") - componentCreateCmd.Flags().Lookup("starter").NoOptDefVal = defaultProjectName //Default value to pass to the flag if one is not specified. - componentCreateCmd.Flags().StringVar(&co.devfileMetadata.devfileRegistry.Name, "registry", "", "Create devfile component from specific registry") - componentCreateCmd.Flags().StringVar(&co.devfileMetadata.devfilePath.value, "devfile", "", "Path to the user specify devfile") - componentCreateCmd.Flags().StringVar(&co.devfileMetadata.token, "token", "", "Token to be used when downloading devfile from the devfile path that is specified via --devfile") componentCreateCmd.Flags().StringVar(&co.devfileMetadata.starter, "starter", "", "Download a project specified in the devfile") componentCreateCmd.Flags().Lookup("starter").NoOptDefVal = defaultProjectName //Default value to pass to the flag if one is not specified. componentCreateCmd.Flags().StringVar(&co.devfileMetadata.devfileRegistry.Name, "registry", "", "Create devfile component from specific registry") diff --git a/pkg/odo/cli/component/delete.go b/pkg/odo/cli/component/delete.go index a7c2819ccdd..587626c7805 100644 --- a/pkg/odo/cli/component/delete.go +++ b/pkg/odo/cli/component/delete.go @@ -78,7 +78,7 @@ func (do *DeleteOptions) Complete(name string, cmd *cobra.Command, args []string do.devfilePath = filepath.Join(do.componentContext, DevfilePath) ConfigFilePath = filepath.Join(do.componentContext, configFile) - // if experimental mode is enabled and devfile is present + // If devfile is present if !do.componentDeleteS2iFlag && util.CheckPathExists(do.devfilePath) { do.EnvSpecificInfo, err = envinfo.NewEnvSpecificInfo(do.componentContext) if err != nil { @@ -103,7 +103,7 @@ func (do *DeleteOptions) Complete(name string, cmd *cobra.Command, args []string // Validate validates the list parameters func (do *DeleteOptions) Validate() (err error) { - // if experimental mode is enabled and devfile is present + // If devfile is present if !do.componentDeleteS2iFlag && util.CheckPathExists(do.devfilePath) { return nil } @@ -311,10 +311,7 @@ func NewCmdDelete(name, fullName string) *cobra.Command { componentDeleteCmd.Flags().BoolVarP(&do.componentDeleteWaitFlag, "wait", "w", false, "Wait for complete deletion of component and its dependent") componentDeleteCmd.Flags().BoolVarP(&do.componentDeleteS2iFlag, "s2i", "", false, "Delete s2i component if devfile and s2i both component present with same name") - // enable show flag if experimental mode is enabled - if experimental.IsExperimentalModeEnabled() { - componentDeleteCmd.Flags().BoolVar(&do.show, "show-log", false, "If enabled, logs will be shown when deleted") - } + componentDeleteCmd.Flags().BoolVar(&do.show, "show-log", false, "If enabled, logs will be shown when deleted") componentDeleteCmd.SetUsageTemplate(odoutil.CmdUsageTemplate) completion.RegisterCommandHandler(componentDeleteCmd, completion.ComponentNameCompletionHandler) diff --git a/pkg/odo/cli/service/create.go b/pkg/odo/cli/service/create.go index b6849c09a3e..d723a491e5f 100644 --- a/pkg/odo/cli/service/create.go +++ b/pkg/odo/cli/service/create.go @@ -522,7 +522,7 @@ func NewCmdServiceCreate(name, fullName string) *cobra.Command { serviceCreateCmd.Use += fmt.Sprintf(" [flags]\n %s / [service_name] [flags]", o.CmdFullName) serviceCreateCmd.Short = createShortDescExperimental serviceCreateCmd.Long = createLongDescExperimental - serviceCreateCmd.Example += fmt.Sprintf("\n\n") + fmt.Sprintf(createOperatorExample, fullName) + serviceCreateCmd.Example += "\n\n" + fmt.Sprintf(createOperatorExample, fullName) serviceCreateCmd.Flags().BoolVar(&o.DryRun, "dry-run", false, "Print the yaml specificiation that will be used to create the service") // remove this feature after enabling service create interactive mode for operator backed services serviceCreateCmd.Flags().StringVar(&o.fromFile, "from-file", "", "Path to the file containing yaml specification to use to start operator backed service")