kubewharf / kubezoo

a lightweight kubernetes multi-tenancy gateway
Apache License 2.0
689 stars 57 forks source link

tanentID doesn't exist if name/ID is large #12

Closed SOF3 closed 2 years ago

SOF3 commented 2 years ago

What happened?

Error from server: tanentID doesn't exist in context context.Background.WithValue(type *http.contextKey, val <not Stringer>).WithValue(type *http.contextKey, val 127.0.0.1:6443).WithCancel.WithValue(type *http.contextKey, val 127.0.0.1:6443).WithValue(type *http.contextKey, val <not Stringer>).WithCancel.WithValue(type httplog.respLoggerContextKeyType, val <not Stringer>).WithValue(type request.requestInfoKeyType, val <not Stringer>).WithCancel.WithValue(type request.key, val <not Stringer>).WithValue(type request.key, val default)

What did you expect to happen?

Should be able to fetch pods

How can we reproduce it (as minimally and precisely as possible)?

I follow the steps in manually-setup.md

I test tenant creation with the following function:

sed "s/111111/$tenant/g" $KUBEZOO_PATH/config/setup/sample_tenant.yml \
        | kubectl apply -f -
sleep 5
kubectl --context kind-kind get tenant $tenant -o json \
        | jq '.metadata.annotations["kubezoo.io/tenant.kubeconfig.base64"]' -r \
        | base64 -d > tenant.yaml
kubectl --kubeconfig tenant.yaml get pod

When tenant=111111, this works correctly

When tenant=1232408922 (4975115b in hex, which is a bit more than 2^30, still fits in the int32 bounds), the tenant kubeconfig annotation still gets populated, but last step doesn't work, with the error shown above.

Then I try again with tenant=123240 (without deleting existing tenants from previous steps), this works correctly

So I tried again with tenant=1232408923 (the second step plus one), doesn't work again

Software version

docker image: kubezoo/kubezoo:v0.1.0

SOF3 commented 2 years ago

Turns out that there is a restriction of 6 characters in tenant ID. https://github.com/kubewharf/kubezoo/blob/a71c394bbadc4b81791138b1f0d5a4d57a34541b/pkg/util/util.go#L47 Can this be documented more clearly?

caohe commented 2 years ago

Thanks for pointing out it! We will add this restriction in the documentation. And it would be greatly appreciated if you could help improve the documentation :)