Skip to content

feat(request): implement PUT for configmaps and add payloadSize to postDel#238

Merged
fuweid merged 3 commits into
mainfrom
xinwei/put
Jul 2, 2026
Merged

feat(request): implement PUT for configmaps and add payloadSize to postDel#238
fuweid merged 3 commits into
mainfrom
xinwei/put

Conversation

@xinWeiWei24

Copy link
Copy Markdown
Contributor
  • Wire RequestPut through requestPutBuilder; build ConfigMap body inline and PUT to /api/v1/namespaces//configmaps/. Restricted to core/v1 configmaps (validated in load_traffic.go).
  • Add payloadSize to RequestPostDel; expose it as env.PAYLOAD in pod.tpl so POST'd fake pods actually carry the configured bytes.
  • Add randomPayload helper (crypto/rand, [a-zA-Z0-9]).

…stDel

- Wire RequestPut through requestPutBuilder; build ConfigMap body inline
  and PUT to /api/v1/namespaces/<ns>/configmaps/<name>.
  Restricted to core/v1 configmaps (validated in load_traffic.go).
- Add payloadSize to RequestPostDel; expose it as env.PAYLOAD in pod.tpl
  so POST'd fake pods actually carry the configured bytes.
- Add randomPayload helper (crypto/rand, [a-zA-Z0-9]).
Comment thread request/random.go

// randomPayload returns a string of exactly n bytes from a printable
// alphabet, generated from crypto/rand. Returns "" when n <= 0.
func randomPayload(n int) string {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

how about this?

func randomPayload(n int) string {
        if n <= 0 {
                return ""
        }

        const alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

        // Only use byte values in [0, max). Since len(alphabet)=62 and
        // 248 is the largest multiple of 62 below 256, mapping b%62 is uniform
        // for accepted bytes. Bytes 248..255 are skipped to avoid modulo bias.
        const max = byte(256 - 256%len(alphabet))

        out := make([]byte, n)

        bufSize := n
        if bufSize > 4096 {
                bufSize = 4096
        }
        buf := make([]byte, bufSize)

        for i := 0; i < n; {
                if _, err := rand.Read(buf); err != nil {
                        panic(fmt.Errorf("failed to read random bytes: %w", err))
                }

                for _, b := range buf {
                        if b >= max {
                                continue
                        }
                        out[i] = alphabet[int(b)%len(alphabet)]
                        i++
                        if i == n {
                                return string(out)
                        }
                }
        }

        return string(out)
  }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! Updated in the latest commit, PTAL.

@fuweid fuweid merged commit d6305d5 into main Jul 2, 2026
4 checks passed
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.

2 participants