Skip to content

Handle []byte envvar value for CRI - #13453

Merged
mikebrow merged 2 commits into
containerd:mainfrom
liggitt:binary-env-main
Jul 23, 2026
Merged

mikebrow merged 2 commits into
containerd:mainfrom
liggitt:binary-env-main

Conversation

@liggitt

@liggitt liggitt commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Part of recovering from a regression in the ability of v0.34.0+ cri-api being able to transmit binary non-utf8 envvar values

xref

cc @mikebrow @samuelkarp

This updates to a cri-api patch release that switched the proto type of the envvar value field from string to bytes, and adds a []byte → go string cast in the spot that handles this CRI field.

Support non-UTF-8 binary environment variable values in CRI

Copilot AI left a comment

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates CRI container creation to support environment variable values represented as []byte (instead of string), and aligns existing unit tests with the updated runtime.KeyValue shape.

Changes:

  • Updated Linux/Windows/Darwin spec builders to convert env var values from []byte to string when assembling OCI env entries.
  • Updated container creation test data on Linux/Windows/Other to use []byte(...) env values.

Reviewed changes

Copilot reviewed 4 out of 7 changed files in this pull request and generated 3 comments.

File Description
internal/cri/server/container_create.go Converts runtime.KeyValue.Value bytes to string when building OCI env arrays across OS-specific spec builders.
internal/cri/server/container_create_linux_test.go Adjusts test container config env values to []byte.
internal/cri/server/container_create_windows_test.go Adjusts test container config env values to []byte.
internal/cri/server/container_create_other_test.go Adjusts test container config env values to []byte.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/cri/server/container_create.go Resolved
Comment thread internal/cri/server/container_create.go Resolved
Comment thread internal/cri/server/container_create.go Resolved
@liggitt
liggitt force-pushed the binary-env-main branch 2 times, most recently from 12bbf46 to 66f4cbc Compare May 20, 2026 19:41
@liggitt

liggitt commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

(the vendor verification task of the "Project Checks" CI is expected to fail since this is monkeying with a vendored cri-api file ... other compile / test checks should succeed)

@liggitt liggitt changed the title WIP: POC: Handle []byte envvar value WIP: POC: [main] Handle []byte envvar value May 20, 2026
@liggitt

liggitt commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

e2e failure doesn't look related:

  [FAILED] Failed after 15.060s.
  Expected
      <string>: Summary
  to match fields: {
  [.Pods[summary-test-4224::stats-busybox-0].Containers[busybox-container].CPU:
  	Expected
  	    <string>: CPUStats
  	to match fields: {
  	.UsageNanoCores:
  		Expected
  		    <uint64>: 1002307858
  		to be <=
  		    <float64>: 1e+09
  	}
  	, .Pods[summary-test-4224::stats-busybox-0].CPU:
  	Expected
  	    <string>: CPUStats
  	to match fields: {
  	.UsageNanoCores:
  		Expected
  		    <uint64>: 1000651002
  		to be <=
  		    <float64>: 1e+09
  	}
  	]
  }

looks like other tests passed

@mikebrow

Copy link
Copy Markdown
Member

I believe this PR converts the CRI request ENV options, as an []byte, over to the container spec's array of strings early enough to avoid type issues.

For awareness https://github.com/containerd/nri/blob/main/pkg/api/api.proto#L748-L752
^ over in NRI land we have the ability to crud ENV vars for a container but as you can see it's all golang []string, and using ttrpc over the wire not grpc.

Since we're converting to type string before storage into the meta store and creation of the container spec.. and calling over ttRPC to NRI for NRI adjustments ... this change direction should be good, will look forward to seeing this merge and perhaps we'll want to pipe through some docs (NRI etc) to explain that these strings might need to be treated as []byte for cases where the kubelet/crictl users etal. are pushing binary env's https://github.com/containerd/containerd/blob/main/vendor/github.com/opencontainers/runtime-spec/specs-go/config.go#L79

/cc @klihub @fuweid

@k8s-ci-robot
k8s-ci-robot requested review from fuweid and klihub May 20, 2026 21:28
@mikebrow

Copy link
Copy Markdown
Member

e2e failure doesn't look related:

...

looks like other tests passed

nod was a flake.. retry succedded

@fuweid

fuweid commented May 20, 2026

Copy link
Copy Markdown
Member

The change looks good to me.

Copilot AI review requested due to automatic review settings May 21, 2026 22:38
@liggitt
liggitt force-pushed the binary-env-main branch from 66f4cbc to 9a906dc Compare May 21, 2026 22:38

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 4 comments.

Comment thread internal/cri/server/container_create.go Resolved
Comment thread internal/cri/server/container_create.go Resolved
Comment thread internal/cri/server/container_create.go Resolved
@samuelkarp

Copy link
Copy Markdown
Member

CI is failing on the manual vendor changes. You could bypass that with a replace directive in the go.mod temporarily.

@liggitt

liggitt commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

CI is failing on the manual vendor changes. You could bypass that with a replace directive in the go.mod temporarily.

I don't really care if the project vendor check fails for now (unless it's keeping us from getting unit/integration/e2e signal), I just wanted to mock out the rest of the changes

@samuelkarp

Copy link
Copy Markdown
Member

unless it's keeping us from getting unit/integration/e2e signal

It is. These workflows all get skipped when the project checks fail:

image

@liggitt
liggitt force-pushed the binary-env-main branch from 9a906dc to 48a0022 Compare May 22, 2026 15:50
Copilot AI review requested due to automatic review settings June 12, 2026 22:19

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 6 out of 11 changed files in this pull request and generated 2 comments.

Comment thread go.mod Outdated
Comment on lines +168 to +170
replace github.com/containerd/containerd/api => ./api

replace k8s.io/cri-api => github.com/liggitt/cri-api v0.37.0-alpha.0.0.20260623175924-f29312ad3d70
Comment on lines 775 to 779
env := append([]string{}, imageConfig.Env...)
for _, e := range config.GetEnvs() {
env = append(env, e.GetKey()+"="+e.GetValue())
env = append(env, e.GetKey()+"="+string(e.GetValue()))
}
specOpts = append(specOpts, oci.WithEnv(env))
@brandond

Copy link
Copy Markdown
Contributor

@liggitt
[1.36] Automated cherry pick of #139964: Restore string JSON encoding of cri-api KeyValue kubernetes/kubernetes#139965

Can confirm that a build of K3s with this replacement for cri-api, along with a cherry-pick of the commits from this PR on to containerd v2.3, work properly.

@liggitt liggitt changed the title WIP: Handle []byte envvar value for CRI Handle []byte envvar value for CRI Jul 23, 2026
@liggitt
liggitt marked this pull request as ready for review July 23, 2026 14:40
@liggitt

liggitt commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

updated to release v0.36.3 tag containing kubernetes/kubernetes#139964

@github-project-automation github-project-automation Bot moved this from Work In Progress to Review In Progress in Pull Request Review Jul 23, 2026

@mikebrow mikebrow left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

still LGTM

@mikebrow
mikebrow added this pull request to the merge queue Jul 23, 2026
@samuelkarp samuelkarp added cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels Jul 23, 2026
Merged via the queue into containerd:main with commit 8572378 Jul 23, 2026
89 of 90 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cri Container Runtime Interface (CRI) cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch cherry-pick/2.3.x Change to be cherry picked to release/2.3 size/L

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants