Skip to content

Commit 4ae6409

Browse files
jschwinger233CMGS
authored andcommitted
extract ip for net inherit replace (#424)
1 parent c927988 commit 4ae6409

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

engine/docker/container.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func loadRawArgs(b []byte) (*RawArgs, error) {
8282
}
8383

8484
// VirtualizationCreate create a workload
85-
func (e *Engine) VirtualizationCreate(ctx context.Context, opts *enginetypes.VirtualizationCreateOptions) (*enginetypes.VirtualizationCreated, error) {
85+
func (e *Engine) VirtualizationCreate(ctx context.Context, opts *enginetypes.VirtualizationCreateOptions) (*enginetypes.VirtualizationCreated, error) { // nolint
8686
r := &enginetypes.VirtualizationCreated{}
8787
// memory should more than 4MiB
8888
if opts.Memory > 0 && opts.Memory < minMemory || opts.Memory < 0 {
@@ -244,6 +244,11 @@ func (e *Engine) VirtualizationCreate(ctx context.Context, opts *enginetypes.Vir
244244
EndpointsConfig: map[string]*dockernetwork.EndpointSettings{},
245245
}
246246
for networkID, ipv4 := range networks {
247+
if useCNI(opts.Labels) && ipv4 != "" {
248+
config.Labels["ipv4"] = ipv4
249+
break
250+
}
251+
247252
endpointSetting, err := e.makeIPV4EndpointSetting(ipv4)
248253
if err != nil {
249254
return r, err

engine/docker/helper.go

+9
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,12 @@ func dumpFromString(ctx context.Context, ca, cert, key *os.File, caStr, certStr,
282282
log.Debug(ctx, "[dumpFromString] Dump ca.pem, cert.pem, key.pem from string")
283283
return nil
284284
}
285+
286+
func useCNI(labels map[string]string) bool {
287+
for k, v := range labels {
288+
if k == "cni" && v == "1" {
289+
return true
290+
}
291+
}
292+
return false
293+
}

0 commit comments

Comments
 (0)