This drops another dependency on k8s.io/kubernetes. This does have the unfortunate side effect that implementers will now get a compile error until they update their code to use the new type. Just as a note: The stats types have moved to k8s.io/kubelet, however the stats types are only there as of v1.20. Currently we support older versions than v1.20, and even our go.mod imports from v1.19. For now we copy the types in. Later we can remove the type defs and change them to type aliases to the k8s.io/kubelet types (which prevents another compile time issue). Anything relying on type assertions to determine if something implements this method will, unfortunately, be broken and it will be hard to notice until runtime. We need to make sure to call this out in the release notes. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
33 lines
890 B
Go
33 lines
890 B
Go
package framework
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"strconv"
|
|
|
|
stats "github.com/virtual-kubelet/virtual-kubelet/node/api/statsv1alpha1"
|
|
"k8s.io/apimachinery/pkg/util/net"
|
|
)
|
|
|
|
// GetStatsSummary queries the /stats/summary endpoint of the virtual-kubelet and returns the Summary object obtained as a response.
|
|
func (f *Framework) GetStatsSummary(ctx context.Context) (*stats.Summary, error) {
|
|
// Query the /stats/summary endpoint.
|
|
b, err := f.KubeClient.CoreV1().
|
|
RESTClient().
|
|
Get().
|
|
Namespace(f.Namespace).
|
|
Resource("pods").
|
|
SubResource("proxy").
|
|
Name(net.JoinSchemeNamePort("http", f.NodeName, strconv.Itoa(10255))).
|
|
Suffix("/stats/summary").DoRaw(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
// Unmarshal the response as a Summary object and return it.
|
|
res := &stats.Summary{}
|
|
if err := json.Unmarshal(b, res); err != nil {
|
|
return nil, err
|
|
}
|
|
return res, nil
|
|
}
|