Skip to content

Commit 32f462e

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

File tree

2 files changed

+79
-5
lines changed

2 files changed

+79
-5
lines changed

cmd/podModify.go

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"github.com/dustin/go-humanize"
56

67
"github.com/lf-edge/eden/pkg/defaults"
78
"github.com/lf-edge/eden/pkg/expect"
@@ -11,6 +12,8 @@ import (
1112
"github.com/spf13/cobra"
1213
)
1314

15+
var podLink string
16+
1417
//podModifyCmd is a command to modify app
1518
var podModifyCmd = &cobra.Command{
1619
Use: "modify <app>",
@@ -52,9 +55,23 @@ var podModifyCmd = &cobra.Command{
5255
}
5356
opts = append(opts, expect.WithACL(acl))
5457
opts = append(opts, expect.WithOldApp(appName))
55-
expectation := expect.AppExpectationFromURL(ctrl, dev, defaults.DefaultDummyExpect, appName, opts...)
56-
appInstanceConfig := expectation.Application()
58+
opts = append(opts, expect.WithHTTPDirectLoad(directLoad))
59+
diskSizeParsed, err := humanize.ParseBytes(diskSize)
60+
if err != nil {
61+
log.Fatal(err)
62+
}
63+
opts = append(opts, expect.WithDiskSize(int64(diskSizeParsed)))
64+
link := defaults.DefaultDummyExpect
65+
newLink := false
5766
needPurge := false
67+
if podLink != "" {
68+
needPurge = true
69+
newLink = true
70+
link = podLink
71+
}
72+
volumes:=dev.GetVolumes()
73+
expectation := expect.AppExpectationFromURL(ctrl, dev, link, appName, opts...)
74+
appInstanceConfig := expectation.Application()
5875
if len(app.Interfaces) != len(appInstanceConfig.Interfaces) {
5976
needPurge = true
6077
} else {
@@ -65,14 +82,67 @@ var podModifyCmd = &cobra.Command{
6582
}
6683
}
6784
}
85+
app.Interfaces = appInstanceConfig.Interfaces
86+
if newLink {
87+
diffInDrives := true
88+
if len(app.Drives) == len(appInstanceConfig.Drives) {
89+
diffInDrives = false
90+
for i, d := range app.Drives {
91+
// check if we have difference in volumes and its images
92+
if appInstanceConfig.Drives[i].Image.Name != d.Image.Name || appInstanceConfig.Drives[i].Image.Sha256 != d.Image.Sha256 {
93+
diffInDrives = true
94+
}
95+
}
96+
}
97+
if diffInDrives {
98+
// user provides different link, so we need to purge volumes
99+
volumeIDs := dev.GetVolumes()
100+
utils.DelEleInSliceByFunction(&volumeIDs, func(i interface{}) bool {
101+
vol, err := ctrl.GetVolume(i.(string))
102+
if err != nil {
103+
log.Fatalf("no volume in cloud %s: %s", i.(string), err)
104+
}
105+
for _, volRef := range app.VolumeRefList {
106+
if vol.Uuid == volRef.Uuid {
107+
return true
108+
}
109+
}
110+
return false
111+
})
112+
for _, volRef := range appInstanceConfig.VolumeRefList {
113+
volumeIDs = append(volumeIDs, volRef.Uuid)
114+
}
115+
dev.SetVolumeConfigs(volumeIDs)
116+
app.VolumeRefList = appInstanceConfig.VolumeRefList
117+
app.Drives = appInstanceConfig.Drives
118+
} else {
119+
// we will increase generation number if user provide the same link
120+
// to run image update
121+
dev.SetVolumeConfigs(volumes)
122+
for _, ctID := range dev.GetContentTrees() {
123+
ct, err := ctrl.GetContentTree(ctID)
124+
if err != nil {
125+
log.Fatalf("no ContentTree in cloud %s: %s", ctID, err)
126+
}
127+
for _, v := range app.VolumeRefList {
128+
volumeConfig, err := ctrl.GetVolume(v.Uuid)
129+
if err != nil {
130+
log.Fatalf("no volume in cloud %s: %s", v.Uuid, err)
131+
}
132+
volumeConfig.GenerationCount++
133+
if ct.GetUuid() == volumeConfig.Origin.DownloadContentTreeID {
134+
ct.GenerationCount++
135+
}
136+
}
137+
}
138+
}
139+
}
68140
if needPurge {
69141
if app.Purge == nil {
70142
app.Purge = &config.InstanceOpsCmd{Counter: 0}
71143
}
72144
app.Purge.Counter++
73145
}
74-
//now we only change networks
75-
app.Interfaces = appInstanceConfig.Interfaces
76146
if err = changer.setControllerAndDev(ctrl, dev); err != nil {
77147
log.Fatalf("setControllerAndDev: %s", err)
78148
}
@@ -89,5 +159,8 @@ func podModifyInit() {
89159
podModifyCmd.Flags().StringSliceVarP(&portPublish, "publish", "p", nil, "Ports to publish in format EXTERNAL_PORT:INTERNAL_PORT")
90160
podModifyCmd.Flags().BoolVar(&aclOnlyHost, "only-host", false, "Allow access only to host and external networks")
91161
podModifyCmd.Flags().StringSliceVar(&podNetworks, "networks", nil, "Networks to connect to app (ports will be mapped to first network)")
162+
podModifyCmd.Flags().StringVar(&podLink, "link", "", "Set new app link for pod")
163+
podModifyCmd.Flags().StringVar(&diskSize, "disk-size", humanize.Bytes(0), "disk size (empty or 0 - same as in image)")
164+
podModifyCmd.Flags().BoolVar(&directLoad, "direct", true, "Use direct download for image instead of eserver")
92165
podModifyCmd.Flags().StringSliceVar(&acl, "acl", nil, "Allow access only to defined hosts/ips/subnets")
93166
}

pkg/expect/volume.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ func (exp *AppExpectation) driveToVolume(dr *config.Drive, numberOfDrive int, co
1414
if err != nil {
1515
log.Fatalf("no volume %s found in controller: %s", volID, err)
1616
}
17-
if el.DisplayName == fmt.Sprintf("%s_%d_m_0", contentTree.DisplayName, numberOfDrive) {
17+
if el.Origin.DownloadContentTreeID == contentTree.Uuid &&
18+
el.DisplayName == fmt.Sprintf("%s_%d_m_0", contentTree.DisplayName, numberOfDrive) {
1819
// we already have this one in controller
1920
return el
2021
}

0 commit comments

Comments
 (0)