diff --git a/go.mod b/go.mod index 8041b9b..3423118 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/francoispqt/onelog v0.0.0-20190306043706-8c2bb31b10a4 - github.com/kubewarden/k8s-objects v1.27.0-kw3 + github.com/kubewarden/k8s-objects v1.27.0-kw4 github.com/kubewarden/policy-sdk-go v0.5.0 github.com/wapc/wapc-guest-tinygo v0.3.3 ) diff --git a/go.sum b/go.sum index ac0792a..4dec4bc 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/kubewarden/k8s-objects v1.27.0-kw2 h1:6ZA72SFtDSbCupwxlIyJimUzN0nSweM github.com/kubewarden/k8s-objects v1.27.0-kw2/go.mod h1:wVx4Rg1HKml8yewPwAHUWp1wYSAtBlKV/tsmteDuK1g= github.com/kubewarden/k8s-objects v1.27.0-kw3 h1:3a5icCAl4gRDFcDhHk/rkHeocrjSzg/gAlfhrLReqWU= github.com/kubewarden/k8s-objects v1.27.0-kw3/go.mod h1:EMF+Hr26oDR4yQkWJAQpl0M0Ek5ioNXlCswjGZO0G2U= +github.com/kubewarden/k8s-objects v1.27.0-kw4 h1:az1qJLD5f5Pcx9ur1oRMhWqZi1AL5MLJoXXgRjCeuQY= +github.com/kubewarden/k8s-objects v1.27.0-kw4/go.mod h1:EMF+Hr26oDR4yQkWJAQpl0M0Ek5ioNXlCswjGZO0G2U= github.com/kubewarden/policy-sdk-go v0.5.0 h1:JnSRf5pHjFzTNNp6jJbSP5a4cwzFzkUBjLujqJd+Z+w= github.com/kubewarden/policy-sdk-go v0.5.0/go.mod h1:1IZXauwI5iCuOZj7tU58nE/SZFb/HsCmj3ZpDVStVQs= github.com/kubewarden/strfmt v0.1.3 h1:bb+2rbotioROjCkziSt+hqnHXzOlumN94NxDKdV2kPI= diff --git a/vendor/github.com/kubewarden/k8s-objects/apimachinery/pkg/util/intstr/int_or_string.go b/vendor/github.com/kubewarden/k8s-objects/apimachinery/pkg/util/intstr/int_or_string.go index 490cf5a..20817d1 100644 --- a/vendor/github.com/kubewarden/k8s-objects/apimachinery/pkg/util/intstr/int_or_string.go +++ b/vendor/github.com/kubewarden/k8s-objects/apimachinery/pkg/util/intstr/int_or_string.go @@ -1,11 +1,93 @@ // Code generated by go-swagger; DO NOT EDIT. +// +// The OpenApi file generated by Kubernetes does not implement OpenAPI v3. Because of that, the +// IntOrString object generated by go-swagger (which currently supports only v2) is not working +// properly. +// +// To fix this issue, we overwrite the code generated by go-swagger with this one, which is +// based on https://github.com/kubernetes/apimachinery/blob/master/pkg/util/intstr/intstr.go package intstr -// This file was generated by the swagger tool. -// Editing this file might prove futile when you re-run the swagger generate command +import ( + "encoding/json" + "fmt" + "strconv" +) + +type IntOrString struct { + Type Type `json:"type" protobuf:"varint,1,opt,name=type,casttype=Type"` + Int64Val int64 `json:"int64Val,omitempty" protobuf:"varint,2,opt,name=int64Val"` + StrVal string `json:"strVal,omitempty" protobuf:"bytes,3,opt,name=strVal"` +} + +// Type represents the stored type of IntOrString. +type Type int64 + +const ( + Int64 Type = iota // The IntOrString holds an int64. + String // The IntOrString holds a string. +) + +// FromString creates an IntOrString object with a string value. +func FromString(val string) IntOrString { + return IntOrString{Type: String, StrVal: val} +} -// IntOrString IntOrString is a type that can hold an int32 or a string. When used in JSON or YAML marshalling and unmarshalling, it produces or consumes the inner type. This allows you to have, for example, a JSON field that can accept a name or number. +// FromInt64 creates an IntOrString object with an int64 value. +func FromInt64(val int64) IntOrString { + return IntOrString{Type: Int64, Int64Val: val} +} + +// Parse the given string and try to convert it to an int64 before +// setting it as a string value. +func Parse(val string) IntOrString { + i, err := strconv.ParseInt(val, 10, 64) + if err != nil { + return FromString(val) + } + return FromInt64(i) +} + +// UnmarshalJSON implements the json.Unmarshaller interface. +func (int64str *IntOrString) UnmarshalJSON(value []byte) error { + if value[0] == '"' { + int64str.Type = String + return json.Unmarshal(value, &int64str.StrVal) + } + int64str.Type = Int64 + return json.Unmarshal(value, &int64str.Int64Val) +} + +// Int64Value returns the Int64Val if type Int64, or if +// it is a String, will attempt a conversion to int64, +// returning 0 if a parsing error occurs. +func (int64str *IntOrString) Int64Value() int64 { + if int64str.Type == String { + i, _ := strconv.ParseInt(int64str.StrVal, 10, 64) + return i + } + return int64str.Int64Val +} + +// MarshalJSON implements the json.Marshaller interface. +func (int64str IntOrString) MarshalJSON() ([]byte, error) { + switch int64str.Type { + case Int64: + return json.Marshal(int64str.Int64Val) + case String: + return json.Marshal(int64str.StrVal) + default: + return []byte{}, fmt.Errorf("impossible IntOrString.Type") + } +} + +// OpenAPISchemaType is used by the kube-openapi generator when constructing +// the OpenAPI spec of this type. // -// swagger:model IntOrString -type IntOrString string +// See: https://github.com/kubernetes/kube-openapi/tree/master/pkg/generators +func (IntOrString) OpenAPISchemaType() []string { return []string{"string"} } + +// OpenAPISchemaFormat is used by the kube-openapi generator when constructing +// the OpenAPI spec of this type. +func (IntOrString) OpenAPISchemaFormat() string { return "int64-or-string" } diff --git a/vendor/modules.txt b/vendor/modules.txt index 993f4e7..9fca4c3 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -7,7 +7,7 @@ github.com/francoispqt/onelog # github.com/go-openapi/strfmt v0.21.3 => github.com/kubewarden/strfmt v0.1.3 ## explicit; go 1.20 github.com/go-openapi/strfmt -# github.com/kubewarden/k8s-objects v1.27.0-kw3 +# github.com/kubewarden/k8s-objects v1.27.0-kw4 ## explicit; go 1.20 github.com/kubewarden/k8s-objects/api/apps/v1 github.com/kubewarden/k8s-objects/api/batch/v1