Skip to content

refactor(oss): extract runtime type determination logic#1584

Merged
k8s-ci-robot merged 3 commits into
kubernetes-sigs:masterfrom
AlbeeSo:oss/runtime-refactor
Dec 16, 2025
Merged

refactor(oss): extract runtime type determination logic#1584
k8s-ci-robot merged 3 commits into
kubernetes-sigs:masterfrom
AlbeeSo:oss/runtime-refactor

Conversation

@AlbeeSo

@AlbeeSo AlbeeSo commented Dec 12, 2025

Copy link
Copy Markdown
Member

Refactor NodePublishVolume to use DetermineRuntimeType function for better code clarity. The function implements a decision tree based on directAssigned, socketPath, and skipAttach to determine runtime type (COCO, RunD, RunC, ECI).

Changes:

  • Add DetermineRuntimeType function with decision tree implementation
  • Add RuntimeType enum and comprehensive unit tests
  • Refactor NodePublishVolume to use runtime type instead of boolean checks
  • Improve error handling by catching invalid combinations early

Maintains 100% logic equivalence with improved readability.

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?


Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 12, 2025
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 12, 2025
Refactor NodePublishVolume to use DetermineRuntimeType function for
better code clarity. The function implements a decision tree based on
directAssigned, socketPath, and skipAttach to determine runtime type
(COCO, RunD, RunC, ECI).

Changes:
- Add DetermineRuntimeType function with decision tree implementation
- Add RuntimeType enum and comprehensive unit tests
- Refactor NodePublishVolume to use runtime type instead of boolean checks
- Improve error handling by catching invalid combinations early

Maintains 100% logic equivalence with improved readability.
@AlbeeSo AlbeeSo force-pushed the oss/runtime-refactor branch from 7f0c2bb to 466c452 Compare December 12, 2025 09:03
Comment thread pkg/oss/utils.go
// Returns:
// - RuntimeType: the determined runtime type
// - error: if the combination is invalid (should not occur scenarios)
func DetermineRuntimeType(directAssigned bool, socketPath string, skipAttach bool) (RuntimeType, error) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't like this change. We don't actually care about the name of each runtime. We should have an abstract level to extract what is really different between these runtimes, and write code based on those differences. We can add comments about typical runtime, but don't depends on the runtime name in code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The actual difference is 'skipAttach, directAssigned amd socketPath'. I write down the meaning of them but It's still difficult to manage the code if we don't name the runtime type clearly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think skipAttach should be renamed to something like agentMode. Most branches should already be self-explanatory.

The only difficult case is

	// Note: In non-csi-agent environment (!ns.skipAttach),
	//   if DirectAssigned is True, it's a confidential container scenario (coco)
	if opts.DirectAssigned && !ns.skipAttach {
		return ns.publishDirectVolume(ctx, req, opts)
	}

and we already have comments about it.

Particularly, socketPath == "" is a lot better than runtimeType == RuntimeTypeMicroVM, because the former clearly tells us we don't have mount proxy for this case.

Similarly, ns.agentMode (renamed from skipAttach) should be better than runtimeType == RuntimeTypeRunD || runtimeType == RuntimeTypeMicroVM. When run as agent, we don't need to care about globalmount.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If the logic is more difficult? It's hard to manage the code. I dont want to spend minute to consider every if-else.

@mowangdk

Copy link
Copy Markdown
Contributor

We can simplify the logic by potentially removing coco and using a sidecar instead

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Dec 16, 2025
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AlbeeSo, mowangdk

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

The pull request process is described here

Details 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

@k8s-ci-robot k8s-ci-robot merged commit ec18374 into kubernetes-sigs:master Dec 16, 2025
9 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", 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.

4 participants