Skip to content

Commit e23bc03

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

File tree

1 file changed

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

1 file changed

+82
-1
lines changed

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

+82-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ tags, and then generate with `hack/update-toc.sh`.
9292
- [Vocabulary: OCI Images, Artifacts, and Objects](#vocabulary-oci-images-artifacts-and-objects)
9393
- [Risks and Mitigations](#risks-and-mitigations)
9494
- [Design Details](#design-details)
95+
- [Kubernetes API](#kubernetes-api)
9596
- [Kubelet and Container Runtime Interface (CRI) support for OCI artifacts](#kubelet-and-container-runtime-interface-cri-support-for-oci-artifacts)
9697
- [kubelet](#kubelet)
9798
- [Pull Policy](#pull-policy)
@@ -323,6 +324,8 @@ to support this source type. Key design aspects include:
323324
- For OCI artifacts, we want to convert and represent them as a directory with
324325
files. A single file could also be nested inside a directory.
325326

327+
### Kubernetes API
328+
326329
The following code snippet illustrates the proposed API change:
327330

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

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

376457
**Validation:**
377458
- Extend validation and security checks to cover new artifact types.
378-
- Disallow `subPath` mounting through the API validation
459+
- Disallow `subPath`/`subPathExpr` mounting through the API validation
379460

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

0 commit comments

Comments
 (0)