Skip to content

Commit febdfee

Browse files
committed
modify pod app link support
Signed-off-by: Petr Fedchenkov <giggsoff@gmail.com>
1 parent ecf7086 commit febdfee

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

cmd/podModify.go

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/spf13/cobra"
1212
)
1313

14+
var podLink string
15+
1416
//podModifyCmd is a command to modify app
1517
var podModifyCmd = &cobra.Command{
1618
Use: "modify",
@@ -51,9 +53,31 @@ var podModifyCmd = &cobra.Command{
5153
opts = append(opts, expect.WithPortsPublish(portPublish))
5254
}
5355
opts = append(opts, expect.WithOldApp(appName))
54-
expectation := expect.AppExpectationFromURL(ctrl, dev, defaults.DefaultDummyExpect, appName, opts...)
55-
appInstanceConfig := expectation.Application()
56+
link := defaults.DefaultDummyExpect
57+
newLink := false
5658
needPurge := false
59+
if podLink != "" {
60+
needPurge = true
61+
newLink = true
62+
link = podLink
63+
volumeIDs := dev.GetVolumes()
64+
// we need to purge old volumes from controller
65+
utils.DelEleInSliceByFunction(&volumeIDs, func(i interface{}) bool {
66+
vol, err := ctrl.GetVolume(i.(string))
67+
if err != nil {
68+
log.Fatalf("no volume in cloud %s: %s", i.(string), err)
69+
}
70+
for _, volRef := range app.VolumeRefList {
71+
if vol.Uuid == volRef.Uuid {
72+
return true
73+
}
74+
}
75+
return false
76+
})
77+
dev.SetVolumeConfigs(volumeIDs)
78+
}
79+
expectation := expect.AppExpectationFromURL(ctrl, dev, link, appName, opts...)
80+
appInstanceConfig := expectation.Application()
5781
if len(app.Interfaces) != len(appInstanceConfig.Interfaces) {
5882
needPurge = true
5983
} else {
@@ -64,14 +88,17 @@ var podModifyCmd = &cobra.Command{
6488
}
6589
}
6690
}
91+
app.Interfaces = appInstanceConfig.Interfaces
92+
if newLink {
93+
app.VolumeRefList = appInstanceConfig.VolumeRefList
94+
app.Drives = appInstanceConfig.Drives
95+
}
6796
if needPurge {
6897
if app.Purge == nil {
6998
app.Purge = &config.InstanceOpsCmd{Counter: 0}
7099
}
71100
app.Purge.Counter++
72101
}
73-
//now we only change networks
74-
app.Interfaces = appInstanceConfig.Interfaces
75102
if err = changer.setControllerAndDev(ctrl, dev); err != nil {
76103
log.Fatalf("setControllerAndDev: %s", err)
77104
}
@@ -88,4 +115,5 @@ func podModifyInit() {
88115
podModifyCmd.Flags().StringSliceVarP(&portPublish, "publish", "p", nil, "Ports to publish in format EXTERNAL_PORT:INTERNAL_PORT")
89116
podModifyCmd.Flags().BoolVar(&aclOnlyHost, "only-host", false, "Allow access only to host and external networks")
90117
podModifyCmd.Flags().StringSliceVar(&podNetworks, "networks", nil, "Networks to connect to app (ports will be mapped to first network)")
118+
podModifyCmd.Flags().StringVar(&podLink, "link", "", "Set new app link for pod")
91119
}

0 commit comments

Comments
 (0)