Skip to content

Commit abaeb5f

Browse files
committed
modify pod app link support
Signed-off-by: Petr Fedchenkov <[email protected]>
1 parent ecf7086 commit abaeb5f

File tree

1 file changed

+70
-4
lines changed

1 file changed

+70
-4
lines changed

cmd/podModify.go

Lines changed: 70 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,18 @@ 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+
opts = append(opts, expect.WithHTTPDirectLoad(directLoad))
57+
link := defaults.DefaultDummyExpect
58+
newLink := false
5659
needPurge := false
60+
if podLink != "" {
61+
needPurge = true
62+
newLink = true
63+
link = podLink
64+
}
65+
volumes:=dev.GetVolumes()
66+
expectation := expect.AppExpectationFromURL(ctrl, dev, link, appName, opts...)
67+
appInstanceConfig := expectation.Application()
5768
if len(app.Interfaces) != len(appInstanceConfig.Interfaces) {
5869
needPurge = true
5970
} else {
@@ -64,14 +75,67 @@ var podModifyCmd = &cobra.Command{
6475
}
6576
}
6677
}
78+
app.Interfaces = appInstanceConfig.Interfaces
79+
if newLink {
80+
diffInDrives := true
81+
if len(app.Drives) == len(appInstanceConfig.Drives) {
82+
diffInDrives = false
83+
for i, d := range app.Drives {
84+
// check if we have difference in volumes and its images
85+
if appInstanceConfig.Drives[i].Image.Name != d.Image.Name || appInstanceConfig.Drives[i].Image.Sha256 != d.Image.Sha256 {
86+
diffInDrives = true
87+
}
88+
}
89+
}
90+
if diffInDrives {
91+
// user provides different link, so we need to purge all volumes
92+
volumeIDs := dev.GetVolumes()
93+
utils.DelEleInSliceByFunction(&volumeIDs, func(i interface{}) bool {
94+
vol, err := ctrl.GetVolume(i.(string))
95+
if err != nil {
96+
log.Fatalf("no volume in cloud %s: %s", i.(string), err)
97+
}
98+
for _, volRef := range app.VolumeRefList {
99+
if vol.Uuid == volRef.Uuid {
100+
return true
101+
}
102+
}
103+
return false
104+
})
105+
dev.SetVolumeConfigs(volumeIDs)
106+
app.VolumeRefList = appInstanceConfig.VolumeRefList
107+
app.Drives = appInstanceConfig.Drives
108+
} else {
109+
// we will increase generation number if user provide the same link
110+
// to run image update
111+
dev.SetVolumeConfigs(volumes)
112+
for _, ctID := range dev.GetContentTrees() {
113+
ct, err := ctrl.GetContentTree(ctID)
114+
if err != nil {
115+
log.Fatalf("no ContentTree in cloud %s: %s", ctID, err)
116+
}
117+
for _, v := range app.VolumeRefList {
118+
volumeConfig, err := ctrl.GetVolume(v.Uuid)
119+
if err != nil {
120+
log.Fatalf("no volume in cloud %s: %s", v.Uuid, err)
121+
}
122+
volumeConfig.GenerationCount++
123+
if ct.GetUuid() == volumeConfig.Origin.DownloadContentTreeID {
124+
ct.GenerationCount++
125+
}
126+
}
127+
}
128+
for _, v := range app.VolumeRefList {
129+
v.GenerationCount++
130+
}
131+
}
132+
}
67133
if needPurge {
68134
if app.Purge == nil {
69135
app.Purge = &config.InstanceOpsCmd{Counter: 0}
70136
}
71137
app.Purge.Counter++
72138
}
73-
//now we only change networks
74-
app.Interfaces = appInstanceConfig.Interfaces
75139
if err = changer.setControllerAndDev(ctrl, dev); err != nil {
76140
log.Fatalf("setControllerAndDev: %s", err)
77141
}
@@ -88,4 +152,6 @@ func podModifyInit() {
88152
podModifyCmd.Flags().StringSliceVarP(&portPublish, "publish", "p", nil, "Ports to publish in format EXTERNAL_PORT:INTERNAL_PORT")
89153
podModifyCmd.Flags().BoolVar(&aclOnlyHost, "only-host", false, "Allow access only to host and external networks")
90154
podModifyCmd.Flags().StringSliceVar(&podNetworks, "networks", nil, "Networks to connect to app (ports will be mapped to first network)")
155+
podModifyCmd.Flags().StringVar(&podLink, "link", "", "Set new app link for pod")
156+
podModifyCmd.Flags().BoolVar(&directLoad, "direct", true, "Use direct download for image instead of eserver")
91157
}

0 commit comments

Comments
 (0)