Skip to content

Commit a44ca22

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

File tree

1 file changed

+67
-4
lines changed

1 file changed

+67
-4
lines changed

cmd/podModify.go

Lines changed: 67 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 <app>",
@@ -52,9 +54,18 @@ var podModifyCmd = &cobra.Command{
5254
}
5355
opts = append(opts, expect.WithACL(acl))
5456
opts = append(opts, expect.WithOldApp(appName))
55-
expectation := expect.AppExpectationFromURL(ctrl, dev, defaults.DefaultDummyExpect, appName, opts...)
56-
appInstanceConfig := expectation.Application()
57+
opts = append(opts, expect.WithHTTPDirectLoad(directLoad))
58+
link := defaults.DefaultDummyExpect
59+
newLink := false
5760
needPurge := false
61+
if podLink != "" {
62+
needPurge = true
63+
newLink = true
64+
link = podLink
65+
}
66+
volumes:=dev.GetVolumes()
67+
expectation := expect.AppExpectationFromURL(ctrl, dev, link, appName, opts...)
68+
appInstanceConfig := expectation.Application()
5869
if len(app.Interfaces) != len(appInstanceConfig.Interfaces) {
5970
needPurge = true
6071
} else {
@@ -65,14 +76,64 @@ var podModifyCmd = &cobra.Command{
6576
}
6677
}
6778
}
79+
app.Interfaces = appInstanceConfig.Interfaces
80+
if newLink {
81+
diffInDrives := true
82+
if len(app.Drives) == len(appInstanceConfig.Drives) {
83+
diffInDrives = false
84+
for i, d := range app.Drives {
85+
// check if we have difference in volumes and its images
86+
if appInstanceConfig.Drives[i].Image.Name != d.Image.Name || appInstanceConfig.Drives[i].Image.Sha256 != d.Image.Sha256 {
87+
diffInDrives = true
88+
}
89+
}
90+
}
91+
if diffInDrives {
92+
// user provides different link, so we need to purge all volumes
93+
volumeIDs := dev.GetVolumes()
94+
utils.DelEleInSliceByFunction(&volumeIDs, func(i interface{}) bool {
95+
vol, err := ctrl.GetVolume(i.(string))
96+
if err != nil {
97+
log.Fatalf("no volume in cloud %s: %s", i.(string), err)
98+
}
99+
for _, volRef := range app.VolumeRefList {
100+
if vol.Uuid == volRef.Uuid {
101+
return true
102+
}
103+
}
104+
return false
105+
})
106+
dev.SetVolumeConfigs(volumeIDs)
107+
app.VolumeRefList = appInstanceConfig.VolumeRefList
108+
app.Drives = appInstanceConfig.Drives
109+
} else {
110+
// we will increase generation number if user provide the same link
111+
// to run image update
112+
dev.SetVolumeConfigs(volumes)
113+
for _, ctID := range dev.GetContentTrees() {
114+
ct, err := ctrl.GetContentTree(ctID)
115+
if err != nil {
116+
log.Fatalf("no ContentTree in cloud %s: %s", ctID, err)
117+
}
118+
for _, v := range app.VolumeRefList {
119+
volumeConfig, err := ctrl.GetVolume(v.Uuid)
120+
if err != nil {
121+
log.Fatalf("no volume in cloud %s: %s", v.Uuid, err)
122+
}
123+
volumeConfig.GenerationCount++
124+
if ct.GetUuid() == volumeConfig.Origin.DownloadContentTreeID {
125+
ct.GenerationCount++
126+
}
127+
}
128+
}
129+
}
130+
}
68131
if needPurge {
69132
if app.Purge == nil {
70133
app.Purge = &config.InstanceOpsCmd{Counter: 0}
71134
}
72135
app.Purge.Counter++
73136
}
74-
//now we only change networks
75-
app.Interfaces = appInstanceConfig.Interfaces
76137
if err = changer.setControllerAndDev(ctrl, dev); err != nil {
77138
log.Fatalf("setControllerAndDev: %s", err)
78139
}
@@ -89,5 +150,7 @@ func podModifyInit() {
89150
podModifyCmd.Flags().StringSliceVarP(&portPublish, "publish", "p", nil, "Ports to publish in format EXTERNAL_PORT:INTERNAL_PORT")
90151
podModifyCmd.Flags().BoolVar(&aclOnlyHost, "only-host", false, "Allow access only to host and external networks")
91152
podModifyCmd.Flags().StringSliceVar(&podNetworks, "networks", nil, "Networks to connect to app (ports will be mapped to first network)")
153+
podModifyCmd.Flags().StringVar(&podLink, "link", "", "Set new app link for pod")
154+
podModifyCmd.Flags().BoolVar(&directLoad, "direct", true, "Use direct download for image instead of eserver")
92155
podModifyCmd.Flags().StringSliceVar(&acl, "acl", nil, "Allow access only to defined hosts/ips/subnets")
93156
}

0 commit comments

Comments
 (0)