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

Updating url delete to apply --now on devfile #3139

Merged
12 changes: 11 additions & 1 deletion pkg/odo/cli/component/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,19 @@ func NewPushOptions() *PushOptions {
}
}

// CompleteDevfilePath completes the devfile path from context
func (po *PushOptions) CompleteDevfilePath() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is something that should be more common. But unsure where to put it so keeping it here for now. If anyone has suggessions please provide them :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not do it like url create? https://github.com/openshift/odo/blob/e08aa97dad5a5c27564e0f08cb46600f8f52d540/pkg/odo/cli/url/create.go#L324
Because odo delete doesn't seem to have the devfile path flag like create.

Flags:
      --context string   Use given context directory as a source for component settings
  -f, --force            Delete url without prompting
  -h, --help             Help for delete
      --now              Push changes to the cluster immediately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it does not have the devfile flag, Do you mean to say add devfile flag to delete as well. Ok, i guess we could do that

if len(po.DevfilePath) > 0 {
po.DevfilePath = filepath.Join(po.componentContext, po.DevfilePath)
} else {
po.DevfilePath = filepath.Join(po.componentContext, "devfile.yaml")
}
}

// Complete completes push args
func (po *PushOptions) Complete(name string, cmd *cobra.Command, args []string) (err error) {
po.DevfilePath = filepath.Join(po.componentContext, DevfilePath)
po.CompleteDevfilePath()

// if experimental mode is enabled and devfile is present
if experimental.IsExperimentalModeEnabled() && util.CheckPathExists(po.DevfilePath) {
envInfo, err := envinfo.NewEnvSpecificInfo(po.componentContext)
Expand Down
19 changes: 15 additions & 4 deletions pkg/odo/cli/url/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,29 @@ var (

// URLDeleteOptions encapsulates the options for the odo url delete command
type URLDeleteOptions struct {
*clicomponent.CommonPushOptions
*clicomponent.PushOptions
urlName string
urlForceDeleteFlag bool
now bool
}

// NewURLDeleteOptions creates a new URLDeleteOptions instance
func NewURLDeleteOptions() *URLDeleteOptions {
return &URLDeleteOptions{CommonPushOptions: clicomponent.NewCommonPushOptions()}
return &URLDeleteOptions{PushOptions: clicomponent.NewPushOptions()}
}

// Complete completes URLDeleteOptions after they've been Deleted
func (o *URLDeleteOptions) Complete(name string, cmd *cobra.Command, args []string) (err error) {

if experimental.IsExperimentalModeEnabled() {

o.Context = genericclioptions.NewDevfileContext(cmd)
o.urlName = args[0]
err = o.InitEnvInfoFromContext()
if err != nil {
return err
}
o.CompleteDevfilePath()
} else {
if o.now {
o.Context = genericclioptions.NewContextCreatingAppIfNeeded(cmd)
Expand Down Expand Up @@ -114,8 +117,15 @@ func (o *URLDeleteOptions) Run() (err error) {
if err != nil {
return err
}
log.Successf("URL %s removed from the env file", o.urlName)
log.Italic("\nTo delete the URL on the cluster, please use `odo push`")
if o.now {
err = o.DevfilePush()
if err != nil {
return err
}
} else {
log.Successf("URL %s removed from the env file", o.urlName)
log.Italic("\nTo delete the URL on the cluster, please use `odo push`")
}
} else {
err = o.LocalConfigInfo.DeleteURL(o.urlName)
if err != nil {
Expand Down Expand Up @@ -152,6 +162,7 @@ func NewCmdURLDelete(name, fullName string) *cobra.Command {
}
urlDeleteCmd.Flags().BoolVarP(&o.urlForceDeleteFlag, "force", "f", false, "Delete url without prompting")
o.AddContextFlag(urlDeleteCmd)
urlDeleteCmd.Flags().StringVar(&o.DevfilePath, "devfile", "./devfile.yaml", "Path to a devfile.yaml")
genericclioptions.AddNowFlag(urlDeleteCmd, &o.now)
completion.RegisterCommandHandler(urlDeleteCmd, completion.URLCompletionHandler)
completion.RegisterCommandFlagHandler(urlDeleteCmd, "context", completion.FileCompletionHandler)
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/devfile/cmd_devfile_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var _ = Describe("odo devfile url command tests", func() {
Expect(stdout).To(ContainSubstring("no URLs found"))
})

It("create with now flag should pass", func() {
It("create and delete with now flag should pass", func() {
var stdout string
url1 := helper.RandString(5)
host := helper.RandString(5) + ".com"
Expand All @@ -159,6 +159,8 @@ var _ = Describe("odo devfile url command tests", func() {

stdout = helper.CmdShouldPass("odo", "url", "create", url1, "--port", "3000", "--host", host, "--now", "--ingress")
helper.MatchAllInOutput(stdout, []string{"URL " + url1 + " created for component", "http:", url1 + "." + host})
stdout = helper.CmdShouldPass("odo", "url", "delete", url1, "--now", "-f")
helper.MatchAllInOutput(stdout, []string{"URL " + url1 + " successfully deleted", "Applying URL changes"})
})

It("should create a automatically route on a openShift cluster", func() {
Expand Down