这是indexloc提供的服务,不要输入任何密码
Skip to content

Add support for Kubernetes “image” volume type #15878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 23, 2025

Conversation

Fedosin
Copy link
Contributor

@Fedosin Fedosin commented May 9, 2025

Fixes #15488

Proposed Changes

Kubernetes v1.31 introduced image volumes that allow mounting OCI images directly into Pods.
This patch extends Knative Serving to recognize and validate this new type.

Highlights

• Feature gate
– New config-map key kubernetes.podspec-volumes-image and flag PodSpecVolumesImage (disabled by default).

• API / field-mask updates
– VolumeSourceMask now preserves .image when the gate is enabled.
– Added ImageVolumeSourceMask helper for shallow-copying allowed fields.

• Validation
– validateVolume checks feature-gate state, treats image as a mutually-exclusive source and performs per-field checks via validateImageVolumeSource.

• Schema-tweak overrides
– Whitelisted volumes.image behind the new feature gate so generated CRD/OpenAPI stays in sync.

• Tests
– Added helper to enable the feature in tests.
– Expanded TestVolumeValidation with positive/negative cases for the image volume.

Release Note

Knative Serving now supports Kubernetes’ new "image" volume type.

@knative-prow knative-prow bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 9, 2025
@knative-prow knative-prow bot requested review from dprotaso and skonto May 9, 2025 17:37
Copy link

codecov bot commented May 9, 2025

Codecov Report

Attention: Patch coverage is 78.94737% with 8 lines in your changes missing coverage. Please review.

Project coverage is 80.93%. Comparing base (589b6ab) to head (885c72d).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
pkg/apis/serving/k8s_validation.go 77.27% 4 Missing and 1 partial ⚠️
pkg/apis/serving/fieldmask.go 78.57% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15878      +/-   ##
==========================================
+ Coverage   80.91%   80.93%   +0.01%     
==========================================
  Files         210      210              
  Lines       16731    16769      +38     
==========================================
+ Hits        13538    13572      +34     
- Misses       2842     2843       +1     
- Partials      351      354       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Fedosin Fedosin force-pushed the image-volume-mount branch from 891eb23 to 10844df Compare May 9, 2025 17:45
@@ -77,6 +77,7 @@ const (
FeaturePodSpecShareProcessNamespace = "kubernetes.podspec-shareprocessnamespace"
FeaturePodSpecTolerations = "kubernetes.podspec-tolerations"
FeaturePodSpecTopologySpreadConstraints = "kubernetes.podspec-topologyspreadconstraints"
FeaturePodSpecVolumesImage = "kubernetes.podspec-volumes-image"
Copy link
Contributor

@dsimansk dsimansk May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fedosin a little nit, there's should be at least a enable/disable feature flag test added into features_test.go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I added the test there.

Copy link
Contributor

@dsimansk dsimansk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing entry and and short explanation in default ConfigMap: https://github.com/knative/serving/blob/main/config/core/configmaps/features.yaml

Otherwise looks good, thanks a lot @Fedosin!


switch iv.PullPolicy {
case corev1.PullIfNotPresent, corev1.PullAlways, corev1.PullNever, "":
// ok
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be consistent with what K8s has wrt policy validation e.g. "" case, 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! I think the function you provided is for internal Kubernetes validation. From the user's perspective, pullPolicy is an optional parameter, and an empty string ("") is a valid value.

Here's how I tested it:

➭ cat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: image-volume
spec:
  containers:
  - name: shell
    image: debian
    command: ["sleep", "infinity"]
    volumeMounts:
    - name: volume
      mountPath: /volume
  volumes:
  - name: volume
    image:
      reference: quay.io/crio/artifact:v2
      pullPolicy: ""
EOF
pod/image-volume created
➭ kubectl get pod image-volume -o jsonpath='{.spec.volumes[?(@.name=="volume")].image.pullPolicy}'
IfNotPresent

I took the code from here and changed pullPolicy to "".

From the field description it also appears that the
value can be "", because it "defaults to Always if :latest tag is specified, or IfNotPresent otherwise."

@Fedosin Fedosin force-pushed the image-volume-mount branch from 713f6be to 5a556bf Compare May 14, 2025 15:20
@dsimansk
Copy link
Contributor

Missing entry and and short explanation in default ConfigMap: https://github.com/knative/serving/blob/main/config/core/configmaps/features.yaml

PTAL, the above config map should be updated.

@Fedosin Fedosin force-pushed the image-volume-mount branch from 5a556bf to 853e8c3 Compare May 14, 2025 18:47
Fedosin added 2 commits May 14, 2025 20:57
Kubernetes v1.31 introduces image volumes that allow mounting OCI
images/artefacts directly into Pods.
This patch extends Knative Serving to recognise and validate this new
type.
Highlights
• Feature gate
– New config-map key kubernetes.podspec-volumes-image and flag
PodSpecVolumesImage (disabled by default).
• API / field-mask updates
– VolumeSourceMask now preserves .image when the gate is enabled.
– Added ImageVolumeSourceMask helper for shallow-copying allowed
fields.
• Validation
– validateVolume checks feature-gate state, treats image as a
mutually-exclusive source and performs per-field checks via
validateImageVolumeSource.
• Schema-tweak overrides
– Whitelisted volumes.image behind the new feature gate so generated
CRD/OpenAPI stays in sync.
• Tests
– Added helper to enable the feature in tests.
– Expanded TestVolumeValidation with positive/negative cases for the
image volume.
All unit tests (go test ./...) pass.
Generated by ./hack/update-codegen.sh
@Fedosin Fedosin force-pushed the image-volume-mount branch from 853e8c3 to 885c72d Compare May 14, 2025 18:58
@dsimansk
Copy link
Contributor

/lgtm
Looks good to me, thanks!

Deferring to Dave for approval, PTAL.
/assign @dprotaso

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label May 15, 2025
@dprotaso
Copy link
Member

So we usually have feature flags to gate end users from using PodSpec features that may affect scalability etc. Hence why we've guarded persistent volumes before since at a certain scale it's not clear how many readers/writers say an EFS volume can support.

I think for image volumes it doesn't suffer from this problem since it's just pulling down an OCI image. Thus I'm inclined to just support this feature without needing a feature flag.

@Fedosin
Copy link
Contributor Author

Fedosin commented May 16, 2025

@dprotaso Hey! As I understand Image volume types are disabled by default in kubernetes and might be removed from API (very unlikely, but still). So, maybe we should keep the flag for now until the feature is GA in kubernetes, or at least it is enabled by default?

@skonto
Copy link
Contributor

skonto commented May 16, 2025

Regarding scalability there might be some concerns not sure to what extent this is battle tested:
a) Large static content may cause delays, for example LLM images.
b) Ephemeral disk pressure: kubernetes/enhancements#4639 (comment)
c) Registry pressure

WDYT?

@Fedosin
Copy link
Contributor Author

Fedosin commented May 20, 2025

@skonto Yeah, bugs and other issues are the reason why the "image" volume type is not enabled by default in Kubernetes. But I believe they will fix the issues and make it stable in the near future.
As for now, I would advise against adding this volume type to the stable serving API and recommend hiding it behind a feature flag until the Kubernetes feature is GA.

@dprotaso
Copy link
Member

Regarding scalability there might be some concerns not sure to what extent this is battle tested: a) Large static content may cause delays, for example LLM images. b) Ephemeral disk pressure: kubernetes/enhancements#4639 (comment) c) Registry pressure

WDYT?

I think this applies to containers images which users can already abuse - so I'm not concerned about volumes.

@dprotaso
Copy link
Member

dprotaso commented May 22, 2025

If it's alpha I'm ok putting this behind a flag. @Fedosin can we create a follow up issue to drop the flag when the feature GAs and we catch up to that release of K8s?

@dprotaso
Copy link
Member

/lgtm
/approve

Copy link

knative-prow bot commented May 22, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dprotaso, Fedosin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow knative-prow bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 22, 2025
@knative-prow knative-prow bot merged commit c36383e into knative:main May 23, 2025
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support volume type "image" for volume mounting
4 participants