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

mockkubeapiserver: Support stringData when creating a secret #383

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

justinsb
Copy link
Contributor

This is an edge case in the kube apiserver, but there is special
handling for the stringData field of a secret, that is mapped to
base64 data.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 17, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb

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

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 17, 2024
@justinsb justinsb force-pushed the mock_kubeapiserver_support_secret_plaintext branch 2 times, most recently from 2699368 to e09355f Compare June 8, 2024 11:21
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 8, 2024
@justinsb justinsb force-pushed the mock_kubeapiserver_support_secret_plaintext branch from e09355f to 9e7a576 Compare June 8, 2024 11:24
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 8, 2024
@justinsb justinsb force-pushed the mock_kubeapiserver_support_secret_plaintext branch from 9e7a576 to 41b0c21 Compare June 10, 2024 13:57
@justinsb
Copy link
Contributor Author

Hmmm .... this no longer needs a rebase (at least it shouldn't)... I'll try a retest

/retest

Copy link
Member

@tomasaschan tomasaschan left a comment

Choose a reason for hiding this comment

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

A bit of a nit, but still: the errors could be more descriptive.

Also, wouldn't hurt to cover/document this behavior in tests :)

mockkubeapiserver/postresource.go Outdated Show resolved Hide resolved
mockkubeapiserver/postresource.go Outdated Show resolved Hide resolved
mockkubeapiserver/postresource.go Outdated Show resolved Hide resolved
if !ok {
return fmt.Errorf("unexpected type for v1.Secret stringData entry, got %T", vAny)
}
dataMap[k] = base64.StdEncoding.EncodeToString([]byte(v))
Copy link
Member

Choose a reason for hiding this comment

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

I'm not familiar enough with what Go will do through all of these casts; will this actually end up mutating obj? Or does it just mutate the dataMap we've created, but not actually propagate those changes back?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the answer is yes, and the test will (hopefully!) prove it. I'll have a go at rewriting it to be more self-evidently true though, I agree there's too much happening here.

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 11, 2024
@justinsb
Copy link
Contributor Author

justinsb commented Jun 14, 2024

Also, wouldn't hurt to cover/document this behavior in tests :)

A great point, I was thinking about that the other day. This change was to support testing in k8s-config-connector, so it got test coverage there, but we could easily create some simple tests directly in this repo - let me do that!

@justinsb justinsb force-pushed the mock_kubeapiserver_support_secret_plaintext branch from 6ad6bda to 7a17600 Compare June 15, 2024 01:53
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 15, 2024
@justinsb justinsb force-pushed the mock_kubeapiserver_support_secret_plaintext branch 2 times, most recently from 7c2a843 to 161f176 Compare June 15, 2024 01:57
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jun 15, 2024
@justinsb justinsb force-pushed the mock_kubeapiserver_support_secret_plaintext branch from 427f43b to 0f0006b Compare June 15, 2024 12:48
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jun 15, 2024
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jun 15, 2024
@justinsb
Copy link
Contributor Author

This is escalating a bit ... looks like I need to break out a new module to avoid a circular dependency: #398

@justinsb justinsb force-pushed the mock_kubeapiserver_support_secret_plaintext branch 7 times, most recently from 3d17dbd to bf72339 Compare July 2, 2024 11:52
justinsb and others added 4 commits July 2, 2024 07:54
The developer experience of working without go.work is pretty bad - we
have to break changes into lots of PRs.  We're going to try checking
in go.work instead.
This is an edge case in the kube apiserver, but there is special
handling for the stringData field of a secret, that is mapped to
base64 data.

Co-authored-by: Tomas Aschan <1550920+tomasaschan@users.noreply.github.com>
Not (yet) applying this everywhere to keep the changes reasonable, but
for our new tests it is much easier to read.
This avoids a circular (module) dependency between mockkubeapiserver
and kdp itself.
@justinsb justinsb force-pushed the mock_kubeapiserver_support_secret_plaintext branch from bf72339 to 454214e Compare July 2, 2024 11:54
@justinsb justinsb force-pushed the mock_kubeapiserver_support_secret_plaintext branch from 454214e to 82a46e7 Compare July 2, 2024 11:57
@justinsb
Copy link
Contributor Author

justinsb commented Jul 2, 2024

Had a bit of trouble with the go.sum / go.mod checking (dev/format-gomod), but I finally figured out that the go.sum difference was to do with my cache; I did go clean -cache -modcache before running dev/format-gomod. I think it's still worth trying go.work (and I added a note to the dev/format-gomod script and to the GitHub action error message)

@justinsb
Copy link
Contributor Author

justinsb commented Jul 3, 2024

This might be much easier if we merged a (basically empty) ktest module first - then I think we could stay away from go work sync which is the root of all the problems. Maybe that's a reasonable compromise that's worth a go.

@justinsb
Copy link
Contributor Author

justinsb commented Jul 3, 2024

I tried staging the ktest module in #400. I think that would mean I could back out the go work sync logic which gave me so much trouble

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. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants