diff --git a/cmd/podModify.go b/cmd/podModify.go index 24f381ee0..5cd8d94ab 100644 --- a/cmd/podModify.go +++ b/cmd/podModify.go @@ -11,6 +11,8 @@ import ( "github.com/spf13/cobra" ) +var podLink string + //podModifyCmd is a command to modify app var podModifyCmd = &cobra.Command{ Use: "modify", @@ -51,9 +53,31 @@ var podModifyCmd = &cobra.Command{ opts = append(opts, expect.WithPortsPublish(portPublish)) } opts = append(opts, expect.WithOldApp(appName)) - expectation := expect.AppExpectationFromURL(ctrl, dev, defaults.DefaultDummyExpect, appName, opts...) - appInstanceConfig := expectation.Application() + link := defaults.DefaultDummyExpect + newLink := false needPurge := false + if podLink != "" { + needPurge = true + newLink = true + link = podLink + volumeIDs := dev.GetVolumes() + // we need to purge old volumes from controller + utils.DelEleInSliceByFunction(&volumeIDs, func(i interface{}) bool { + vol, err := ctrl.GetVolume(i.(string)) + if err != nil { + log.Fatalf("no volume in cloud %s: %s", i.(string), err) + } + for _, volRef := range app.VolumeRefList { + if vol.Uuid == volRef.Uuid { + return true + } + } + return false + }) + dev.SetVolumeConfigs(volumeIDs) + } + expectation := expect.AppExpectationFromURL(ctrl, dev, link, appName, opts...) + appInstanceConfig := expectation.Application() if len(app.Interfaces) != len(appInstanceConfig.Interfaces) { needPurge = true } else { @@ -64,14 +88,17 @@ var podModifyCmd = &cobra.Command{ } } } + app.Interfaces = appInstanceConfig.Interfaces + if newLink { + app.VolumeRefList = appInstanceConfig.VolumeRefList + app.Drives = appInstanceConfig.Drives + } if needPurge { if app.Purge == nil { app.Purge = &config.InstanceOpsCmd{Counter: 0} } app.Purge.Counter++ } - //now we only change networks - app.Interfaces = appInstanceConfig.Interfaces if err = changer.setControllerAndDev(ctrl, dev); err != nil { log.Fatalf("setControllerAndDev: %s", err) } @@ -88,4 +115,5 @@ func podModifyInit() { podModifyCmd.Flags().StringSliceVarP(&portPublish, "publish", "p", nil, "Ports to publish in format EXTERNAL_PORT:INTERNAL_PORT") podModifyCmd.Flags().BoolVar(&aclOnlyHost, "only-host", false, "Allow access only to host and external networks") podModifyCmd.Flags().StringSliceVar(&podNetworks, "networks", nil, "Networks to connect to app (ports will be mapped to first network)") + podModifyCmd.Flags().StringVar(&podLink, "link", "", "Set new app link for pod") }