(ctx context.Context, dockerCLI command.Cli, configs []swarm.ConfigSpec)
| 139 | } |
| 140 | |
| 141 | func createConfigs(ctx context.Context, dockerCLI command.Cli, configs []swarm.ConfigSpec) error { |
| 142 | apiClient := dockerCLI.Client() |
| 143 | |
| 144 | for _, configSpec := range configs { |
| 145 | res, err := apiClient.ConfigInspect(ctx, configSpec.Name, client.ConfigInspectOptions{}) |
| 146 | switch { |
| 147 | case err == nil: |
| 148 | // config already exists, then we update that |
| 149 | _, err := apiClient.ConfigUpdate(ctx, res.Config.ID, client.ConfigUpdateOptions{ |
| 150 | Version: res.Config.Meta.Version, |
| 151 | Spec: configSpec, |
| 152 | }) |
| 153 | if err != nil { |
| 154 | return fmt.Errorf("failed to update config %s: %w", configSpec.Name, err) |
| 155 | } |
| 156 | case errdefs.IsNotFound(err): |
| 157 | // config does not exist, then we create a new one. |
| 158 | _, _ = fmt.Fprintln(dockerCLI.Out(), "Creating config", configSpec.Name) |
| 159 | _, err := apiClient.ConfigCreate(ctx, client.ConfigCreateOptions{ |
| 160 | Spec: configSpec, |
| 161 | }) |
| 162 | if err != nil { |
| 163 | return fmt.Errorf("failed to create config %s: %w", configSpec.Name, err) |
| 164 | } |
| 165 | default: |
| 166 | return err |
| 167 | } |
| 168 | } |
| 169 | return nil |
| 170 | } |
| 171 | |
| 172 | func createNetworks(ctx context.Context, dockerCLI command.Cli, namespace convert.Namespace, networks map[string]client.NetworkCreateOptions) error { |
| 173 | apiClient := dockerCLI.Client() |
no test coverage detected
searching dependent graphs…