(ctx context.Context, dockerCli command.Cli, options createOptions)
| 117 | } |
| 118 | |
| 119 | func runCreate(ctx context.Context, dockerCli command.Cli, options createOptions) error { |
| 120 | volOpts := client.VolumeCreateOptions{ |
| 121 | Driver: options.driver, |
| 122 | DriverOpts: options.driverOpts.GetAll(), |
| 123 | Name: options.name, |
| 124 | Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()), |
| 125 | } |
| 126 | if options.cluster { |
| 127 | volOpts.ClusterVolumeSpec = &volume.ClusterVolumeSpec{ |
| 128 | Group: options.group, |
| 129 | AccessMode: &volume.AccessMode{ |
| 130 | Scope: volume.Scope(options.scope), |
| 131 | Sharing: volume.SharingMode(options.sharing), |
| 132 | }, |
| 133 | Availability: volume.Availability(options.availability), |
| 134 | } |
| 135 | |
| 136 | switch options.accessType { |
| 137 | case "mount": |
| 138 | volOpts.ClusterVolumeSpec.AccessMode.MountVolume = &volume.TypeMount{} |
| 139 | case "block": |
| 140 | volOpts.ClusterVolumeSpec.AccessMode.BlockVolume = &volume.TypeBlock{} |
| 141 | } |
| 142 | |
| 143 | vcr := &volume.CapacityRange{} |
| 144 | if r := options.requiredBytes.Value(); r >= 0 { |
| 145 | vcr.RequiredBytes = r |
| 146 | } |
| 147 | |
| 148 | if l := options.limitBytes.Value(); l >= 0 { |
| 149 | vcr.LimitBytes = l |
| 150 | } |
| 151 | volOpts.ClusterVolumeSpec.CapacityRange = vcr |
| 152 | |
| 153 | for key, secret := range options.secrets.GetAll() { |
| 154 | volOpts.ClusterVolumeSpec.Secrets = append( |
| 155 | volOpts.ClusterVolumeSpec.Secrets, |
| 156 | volume.Secret{ |
| 157 | Key: key, |
| 158 | Secret: secret, |
| 159 | }, |
| 160 | ) |
| 161 | } |
| 162 | sort.SliceStable(volOpts.ClusterVolumeSpec.Secrets, func(i, j int) bool { |
| 163 | return volOpts.ClusterVolumeSpec.Secrets[i].Key < volOpts.ClusterVolumeSpec.Secrets[j].Key |
| 164 | }) |
| 165 | |
| 166 | // TODO(dperny): ignore if no topology specified |
| 167 | topology := &volume.TopologyRequirement{} |
| 168 | for _, top := range options.requisiteTopology.GetSlice() { |
| 169 | // each topology takes the form segment=value,segment=value |
| 170 | // comma-separated list of equal separated maps |
| 171 | segments := map[string]string{} |
| 172 | for segment := range strings.SplitSeq(top, ",") { |
| 173 | // TODO(dperny): validate topology syntax |
| 174 | k, v, _ := strings.Cut(segment, "=") |
| 175 | segments[k] = v |
| 176 | } |
no test coverage detected
searching dependent graphs…