diff --git a/apis/discovery/v1/endpointslice.go b/apis/discovery/v1/endpointslice.go new file mode 100644 index 0000000..634af95 --- /dev/null +++ b/apis/discovery/v1/endpointslice.go @@ -0,0 +1,100 @@ +/* +Copyright 2024 the original author or authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v1 + +import ( + discoveryv1 "k8s.io/api/discovery/v1" + diecorev1 "reconciler.io/dies/apis/core/v1" +) + +// +die:object=true +type _ = discoveryv1.EndpointSlice + +func (d *EndpointSliceDie) EndpointsDie(endpoints ...*EndpointDie) *EndpointSliceDie { + return d.DieStamp(func(r *discoveryv1.EndpointSlice) { + r.Endpoints = make([]discoveryv1.Endpoint, len(endpoints)) + for i := range endpoints { + r.Endpoints[i] = endpoints[i].DieRelease() + } + }) +} + +func (d *EndpointSliceDie) PortsDie(ports ...*EndpointPortDie) *EndpointSliceDie { + return d.DieStamp(func(r *discoveryv1.EndpointSlice) { + r.Ports = make([]discoveryv1.EndpointPort, len(ports)) + for i := range ports { + r.Ports[i] = ports[i].DieRelease() + } + }) +} + +// +die +type _ = discoveryv1.Endpoint + +func (d *EndpointDie) ConditionsDie(fn func(d *EndpointConditionsDie)) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + d := EndpointConditionsBlank.DieImmutable(false).DieFeed(r.Conditions) + fn(d) + r.Conditions = d.DieRelease() + }) +} + +func (d *EndpointDie) TargetRefDie(fn func(d *diecorev1.ObjectReferenceDie)) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + d := diecorev1.ObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.TargetRef) + fn(d) + r.TargetRef = d.DieReleasePtr() + }) +} + +func (d *EndpointDie) AddDeprecatedTopology(key, value string) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + if r.DeprecatedTopology == nil { + r.DeprecatedTopology = map[string]string{} + } + r.DeprecatedTopology[key] = value + }) +} + +func (d *EndpointDie) HintsDie(fn func(d *EndpointHintsDie)) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + d := EndpointHintsBlank.DieImmutable(false).DieFeedPtr(r.Hints) + fn(d) + r.Hints = d.DieReleasePtr() + }) +} + +// +die +type _ = discoveryv1.EndpointConditions + +// +die +type _ = discoveryv1.EndpointHints + +func (d *EndpointHintsDie) ForZonesDie(zones ...*ForZoneDie) *EndpointHintsDie { + return d.DieStamp(func(r *discoveryv1.EndpointHints) { + r.ForZones = make([]discoveryv1.ForZone, len(zones)) + for i := range zones { + r.ForZones[i] = zones[i].DieRelease() + } + }) +} + +// +die +type _ = discoveryv1.ForZone + +// +die +type _ = discoveryv1.EndpointPort diff --git a/apis/discovery/v1/zz_generated.die.go b/apis/discovery/v1/zz_generated.die.go new file mode 100644 index 0000000..34f9d70 --- /dev/null +++ b/apis/discovery/v1/zz_generated.die.go @@ -0,0 +1,1458 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright 2021-2022 the original author or authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by diegen. DO NOT EDIT. + +package v1 + +import ( + json "encoding/json" + fmtx "fmt" + corev1 "k8s.io/api/core/v1" + discoveryv1 "k8s.io/api/discovery/v1" + unstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + jsonpath "k8s.io/client-go/util/jsonpath" + osx "os" + metav1 "reconciler.io/dies/apis/meta/v1" + reflectx "reflect" + yaml "sigs.k8s.io/yaml" +) + +var EndpointSliceBlank = (&EndpointSliceDie{}).DieFeed(discoveryv1.EndpointSlice{}) + +type EndpointSliceDie struct { + metav1.FrozenObjectMeta + mutable bool + r discoveryv1.EndpointSlice +} + +// DieImmutable returns a new die for the current die's state that is either mutable (`false`) or immutable (`true`). +func (d *EndpointSliceDie) DieImmutable(immutable bool) *EndpointSliceDie { + if d.mutable == !immutable { + return d + } + d = d.DeepCopy() + d.mutable = !immutable + return d +} + +// DieFeed returns a new die with the provided resource. +func (d *EndpointSliceDie) DieFeed(r discoveryv1.EndpointSlice) *EndpointSliceDie { + if d.mutable { + d.FrozenObjectMeta = metav1.FreezeObjectMeta(r.ObjectMeta) + d.r = r + return d + } + return &EndpointSliceDie{ + FrozenObjectMeta: metav1.FreezeObjectMeta(r.ObjectMeta), + mutable: d.mutable, + r: r, + } +} + +// DieFeedPtr returns a new die with the provided resource pointer. If the resource is nil, the empty value is used instead. +func (d *EndpointSliceDie) DieFeedPtr(r *discoveryv1.EndpointSlice) *EndpointSliceDie { + if r == nil { + r = &discoveryv1.EndpointSlice{} + } + return d.DieFeed(*r) +} + +// DieFeedJSON returns a new die with the provided JSON. Panics on error. +func (d *EndpointSliceDie) DieFeedJSON(j []byte) *EndpointSliceDie { + r := discoveryv1.EndpointSlice{} + if err := json.Unmarshal(j, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAML returns a new die with the provided YAML. Panics on error. +func (d *EndpointSliceDie) DieFeedYAML(y []byte) *EndpointSliceDie { + r := discoveryv1.EndpointSlice{} + if err := yaml.Unmarshal(y, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAMLFile returns a new die loading YAML from a file path. Panics on error. +func (d *EndpointSliceDie) DieFeedYAMLFile(name string) *EndpointSliceDie { + y, err := osx.ReadFile(name) + if err != nil { + panic(err) + } + return d.DieFeedYAML(y) +} + +// DieFeedRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *EndpointSliceDie) DieFeedRawExtension(raw runtime.RawExtension) *EndpointSliceDie { + j, err := json.Marshal(raw) + if err != nil { + panic(err) + } + return d.DieFeedJSON(j) +} + +// DieRelease returns the resource managed by the die. +func (d *EndpointSliceDie) DieRelease() discoveryv1.EndpointSlice { + if d.mutable { + return d.r + } + return *d.r.DeepCopy() +} + +// DieReleasePtr returns a pointer to the resource managed by the die. +func (d *EndpointSliceDie) DieReleasePtr() *discoveryv1.EndpointSlice { + r := d.DieRelease() + return &r +} + +// DieReleaseUnstructured returns the resource managed by the die as an unstructured object. Panics on error. +func (d *EndpointSliceDie) DieReleaseUnstructured() *unstructured.Unstructured { + r := d.DieReleasePtr() + u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(r) + if err != nil { + panic(err) + } + return &unstructured.Unstructured{ + Object: u, + } +} + +// DieReleaseJSON returns the resource managed by the die as JSON. Panics on error. +func (d *EndpointSliceDie) DieReleaseJSON() []byte { + r := d.DieReleasePtr() + j, err := json.Marshal(r) + if err != nil { + panic(err) + } + return j +} + +// DieReleaseYAML returns the resource managed by the die as YAML. Panics on error. +func (d *EndpointSliceDie) DieReleaseYAML() []byte { + r := d.DieReleasePtr() + y, err := yaml.Marshal(r) + if err != nil { + panic(err) + } + return y +} + +// DieReleaseRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *EndpointSliceDie) DieReleaseRawExtension() runtime.RawExtension { + j := d.DieReleaseJSON() + raw := runtime.RawExtension{} + if err := json.Unmarshal(j, &raw); err != nil { + panic(err) + } + return raw +} + +// DieStamp returns a new die with the resource passed to the callback function. The resource is mutable. +func (d *EndpointSliceDie) DieStamp(fn func(r *discoveryv1.EndpointSlice)) *EndpointSliceDie { + r := d.DieRelease() + fn(&r) + return d.DieFeed(r) +} + +// Experimental: DieStampAt uses a JSON path (http://goessner.net/articles/JsonPath/) expression to stamp portions of the resource. The callback is invoked with each JSON path match. Panics if the callback function does not accept a single argument of the same type or a pointer to that type as found on the resource at the target location. +// +// Future iterations will improve type coercion from the resource to the callback argument. +func (d *EndpointSliceDie) DieStampAt(jp string, fn interface{}) *EndpointSliceDie { + return d.DieStamp(func(r *discoveryv1.EndpointSlice) { + if ni := reflectx.ValueOf(fn).Type().NumIn(); ni != 1 { + panic(fmtx.Errorf("callback function must have 1 input parameters, found %d", ni)) + } + if no := reflectx.ValueOf(fn).Type().NumOut(); no != 0 { + panic(fmtx.Errorf("callback function must have 0 output parameters, found %d", no)) + } + + cp := jsonpath.New("") + if err := cp.Parse(fmtx.Sprintf("{%s}", jp)); err != nil { + panic(err) + } + cr, err := cp.FindResults(r) + if err != nil { + // errors are expected if a path is not found + return + } + for _, cv := range cr[0] { + arg0t := reflectx.ValueOf(fn).Type().In(0) + + var args []reflectx.Value + if cv.Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv} + } else if cv.CanAddr() && cv.Addr().Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv.Addr()} + } else { + panic(fmtx.Errorf("callback function must accept value of type %q, found type %q", cv.Type(), arg0t)) + } + + reflectx.ValueOf(fn).Call(args) + } + }) +} + +// DieWith returns a new die after passing the current die to the callback function. The passed die is mutable. +func (d *EndpointSliceDie) DieWith(fns ...func(d *EndpointSliceDie)) *EndpointSliceDie { + nd := EndpointSliceBlank.DieFeed(d.DieRelease()).DieImmutable(false) + for _, fn := range fns { + if fn != nil { + fn(nd) + } + } + return d.DieFeed(nd.DieRelease()) +} + +// DeepCopy returns a new die with equivalent state. Useful for snapshotting a mutable die. +func (d *EndpointSliceDie) DeepCopy() *EndpointSliceDie { + r := *d.r.DeepCopy() + return &EndpointSliceDie{ + FrozenObjectMeta: metav1.FreezeObjectMeta(r.ObjectMeta), + mutable: d.mutable, + r: r, + } +} + +var _ runtime.Object = (*EndpointSliceDie)(nil) + +func (d *EndpointSliceDie) DeepCopyObject() runtime.Object { + return d.r.DeepCopy() +} + +func (d *EndpointSliceDie) GetObjectKind() schema.ObjectKind { + r := d.DieRelease() + return r.GetObjectKind() +} + +func (d *EndpointSliceDie) MarshalJSON() ([]byte, error) { + return json.Marshal(d.r) +} + +func (d *EndpointSliceDie) UnmarshalJSON(b []byte) error { + if d == EndpointSliceBlank { + return fmtx.Errorf("cannot unmarshal into the blank die, create a copy first") + } + if !d.mutable { + return fmtx.Errorf("cannot unmarshal into immutable dies, create a mutable version first") + } + r := &discoveryv1.EndpointSlice{} + err := json.Unmarshal(b, r) + *d = *d.DieFeed(*r) + return err +} + +// APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources +func (d *EndpointSliceDie) APIVersion(v string) *EndpointSliceDie { + return d.DieStamp(func(r *discoveryv1.EndpointSlice) { + r.APIVersion = v + }) +} + +// Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds +func (d *EndpointSliceDie) Kind(v string) *EndpointSliceDie { + return d.DieStamp(func(r *discoveryv1.EndpointSlice) { + r.Kind = v + }) +} + +// MetadataDie stamps the resource's ObjectMeta field with a mutable die. +func (d *EndpointSliceDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *EndpointSliceDie { + return d.DieStamp(func(r *discoveryv1.EndpointSlice) { + d := metav1.ObjectMetaBlank.DieImmutable(false).DieFeed(r.ObjectMeta) + fn(d) + r.ObjectMeta = d.DieRelease() + }) +} + +// addressType specifies the type of address carried by this EndpointSlice. +// +// All addresses in this slice must be the same type. This field is +// +// immutable after creation. The following address types are currently +// +// supported: +// +// * IPv4: Represents an IPv4 Address. +// +// * IPv6: Represents an IPv6 Address. +// +// * FQDN: Represents a Fully Qualified Domain Name. +func (d *EndpointSliceDie) AddressType(v discoveryv1.AddressType) *EndpointSliceDie { + return d.DieStamp(func(r *discoveryv1.EndpointSlice) { + r.AddressType = v + }) +} + +// endpoints is a list of unique endpoints in this slice. Each slice may +// +// include a maximum of 1000 endpoints. +func (d *EndpointSliceDie) Endpoints(v ...discoveryv1.Endpoint) *EndpointSliceDie { + return d.DieStamp(func(r *discoveryv1.EndpointSlice) { + r.Endpoints = v + }) +} + +// ports specifies the list of network ports exposed by each endpoint in +// +// this slice. Each port must have a unique name. When ports is empty, it +// +// indicates that there are no defined ports. When a port is defined with a +// +// nil port value, it indicates "all ports". Each slice may include a +// +// maximum of 100 ports. +func (d *EndpointSliceDie) Ports(v ...discoveryv1.EndpointPort) *EndpointSliceDie { + return d.DieStamp(func(r *discoveryv1.EndpointSlice) { + r.Ports = v + }) +} + +var EndpointBlank = (&EndpointDie{}).DieFeed(discoveryv1.Endpoint{}) + +type EndpointDie struct { + mutable bool + r discoveryv1.Endpoint +} + +// DieImmutable returns a new die for the current die's state that is either mutable (`false`) or immutable (`true`). +func (d *EndpointDie) DieImmutable(immutable bool) *EndpointDie { + if d.mutable == !immutable { + return d + } + d = d.DeepCopy() + d.mutable = !immutable + return d +} + +// DieFeed returns a new die with the provided resource. +func (d *EndpointDie) DieFeed(r discoveryv1.Endpoint) *EndpointDie { + if d.mutable { + d.r = r + return d + } + return &EndpointDie{ + mutable: d.mutable, + r: r, + } +} + +// DieFeedPtr returns a new die with the provided resource pointer. If the resource is nil, the empty value is used instead. +func (d *EndpointDie) DieFeedPtr(r *discoveryv1.Endpoint) *EndpointDie { + if r == nil { + r = &discoveryv1.Endpoint{} + } + return d.DieFeed(*r) +} + +// DieFeedJSON returns a new die with the provided JSON. Panics on error. +func (d *EndpointDie) DieFeedJSON(j []byte) *EndpointDie { + r := discoveryv1.Endpoint{} + if err := json.Unmarshal(j, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAML returns a new die with the provided YAML. Panics on error. +func (d *EndpointDie) DieFeedYAML(y []byte) *EndpointDie { + r := discoveryv1.Endpoint{} + if err := yaml.Unmarshal(y, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAMLFile returns a new die loading YAML from a file path. Panics on error. +func (d *EndpointDie) DieFeedYAMLFile(name string) *EndpointDie { + y, err := osx.ReadFile(name) + if err != nil { + panic(err) + } + return d.DieFeedYAML(y) +} + +// DieFeedRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *EndpointDie) DieFeedRawExtension(raw runtime.RawExtension) *EndpointDie { + j, err := json.Marshal(raw) + if err != nil { + panic(err) + } + return d.DieFeedJSON(j) +} + +// DieRelease returns the resource managed by the die. +func (d *EndpointDie) DieRelease() discoveryv1.Endpoint { + if d.mutable { + return d.r + } + return *d.r.DeepCopy() +} + +// DieReleasePtr returns a pointer to the resource managed by the die. +func (d *EndpointDie) DieReleasePtr() *discoveryv1.Endpoint { + r := d.DieRelease() + return &r +} + +// DieReleaseJSON returns the resource managed by the die as JSON. Panics on error. +func (d *EndpointDie) DieReleaseJSON() []byte { + r := d.DieReleasePtr() + j, err := json.Marshal(r) + if err != nil { + panic(err) + } + return j +} + +// DieReleaseYAML returns the resource managed by the die as YAML. Panics on error. +func (d *EndpointDie) DieReleaseYAML() []byte { + r := d.DieReleasePtr() + y, err := yaml.Marshal(r) + if err != nil { + panic(err) + } + return y +} + +// DieReleaseRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *EndpointDie) DieReleaseRawExtension() runtime.RawExtension { + j := d.DieReleaseJSON() + raw := runtime.RawExtension{} + if err := json.Unmarshal(j, &raw); err != nil { + panic(err) + } + return raw +} + +// DieStamp returns a new die with the resource passed to the callback function. The resource is mutable. +func (d *EndpointDie) DieStamp(fn func(r *discoveryv1.Endpoint)) *EndpointDie { + r := d.DieRelease() + fn(&r) + return d.DieFeed(r) +} + +// Experimental: DieStampAt uses a JSON path (http://goessner.net/articles/JsonPath/) expression to stamp portions of the resource. The callback is invoked with each JSON path match. Panics if the callback function does not accept a single argument of the same type or a pointer to that type as found on the resource at the target location. +// +// Future iterations will improve type coercion from the resource to the callback argument. +func (d *EndpointDie) DieStampAt(jp string, fn interface{}) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + if ni := reflectx.ValueOf(fn).Type().NumIn(); ni != 1 { + panic(fmtx.Errorf("callback function must have 1 input parameters, found %d", ni)) + } + if no := reflectx.ValueOf(fn).Type().NumOut(); no != 0 { + panic(fmtx.Errorf("callback function must have 0 output parameters, found %d", no)) + } + + cp := jsonpath.New("") + if err := cp.Parse(fmtx.Sprintf("{%s}", jp)); err != nil { + panic(err) + } + cr, err := cp.FindResults(r) + if err != nil { + // errors are expected if a path is not found + return + } + for _, cv := range cr[0] { + arg0t := reflectx.ValueOf(fn).Type().In(0) + + var args []reflectx.Value + if cv.Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv} + } else if cv.CanAddr() && cv.Addr().Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv.Addr()} + } else { + panic(fmtx.Errorf("callback function must accept value of type %q, found type %q", cv.Type(), arg0t)) + } + + reflectx.ValueOf(fn).Call(args) + } + }) +} + +// DieWith returns a new die after passing the current die to the callback function. The passed die is mutable. +func (d *EndpointDie) DieWith(fns ...func(d *EndpointDie)) *EndpointDie { + nd := EndpointBlank.DieFeed(d.DieRelease()).DieImmutable(false) + for _, fn := range fns { + if fn != nil { + fn(nd) + } + } + return d.DieFeed(nd.DieRelease()) +} + +// DeepCopy returns a new die with equivalent state. Useful for snapshotting a mutable die. +func (d *EndpointDie) DeepCopy() *EndpointDie { + r := *d.r.DeepCopy() + return &EndpointDie{ + mutable: d.mutable, + r: r, + } +} + +// addresses of this endpoint. The contents of this field are interpreted +// +// according to the corresponding EndpointSlice addressType field. Consumers +// +// must handle different types of addresses in the context of their own +// +// capabilities. This must contain at least one address but no more than +// +// 100. These are all assumed to be fungible and clients may choose to only +// +// use the first element. Refer to: https://issue.k8s.io/106267 +func (d *EndpointDie) Addresses(v ...string) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + r.Addresses = v + }) +} + +// conditions contains information about the current status of the endpoint. +func (d *EndpointDie) Conditions(v discoveryv1.EndpointConditions) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + r.Conditions = v + }) +} + +// hostname of this endpoint. This field may be used by consumers of +// +// endpoints to distinguish endpoints from each other (e.g. in DNS names). +// +// # Multiple endpoints which use the same hostname should be considered +// +// fungible (e.g. multiple A values in DNS). Must be lowercase and pass DNS +// +// Label (RFC 1123) validation. +func (d *EndpointDie) Hostname(v *string) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + r.Hostname = v + }) +} + +// targetRef is a reference to a Kubernetes object that represents this +// +// endpoint. +func (d *EndpointDie) TargetRef(v *corev1.ObjectReference) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + r.TargetRef = v + }) +} + +// deprecatedTopology contains topology information part of the v1beta1 +// +// API. This field is deprecated, and will be removed when the v1beta1 +// +// API is removed (no sooner than kubernetes v1.24). While this field can +// +// hold values, it is not writable through the v1 API, and any attempts to +// +// write to it will be silently ignored. Topology information can be found +// +// in the zone and nodeName fields instead. +func (d *EndpointDie) DeprecatedTopology(v map[string]string) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + r.DeprecatedTopology = v + }) +} + +// nodeName represents the name of the Node hosting this endpoint. This can +// +// be used to determine endpoints local to a Node. +func (d *EndpointDie) NodeName(v *string) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + r.NodeName = v + }) +} + +// zone is the name of the Zone this endpoint exists in. +func (d *EndpointDie) Zone(v *string) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + r.Zone = v + }) +} + +// hints contains information associated with how an endpoint should be +// +// consumed. +func (d *EndpointDie) Hints(v *discoveryv1.EndpointHints) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + r.Hints = v + }) +} + +var EndpointConditionsBlank = (&EndpointConditionsDie{}).DieFeed(discoveryv1.EndpointConditions{}) + +type EndpointConditionsDie struct { + mutable bool + r discoveryv1.EndpointConditions +} + +// DieImmutable returns a new die for the current die's state that is either mutable (`false`) or immutable (`true`). +func (d *EndpointConditionsDie) DieImmutable(immutable bool) *EndpointConditionsDie { + if d.mutable == !immutable { + return d + } + d = d.DeepCopy() + d.mutable = !immutable + return d +} + +// DieFeed returns a new die with the provided resource. +func (d *EndpointConditionsDie) DieFeed(r discoveryv1.EndpointConditions) *EndpointConditionsDie { + if d.mutable { + d.r = r + return d + } + return &EndpointConditionsDie{ + mutable: d.mutable, + r: r, + } +} + +// DieFeedPtr returns a new die with the provided resource pointer. If the resource is nil, the empty value is used instead. +func (d *EndpointConditionsDie) DieFeedPtr(r *discoveryv1.EndpointConditions) *EndpointConditionsDie { + if r == nil { + r = &discoveryv1.EndpointConditions{} + } + return d.DieFeed(*r) +} + +// DieFeedJSON returns a new die with the provided JSON. Panics on error. +func (d *EndpointConditionsDie) DieFeedJSON(j []byte) *EndpointConditionsDie { + r := discoveryv1.EndpointConditions{} + if err := json.Unmarshal(j, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAML returns a new die with the provided YAML. Panics on error. +func (d *EndpointConditionsDie) DieFeedYAML(y []byte) *EndpointConditionsDie { + r := discoveryv1.EndpointConditions{} + if err := yaml.Unmarshal(y, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAMLFile returns a new die loading YAML from a file path. Panics on error. +func (d *EndpointConditionsDie) DieFeedYAMLFile(name string) *EndpointConditionsDie { + y, err := osx.ReadFile(name) + if err != nil { + panic(err) + } + return d.DieFeedYAML(y) +} + +// DieFeedRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *EndpointConditionsDie) DieFeedRawExtension(raw runtime.RawExtension) *EndpointConditionsDie { + j, err := json.Marshal(raw) + if err != nil { + panic(err) + } + return d.DieFeedJSON(j) +} + +// DieRelease returns the resource managed by the die. +func (d *EndpointConditionsDie) DieRelease() discoveryv1.EndpointConditions { + if d.mutable { + return d.r + } + return *d.r.DeepCopy() +} + +// DieReleasePtr returns a pointer to the resource managed by the die. +func (d *EndpointConditionsDie) DieReleasePtr() *discoveryv1.EndpointConditions { + r := d.DieRelease() + return &r +} + +// DieReleaseJSON returns the resource managed by the die as JSON. Panics on error. +func (d *EndpointConditionsDie) DieReleaseJSON() []byte { + r := d.DieReleasePtr() + j, err := json.Marshal(r) + if err != nil { + panic(err) + } + return j +} + +// DieReleaseYAML returns the resource managed by the die as YAML. Panics on error. +func (d *EndpointConditionsDie) DieReleaseYAML() []byte { + r := d.DieReleasePtr() + y, err := yaml.Marshal(r) + if err != nil { + panic(err) + } + return y +} + +// DieReleaseRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *EndpointConditionsDie) DieReleaseRawExtension() runtime.RawExtension { + j := d.DieReleaseJSON() + raw := runtime.RawExtension{} + if err := json.Unmarshal(j, &raw); err != nil { + panic(err) + } + return raw +} + +// DieStamp returns a new die with the resource passed to the callback function. The resource is mutable. +func (d *EndpointConditionsDie) DieStamp(fn func(r *discoveryv1.EndpointConditions)) *EndpointConditionsDie { + r := d.DieRelease() + fn(&r) + return d.DieFeed(r) +} + +// Experimental: DieStampAt uses a JSON path (http://goessner.net/articles/JsonPath/) expression to stamp portions of the resource. The callback is invoked with each JSON path match. Panics if the callback function does not accept a single argument of the same type or a pointer to that type as found on the resource at the target location. +// +// Future iterations will improve type coercion from the resource to the callback argument. +func (d *EndpointConditionsDie) DieStampAt(jp string, fn interface{}) *EndpointConditionsDie { + return d.DieStamp(func(r *discoveryv1.EndpointConditions) { + if ni := reflectx.ValueOf(fn).Type().NumIn(); ni != 1 { + panic(fmtx.Errorf("callback function must have 1 input parameters, found %d", ni)) + } + if no := reflectx.ValueOf(fn).Type().NumOut(); no != 0 { + panic(fmtx.Errorf("callback function must have 0 output parameters, found %d", no)) + } + + cp := jsonpath.New("") + if err := cp.Parse(fmtx.Sprintf("{%s}", jp)); err != nil { + panic(err) + } + cr, err := cp.FindResults(r) + if err != nil { + // errors are expected if a path is not found + return + } + for _, cv := range cr[0] { + arg0t := reflectx.ValueOf(fn).Type().In(0) + + var args []reflectx.Value + if cv.Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv} + } else if cv.CanAddr() && cv.Addr().Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv.Addr()} + } else { + panic(fmtx.Errorf("callback function must accept value of type %q, found type %q", cv.Type(), arg0t)) + } + + reflectx.ValueOf(fn).Call(args) + } + }) +} + +// DieWith returns a new die after passing the current die to the callback function. The passed die is mutable. +func (d *EndpointConditionsDie) DieWith(fns ...func(d *EndpointConditionsDie)) *EndpointConditionsDie { + nd := EndpointConditionsBlank.DieFeed(d.DieRelease()).DieImmutable(false) + for _, fn := range fns { + if fn != nil { + fn(nd) + } + } + return d.DieFeed(nd.DieRelease()) +} + +// DeepCopy returns a new die with equivalent state. Useful for snapshotting a mutable die. +func (d *EndpointConditionsDie) DeepCopy() *EndpointConditionsDie { + r := *d.r.DeepCopy() + return &EndpointConditionsDie{ + mutable: d.mutable, + r: r, + } +} + +// ready indicates that this endpoint is prepared to receive traffic, +// +// according to whatever system is managing the endpoint. A nil value +// +// indicates an unknown state. In most cases consumers should interpret this +// +// unknown state as ready. For compatibility reasons, ready should never be +// +// "true" for terminating endpoints, except when the normal readiness +// +// behavior is being explicitly overridden, for example when the associated +// +// Service has set the publishNotReadyAddresses flag. +func (d *EndpointConditionsDie) Ready(v *bool) *EndpointConditionsDie { + return d.DieStamp(func(r *discoveryv1.EndpointConditions) { + r.Ready = v + }) +} + +// serving is identical to ready except that it is set regardless of the +// +// terminating state of endpoints. This condition should be set to true for +// +// a ready endpoint that is terminating. If nil, consumers should defer to +// +// the ready condition. +func (d *EndpointConditionsDie) Serving(v *bool) *EndpointConditionsDie { + return d.DieStamp(func(r *discoveryv1.EndpointConditions) { + r.Serving = v + }) +} + +// terminating indicates that this endpoint is terminating. A nil value +// +// indicates an unknown state. Consumers should interpret this unknown state +// +// to mean that the endpoint is not terminating. +func (d *EndpointConditionsDie) Terminating(v *bool) *EndpointConditionsDie { + return d.DieStamp(func(r *discoveryv1.EndpointConditions) { + r.Terminating = v + }) +} + +var EndpointHintsBlank = (&EndpointHintsDie{}).DieFeed(discoveryv1.EndpointHints{}) + +type EndpointHintsDie struct { + mutable bool + r discoveryv1.EndpointHints +} + +// DieImmutable returns a new die for the current die's state that is either mutable (`false`) or immutable (`true`). +func (d *EndpointHintsDie) DieImmutable(immutable bool) *EndpointHintsDie { + if d.mutable == !immutable { + return d + } + d = d.DeepCopy() + d.mutable = !immutable + return d +} + +// DieFeed returns a new die with the provided resource. +func (d *EndpointHintsDie) DieFeed(r discoveryv1.EndpointHints) *EndpointHintsDie { + if d.mutable { + d.r = r + return d + } + return &EndpointHintsDie{ + mutable: d.mutable, + r: r, + } +} + +// DieFeedPtr returns a new die with the provided resource pointer. If the resource is nil, the empty value is used instead. +func (d *EndpointHintsDie) DieFeedPtr(r *discoveryv1.EndpointHints) *EndpointHintsDie { + if r == nil { + r = &discoveryv1.EndpointHints{} + } + return d.DieFeed(*r) +} + +// DieFeedJSON returns a new die with the provided JSON. Panics on error. +func (d *EndpointHintsDie) DieFeedJSON(j []byte) *EndpointHintsDie { + r := discoveryv1.EndpointHints{} + if err := json.Unmarshal(j, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAML returns a new die with the provided YAML. Panics on error. +func (d *EndpointHintsDie) DieFeedYAML(y []byte) *EndpointHintsDie { + r := discoveryv1.EndpointHints{} + if err := yaml.Unmarshal(y, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAMLFile returns a new die loading YAML from a file path. Panics on error. +func (d *EndpointHintsDie) DieFeedYAMLFile(name string) *EndpointHintsDie { + y, err := osx.ReadFile(name) + if err != nil { + panic(err) + } + return d.DieFeedYAML(y) +} + +// DieFeedRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *EndpointHintsDie) DieFeedRawExtension(raw runtime.RawExtension) *EndpointHintsDie { + j, err := json.Marshal(raw) + if err != nil { + panic(err) + } + return d.DieFeedJSON(j) +} + +// DieRelease returns the resource managed by the die. +func (d *EndpointHintsDie) DieRelease() discoveryv1.EndpointHints { + if d.mutable { + return d.r + } + return *d.r.DeepCopy() +} + +// DieReleasePtr returns a pointer to the resource managed by the die. +func (d *EndpointHintsDie) DieReleasePtr() *discoveryv1.EndpointHints { + r := d.DieRelease() + return &r +} + +// DieReleaseJSON returns the resource managed by the die as JSON. Panics on error. +func (d *EndpointHintsDie) DieReleaseJSON() []byte { + r := d.DieReleasePtr() + j, err := json.Marshal(r) + if err != nil { + panic(err) + } + return j +} + +// DieReleaseYAML returns the resource managed by the die as YAML. Panics on error. +func (d *EndpointHintsDie) DieReleaseYAML() []byte { + r := d.DieReleasePtr() + y, err := yaml.Marshal(r) + if err != nil { + panic(err) + } + return y +} + +// DieReleaseRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *EndpointHintsDie) DieReleaseRawExtension() runtime.RawExtension { + j := d.DieReleaseJSON() + raw := runtime.RawExtension{} + if err := json.Unmarshal(j, &raw); err != nil { + panic(err) + } + return raw +} + +// DieStamp returns a new die with the resource passed to the callback function. The resource is mutable. +func (d *EndpointHintsDie) DieStamp(fn func(r *discoveryv1.EndpointHints)) *EndpointHintsDie { + r := d.DieRelease() + fn(&r) + return d.DieFeed(r) +} + +// Experimental: DieStampAt uses a JSON path (http://goessner.net/articles/JsonPath/) expression to stamp portions of the resource. The callback is invoked with each JSON path match. Panics if the callback function does not accept a single argument of the same type or a pointer to that type as found on the resource at the target location. +// +// Future iterations will improve type coercion from the resource to the callback argument. +func (d *EndpointHintsDie) DieStampAt(jp string, fn interface{}) *EndpointHintsDie { + return d.DieStamp(func(r *discoveryv1.EndpointHints) { + if ni := reflectx.ValueOf(fn).Type().NumIn(); ni != 1 { + panic(fmtx.Errorf("callback function must have 1 input parameters, found %d", ni)) + } + if no := reflectx.ValueOf(fn).Type().NumOut(); no != 0 { + panic(fmtx.Errorf("callback function must have 0 output parameters, found %d", no)) + } + + cp := jsonpath.New("") + if err := cp.Parse(fmtx.Sprintf("{%s}", jp)); err != nil { + panic(err) + } + cr, err := cp.FindResults(r) + if err != nil { + // errors are expected if a path is not found + return + } + for _, cv := range cr[0] { + arg0t := reflectx.ValueOf(fn).Type().In(0) + + var args []reflectx.Value + if cv.Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv} + } else if cv.CanAddr() && cv.Addr().Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv.Addr()} + } else { + panic(fmtx.Errorf("callback function must accept value of type %q, found type %q", cv.Type(), arg0t)) + } + + reflectx.ValueOf(fn).Call(args) + } + }) +} + +// DieWith returns a new die after passing the current die to the callback function. The passed die is mutable. +func (d *EndpointHintsDie) DieWith(fns ...func(d *EndpointHintsDie)) *EndpointHintsDie { + nd := EndpointHintsBlank.DieFeed(d.DieRelease()).DieImmutable(false) + for _, fn := range fns { + if fn != nil { + fn(nd) + } + } + return d.DieFeed(nd.DieRelease()) +} + +// DeepCopy returns a new die with equivalent state. Useful for snapshotting a mutable die. +func (d *EndpointHintsDie) DeepCopy() *EndpointHintsDie { + r := *d.r.DeepCopy() + return &EndpointHintsDie{ + mutable: d.mutable, + r: r, + } +} + +// forZones indicates the zone(s) this endpoint should be consumed by to +// +// enable topology aware routing. +func (d *EndpointHintsDie) ForZones(v ...discoveryv1.ForZone) *EndpointHintsDie { + return d.DieStamp(func(r *discoveryv1.EndpointHints) { + r.ForZones = v + }) +} + +var ForZoneBlank = (&ForZoneDie{}).DieFeed(discoveryv1.ForZone{}) + +type ForZoneDie struct { + mutable bool + r discoveryv1.ForZone +} + +// DieImmutable returns a new die for the current die's state that is either mutable (`false`) or immutable (`true`). +func (d *ForZoneDie) DieImmutable(immutable bool) *ForZoneDie { + if d.mutable == !immutable { + return d + } + d = d.DeepCopy() + d.mutable = !immutable + return d +} + +// DieFeed returns a new die with the provided resource. +func (d *ForZoneDie) DieFeed(r discoveryv1.ForZone) *ForZoneDie { + if d.mutable { + d.r = r + return d + } + return &ForZoneDie{ + mutable: d.mutable, + r: r, + } +} + +// DieFeedPtr returns a new die with the provided resource pointer. If the resource is nil, the empty value is used instead. +func (d *ForZoneDie) DieFeedPtr(r *discoveryv1.ForZone) *ForZoneDie { + if r == nil { + r = &discoveryv1.ForZone{} + } + return d.DieFeed(*r) +} + +// DieFeedJSON returns a new die with the provided JSON. Panics on error. +func (d *ForZoneDie) DieFeedJSON(j []byte) *ForZoneDie { + r := discoveryv1.ForZone{} + if err := json.Unmarshal(j, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAML returns a new die with the provided YAML. Panics on error. +func (d *ForZoneDie) DieFeedYAML(y []byte) *ForZoneDie { + r := discoveryv1.ForZone{} + if err := yaml.Unmarshal(y, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAMLFile returns a new die loading YAML from a file path. Panics on error. +func (d *ForZoneDie) DieFeedYAMLFile(name string) *ForZoneDie { + y, err := osx.ReadFile(name) + if err != nil { + panic(err) + } + return d.DieFeedYAML(y) +} + +// DieFeedRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *ForZoneDie) DieFeedRawExtension(raw runtime.RawExtension) *ForZoneDie { + j, err := json.Marshal(raw) + if err != nil { + panic(err) + } + return d.DieFeedJSON(j) +} + +// DieRelease returns the resource managed by the die. +func (d *ForZoneDie) DieRelease() discoveryv1.ForZone { + if d.mutable { + return d.r + } + return *d.r.DeepCopy() +} + +// DieReleasePtr returns a pointer to the resource managed by the die. +func (d *ForZoneDie) DieReleasePtr() *discoveryv1.ForZone { + r := d.DieRelease() + return &r +} + +// DieReleaseJSON returns the resource managed by the die as JSON. Panics on error. +func (d *ForZoneDie) DieReleaseJSON() []byte { + r := d.DieReleasePtr() + j, err := json.Marshal(r) + if err != nil { + panic(err) + } + return j +} + +// DieReleaseYAML returns the resource managed by the die as YAML. Panics on error. +func (d *ForZoneDie) DieReleaseYAML() []byte { + r := d.DieReleasePtr() + y, err := yaml.Marshal(r) + if err != nil { + panic(err) + } + return y +} + +// DieReleaseRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *ForZoneDie) DieReleaseRawExtension() runtime.RawExtension { + j := d.DieReleaseJSON() + raw := runtime.RawExtension{} + if err := json.Unmarshal(j, &raw); err != nil { + panic(err) + } + return raw +} + +// DieStamp returns a new die with the resource passed to the callback function. The resource is mutable. +func (d *ForZoneDie) DieStamp(fn func(r *discoveryv1.ForZone)) *ForZoneDie { + r := d.DieRelease() + fn(&r) + return d.DieFeed(r) +} + +// Experimental: DieStampAt uses a JSON path (http://goessner.net/articles/JsonPath/) expression to stamp portions of the resource. The callback is invoked with each JSON path match. Panics if the callback function does not accept a single argument of the same type or a pointer to that type as found on the resource at the target location. +// +// Future iterations will improve type coercion from the resource to the callback argument. +func (d *ForZoneDie) DieStampAt(jp string, fn interface{}) *ForZoneDie { + return d.DieStamp(func(r *discoveryv1.ForZone) { + if ni := reflectx.ValueOf(fn).Type().NumIn(); ni != 1 { + panic(fmtx.Errorf("callback function must have 1 input parameters, found %d", ni)) + } + if no := reflectx.ValueOf(fn).Type().NumOut(); no != 0 { + panic(fmtx.Errorf("callback function must have 0 output parameters, found %d", no)) + } + + cp := jsonpath.New("") + if err := cp.Parse(fmtx.Sprintf("{%s}", jp)); err != nil { + panic(err) + } + cr, err := cp.FindResults(r) + if err != nil { + // errors are expected if a path is not found + return + } + for _, cv := range cr[0] { + arg0t := reflectx.ValueOf(fn).Type().In(0) + + var args []reflectx.Value + if cv.Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv} + } else if cv.CanAddr() && cv.Addr().Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv.Addr()} + } else { + panic(fmtx.Errorf("callback function must accept value of type %q, found type %q", cv.Type(), arg0t)) + } + + reflectx.ValueOf(fn).Call(args) + } + }) +} + +// DieWith returns a new die after passing the current die to the callback function. The passed die is mutable. +func (d *ForZoneDie) DieWith(fns ...func(d *ForZoneDie)) *ForZoneDie { + nd := ForZoneBlank.DieFeed(d.DieRelease()).DieImmutable(false) + for _, fn := range fns { + if fn != nil { + fn(nd) + } + } + return d.DieFeed(nd.DieRelease()) +} + +// DeepCopy returns a new die with equivalent state. Useful for snapshotting a mutable die. +func (d *ForZoneDie) DeepCopy() *ForZoneDie { + r := *d.r.DeepCopy() + return &ForZoneDie{ + mutable: d.mutable, + r: r, + } +} + +// name represents the name of the zone. +func (d *ForZoneDie) Name(v string) *ForZoneDie { + return d.DieStamp(func(r *discoveryv1.ForZone) { + r.Name = v + }) +} + +var EndpointPortBlank = (&EndpointPortDie{}).DieFeed(discoveryv1.EndpointPort{}) + +type EndpointPortDie struct { + mutable bool + r discoveryv1.EndpointPort +} + +// DieImmutable returns a new die for the current die's state that is either mutable (`false`) or immutable (`true`). +func (d *EndpointPortDie) DieImmutable(immutable bool) *EndpointPortDie { + if d.mutable == !immutable { + return d + } + d = d.DeepCopy() + d.mutable = !immutable + return d +} + +// DieFeed returns a new die with the provided resource. +func (d *EndpointPortDie) DieFeed(r discoveryv1.EndpointPort) *EndpointPortDie { + if d.mutable { + d.r = r + return d + } + return &EndpointPortDie{ + mutable: d.mutable, + r: r, + } +} + +// DieFeedPtr returns a new die with the provided resource pointer. If the resource is nil, the empty value is used instead. +func (d *EndpointPortDie) DieFeedPtr(r *discoveryv1.EndpointPort) *EndpointPortDie { + if r == nil { + r = &discoveryv1.EndpointPort{} + } + return d.DieFeed(*r) +} + +// DieFeedJSON returns a new die with the provided JSON. Panics on error. +func (d *EndpointPortDie) DieFeedJSON(j []byte) *EndpointPortDie { + r := discoveryv1.EndpointPort{} + if err := json.Unmarshal(j, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAML returns a new die with the provided YAML. Panics on error. +func (d *EndpointPortDie) DieFeedYAML(y []byte) *EndpointPortDie { + r := discoveryv1.EndpointPort{} + if err := yaml.Unmarshal(y, &r); err != nil { + panic(err) + } + return d.DieFeed(r) +} + +// DieFeedYAMLFile returns a new die loading YAML from a file path. Panics on error. +func (d *EndpointPortDie) DieFeedYAMLFile(name string) *EndpointPortDie { + y, err := osx.ReadFile(name) + if err != nil { + panic(err) + } + return d.DieFeedYAML(y) +} + +// DieFeedRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *EndpointPortDie) DieFeedRawExtension(raw runtime.RawExtension) *EndpointPortDie { + j, err := json.Marshal(raw) + if err != nil { + panic(err) + } + return d.DieFeedJSON(j) +} + +// DieRelease returns the resource managed by the die. +func (d *EndpointPortDie) DieRelease() discoveryv1.EndpointPort { + if d.mutable { + return d.r + } + return *d.r.DeepCopy() +} + +// DieReleasePtr returns a pointer to the resource managed by the die. +func (d *EndpointPortDie) DieReleasePtr() *discoveryv1.EndpointPort { + r := d.DieRelease() + return &r +} + +// DieReleaseJSON returns the resource managed by the die as JSON. Panics on error. +func (d *EndpointPortDie) DieReleaseJSON() []byte { + r := d.DieReleasePtr() + j, err := json.Marshal(r) + if err != nil { + panic(err) + } + return j +} + +// DieReleaseYAML returns the resource managed by the die as YAML. Panics on error. +func (d *EndpointPortDie) DieReleaseYAML() []byte { + r := d.DieReleasePtr() + y, err := yaml.Marshal(r) + if err != nil { + panic(err) + } + return y +} + +// DieReleaseRawExtension returns the resource managed by the die as an raw extension. Panics on error. +func (d *EndpointPortDie) DieReleaseRawExtension() runtime.RawExtension { + j := d.DieReleaseJSON() + raw := runtime.RawExtension{} + if err := json.Unmarshal(j, &raw); err != nil { + panic(err) + } + return raw +} + +// DieStamp returns a new die with the resource passed to the callback function. The resource is mutable. +func (d *EndpointPortDie) DieStamp(fn func(r *discoveryv1.EndpointPort)) *EndpointPortDie { + r := d.DieRelease() + fn(&r) + return d.DieFeed(r) +} + +// Experimental: DieStampAt uses a JSON path (http://goessner.net/articles/JsonPath/) expression to stamp portions of the resource. The callback is invoked with each JSON path match. Panics if the callback function does not accept a single argument of the same type or a pointer to that type as found on the resource at the target location. +// +// Future iterations will improve type coercion from the resource to the callback argument. +func (d *EndpointPortDie) DieStampAt(jp string, fn interface{}) *EndpointPortDie { + return d.DieStamp(func(r *discoveryv1.EndpointPort) { + if ni := reflectx.ValueOf(fn).Type().NumIn(); ni != 1 { + panic(fmtx.Errorf("callback function must have 1 input parameters, found %d", ni)) + } + if no := reflectx.ValueOf(fn).Type().NumOut(); no != 0 { + panic(fmtx.Errorf("callback function must have 0 output parameters, found %d", no)) + } + + cp := jsonpath.New("") + if err := cp.Parse(fmtx.Sprintf("{%s}", jp)); err != nil { + panic(err) + } + cr, err := cp.FindResults(r) + if err != nil { + // errors are expected if a path is not found + return + } + for _, cv := range cr[0] { + arg0t := reflectx.ValueOf(fn).Type().In(0) + + var args []reflectx.Value + if cv.Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv} + } else if cv.CanAddr() && cv.Addr().Type().AssignableTo(arg0t) { + args = []reflectx.Value{cv.Addr()} + } else { + panic(fmtx.Errorf("callback function must accept value of type %q, found type %q", cv.Type(), arg0t)) + } + + reflectx.ValueOf(fn).Call(args) + } + }) +} + +// DieWith returns a new die after passing the current die to the callback function. The passed die is mutable. +func (d *EndpointPortDie) DieWith(fns ...func(d *EndpointPortDie)) *EndpointPortDie { + nd := EndpointPortBlank.DieFeed(d.DieRelease()).DieImmutable(false) + for _, fn := range fns { + if fn != nil { + fn(nd) + } + } + return d.DieFeed(nd.DieRelease()) +} + +// DeepCopy returns a new die with equivalent state. Useful for snapshotting a mutable die. +func (d *EndpointPortDie) DeepCopy() *EndpointPortDie { + r := *d.r.DeepCopy() + return &EndpointPortDie{ + mutable: d.mutable, + r: r, + } +} + +// name represents the name of this port. All ports in an EndpointSlice must have a unique name. +// +// If the EndpointSlice is derived from a Kubernetes service, this corresponds to the Service.ports[].name. +// +// Name must either be an empty string or pass DNS_LABEL validation: +// +// * must be no more than 63 characters long. +// +// * must consist of lower case alphanumeric characters or '-'. +// +// * must start and end with an alphanumeric character. +// +// Default is empty string. +func (d *EndpointPortDie) Name(v *string) *EndpointPortDie { + return d.DieStamp(func(r *discoveryv1.EndpointPort) { + r.Name = v + }) +} + +// protocol represents the IP protocol for this port. +// +// Must be UDP, TCP, or SCTP. +// +// Default is TCP. +func (d *EndpointPortDie) Protocol(v *corev1.Protocol) *EndpointPortDie { + return d.DieStamp(func(r *discoveryv1.EndpointPort) { + r.Protocol = v + }) +} + +// port represents the port number of the endpoint. +// +// # If this is not specified, ports are not restricted and must be +// +// interpreted in the context of the specific consumer. +func (d *EndpointPortDie) Port(v *int32) *EndpointPortDie { + return d.DieStamp(func(r *discoveryv1.EndpointPort) { + r.Port = v + }) +} + +// The application protocol for this port. +// +// This is used as a hint for implementations to offer richer behavior for protocols that they understand. +// +// This field follows standard Kubernetes label syntax. +// +// Valid values are either: +// +// * Un-prefixed protocol names - reserved for IANA standard service names (as per +// +// RFC-6335 and https://www.iana.org/assignments/service-names). +// +// * Kubernetes-defined prefixed names: +// +// * 'kubernetes.io/h2c' - HTTP/2 prior knowledge over cleartext as described in https://www.rfc-editor.org/rfc/rfc9113.html#name-starting-http-2-with-prior- +// +// * 'kubernetes.io/ws' - WebSocket over cleartext as described in https://www.rfc-editor.org/rfc/rfc6455 +// +// * 'kubernetes.io/wss' - WebSocket over TLS as described in https://www.rfc-editor.org/rfc/rfc6455 +// +// * Other protocols should use implementation-defined prefixed names such as +// +// mycompany.com/my-custom-protocol. +func (d *EndpointPortDie) AppProtocol(v *string) *EndpointPortDie { + return d.DieStamp(func(r *discoveryv1.EndpointPort) { + r.AppProtocol = v + }) +} diff --git a/apis/discovery/v1/zz_generated.die_test.go b/apis/discovery/v1/zz_generated.die_test.go new file mode 100644 index 0000000..cf2b5af --- /dev/null +++ b/apis/discovery/v1/zz_generated.die_test.go @@ -0,0 +1,81 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +Copyright 2021-2022 the original author or authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by diegen. DO NOT EDIT. + +package v1 + +import ( + testing "reconciler.io/dies/testing" + testingx "testing" +) + +func TestEndpointSliceDie_MissingMethods(t *testingx.T) { + die := EndpointSliceBlank + ignore := []string{"TypeMeta", "ObjectMeta"} + diff := testing.DieFieldDiff(die).Delete(ignore...) + if diff.Len() != 0 { + t.Errorf("found missing fields for EndpointSliceDie: %s", diff.List()) + } +} + +func TestEndpointDie_MissingMethods(t *testingx.T) { + die := EndpointBlank + ignore := []string{} + diff := testing.DieFieldDiff(die).Delete(ignore...) + if diff.Len() != 0 { + t.Errorf("found missing fields for EndpointDie: %s", diff.List()) + } +} + +func TestEndpointConditionsDie_MissingMethods(t *testingx.T) { + die := EndpointConditionsBlank + ignore := []string{} + diff := testing.DieFieldDiff(die).Delete(ignore...) + if diff.Len() != 0 { + t.Errorf("found missing fields for EndpointConditionsDie: %s", diff.List()) + } +} + +func TestEndpointHintsDie_MissingMethods(t *testingx.T) { + die := EndpointHintsBlank + ignore := []string{} + diff := testing.DieFieldDiff(die).Delete(ignore...) + if diff.Len() != 0 { + t.Errorf("found missing fields for EndpointHintsDie: %s", diff.List()) + } +} + +func TestForZoneDie_MissingMethods(t *testingx.T) { + die := ForZoneBlank + ignore := []string{} + diff := testing.DieFieldDiff(die).Delete(ignore...) + if diff.Len() != 0 { + t.Errorf("found missing fields for ForZoneDie: %s", diff.List()) + } +} + +func TestEndpointPortDie_MissingMethods(t *testingx.T) { + die := EndpointPortBlank + ignore := []string{} + diff := testing.DieFieldDiff(die).Delete(ignore...) + if diff.Len() != 0 { + t.Errorf("found missing fields for EndpointPortDie: %s", diff.List()) + } +}