Skip to content

Commit fb66d1b

Browse files
committed
Make API section dedicated
Signed-off-by: Sascha Grunert <[email protected]>
1 parent 2300ee9 commit fb66d1b

File tree

1 file changed

+80
-1
lines changed
  • keps/sig-node/4639-oci-volume-source

1 file changed

+80
-1
lines changed

keps/sig-node/4639-oci-volume-source/README.md

+80-1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ to support this source type. Key design aspects include:
323323
- For OCI artifacts, we want to convert and represent them as a directory with
324324
files. A single file could also be nested inside a directory.
325325

326+
### Kubernetes API
327+
326328
The following code snippet illustrates the proposed API change:
327329

328330
```yaml
@@ -344,6 +346,83 @@ spec:
344346
name: oci-volume
345347
```
346348
349+
350+
This means we extend the [`VolumeSource`](https://github.com/kubernetes/kubernetes/blob/7b359a2f9e1ff5cdc49cfcc4e350e9d796f502c0/staging/src/k8s.io/api/core/v1/types.go#L49)
351+
by:
352+
353+
```go
354+
// Represents the source of a volume to mount.
355+
// Only one of its members may be specified.
356+
type VolumeSource struct {
357+
// …
358+
359+
// oci represents a OCI object pulled and mounted on kubelet's host machine
360+
// +optional
361+
OCI *OCIVolumeSource `json:"oci,omitempty" protobuf:"bytes,30,opt,name=oci"
362+
```
363+
364+
And add the corresponding `OCIVolumeSource` type:
365+
366+
```go
367+
// OCIVolumeSource represents a OCI volume resource.
368+
type OCIVolumeSource struct {
369+
// Required: Image or artifact reference to be used
370+
Reference string `json:"reference,omitempty" protobuf:"bytes,1,opt,name=reference"`
371+
372+
// Policy for pulling OCI objects
373+
// Defaults to IfNotPresent
374+
// +optional
375+
PullPolicy PullPolicy `json:"pullPolicy,omitempty" protobuf:"bytes,2,opt,name=pullPolicy,casttype=PullPolicy"`
376+
}
377+
```
378+
379+
The same will apply to [`pkg/apis/core/types.VolumeSource`](https://github.com/kubernetes/kubernetes/blob/7b359a2f9e1ff5cdc49cfcc4e350e9d796f502c0/pkg/apis/core/types.go#L58),
380+
which is the internal API compared to the external one from staging. The [API Validation](https://github.com/kubernetes/kubernetes/blob/7b359a2f9e1ff5cdc49cfcc4e350e9d796f502c0/pkg/apis/core/validation/validation.go)
381+
validation will be extended to disallow the `subPath`/`subPathExpr` field as
382+
well as making the `reference` mandatory:
383+
384+
```go
385+
//
386+
387+
if source.OCI != nil {
388+
if numVolumes > 0 {
389+
allErrs = append(allErrs, field.Forbidden(fldPath.Child("oci"), "may not specify more than 1 volume type"))
390+
} else {
391+
numVolumes++
392+
allErrs = append(allErrs, validateOCIVolumeSource(source.OCI, fldPath.Child("oci"))...)
393+
}
394+
}
395+
396+
//
397+
```
398+
399+
```go
400+
func validateOCIVolumeSource(oci *core.OCIVolumeSource, fldPath *field.Path) field.ErrorList {
401+
allErrs := field.ErrorList{}
402+
if len(oci.Reference) == 0 {
403+
allErrs = append(allErrs, field.Required(fldPath.Child("reference"), ""))
404+
}
405+
allErrs = append(allErrs, validatePullPolicy(oci.PullPolicy, fldPath.Child("pullPolicy"))...)
406+
return allErrs
407+
}
408+
```
409+
410+
```go
411+
//
412+
413+
// Disallow subPath/subPathExpr for OCI volumes
414+
if v, ok := volumes[mnt.Name]; ok && v.OCI != nil {
415+
if mnt.SubPath != "" {
416+
allErrs = append(allErrs, field.Invalid(idxPath.Child("subPath"), mnt.SubPath, "not allowed in OCI volume sources"))
417+
}
418+
if mnt.SubPathExpr != "" {
419+
allErrs = append(allErrs, field.Invalid(idxPath.Child("subPathExpr"), mnt.SubPathExpr, "not allowed in OCI volume sources"))
420+
}
421+
}
422+
423+
//
424+
```
425+
347426
### Kubelet and Container Runtime Interface (CRI) support for OCI artifacts
348427

349428
Kubelet and the Container Runtime Interface (CRI) currently handle OCI images. To support OCI artifacts,
@@ -375,7 +454,7 @@ potential enhancements may be required:
375454

376455
**Validation:**
377456
- Extend validation and security checks to cover new artifact types.
378-
- Disallow `subPath` mounting through the API validation
457+
- Disallow `subPath`/`subPathExpr` mounting through the API validation
379458

380459
**Storage Optimization in the container runtime:**
381460
- Develop optimized storage solutions tailored for different artifact types,

0 commit comments

Comments
 (0)