mirror of
https://github.com/slimtoolkit/slim.git
synced 2025-06-03 04:00:23 +00:00

Similarly to the compose mode, this series of squashed commits adds support for Kubernetes as an execution environment for the target container image. The branch is a few months old, so it has been squashed to a single commit to reduce the complexity of the rebase & merge. Below are the messages from the squashed commits: [Refactoring] Group all Node.js inspect flags into a single DTO With the upcoming addition of Kubernetes support, we need to figure out a way of sharing code between the existing container.Insepector and the new pod.Inspector. In particular, it can be done through shared config objects. [Refactoring] Extract fat image building into a separate function [Refactoring] Extract fat image inspection into a separate subroutine. Bring in Kubernetes client-go dependency Fix github.com/getkin/kin-openapi usage - got broken by version bump Finding K8s workloads Inspecting fat kubernetes workload image Injecting sensor into K8s workload - initial phase Introduce `kubectl` client Injecting sensor into pod (cont.) Get artifacts from the pod [Refactoring] Extract building slim images into a subroutine Put the rest of the build.handler logic to the kubernetes build subroutine Applying Kubernetes manifest(s) [Refactoring] Revamped Kubernetes Workload Finder [Refactoring] Reshape Kubernetes logic Scale down Kubernetes workloads after slimming Restore Kubernetes workload to the original state if no manifest is used [Refactoring] Introduce HTTPProbeOptions struct and refactor the code Basic Kubernetes workload monitoring - CAMEnter, CAMTimeout, CAMSignal, CAMExec Fix (workaround) for kubectl cp missing file permissions master rebase [Refactoring] Remove unused HTTP Probe Proxy flags Fix HTTP probe having no ports Use latest set of e2e tests HTTP probe for Kubernetes workloads Refine Kubernetes-related flag names Bump down Kubernetes deps to v1.22 to keep Go at v1.16
113 lines
2.6 KiB
Go
113 lines
2.6 KiB
Go
package jsoniter
|
|
|
|
import (
|
|
"encoding/json"
|
|
"github.com/modern-go/reflect2"
|
|
"strconv"
|
|
"unsafe"
|
|
)
|
|
|
|
type Number string
|
|
|
|
// String returns the literal text of the number.
|
|
func (n Number) String() string { return string(n) }
|
|
|
|
// Float64 returns the number as a float64.
|
|
func (n Number) Float64() (float64, error) {
|
|
return strconv.ParseFloat(string(n), 64)
|
|
}
|
|
|
|
// Int64 returns the number as an int64.
|
|
func (n Number) Int64() (int64, error) {
|
|
return strconv.ParseInt(string(n), 10, 64)
|
|
}
|
|
|
|
func CastJsonNumber(val interface{}) (string, bool) {
|
|
switch typedVal := val.(type) {
|
|
case json.Number:
|
|
return string(typedVal), true
|
|
case Number:
|
|
return string(typedVal), true
|
|
}
|
|
return "", false
|
|
}
|
|
|
|
var jsonNumberType = reflect2.TypeOfPtr((*json.Number)(nil)).Elem()
|
|
var jsoniterNumberType = reflect2.TypeOfPtr((*Number)(nil)).Elem()
|
|
|
|
func createDecoderOfJsonNumber(ctx *ctx, typ reflect2.Type) ValDecoder {
|
|
if typ.AssignableTo(jsonNumberType) {
|
|
return &jsonNumberCodec{}
|
|
}
|
|
if typ.AssignableTo(jsoniterNumberType) {
|
|
return &jsoniterNumberCodec{}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func createEncoderOfJsonNumber(ctx *ctx, typ reflect2.Type) ValEncoder {
|
|
if typ.AssignableTo(jsonNumberType) {
|
|
return &jsonNumberCodec{}
|
|
}
|
|
if typ.AssignableTo(jsoniterNumberType) {
|
|
return &jsoniterNumberCodec{}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type jsonNumberCodec struct {
|
|
}
|
|
|
|
func (codec *jsonNumberCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
|
switch iter.WhatIsNext() {
|
|
case StringValue:
|
|
*((*json.Number)(ptr)) = json.Number(iter.ReadString())
|
|
case NilValue:
|
|
iter.skipFourBytes('n', 'u', 'l', 'l')
|
|
*((*json.Number)(ptr)) = ""
|
|
default:
|
|
*((*json.Number)(ptr)) = json.Number([]byte(iter.readNumberAsString()))
|
|
}
|
|
}
|
|
|
|
func (codec *jsonNumberCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
|
number := *((*json.Number)(ptr))
|
|
if len(number) == 0 {
|
|
stream.writeByte('0')
|
|
} else {
|
|
stream.WriteRaw(string(number))
|
|
}
|
|
}
|
|
|
|
func (codec *jsonNumberCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
|
return len(*((*json.Number)(ptr))) == 0
|
|
}
|
|
|
|
type jsoniterNumberCodec struct {
|
|
}
|
|
|
|
func (codec *jsoniterNumberCodec) Decode(ptr unsafe.Pointer, iter *Iterator) {
|
|
switch iter.WhatIsNext() {
|
|
case StringValue:
|
|
*((*Number)(ptr)) = Number(iter.ReadString())
|
|
case NilValue:
|
|
iter.skipFourBytes('n', 'u', 'l', 'l')
|
|
*((*Number)(ptr)) = ""
|
|
default:
|
|
*((*Number)(ptr)) = Number([]byte(iter.readNumberAsString()))
|
|
}
|
|
}
|
|
|
|
func (codec *jsoniterNumberCodec) Encode(ptr unsafe.Pointer, stream *Stream) {
|
|
number := *((*Number)(ptr))
|
|
if len(number) == 0 {
|
|
stream.writeByte('0')
|
|
} else {
|
|
stream.WriteRaw(string(number))
|
|
}
|
|
}
|
|
|
|
func (codec *jsoniterNumberCodec) IsEmpty(ptr unsafe.Pointer) bool {
|
|
return len(*((*Number)(ptr))) == 0
|
|
}
|