@@ -2,6 +2,7 @@ package cmd
2
2
3
3
import (
4
4
"fmt"
5
+ "github.com/dustin/go-humanize"
5
6
6
7
"github.com/lf-edge/eden/pkg/defaults"
7
8
"github.com/lf-edge/eden/pkg/expect"
@@ -11,6 +12,8 @@ import (
11
12
"github.com/spf13/cobra"
12
13
)
13
14
15
+ var podLink string
16
+
14
17
//podModifyCmd is a command to modify app
15
18
var podModifyCmd = & cobra.Command {
16
19
Use : "modify <app>" ,
@@ -52,9 +55,23 @@ var podModifyCmd = &cobra.Command{
52
55
}
53
56
opts = append (opts , expect .WithACL (acl ))
54
57
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
57
66
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 ()
58
75
if len (app .Interfaces ) != len (appInstanceConfig .Interfaces ) {
59
76
needPurge = true
60
77
} else {
@@ -65,14 +82,67 @@ var podModifyCmd = &cobra.Command{
65
82
}
66
83
}
67
84
}
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
+ }
68
140
if needPurge {
69
141
if app .Purge == nil {
70
142
app .Purge = & config.InstanceOpsCmd {Counter : 0 }
71
143
}
72
144
app .Purge .Counter ++
73
145
}
74
- //now we only change networks
75
- app .Interfaces = appInstanceConfig .Interfaces
76
146
if err = changer .setControllerAndDev (ctrl , dev ); err != nil {
77
147
log .Fatalf ("setControllerAndDev: %s" , err )
78
148
}
@@ -89,5 +159,8 @@ func podModifyInit() {
89
159
podModifyCmd .Flags ().StringSliceVarP (& portPublish , "publish" , "p" , nil , "Ports to publish in format EXTERNAL_PORT:INTERNAL_PORT" )
90
160
podModifyCmd .Flags ().BoolVar (& aclOnlyHost , "only-host" , false , "Allow access only to host and external networks" )
91
161
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" )
92
165
podModifyCmd .Flags ().StringSliceVar (& acl , "acl" , nil , "Allow access only to defined hosts/ips/subnets" )
93
166
}
0 commit comments