Skip to content

Commit

Permalink
Update resource metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Jun 11, 2024
1 parent 485cee6 commit 528d106
Show file tree
Hide file tree
Showing 28 changed files with 284 additions and 157 deletions.
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module kmodules.xyz/resource-metadata

go 1.22.0
go 1.22.1

toolchain go1.22.1
toolchain go1.22.4

require (
github.com/Masterminds/sprig/v3 v3.2.3
Expand All @@ -17,7 +17,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/yudai/gojsondiff v1.0.0
golang.org/x/net v0.24.0
gomodules.xyz/encoding v0.0.7
gomodules.xyz/encoding v0.0.8
gomodules.xyz/jsonpath v0.0.2
gomodules.xyz/x v0.0.17
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -31,7 +31,7 @@ require (
kmodules.xyz/client-go v0.30.3
kmodules.xyz/crd-schema-fuzz v0.29.1
kmodules.xyz/go-containerregistry v0.0.12
kmodules.xyz/resource-metrics v0.29.5
kmodules.xyz/resource-metrics v0.30.1
kmodules.xyz/schema-checker v0.4.1
sigs.k8s.io/cli-utils v0.34.0
sigs.k8s.io/controller-runtime v0.18.2
Expand Down Expand Up @@ -91,7 +91,6 @@ require (
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.1 // indirect
Expand All @@ -117,7 +116,7 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.1.0 // indirect
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
kmodules.xyz/offshoot-api v0.29.0 // indirect
kmodules.xyz/offshoot-api v0.29.4 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/encoding v0.0.7 h1:Y4PaflVS+vkYgkw6FwyF1S0ab4Y1BAdOqB3Uwjcx8qI=
gomodules.xyz/encoding v0.0.7/go.mod h1:blYJWy456Bzxj3L2G7G5WV1l5rFXl6uYXrmeFqxxqk8=
gomodules.xyz/encoding v0.0.8 h1:r2Koq0BJ4HQCCjPTHuti0ItJDXqWJoLRHcm14Ayyp10=
gomodules.xyz/encoding v0.0.8/go.mod h1:tn9zeeM1vHMxwVIwJQo7gGfJSCOklnU11tZ+3gSbj08=
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
gomodules.xyz/jsonpath v0.0.2 h1:taUvqxKQ9KqVl3vq/+hLg7rCZUIQjq+izhbvo6nTIkE=
Expand Down Expand Up @@ -337,10 +337,10 @@ kmodules.xyz/crd-schema-fuzz v0.29.1 h1:zJTlWYOrT5dsVVHW8HGcnR/vaWfxQfNh11QwTtkY
kmodules.xyz/crd-schema-fuzz v0.29.1/go.mod h1:n708z9YQqLMP2KNLQVgBcRJw1QpSWLvpNCEi+KJDOYE=
kmodules.xyz/go-containerregistry v0.0.12 h1:Tl32QGmSqRVm9PUEb/f3dgDeu9zW5fVzt3qmAFIE37I=
kmodules.xyz/go-containerregistry v0.0.12/go.mod h1:KgeNg0hDsgeda+qc0NzWk0iVRdF0+ZIg/oRzGoYh78I=
kmodules.xyz/offshoot-api v0.29.0 h1:GHLhxxT9jU1N8+FvOCCeJNyU5g0duYS46UGrs6AHNLY=
kmodules.xyz/offshoot-api v0.29.0/go.mod h1:5NxhBblXoDHWStx9HCDJR2KFTwYjEZ7i1Id3jelIunw=
kmodules.xyz/resource-metrics v0.29.5 h1:ciuvRXuXsloLNW/JwkubqbYySsvHvHr6/nhkTL5Sf1o=
kmodules.xyz/resource-metrics v0.29.5/go.mod h1:OuG/QobZ7o8GFHl/u3lqaUR0fDZDegxtV8Vdh+MNBD4=
kmodules.xyz/offshoot-api v0.29.4 h1:WQV2BIUIoVKKiqZNmZ4gAy367jEdwBhEl3dFCLZM1qA=
kmodules.xyz/offshoot-api v0.29.4/go.mod h1:e+NQ0s4gW/YTPWBWEfdISZcmk+tlTq8IjvP5SLdqvko=
kmodules.xyz/resource-metrics v0.30.1 h1:o7mVY8ZwSe5iEILy1eMG4EPZCli7mXZCkgQONjoY9uU=
kmodules.xyz/resource-metrics v0.30.1/go.mod h1:UYcQQLN+3o8rNPQJwJa2D9bt5ihJCeo5bCDuQ4O3MPY=
kmodules.xyz/schema-checker v0.4.1 h1:V5UEjR6UMAXf307lTgw+9rDRfHLTNA8g/q9DngqYI9M=
kmodules.xyz/schema-checker v0.4.1/go.mod h1:BRXLB3Osuc9raHRJxHOgZFGecZ2aZumLXCHAOa5NPdA=
sigs.k8s.io/cli-utils v0.34.0 h1:zCUitt54f0/MYj/ajVFnG6XSXMhpZ72O/3RewIchW8w=
Expand Down
76 changes: 32 additions & 44 deletions vendor/gomodules.xyz/encoding/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ limitations under the License.
package json

import (
"bytes"
"encoding/json"
"fmt"
"io"

kjson "sigs.k8s.io/json"
)

// NewEncoder delegates to json.NewEncoder
Expand All @@ -44,50 +45,11 @@ func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
// limit recursive depth to prevent stack overflow errors
const maxDepth = 10000

// Unmarshal unmarshals the given data
// If v is a *map[string]interface{}, *[]interface{}, or *interface{} numbers
// are converted to int64 or float64
// Unmarshal unmarshals the given data.
// Object keys are case-sensitive.
// Numbers decoded into interface{} fields are converted to int64 or float64.
func Unmarshal(data []byte, v interface{}) error {
switch v := v.(type) {
case *map[string]interface{}:
// Build a decoder from the given data
decoder := json.NewDecoder(bytes.NewBuffer(data))
// Preserve numbers, rather than casting to float64 automatically
decoder.UseNumber()
// Run the decode
if err := decoder.Decode(v); err != nil {
return err
}
// If the decode succeeds, post-process the map to convert json.Number objects to int64 or float64
return ConvertMapNumbers(*v, 0)

case *[]interface{}:
// Build a decoder from the given data
decoder := json.NewDecoder(bytes.NewBuffer(data))
// Preserve numbers, rather than casting to float64 automatically
decoder.UseNumber()
// Run the decode
if err := decoder.Decode(v); err != nil {
return err
}
// If the decode succeeds, post-process the map to convert json.Number objects to int64 or float64
return ConvertSliceNumbers(*v, 0)

case *interface{}:
// Build a decoder from the given data
decoder := json.NewDecoder(bytes.NewBuffer(data))
// Preserve numbers, rather than casting to float64 automatically
decoder.UseNumber()
// Run the decode
if err := decoder.Decode(v); err != nil {
return err
}
// If the decode succeeds, post-process the map to convert json.Number objects to int64 or float64
return ConvertInterfaceNumbers(v, 0)

default:
return json.Unmarshal(data, v)
}
return kjson.UnmarshalCaseSensitivePreserveInts(data, v)
}

// ConvertInterfaceNumbers converts any json.Number values to int64 or float64.
Expand Down Expand Up @@ -163,3 +125,29 @@ func convertNumber(n json.Number) (interface{}, error) {
// An overflow will return an error
return n.Float64()
}

func ToJsonMap(v any) (map[string]any, error) {
data, err := Marshal(v)
if err != nil {
return nil, err
}
var out map[string]any
err = Unmarshal(data, &out)
if err != nil {
return nil, err
}
return out, nil
}

func ToJsonArray(v any) ([]any, error) {
data, err := Marshal(v)
if err != nil {
return nil, err
}
var out []any
err = Unmarshal(data, &out)
if err != nil {
return nil, err
}
return out, nil
}
3 changes: 2 additions & 1 deletion vendor/gomodules.xyz/encoding/json/query/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package query

import (
"fmt"
"reflect"
"strings"

"gomodules.xyz/encoding/json"
Expand Down Expand Up @@ -206,7 +207,7 @@ func setNestedFieldNoCopy(obj map[string]interface{}, value interface{}, fields
m := obj

for i, field := range fields[:len(fields)-1] {
if val, ok := m[field]; ok {
if val, ok := m[field]; ok && !reflect.ValueOf(val).IsNil() {
if valMap, ok := val.(map[string]interface{}); ok {
m = valMap
} else {
Expand Down
1 change: 1 addition & 0 deletions vendor/kmodules.xyz/offshoot-api/api/v1/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License.
*/

// +k8s:deepcopy-gen=package
// +k8s:conversion-gen=kmodules.xyz/offshoot-api/api/v2
// +k8s:openapi-gen=true
// +gencrdrefdocs:force=true
package v1 // import "kmodules.xyz/offshoot-api/api/v1"
50 changes: 50 additions & 0 deletions vendor/kmodules.xyz/offshoot-api/api/v1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 23 additions & 4 deletions vendor/kmodules.xyz/offshoot-api/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,16 @@ type PodSpec struct {
// Host networking requested for this pod. Use the host's network namespace.
// If this option is set, the ports that will be used must be specified.
// Default to false.
// +k8s:conversion-gen=false
// +optional
HostNetwork bool `json:"hostNetwork,omitempty"`

// Use the host's pid namespace.
// Optional: Default to false.
// +k8s:conversion-gen=false
// +optional
HostPID bool `json:"hostPID,omitempty"`

// Use the host's ipc namespace.
// Optional: Default to false.
// +k8s:conversion-gen=false
// +optional
HostIPC bool `json:"hostIPC,omitempty"`

Expand All @@ -137,7 +134,6 @@ type PodSpec struct {
// in the same pod, and the first process in each container will not be assigned PID 1.
// HostPID and ShareProcessNamespace cannot both be set.
// Optional: Default to false.
// +k8s:conversion-gen=false
// +optional
ShareProcessNamespace *bool `json:"shareProcessNamespace,omitempty"`

Expand Down Expand Up @@ -274,6 +270,10 @@ type PodSpec struct {
// +patchMergeKey=mountPath
// +patchStrategy=merge
VolumeMounts []core.VolumeMount `json:"volumeMounts,omitempty" patchStrategy:"merge" patchMergeKey:"mountPath"`

// PodPlacementPolicy is the reference of the podPlacementPolicy
// +optional
PodPlacementPolicy *core.LocalObjectReference `json:"podPlacementPolicy,omitempty"`
}

// ServiceTemplateSpec describes the data a service should have when created from a template
Expand Down Expand Up @@ -392,6 +392,25 @@ type ServicePort struct {
NodePort int32 `json:"nodePort,omitempty"`
}

// GatewayPort contains information on Gateway service's port.
type GatewayPort struct {
// The name of this port within the gateway service.
// +optional
Name string `json:"name,omitempty"`

// The port that will be exposed by the gateway service.
Port int32 `json:"port"`

// Number of the port to access the backend service.
// +optional
BackendServicePort int32 `json:"backendServicePort,omitempty"`

// The port on each node on which this gateway service is exposed when type is
// NodePort or LoadBalancer.
// +optional
NodePort int32 `json:"nodePort,omitempty"`
}

// Beware of MergeServicePorts
// ref: https://github.com/kmodules/client-go/blob/03dac1aea5084354127990a10d0b0e7529460dd5/core/v1/service.go#L103-L136
func PatchServicePorts(cur []core.ServicePort, desired []ServicePort) []core.ServicePort {
Expand Down
21 changes: 21 additions & 0 deletions vendor/kmodules.xyz/offshoot-api/api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 528d106

Please sign in to comment.