Skip to content

Conversation

muicoder
Copy link
Contributor

@muicoder muicoder commented Jul 29, 2025

Proposed Changes

Types of Changes

tech debt

Verification

no more codegen steps in CI, no more go-bindata in go.mod

Testing

yes

Linked Issues

User-Facing Change

Further Comments

Thanks to @eugercek for pointing out that this was something that needed attention, and an initial PR for partial replacement of go-bindata.

@muicoder muicoder requested a review from a team as a code owner July 29, 2025 08:17
@muicoder muicoder force-pushed the go-bindata branch 6 times, most recently from 8857859 to 1035431 Compare July 29, 2025 10:00
Copy link
Member

@brandond brandond left a comment

Choose a reason for hiding this comment

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

LGTM, except for one thing as discussed at #12670 (comment) - please add build tags to deploy/data.go and static/data.go:

//go:build !no_stage
// +build !no_stage

@muicoder muicoder force-pushed the go-bindata branch 9 times, most recently from 3320999 to 3834886 Compare July 30, 2025 05:32
@brandond
Copy link
Member

Hmm, it looks like this significantly increases the size of the k3s binary:

k3s binary dist/artifacts/k3s size 113377464 exceeds max acceptable size of 78643200 bytes (75 MiB)

go-bindata did have built-in compression support, which go:embed does not. We'll need to address that somehow.

@muicoder
Copy link
Contributor Author

muicoder commented Jul 30, 2025

This occurs when referencing github.com/k3s-io/k3s/pkg/util/embedutil.go in pkg/data/data.go,so the AssetNames and Asset implementations of these 2 packages are separated.

+ cp -av manifests pkg/deploy/embed
'manifests' -> 'pkg/deploy/embed'
'manifests/ccm.yaml' -> 'pkg/deploy/embed/ccm.yaml'
'manifests/coredns.yaml' -> 'pkg/deploy/embed/coredns.yaml'
'manifests/local-storage.yaml' -> 'pkg/deploy/embed/local-storage.yaml'
'manifests/metrics-server' -> 'pkg/deploy/embed/metrics-server'
'manifests/metrics-server/aggregated-metrics-reader.yaml' -> 'pkg/deploy/embed/metrics-server/aggregated-metrics-reader.yaml'
'manifests/metrics-server/auth-delegator.yaml' -> 'pkg/deploy/embed/metrics-server/auth-delegator.yaml'
'manifests/metrics-server/auth-reader.yaml' -> 'pkg/deploy/embed/metrics-server/auth-reader.yaml'
'manifests/metrics-server/metrics-apiservice.yaml' -> 'pkg/deploy/embed/metrics-server/metrics-apiservice.yaml'
'manifests/metrics-server/metrics-server-deployment.yaml' -> 'pkg/deploy/embed/metrics-server/metrics-server-deployment.yaml'
'manifests/metrics-server/metrics-server-service.yaml' -> 'pkg/deploy/embed/metrics-server/metrics-server-service.yaml'
+ cp -av build/static pkg/static/embed
'build/static' -> 'pkg/static/embed'
'build/static/charts' -> 'pkg/static/embed/charts'
'build/static/charts/traefik-crd-34.2.1+up34.2.0.tgz' -> 'pkg/static/embed/charts/traefik-crd-34.2.1+up34.2.0.tgz'
'build/static/charts/traefik-34.2.1+up34.2.0.tgz' -> 'pkg/static/embed/charts/traefik-34.2.1+up34.2.0.tgz'
+ cp -av build/data pkg/data/embed
'build/data' -> 'pkg/data/embed'
'build/data/79331e8a48ca31e01b9ef36e15be4c987ee87dca459ecbb6ee232856ec375bdf.tar.zst' -> 'pkg/data/embed/79331e8a48ca31e01b9ef36e15be4c987ee87dca459ecbb6ee232856ec375bdf.tar.zst'

Above are the specific files for the 3 embeds, which have already been compressed except for the yaml text.
Secondary compression of already compressed files will not result in a significant reduction in size.

@brandond
Copy link
Member

Ah right. I think we can avoid duplication while also handling it with a common wrapper if we just put it in a separate package.

I've pushed another commit to your PR branch with a couple suggested enhancements, hope you don't mind.

@muicoder
Copy link
Contributor Author

LGTM

@muicoder muicoder force-pushed the go-bindata branch 5 times, most recently from 0145214 to 855112b Compare July 31, 2025 03:56
@brandond
Copy link
Member

brandond commented Jul 31, 2025

I don't like the variable and rm; cp pattern. Why is that necessary? I see that you're doing this to avoid embedding the the .empty file but according to the embed docs:

If a pattern names a directory, all files in the subtree rooted at that directory are embedded (recursively), except that files with names beginning with ‘.’ or ‘_’ are excluded.

Without the .empty file, go vet fails:

brandond@dev01:~/go/src/github.com/k3s-io/k3s$ go vet ./pkg/...
pkg/data/data.go:9:12: pattern embed/*: no matching files found

So I think the correct fix would be to revert your last change, and simply change the embeds to refer to the directory, instead of globbing within that directory:

//go:embed embed
var embedFS embed.FS

muicoder added a commit to muicoder/k3s that referenced this pull request Jul 31, 2025
@brandond
Copy link
Member

Indeed. I guess it's not really designed to be used like this, where the embedded files are not always present.

Maybe we leave the glob, but modify the AssetNames function to skip files starting with . or _, with a comment explaining why?

muicoder added a commit to muicoder/k3s that referenced this pull request Jul 31, 2025
@muicoder
Copy link
Contributor Author

Indeed. I guess it's not really designed to be used like this, where the embedded files are not always present.

Maybe we leave the glob, but modify the AssetNames function to skip files starting with . or _, with a comment explaining why?

Nice way to skip in AssetNames, committed.

muicoder added a commit to muicoder/k3s that referenced this pull request Jul 31, 2025
brandond
brandond previously approved these changes Jul 31, 2025
manuelbuil
manuelbuil previously approved these changes Jul 31, 2025
@manuelbuil
Copy link
Contributor

Won't we need to change the BUILD instructions?

@brandond
Copy link
Member

@manuelbuil how so? We only support building via build scripts. Just running go build in the project has never been sufficient.

@manuelbuil
Copy link
Contributor

@manuelbuil how so? We only support building via build scripts. Just running go build in the project has never been sufficient.

I we do away with all codegen entirely we should change this line https://github.com/k3s-io/k3s/blob/master/BUILDING.md?plain=1#L14, right? And thereby this file https://github.com/k3s-io/k3s/blob/master/scripts/generate

@brandond
Copy link
Member

brandond commented Jul 31, 2025

@manuelbuil oh I missed that one because it is "${GO}" generate for some reason instead of just go generate and it didn't turn up in my search. I'll update.

@brandond brandond dismissed stale reviews from manuelbuil and themself via 397fc89 July 31, 2025 18:00
@brandond brandond requested review from manuelbuil and a team July 31, 2025 18:00
muicoder and others added 2 commits July 31, 2025 18:05
@brandond
Copy link
Member

Thanks @muicoder @eugercek!

@brandond brandond merged commit cb06168 into k3s-io:master Jul 31, 2025
54 checks passed
@muicoder muicoder deleted the go-bindata branch August 1, 2025 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants