Skip to content
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

Add support for hostPath #15648

Merged
merged 8 commits into from
Jan 6, 2025
Merged

Conversation

amarflybot
Copy link
Contributor

@amarflybot amarflybot commented Dec 9, 2024

Fixes #15546

Description

This feature introduces support for the hostPath volume type in Knative Serving, enabling users to mount directories from the host node’s filesystem into their service containers. This allows direct access to node-specific data or preloaded resources like certificates, enhancing flexibility while retaining Knative’s serverless capabilities.

Proposed Changes

  • Add support for the hostPath volume type in Knative Serving.
  • Enable users to mount directories from the host node's filesystem into their Knative service containers.
  • Update relevant documentation and examples to include usage of hostPath volumes.

Release Note


Adding support for the "hostPath" volume type. The feature allows users to mount directories from the host node's filesystem into their Knative service containers. It enables access to local storage on the node, facilitating use cases such as accessing node-specific data or utilizing local caches. The feature is behind the flag `kubernetes.podspec-volumes-hostpath`.

Copy link

linux-foundation-easycla bot commented Dec 9, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@knative-prow knative-prow bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 9, 2024
Copy link

knative-prow bot commented Dec 9, 2024

Hi @amarflybot. Thanks for your PR.

I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 83.52%. Comparing base (2d5a1e9) to head (01bb99f).
Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
pkg/apis/serving/fieldmask.go 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15648      +/-   ##
==========================================
+ Coverage   83.51%   83.52%   +0.01%     
==========================================
  Files         219      219              
  Lines       17427    17432       +5     
==========================================
+ Hits        14554    14560       +6     
+ Misses       2502     2499       -3     
- Partials      371      373       +2     

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

@amarflybot amarflybot force-pushed the feature/add_hostPath branch from a821b44 to e1c0c42 Compare December 9, 2024 14:06
@skonto
Copy link
Contributor

skonto commented Dec 9, 2024

--- a/config/core/300-resources/configuration.yaml +++ b/config/core/300-resources/configuration.yaml @@ -1582,4 +1582,4 @@ spec: ObservedGeneration is the 'Generation' of the Service that was last processed by the controller. type: integer - format: int64 \ No newline at end of file + format: int64

This needs fix.

@skonto
Copy link
Contributor

skonto commented Dec 9, 2024

/ok-to-test

@knative-prow knative-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Dec 9, 2024
# Part of a feature flag - so we want to omit the schema and preserve unknown fields
- kubebuilder:validation:DropProperties
- kubebuilder:pruning:PreserveUnknownFields
# Part of a feature flag - so we want to omit the schema and preserve unknown fields
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you remove additional space?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@amarflybot
Copy link
Contributor Author

--- a/config/core/300-resources/configuration.yaml +++ b/config/core/300-resources/configuration.yaml @@ -1582,4 +1582,4 @@ spec: ObservedGeneration is the 'Generation' of the Service that was last processed by the controller. type: integer - format: int64 \ No newline at end of file + format: int64

This needs fix.

Fixed

kind: Revision
plural: revisions
singular: revision
kind: Service
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the revision file this should not be changed.

@@ -1728,4 +1732,4 @@ spec:
description: |-
URL holds the url that will distribute traffic over the provided traffic targets.
It generally has the form http[s]://{route-name}.{route-namespace}.{cluster-level-suffix}
type: string
type: string
Copy link
Contributor

Choose a reason for hiding this comment

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

A new line is missing.

@knative-prow knative-prow bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Dec 9, 2024
@amarflybot
Copy link
Contributor Author

/retest

@skonto
Copy link
Contributor

skonto commented Dec 10, 2024

@amarflybot could you update the description and add release notes. Also we need a follow up PR at the knative/docs repo to document this addition.

@amarflybot
Copy link
Contributor Author

@amarflybot could you update the description and add release notes.

I have added. Will that do ?

@skonto
Copy link
Contributor

skonto commented Dec 10, 2024

/lgtm
/approve

/hold for @dprotaso for any additional comments.

@skonto skonto changed the title 15546: Add support for hostPath Add support for hostPath Dec 10, 2024
@knative-prow knative-prow bot removed the lgtm Indicates that a PR is ready to be merged. label Dec 10, 2024
@amarflybot
Copy link
Contributor Author

/retest

1 similar comment
@amarflybot
Copy link
Contributor Author

/retest

@skonto
Copy link
Contributor

skonto commented Dec 13, 2024

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Dec 13, 2024
@skonto
Copy link
Contributor

skonto commented Dec 13, 2024

/unhold

@knative-prow knative-prow bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 13, 2024
@skonto
Copy link
Contributor

skonto commented Dec 16, 2024

@dprotaso hi, gentle ping.

Copy link
Member

@dprotaso dprotaso left a comment

Choose a reason for hiding this comment

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

one minor thing for feedback

pkg/apis/serving/k8s_validation.go Outdated Show resolved Hide resolved
@knative-prow knative-prow bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 6, 2025
@dprotaso
Copy link
Member

dprotaso commented Jan 6, 2025

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Jan 6, 2025
Copy link

knative-prow bot commented Jan 6, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: amarflybot, dprotaso, skonto

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 Jan 6, 2025
@dprotaso
Copy link
Member

dprotaso commented Jan 6, 2025

thanks for the changes @amarflybot

@dprotaso
Copy link
Member

dprotaso commented Jan 6, 2025

/retest

1 similar comment
@amarflybot
Copy link
Contributor Author

/retest

@knative-prow knative-prow bot merged commit 0d589da into knative:main Jan 6, 2025
68 checks passed
@vthurimella
Copy link
Contributor

vthurimella commented Jan 6, 2025

Adding a hostPath to a serving.knative.dev/v1 Service will fail the validateVolume with this change. I think serving/pkg/apis/serving/k8s_validation.go needs to be updated as well to be the following

func validateVolume(ctx context.Context, volume corev1.Volume) *apis.FieldError {
	features := config.FromContextOrDefaults(ctx).Features
	errs := validatePersistentVolumeClaims(volume.VolumeSource, features)
	if volume.EmptyDir != nil && features.PodSpecVolumesEmptyDir != config.Enabled {
		errs = errs.Also(&apis.FieldError{Message: fmt.Sprintf("EmptyDir volume support is disabled, "+
			"but found EmptyDir volume %s", volume.Name)})
	}
	errs = errs.Also(apis.CheckDisallowedFields(volume, *VolumeMask(ctx, &volume)))
	if volume.Name == "" {
		errs = apis.ErrMissingField("name")
	} else if len(validation.IsDNS1123Label(volume.Name)) != 0 {
		errs = apis.ErrInvalidValue(volume.Name, "name")
	}
	vs := volume.VolumeSource
	errs = errs.Also(apis.CheckDisallowedFields(vs, *VolumeSourceMask(ctx, &vs)))
	var specified []string
	if vs.Secret != nil {
		specified = append(specified, "secret")
		for i, item := range vs.Secret.Items {
			errs = errs.Also(validateKeyToPath(item).ViaFieldIndex("items", i))
		}
	}
	if vs.ConfigMap != nil {
		specified = append(specified, "configMap")
		for i, item := range vs.ConfigMap.Items {
			errs = errs.Also(validateKeyToPath(item).ViaFieldIndex("items", i))
		}
	}
	if vs.Projected != nil {
		specified = append(specified, "projected")
		for i, proj := range vs.Projected.Sources {
			errs = errs.Also(validateProjectedVolumeSource(proj).ViaFieldIndex("projected", i))
		}
	}
	if vs.EmptyDir != nil {
		specified = append(specified, "emptyDir")
		errs = errs.Also(validateEmptyDirFields(vs.EmptyDir).ViaField("emptyDir"))
	}

	if vs.PersistentVolumeClaim != nil {
		specified = append(specified, "persistentVolumeClaim")
	}

	// Add hostPath to the list of specified volumes if it is enabled.
	if vs.HostPath != nil {
		specified = append(specified, "hostPath")
	}

	if len(specified) == 0 {
		fieldPaths := []string{"secret", "configMap", "projected"}
		cfg := config.FromContextOrDefaults(ctx)
		if cfg.Features.PodSpecVolumesEmptyDir == config.Enabled {
			fieldPaths = append(fieldPaths, "emptyDir")
		}
		if cfg.Features.PodSpecPersistentVolumeClaim == config.Enabled {
			fieldPaths = append(fieldPaths, "persistentVolumeClaim")
		}

		// Add hostPath to the list of specified volumes if it is enabled.
		if cfg.Features.PodSpecVolumesHostPath == config.Enabled {
			fieldPaths = append(fieldPaths, "hostPath")
		}
		errs = errs.Also(apis.ErrMissingOneOf(fieldPaths...))
	} else if len(specified) > 1 {
		errs = errs.Also(apis.ErrMultipleOneOf(specified...))
	}

	return errs
}

@dprotaso
Copy link
Member

dprotaso commented Jan 6, 2025

@vthurimella can you make a PR - i can't tell what the diff is from your code block

@vthurimella
Copy link
Contributor

I created a PR here vthurimella#1

@dprotaso
Copy link
Member

dprotaso commented Jan 6, 2025

Can you make the PR against this repo?

Ideally, add a unit test that demonstrates the failure you describe along with your fix.

cheers

@vthurimella
Copy link
Contributor

Can you make the PR against this repo?

Here is my PR: #15669

Ideally, add a unit test that demonstrates the failure you describe along with your fix.

I included some unit tests

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. kind/enhancement lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support volume type "hostPath" for volume mounting
4 participants