Skip to content

Commit 9546ed9

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

File tree

1 file changed

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

1 file changed

+81
-1
lines changed

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

+81-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,83 @@ 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+
And add the corresponding `OCIVolumeSource` type:
366+
367+
```go
368+
// OCIVolumeSource represents a OCI volume resource.
369+
type OCIVolumeSource struct {
370+
// Required: Image or artifact reference to be used
371+
Reference string `json:"reference,omitempty" protobuf:"bytes,1,opt,name=reference"`
372+
373+
// Policy for pulling OCI objects
374+
// Defaults to IfNotPresent
375+
// +optional
376+
PullPolicy PullPolicy `json:"pullPolicy,omitempty" protobuf:"bytes,2,opt,name=pullPolicy,casttype=PullPolicy"`
377+
}
378+
```
379+
380+
The same will apply to [`pkg/apis/core/types.VolumeSource`](https://github.com/kubernetes/kubernetes/blob/7b359a2f9e1ff5cdc49cfcc4e350e9d796f502c0/pkg/apis/core/types.go#L58),
381+
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)
382+
validation will be extended to disallow the `subPath`/`subPathExpr` field as
383+
well as making the `reference` mandatory:
384+
385+
```go
386+
//
387+
388+
if source.OCI != nil {
389+
if numVolumes > 0 {
390+
allErrs = append(allErrs, field.Forbidden(fldPath.Child("oci"), "may not specify more than 1 volume type"))
391+
} else {
392+
numVolumes++
393+
allErrs = append(allErrs, validateOCIVolumeSource(source.OCI, fldPath.Child("oci"))...)
394+
}
395+
}
396+
397+
//
398+
```
399+
400+
```go
401+
func validateOCIVolumeSource(oci *core.OCIVolumeSource, fldPath *field.Path) field.ErrorList {
402+
allErrs := field.ErrorList{}
403+
if len(oci.Reference) == 0 {
404+
allErrs = append(allErrs, field.Required(fldPath.Child("reference"), ""))
405+
}
406+
allErrs = append(allErrs, validatePullPolicy(oci.PullPolicy, fldPath.Child("pullPolicy"))...)
407+
return allErrs
408+
}
409+
```
410+
411+
```go
412+
//
413+
414+
// Disallow subPath/subPathExpr for OCI volumes
415+
if v, ok := volumes[mnt.Name]; ok && v.OCI != nil {
416+
if mnt.SubPath != "" {
417+
allErrs = append(allErrs, field.Invalid(idxPath.Child("subPath"), mnt.SubPath, "not allowed in OCI volume sources"))
418+
}
419+
if mnt.SubPathExpr != "" {
420+
allErrs = append(allErrs, field.Invalid(idxPath.Child("subPathExpr"), mnt.SubPathExpr, "not allowed in OCI volume sources"))
421+
}
422+
}
423+
424+
//
425+
```
426+
347427
### Kubelet and Container Runtime Interface (CRI) support for OCI artifacts
348428

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

376456
**Validation:**
377457
- Extend validation and security checks to cover new artifact types.
378-
- Disallow `subPath` mounting through the API validation
458+
- Disallow `subPath`/`subPathExpr` mounting through the API validation
379459

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

0 commit comments

Comments
 (0)