updateCredSpecConfig updates the value of the credential spec Config field to the config ID if the credential spec has changed. it mutates the passed spec. it does not handle the case where the credential spec specifies a config that does not exist -- that case is handled as part of getUpdatedConfig
(flags *pflag.FlagSet, containerSpec *swarm.ContainerSpec)
| 1364 | // config that does not exist -- that case is handled as part of |
| 1365 | // getUpdatedConfigs |
| 1366 | func updateCredSpecConfig(flags *pflag.FlagSet, containerSpec *swarm.ContainerSpec) { |
| 1367 | if flags.Changed(flagCredentialSpec) { |
| 1368 | credSpecOpt := flags.Lookup(flagCredentialSpec) |
| 1369 | // if the flag has changed, and the value is empty string, then we |
| 1370 | // should remove any credential spec that might be present |
| 1371 | if credSpecOpt.Value.String() == "" { |
| 1372 | if containerSpec.Privileges != nil { |
| 1373 | containerSpec.Privileges.CredentialSpec = nil |
| 1374 | } |
| 1375 | return |
| 1376 | } |
| 1377 | |
| 1378 | // otherwise, set the credential spec to be the parsed value |
| 1379 | credSpec := credSpecOpt.Value.(*credentialSpecOpt).Value() |
| 1380 | |
| 1381 | // if this is a Config credential spec, we still need to replace the |
| 1382 | // value of credSpec.Config with the config ID instead of Name. |
| 1383 | if credSpec.Config != "" { |
| 1384 | for _, config := range containerSpec.Configs { |
| 1385 | // if the config name matches, then set the config ID. we do |
| 1386 | // not need to worry about if this is a Runtime target or not. |
| 1387 | // even if it is not a Runtime target, getUpdatedConfigs |
| 1388 | // ensures that a Runtime target for this config exists, and |
| 1389 | // the Name is unique so the ID is correct no matter the |
| 1390 | // target. |
| 1391 | if config.ConfigName == credSpec.Config { |
| 1392 | credSpec.Config = config.ConfigID |
| 1393 | break |
| 1394 | } |
| 1395 | } |
| 1396 | } |
| 1397 | |
| 1398 | if containerSpec.Privileges == nil { |
| 1399 | containerSpec.Privileges = &swarm.Privileges{} |
| 1400 | } |
| 1401 | |
| 1402 | containerSpec.Privileges.CredentialSpec = credSpec |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | // updateCapabilities calculates the list of capabilities to "drop" and to "add" |
| 1407 | // after applying the capabilities passed through `--cap-add` and `--cap-drop` |
searching dependent graphs…