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 4, 2021
1 parent ecf7086 commit abaeb5f
Showing 1 changed file with 70 additions and 4 deletions.
74 changes: 70 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,18 @@ 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()
opts = append(opts, expect.WithHTTPDirectLoad(directLoad))
link := defaults.DefaultDummyExpect
newLink := false
needPurge := false
if podLink != "" {
needPurge = true
newLink = true
link = podLink
}
volumes:=dev.GetVolumes()
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 +75,67 @@ var podModifyCmd = &cobra.Command{
}
}
}
app.Interfaces = appInstanceConfig.Interfaces
if newLink {
diffInDrives := true
if len(app.Drives) == len(appInstanceConfig.Drives) {
diffInDrives = false
for i, d := range app.Drives {
// check if we have difference in volumes and its images
if appInstanceConfig.Drives[i].Image.Name != d.Image.Name || appInstanceConfig.Drives[i].Image.Sha256 != d.Image.Sha256 {
diffInDrives = true
}
}
}
if diffInDrives {
// user provides different link, so we need to purge all volumes
volumeIDs := dev.GetVolumes()
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)
app.VolumeRefList = appInstanceConfig.VolumeRefList
app.Drives = appInstanceConfig.Drives
} else {
// we will increase generation number if user provide the same link
// to run image update
dev.SetVolumeConfigs(volumes)
for _, ctID := range dev.GetContentTrees() {
ct, err := ctrl.GetContentTree(ctID)
if err != nil {
log.Fatalf("no ContentTree in cloud %s: %s", ctID, err)
}
for _, v := range app.VolumeRefList {
volumeConfig, err := ctrl.GetVolume(v.Uuid)
if err != nil {
log.Fatalf("no volume in cloud %s: %s", v.Uuid, err)
}
volumeConfig.GenerationCount++
if ct.GetUuid() == volumeConfig.Origin.DownloadContentTreeID {
ct.GenerationCount++
}
}
}
for _, v := range app.VolumeRefList {
v.GenerationCount++
}
}
}
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 +152,6 @@ 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")
podModifyCmd.Flags().BoolVar(&directLoad, "direct", true, "Use direct download for image instead of eserver")
}

0 comments on commit abaeb5f

Please sign in to comment.