convertServiceConfigObjs takes an API client, a namespace, a ServiceConfig, and a set of compose Config specs, and creates the swarm ConfigReferences required by the service. Unlike convertServiceSecrets, this takes the whole ServiceConfig, because some Configs may be needed as a result of other fie
( ctx context.Context, apiClient client.ConfigAPIClient, namespace Namespace, service composetypes.ServiceConfig, configSpecs map[string]composetypes.ConfigObjConfig, )
| 288 | // |
| 289 | // TODO: fix configs API so that ConfigsAPIClient is not required here |
| 290 | func convertServiceConfigObjs( |
| 291 | ctx context.Context, |
| 292 | apiClient client.ConfigAPIClient, |
| 293 | namespace Namespace, |
| 294 | service composetypes.ServiceConfig, |
| 295 | configSpecs map[string]composetypes.ConfigObjConfig, |
| 296 | ) ([]*swarm.ConfigReference, error) { |
| 297 | refs := []*swarm.ConfigReference{} |
| 298 | |
| 299 | lookup := func(key string) (composetypes.FileObjectConfig, error) { |
| 300 | configSpec, exists := configSpecs[key] |
| 301 | if !exists { |
| 302 | return composetypes.FileObjectConfig{}, fmt.Errorf("undefined config %q", key) |
| 303 | } |
| 304 | return composetypes.FileObjectConfig(configSpec), nil |
| 305 | } |
| 306 | for _, config := range service.Configs { |
| 307 | obj, err := convertFileObject(namespace, composetypes.FileReferenceConfig(config), lookup) |
| 308 | if err != nil { |
| 309 | return nil, err |
| 310 | } |
| 311 | |
| 312 | file := swarm.ConfigReferenceFileTarget(obj.File) |
| 313 | refs = append(refs, &swarm.ConfigReference{ |
| 314 | File: &file, |
| 315 | ConfigName: obj.Name, |
| 316 | }) |
| 317 | } |
| 318 | |
| 319 | // finally, after converting all file objects, create any |
| 320 | // Runtime-type configs that are needed. these are configs that are not |
| 321 | // mounted into the container, but are used in some other way by the |
| 322 | // container runtime. Currently, this only means CredentialSpecs, but in |
| 323 | // the future it may be used for other fields |
| 324 | |
| 325 | // grab the CredentialSpec out of the Service |
| 326 | credSpec := service.CredentialSpec |
| 327 | // if the credSpec uses a config, then we should grab the config name, and |
| 328 | // create a config reference for it. A File or Registry-type CredentialSpec |
| 329 | // does not need this operation. |
| 330 | if credSpec.Config != "" { |
| 331 | // look up the config in the configSpecs. |
| 332 | obj, err := lookup(credSpec.Config) |
| 333 | if err != nil { |
| 334 | return nil, err |
| 335 | } |
| 336 | |
| 337 | // get the actual correct name. |
| 338 | name := namespace.Scope(credSpec.Config) |
| 339 | if obj.Name != "" { |
| 340 | name = obj.Name |
| 341 | } |
| 342 | |
| 343 | // now append a Runtime-type config. |
| 344 | refs = append(refs, &swarm.ConfigReference{ |
| 345 | ConfigName: name, |
| 346 | Runtime: &swarm.ConfigReferenceRuntimeTarget{}, |
| 347 | }) |
searching dependent graphs…