@@ -11,6 +11,8 @@ import (
11
11
"github.com/spf13/cobra"
12
12
)
13
13
14
+ var podLink string
15
+
14
16
//podModifyCmd is a command to modify app
15
17
var podModifyCmd = & cobra.Command {
16
18
Use : "modify" ,
@@ -51,9 +53,18 @@ var podModifyCmd = &cobra.Command{
51
53
opts = append (opts , expect .WithPortsPublish (portPublish ))
52
54
}
53
55
opts = append (opts , expect .WithOldApp (appName ))
54
- expectation := expect .AppExpectationFromURL (ctrl , dev , defaults .DefaultDummyExpect , appName , opts ... )
55
- appInstanceConfig := expectation .Application ()
56
+ opts = append (opts , expect .WithHTTPDirectLoad (directLoad ))
57
+ link := defaults .DefaultDummyExpect
58
+ newLink := false
56
59
needPurge := false
60
+ if podLink != "" {
61
+ needPurge = true
62
+ newLink = true
63
+ link = podLink
64
+ }
65
+ volumes := dev .GetVolumes ()
66
+ expectation := expect .AppExpectationFromURL (ctrl , dev , link , appName , opts ... )
67
+ appInstanceConfig := expectation .Application ()
57
68
if len (app .Interfaces ) != len (appInstanceConfig .Interfaces ) {
58
69
needPurge = true
59
70
} else {
@@ -64,14 +75,67 @@ var podModifyCmd = &cobra.Command{
64
75
}
65
76
}
66
77
}
78
+ app .Interfaces = appInstanceConfig .Interfaces
79
+ if newLink {
80
+ diffInDrives := true
81
+ if len (app .Drives ) == len (appInstanceConfig .Drives ) {
82
+ diffInDrives = false
83
+ for i , d := range app .Drives {
84
+ // check if we have difference in volumes and its images
85
+ if appInstanceConfig .Drives [i ].Image .Name != d .Image .Name || appInstanceConfig .Drives [i ].Image .Sha256 != d .Image .Sha256 {
86
+ diffInDrives = true
87
+ }
88
+ }
89
+ }
90
+ if diffInDrives {
91
+ // user provides different link, so we need to purge all volumes
92
+ volumeIDs := dev .GetVolumes ()
93
+ utils .DelEleInSliceByFunction (& volumeIDs , func (i interface {}) bool {
94
+ vol , err := ctrl .GetVolume (i .(string ))
95
+ if err != nil {
96
+ log .Fatalf ("no volume in cloud %s: %s" , i .(string ), err )
97
+ }
98
+ for _ , volRef := range app .VolumeRefList {
99
+ if vol .Uuid == volRef .Uuid {
100
+ return true
101
+ }
102
+ }
103
+ return false
104
+ })
105
+ dev .SetVolumeConfigs (volumeIDs )
106
+ app .VolumeRefList = appInstanceConfig .VolumeRefList
107
+ app .Drives = appInstanceConfig .Drives
108
+ } else {
109
+ // we will increase generation number if user provide the same link
110
+ // to run image update
111
+ dev .SetVolumeConfigs (volumes )
112
+ for _ , ctID := range dev .GetContentTrees () {
113
+ ct , err := ctrl .GetContentTree (ctID )
114
+ if err != nil {
115
+ log .Fatalf ("no ContentTree in cloud %s: %s" , ctID , err )
116
+ }
117
+ for _ , v := range app .VolumeRefList {
118
+ volumeConfig , err := ctrl .GetVolume (v .Uuid )
119
+ if err != nil {
120
+ log .Fatalf ("no volume in cloud %s: %s" , v .Uuid , err )
121
+ }
122
+ volumeConfig .GenerationCount ++
123
+ if ct .GetUuid () == volumeConfig .Origin .DownloadContentTreeID {
124
+ ct .GenerationCount ++
125
+ }
126
+ }
127
+ }
128
+ for _ , v := range app .VolumeRefList {
129
+ v .GenerationCount ++
130
+ }
131
+ }
132
+ }
67
133
if needPurge {
68
134
if app .Purge == nil {
69
135
app .Purge = & config.InstanceOpsCmd {Counter : 0 }
70
136
}
71
137
app .Purge .Counter ++
72
138
}
73
- //now we only change networks
74
- app .Interfaces = appInstanceConfig .Interfaces
75
139
if err = changer .setControllerAndDev (ctrl , dev ); err != nil {
76
140
log .Fatalf ("setControllerAndDev: %s" , err )
77
141
}
@@ -88,4 +152,6 @@ func podModifyInit() {
88
152
podModifyCmd .Flags ().StringSliceVarP (& portPublish , "publish" , "p" , nil , "Ports to publish in format EXTERNAL_PORT:INTERNAL_PORT" )
89
153
podModifyCmd .Flags ().BoolVar (& aclOnlyHost , "only-host" , false , "Allow access only to host and external networks" )
90
154
podModifyCmd .Flags ().StringSliceVar (& podNetworks , "networks" , nil , "Networks to connect to app (ports will be mapped to first network)" )
155
+ podModifyCmd .Flags ().StringVar (& podLink , "link" , "" , "Set new app link for pod" )
156
+ podModifyCmd .Flags ().BoolVar (& directLoad , "direct" , true , "Use direct download for image instead of eserver" )
91
157
}
0 commit comments