Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] modify pod app link support #545

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 77 additions & 4 deletions cmd/podModify.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/dustin/go-humanize"

"github.com/lf-edge/eden/pkg/defaults"
"github.com/lf-edge/eden/pkg/expect"
Expand All @@ -11,6 +12,8 @@ import (
"github.com/spf13/cobra"
)

var podLink string

//podModifyCmd is a command to modify app
var podModifyCmd = &cobra.Command{
Use: "modify <app>",
Expand Down Expand Up @@ -52,9 +55,23 @@ var podModifyCmd = &cobra.Command{
}
opts = append(opts, expect.WithACL(acl))
opts = append(opts, expect.WithOldApp(appName))
expectation := expect.AppExpectationFromURL(ctrl, dev, defaults.DefaultDummyExpect, appName, opts...)
appInstanceConfig := expectation.Application()
opts = append(opts, expect.WithHTTPDirectLoad(directLoad))
diskSizeParsed, err := humanize.ParseBytes(diskSize)
if err != nil {
log.Fatal(err)
}
opts = append(opts, expect.WithDiskSize(int64(diskSizeParsed)))
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 @@ -65,14 +82,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 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
})
for _, volRef := range appInstanceConfig.VolumeRefList {
volumeIDs = append(volumeIDs, volRef.Uuid)
}
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++
}
}
}
}
}
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 @@ -89,5 +159,8 @@ 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().StringVar(&diskSize, "disk-size", humanize.Bytes(0), "disk size (empty or 0 - same as in image)")
podModifyCmd.Flags().BoolVar(&directLoad, "direct", true, "Use direct download for image instead of eserver")
podModifyCmd.Flags().StringSliceVar(&acl, "acl", nil, "Allow access only to defined hosts/ips/subnets")
}
3 changes: 2 additions & 1 deletion pkg/expect/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func (exp *AppExpectation) driveToVolume(dr *config.Drive, numberOfDrive int, co
if err != nil {
log.Fatalf("no volume %s found in controller: %s", volID, err)
}
if el.DisplayName == fmt.Sprintf("%s_%d_m_0", contentTree.DisplayName, numberOfDrive) {
if el.Origin.DownloadContentTreeID == contentTree.Uuid &&
el.DisplayName == fmt.Sprintf("%s_%d_m_0", contentTree.DisplayName, numberOfDrive) {
// we already have this one in controller
return el
}
Expand Down