Skip to content

Commit

Permalink
modify pod app link support
Browse files Browse the repository at this point in the history
Signed-off-by: Petr Fedchenkov <[email protected]>
  • Loading branch information
giggsoff committed Mar 3, 2021
1 parent ecf7086 commit febdfee
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions cmd/podModify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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")
}

0 comments on commit febdfee

Please sign in to comment.