From 1b2f39f4eb7e6af5559e0951702703e320321cff Mon Sep 17 00:00:00 2001 From: Scott Andrews Date: Tue, 25 Jun 2024 14:26:45 -0400 Subject: [PATCH] Generate mutation die helpers for fields (#149) --- README.md | 116 + apis/admission/v1/admissionrequest.go | 47 +- apis/admission/v1/admissionresponse.go | 10 +- apis/admission/v1/admissionreview.go | 18 +- apis/admission/v1/zz_generated.die.go | 138 +- apis/admissionregistration/v1/common.go | 9 +- .../v1/mutatingwebhookconfiguration.go | 74 +- .../v1/validatingadmissionpolicy.go | 142 +- .../v1/validatingadmissionpolicybinding.go | 28 +- .../v1/validatingwebhookconfiguration.go | 74 +- .../v1/zz_generated.die.go | 825 ++++- .../v1/customresourcedefinition.go | 127 +- apis/apiextensions/v1/zz_generated.die.go | 179 ++ apis/apiregistration/v1/apiservice.go | 9 +- apis/apiregistration/v1/zz_generated.die.go | 17 + .../flowcontrol/v1beta1/flowschema.go | 57 +- .../v1beta1/prioritylevelconfiguration.go | 36 +- .../flowcontrol/v1beta1/zz_generated.die.go | 148 + apis/apps/v1/daemonset.go | 28 +- apis/apps/v1/deployment.go | 28 +- apis/apps/v1/replicaset.go | 19 +- apis/apps/v1/statefulset.go | 56 +- apis/apps/v1/zz_generated.die.go | 252 +- apis/authentication/v1/selfsubjectreview.go | 9 +- apis/authentication/v1/tokenreview.go | 9 +- apis/authentication/v1/zz_generated.die.go | 30 + apis/authorization/rbac/v1/clusterrole.go | 31 +- .../rbac/v1/clusterrolebinding.go | 19 +- apis/authorization/rbac/v1/role.go | 10 +- apis/authorization/rbac/v1/rolebinding.go | 19 +- .../authorization/rbac/v1/zz_generated.die.go | 107 + .../v1/selfsubjectaccessreview.go | 18 +- .../v1/selfsubjectrulesreview.go | 20 +- apis/authorization/v1/subjectaccessreview.go | 18 +- apis/authorization/v1/zz_generated.die.go | 72 + .../autoscaling/v1/horizontalpodautoscaler.go | 9 +- apis/autoscaling/v1/zz_generated.die.go | 13 + .../autoscaling/v2/horizontalpodautoscaler.go | 327 +- apis/autoscaling/v2/zz_generated.die.go | 501 +++ apis/batch/v1/job.go | 85 +- apis/batch/v1/zz_generated.die.go | 183 ++ apis/core/v1/binding.go | 9 +- apis/core/v1/common.go | 10 +- apis/core/v1/container.go | 454 +-- apis/core/v1/endpoints.go | 49 +- apis/core/v1/event.go | 36 +- apis/core/v1/limitrange.go | 10 +- apis/core/v1/node.go | 155 +- apis/core/v1/persistantvolume.go | 171 +- apis/core/v1/persistantvolumeclaim.go | 63 +- apis/core/v1/pod.go | 286 +- apis/core/v1/podtemplate.go | 28 +- apis/core/v1/replicationcontroller.go | 9 +- apis/core/v1/resourcequota.go | 27 +- apis/core/v1/service.go | 46 +- apis/core/v1/serviceaccount.go | 20 +- apis/core/v1/volume.go | 272 +- apis/core/v1/zz_generated.die.go | 2674 +++++++++++++++++ apis/discovery/v1/endpointslice.go | 58 +- apis/discovery/v1/zz_generated.die.go | 92 +- apis/events/v1/event.go | 37 +- apis/events/v1/zz_generated.die.go | 59 +- apis/meta/v1/objectmeta.go | 10 +- apis/meta/v1/status.go | 29 +- apis/meta/v1/typemeta.go | 203 +- apis/meta/v1/zz_generated.die.go | 76 +- apis/networking/v1/ingress.go | 114 +- apis/networking/v1/ingressclass.go | 9 +- apis/networking/v1/networkpolicy.go | 97 +- apis/networking/v1/zz_generated.die.go | 387 ++- apis/node/v1/runtimeclass.go | 18 +- apis/node/v1/zz_generated.die.go | 25 + apis/policy/v1/poddisruptionbudget.go | 11 +- apis/policy/v1/zz_generated.die.go | 34 + apis/storage/v1/csidriver.go | 10 +- apis/storage/v1/csinode.go | 19 +- apis/storage/v1/csistoragecapacities.go | 10 +- apis/storage/v1/storageclass.go | 12 +- apis/storage/v1/volumeattachment.go | 37 +- apis/storage/v1/zz_generated.die.go | 173 +- apis/storage/v1beta1/csistoragecapacity.go | 10 +- apis/storage/v1beta1/zz_generated.die.go | 21 +- diegen/die/gen.go | 74 +- diegen/die/traverse.go | 77 +- 84 files changed, 6773 insertions(+), 3165 deletions(-) diff --git a/README.md b/README.md index 0160968..09013c0 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ - [diegen](#diegen) - [die markers](#die-markers) - [+die](#die) + - [+die:field](#diefield) --- @@ -427,3 +428,118 @@ Properties: - **apiVersion** `string` (optional): defaults the blanks die's APIVersion (only for objects) - **kind** `string` (optional): defaults the blank die's Kind (only for objects) - **ignore** `[]string` (optional): set of fields to ignore on the type + +#### +die:field + +```go +// +die +// +die:field:name=Selector,package=reconciler.io/dies/apis/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=Template,package=reconciler.io/dies/apis/core/v1,die=PodTemplateSpecDie +type MyResourceSpec struct { + Selector *metav1.LabelSelector `json:"selector`" + Template corev1.PodTemplateSpec `json:"template"` +} +``` + +Results in the standard die method and two additional mutation methods for the defined fields: + +```go +// SelectorDie mutates Selector as a die +// +// Label selector for pods. It must match the pod template's labels. +func (d *MyResourceSpecDie) SelectorDie(fn func(d *metav1.LabelSelectorDie)) *MyResourceSpecDie { + return d.DieStamp(func(r *appsv1.DeploymentSpec) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) + fn(d) + r.Selector = d.DieReleasePtr() + }) +} + +// TemplateDie mutates Template as a die +// +// Template describes the pods that will be created. +func (d *MyResourceSpecDie) TemplateDie(fn func(d *corev1.PodTemplateSpecDie)) *MyResourceSpecDie { + return d.DieStamp(func(r *appsv1.DeploymentSpec) { + d := corev1.PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) + fn(d) + r.Template = d.DieRelease() + }) +} +``` + +Mutation methods for fields backed by slices require additional metadata. Depending on the content of the list it the whole listing can be replaced, or a single item in the list can be mutated. + +Atomic lists cannot be mutated incrementally, the whole content is replaced. This pattern is common where there is no unique field inside the list to find a specific entry for. + +```go +// +die:field:name=Ports,die=ContainerPortDie,listType=atomic +``` + +```go +// PortsDie replaces Ports by collecting the released value from each die passed. +func (d *ContainerDie) PortsDie(ports ...*ContainerPortDie) *ContainerDie { + ...snip... +} +``` +[Full source](https://pkg.go.dev/reconciler.io/dies/apis/core/v1#ContainerDie.PortsDie) + +The env field is a map list type with the default key. The named env var in the list will be loaded into the EnvVarDie and passed to the callback with the mutated value updated in the slice. + +Because a single item is mutated the method name uses a singular form. If the conversion from plural to singular produces a non-ideal name, the default method name can be overridden with the **method** parameter. + +```go +// +die:field:name=Env,die=EnvSourceDie,listType=map +``` + +```go +// EnvDie mutates a single item in Env matched by the nested field Name, appending a new item if no match is found. +func (d *ContainerDie) EnvDie(name string, fn func(d *EnvVarDie)) *ContainerDie { + ...snip... +} +``` +[Full source](https://pkg.go.dev/reconciler.io/dies/apis/core/v1#ContainerDie.EnvDie) + +The env from field is a map list type with a custom key. The default map key is `Name`. + +```go +// +die:field:name=EnvFrom,die=EnvFromSourceDie,listType=map,listMapKey=Prefix +``` + +```go +// EnvFromDie mutates a single item in EnvFrom matched by the nested field Prefix, appending a new item if no match is found. +func (d *ContainerDie) EnvFromDie(prefix string, fn func(d *EnvFromSourceDie)) *ContainerDie { + ...snip... +} +``` +[Full source](https://pkg.go.dev/reconciler.io/dies/apis/core/v1#ContainerDie.EnvFromDie) + + +The resize policy field is also a map list type, but the map key field is defined with a custom type. + +```go +// +die:field:name=ResizePolicy,die=ContainerResizePolicyDie,listType=map,listMapKey=ResourceName,listMapKeyPackage=k8s.io/api/core/v1,listMapKeyType=ResourceName +``` + +```go +// ResizePolicyDie mutates a single item in ResizePolicy matched by the nested field ResourceName, appending a new item if no match is found. +func (d *ContainerDie) ResizePolicyDie(resourceName corev1.ResourceName, fn func(d *ContainerResizePolicyDie)) *ContainerDie { + ...snip... +} +``` +[Full source](https://pkg.go.dev/reconciler.io/dies/apis/core/v1#ContainerDie.ResizePolicyDie) + + +Properties: +- **name** `string`: name of the field on the target resource to mutate +- **method** `string` (optional): name of the generated mutation method on the host die (defaults to the name with "Die" appended, for list type map the name is made singular) +- **package** `string` (optional): go package containing the target die and blank. `_/` is an alias to the package prefix for the built in dies, for example `_/core/v1` expands to `reconciler.io/dies/apis/core/v1`. +- **die** `string`: go type for the die backing the field's struct +- **blank** `string` (optional): go type for a blank of the die's type (defaults to the die replacing the "Die" suffix with "Blank") +- **pointer** `bool` (optional): the field is defined as a pointer reference, uses DieFeedPtr and DieReleasePtr +- **listType** `string` (optional): + - ``: field is not a list (default) + - `map`: a single value in the list is mutated, or a new item appended + - `atomic`: the list is replaced +- **listMapKey** `string` (optional): defaults to `Name` for map list types (only for list type map) +- **listMapKeyPackage** `string` (optional): the go package containing the type representing the key field on the target struct, defaults to the current package (only for list type map) +- **listMapKeyType** `string` (optional): the go type representing the key field on the target struct, defaults to `string` (only for list type map) \ No newline at end of file diff --git a/apis/admission/v1/admissionrequest.go b/apis/admission/v1/admissionrequest.go index 082df6d..50bc5f2 100644 --- a/apis/admission/v1/admissionrequest.go +++ b/apis/admission/v1/admissionrequest.go @@ -18,49 +18,12 @@ package v1 import ( admissionv1 "k8s.io/api/admission/v1" - dieauthenticationv1 "reconciler.io/dies/apis/authentication/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die +// +die:field:name=Kind,package=_/meta/v1,die=GroupVersionKindDie +// +die:field:name=Resource,package=_/meta/v1,die=GroupVersionResourceDie +// +die:field:name=RequestKind,package=_/meta/v1,die=GroupVersionKindDie,pointer=true +// +die:field:name=RequestResource,package=_/meta/v1,die=GroupVersionResourceDie,pointer=true +// +die:field:name=UserInfo,package=_/authentication/v1,die=UserInfoDie type _ = admissionv1.AdmissionRequest - -func (d *AdmissionRequestDie) KindDie(fn func(d *diemetav1.GroupVersionKindDie)) *AdmissionRequestDie { - return d.DieStamp(func(r *admissionv1.AdmissionRequest) { - d := diemetav1.GroupVersionKindBlank.DieImmutable(false).DieFeed(r.Kind) - fn(d) - r.Kind = d.DieRelease() - }) -} - -func (d *AdmissionRequestDie) ResourceDie(fn func(d *diemetav1.GroupVersionResourceDie)) *AdmissionRequestDie { - return d.DieStamp(func(r *admissionv1.AdmissionRequest) { - d := diemetav1.GroupVersionResourceBlank.DieImmutable(false).DieFeed(r.Resource) - fn(d) - r.Resource = d.DieRelease() - }) -} - -func (d *AdmissionRequestDie) RequestKindDie(fn func(d *diemetav1.GroupVersionKindDie)) *AdmissionRequestDie { - return d.DieStamp(func(r *admissionv1.AdmissionRequest) { - d := diemetav1.GroupVersionKindBlank.DieImmutable(false).DieFeedPtr(r.RequestKind) - fn(d) - r.RequestKind = d.DieReleasePtr() - }) -} - -func (d *AdmissionRequestDie) RequestResourceDie(fn func(d *diemetav1.GroupVersionResourceDie)) *AdmissionRequestDie { - return d.DieStamp(func(r *admissionv1.AdmissionRequest) { - d := diemetav1.GroupVersionResourceBlank.DieImmutable(false).DieFeedPtr(r.RequestResource) - fn(d) - r.RequestResource = d.DieReleasePtr() - }) -} - -func (d *AdmissionRequestDie) UserInfoDie(fn func(d *dieauthenticationv1.UserInfoDie)) *AdmissionRequestDie { - return d.DieStamp(func(r *admissionv1.AdmissionRequest) { - d := dieauthenticationv1.UserInfoBlank.DieImmutable(false).DieFeed(r.UserInfo) - fn(d) - r.UserInfo = d.DieRelease() - }) -} diff --git a/apis/admission/v1/admissionresponse.go b/apis/admission/v1/admissionresponse.go index 203a09c..c6d30fc 100644 --- a/apis/admission/v1/admissionresponse.go +++ b/apis/admission/v1/admissionresponse.go @@ -18,20 +18,12 @@ package v1 import ( admissionv1 "k8s.io/api/admission/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die +// +die:field:name=Result,package=_/meta/v1,die=StatusDie,pointer=true type _ = admissionv1.AdmissionResponse -func (d *AdmissionResponseDie) ResultDie(fn func(d *diemetav1.StatusDie)) *AdmissionResponseDie { - return d.DieStamp(func(r *admissionv1.AdmissionResponse) { - d := diemetav1.StatusBlank.DieImmutable(false).DieFeedPtr(r.Result) - fn(d) - r.Result = d.DieReleasePtr() - }) -} - func (d *AdmissionResponseDie) AddAuditAnnotation(key, value string) *AdmissionResponseDie { return d.DieStamp(func(r *admissionv1.AdmissionResponse) { if r.AuditAnnotations == nil { diff --git a/apis/admission/v1/admissionreview.go b/apis/admission/v1/admissionreview.go index bd1b32b..ff2b643 100644 --- a/apis/admission/v1/admissionreview.go +++ b/apis/admission/v1/admissionreview.go @@ -21,20 +21,6 @@ import ( ) // +die +// +die:field:name=Request,die=AdmissionRequestDie,pointer=true +// +die:field:name=Response,die=AdmissionResponseDie,pointer=true type _ = admissionv1.AdmissionReview - -func (d *AdmissionReviewDie) RequestDie(fn func(d *AdmissionRequestDie)) *AdmissionReviewDie { - return d.DieStamp(func(r *admissionv1.AdmissionReview) { - d := AdmissionRequestBlank.DieImmutable(false).DieFeedPtr(r.Request) - fn(d) - r.Request = d.DieReleasePtr() - }) -} - -func (d *AdmissionReviewDie) ResponseDie(fn func(d *AdmissionResponseDie)) *AdmissionReviewDie { - return d.DieStamp(func(r *admissionv1.AdmissionReview) { - d := AdmissionResponseBlank.DieImmutable(false).DieFeedPtr(r.Response) - fn(d) - r.Response = d.DieReleasePtr() - }) -} diff --git a/apis/admission/v1/zz_generated.die.go b/apis/admission/v1/zz_generated.die.go index 660b24f..3b761ea 100644 --- a/apis/admission/v1/zz_generated.die.go +++ b/apis/admission/v1/zz_generated.die.go @@ -25,13 +25,15 @@ import ( fmtx "fmt" cmp "github.com/google/go-cmp/cmp" admissionv1 "k8s.io/api/admission/v1" - authenticationv1 "k8s.io/api/authentication/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + apiauthenticationv1 "k8s.io/api/authentication/v1" + apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" types "k8s.io/apimachinery/pkg/types" json "k8s.io/apimachinery/pkg/util/json" jsonpath "k8s.io/client-go/util/jsonpath" osx "os" + authenticationv1 "reconciler.io/dies/apis/authentication/v1" + metav1 "reconciler.io/dies/apis/meta/v1" patch "reconciler.io/dies/patch" reflectx "reflect" yaml "sigs.k8s.io/yaml" @@ -265,6 +267,89 @@ func (d *AdmissionRequestDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// KindDie mutates Kind as a die. +// +// Kind is the fully-qualified type of object being submitted (for example, v1.Pod or autoscaling.v1.Scale) +func (d *AdmissionRequestDie) KindDie(fn func(d *metav1.GroupVersionKindDie)) *AdmissionRequestDie { + return d.DieStamp(func(r *admissionv1.AdmissionRequest) { + d := metav1.GroupVersionKindBlank.DieImmutable(false).DieFeed(r.Kind) + fn(d) + r.Kind = d.DieRelease() + }) +} + +// ResourceDie mutates Resource as a die. +// +// Resource is the fully-qualified resource being requested (for example, v1.pods) +func (d *AdmissionRequestDie) ResourceDie(fn func(d *metav1.GroupVersionResourceDie)) *AdmissionRequestDie { + return d.DieStamp(func(r *admissionv1.AdmissionRequest) { + d := metav1.GroupVersionResourceBlank.DieImmutable(false).DieFeed(r.Resource) + fn(d) + r.Resource = d.DieRelease() + }) +} + +// RequestKindDie mutates RequestKind as a die. +// +// RequestKind is the fully-qualified type of the original API request (for example, v1.Pod or autoscaling.v1.Scale). +// +// If this is specified and differs from the value in "kind", an equivalent match and conversion was performed. +// +// For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of +// +// `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`, +// +// an API request to apps/v1beta1 deployments would be converted and sent to the webhook +// +// with `kind: {group:"apps", version:"v1", kind:"Deployment"}` (matching the rule the webhook registered for), +// +// and `requestKind: {group:"apps", version:"v1beta1", kind:"Deployment"}` (indicating the kind of the original API request). +// +// See documentation for the "matchPolicy" field in the webhook configuration type for more details. +func (d *AdmissionRequestDie) RequestKindDie(fn func(d *metav1.GroupVersionKindDie)) *AdmissionRequestDie { + return d.DieStamp(func(r *admissionv1.AdmissionRequest) { + d := metav1.GroupVersionKindBlank.DieImmutable(false).DieFeedPtr(r.RequestKind) + fn(d) + r.RequestKind = d.DieReleasePtr() + }) +} + +// RequestResourceDie mutates RequestResource as a die. +// +// RequestResource is the fully-qualified resource of the original API request (for example, v1.pods). +// +// If this is specified and differs from the value in "resource", an equivalent match and conversion was performed. +// +// For example, if deployments can be modified via apps/v1 and apps/v1beta1, and a webhook registered a rule of +// +// `apiGroups:["apps"], apiVersions:["v1"], resources: ["deployments"]` and `matchPolicy: Equivalent`, +// +// an API request to apps/v1beta1 deployments would be converted and sent to the webhook +// +// with `resource: {group:"apps", version:"v1", resource:"deployments"}` (matching the resource the webhook registered for), +// +// and `requestResource: {group:"apps", version:"v1beta1", resource:"deployments"}` (indicating the resource of the original API request). +// +// See documentation for the "matchPolicy" field in the webhook configuration type. +func (d *AdmissionRequestDie) RequestResourceDie(fn func(d *metav1.GroupVersionResourceDie)) *AdmissionRequestDie { + return d.DieStamp(func(r *admissionv1.AdmissionRequest) { + d := metav1.GroupVersionResourceBlank.DieImmutable(false).DieFeedPtr(r.RequestResource) + fn(d) + r.RequestResource = d.DieReleasePtr() + }) +} + +// UserInfoDie mutates UserInfo as a die. +// +// UserInfo is information about the requesting user +func (d *AdmissionRequestDie) UserInfoDie(fn func(d *authenticationv1.UserInfoDie)) *AdmissionRequestDie { + return d.DieStamp(func(r *admissionv1.AdmissionRequest) { + d := authenticationv1.UserInfoBlank.DieImmutable(false).DieFeed(r.UserInfo) + fn(d) + r.UserInfo = d.DieRelease() + }) +} + // UID is an identifier for the individual request/response. It allows us to distinguish instances of requests which are // // otherwise identical (parallel requests, requests when earlier requests did not modify etc) @@ -279,14 +364,14 @@ func (d *AdmissionRequestDie) UID(v types.UID) *AdmissionRequestDie { } // Kind is the fully-qualified type of object being submitted (for example, v1.Pod or autoscaling.v1.Scale) -func (d *AdmissionRequestDie) Kind(v metav1.GroupVersionKind) *AdmissionRequestDie { +func (d *AdmissionRequestDie) Kind(v apismetav1.GroupVersionKind) *AdmissionRequestDie { return d.DieStamp(func(r *admissionv1.AdmissionRequest) { r.Kind = v }) } // Resource is the fully-qualified resource being requested (for example, v1.pods) -func (d *AdmissionRequestDie) Resource(v metav1.GroupVersionResource) *AdmissionRequestDie { +func (d *AdmissionRequestDie) Resource(v apismetav1.GroupVersionResource) *AdmissionRequestDie { return d.DieStamp(func(r *admissionv1.AdmissionRequest) { r.Resource = v }) @@ -314,7 +399,7 @@ func (d *AdmissionRequestDie) SubResource(v string) *AdmissionRequestDie { // and `requestKind: {group:"apps", version:"v1beta1", kind:"Deployment"}` (indicating the kind of the original API request). // // See documentation for the "matchPolicy" field in the webhook configuration type for more details. -func (d *AdmissionRequestDie) RequestKind(v *metav1.GroupVersionKind) *AdmissionRequestDie { +func (d *AdmissionRequestDie) RequestKind(v *apismetav1.GroupVersionKind) *AdmissionRequestDie { return d.DieStamp(func(r *admissionv1.AdmissionRequest) { r.RequestKind = v }) @@ -335,7 +420,7 @@ func (d *AdmissionRequestDie) RequestKind(v *metav1.GroupVersionKind) *Admission // and `requestResource: {group:"apps", version:"v1beta1", resource:"deployments"}` (indicating the resource of the original API request). // // See documentation for the "matchPolicy" field in the webhook configuration type. -func (d *AdmissionRequestDie) RequestResource(v *metav1.GroupVersionResource) *AdmissionRequestDie { +func (d *AdmissionRequestDie) RequestResource(v *apismetav1.GroupVersionResource) *AdmissionRequestDie { return d.DieStamp(func(r *admissionv1.AdmissionRequest) { r.RequestResource = v }) @@ -378,7 +463,7 @@ func (d *AdmissionRequestDie) Operation(v admissionv1.Operation) *AdmissionReque } // UserInfo is information about the requesting user -func (d *AdmissionRequestDie) UserInfo(v authenticationv1.UserInfo) *AdmissionRequestDie { +func (d *AdmissionRequestDie) UserInfo(v apiauthenticationv1.UserInfo) *AdmissionRequestDie { return d.DieStamp(func(r *admissionv1.AdmissionRequest) { r.UserInfo = v }) @@ -650,6 +735,19 @@ func (d *AdmissionResponseDie) DiePatch(patchType types.PatchType) ([]byte, erro return patch.Create(d.seal, d.r, patchType) } +// ResultDie mutates Result as a die. +// +// Result contains extra details into why an admission request was denied. +// +// This field IS NOT consulted in any way if "Allowed" is "true". +func (d *AdmissionResponseDie) ResultDie(fn func(d *metav1.StatusDie)) *AdmissionResponseDie { + return d.DieStamp(func(r *admissionv1.AdmissionResponse) { + d := metav1.StatusBlank.DieImmutable(false).DieFeedPtr(r.Result) + fn(d) + r.Result = d.DieReleasePtr() + }) +} + // UID is an identifier for the individual request/response. // // This must be copied over from the corresponding AdmissionRequest. @@ -669,7 +767,7 @@ func (d *AdmissionResponseDie) Allowed(v bool) *AdmissionResponseDie { // Result contains extra details into why an admission request was denied. // // This field IS NOT consulted in any way if "Allowed" is "true". -func (d *AdmissionResponseDie) Result(v *metav1.Status) *AdmissionResponseDie { +func (d *AdmissionResponseDie) Result(v *apismetav1.Status) *AdmissionResponseDie { return d.DieStamp(func(r *admissionv1.AdmissionResponse) { r.Result = v }) @@ -943,7 +1041,29 @@ func (d *AdmissionReviewDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } -func (d *AdmissionReviewDie) TypeMeta(v metav1.TypeMeta) *AdmissionReviewDie { +// RequestDie mutates Request as a die. +// +// Request describes the attributes for the admission request. +func (d *AdmissionReviewDie) RequestDie(fn func(d *AdmissionRequestDie)) *AdmissionReviewDie { + return d.DieStamp(func(r *admissionv1.AdmissionReview) { + d := AdmissionRequestBlank.DieImmutable(false).DieFeedPtr(r.Request) + fn(d) + r.Request = d.DieReleasePtr() + }) +} + +// ResponseDie mutates Response as a die. +// +// Response describes the attributes for the admission response. +func (d *AdmissionReviewDie) ResponseDie(fn func(d *AdmissionResponseDie)) *AdmissionReviewDie { + return d.DieStamp(func(r *admissionv1.AdmissionReview) { + d := AdmissionResponseBlank.DieImmutable(false).DieFeedPtr(r.Response) + fn(d) + r.Response = d.DieReleasePtr() + }) +} + +func (d *AdmissionReviewDie) TypeMeta(v apismetav1.TypeMeta) *AdmissionReviewDie { return d.DieStamp(func(r *admissionv1.AdmissionReview) { r.TypeMeta = v }) diff --git a/apis/admissionregistration/v1/common.go b/apis/admissionregistration/v1/common.go index 0ce9bf5..2b0de6d 100644 --- a/apis/admissionregistration/v1/common.go +++ b/apis/admissionregistration/v1/common.go @@ -21,16 +21,9 @@ import ( ) // +die +// +die:field:name=Service,die=ServiceReferenceDie,pointer=true type _ = admissionregistrationv1.WebhookClientConfig -func (d *WebhookClientConfigDie) ServiceDie(fn func(d *ServiceReferenceDie)) *WebhookClientConfigDie { - return d.DieStamp(func(r *admissionregistrationv1.WebhookClientConfig) { - d := ServiceReferenceBlank.DieImmutable(false).DieFeedPtr(r.Service) - fn(d) - r.Service = d.DieReleasePtr() - }) -} - // +die type _ admissionregistrationv1.ServiceReference diff --git a/apis/admissionregistration/v1/mutatingwebhookconfiguration.go b/apis/admissionregistration/v1/mutatingwebhookconfiguration.go index 6f655d3..2c0cb37 100644 --- a/apis/admissionregistration/v1/mutatingwebhookconfiguration.go +++ b/apis/admissionregistration/v1/mutatingwebhookconfiguration.go @@ -18,78 +18,16 @@ package v1 import ( admissionregistrationv1 "k8s.io/api/admissionregistration/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die:object=true,apiVersion=admissionregistration.k8s.io/v1,kind=MutatingWebhookConfiguration +// +die:field:name=Webhooks,die=MutatingWebhookDie,listType=map type _ = admissionregistrationv1.MutatingWebhookConfiguration -func (d *MutatingWebhookConfigurationDie) WebhookDie(name string, fn func(d *MutatingWebhookDie)) *MutatingWebhookConfigurationDie { - return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhookConfiguration) { - for i := range r.Webhooks { - if name == r.Webhooks[i].Name { - d := MutatingWebhookBlank.DieImmutable(false).DieFeed(r.Webhooks[i]) - fn(d) - r.Webhooks[i] = d.DieRelease() - return - } - } - - d := MutatingWebhookBlank.DieImmutable(false).DieFeed(admissionregistrationv1.MutatingWebhook{Name: name}) - fn(d) - r.Webhooks = append(r.Webhooks, d.DieRelease()) - }) -} - // +die +// +die:field:name=ClientConfig,die=WebhookClientConfigDie +// +die:field:name=NamespaceSelector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=ObjectSelector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=Rules,die=RuleWithOperationsDie,listType=atomic +// +die:field:name=MatchConditions,die=MatchConditionDie,listType=map type _ = admissionregistrationv1.MutatingWebhook - -func (d *MutatingWebhookDie) ClientConfigDie(fn func(d *WebhookClientConfigDie)) *MutatingWebhookDie { - return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhook) { - d := WebhookClientConfigBlank.DieImmutable(false).DieFeed(r.ClientConfig) - fn(d) - r.ClientConfig = d.DieRelease() - }) -} - -func (d *MutatingWebhookDie) RulesDie(rules ...*RuleWithOperationsDie) *MutatingWebhookDie { - return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhook) { - r.Rules = make([]admissionregistrationv1.RuleWithOperations, len(rules)) - for i := range rules { - r.Rules[i] = rules[i].DieRelease() - } - }) -} - -func (d *MutatingWebhookDie) NamespaceSelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *MutatingWebhookDie { - return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhook) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NamespaceSelector) - fn(d) - r.NamespaceSelector = d.DieReleasePtr() - }) -} - -func (d *MutatingWebhookDie) ObjectSelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *MutatingWebhookDie { - return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhook) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.ObjectSelector) - fn(d) - r.ObjectSelector = d.DieReleasePtr() - }) -} - -func (d *MutatingWebhookDie) MatchConditionDie(name string, fn func(d *MatchConditionDie)) *MutatingWebhookDie { - return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhook) { - for i := range r.MatchConditions { - if name == r.MatchConditions[i].Name { - d := MatchConditionBlank.DieImmutable(false).DieFeed(r.MatchConditions[i]) - fn(d) - r.MatchConditions[i] = d.DieRelease() - return - } - } - - d := MatchConditionBlank.DieImmutable(false).DieFeed(admissionregistrationv1.MatchCondition{Name: name}) - fn(d) - r.MatchConditions = append(r.MatchConditions, d.DieRelease()) - }) -} diff --git a/apis/admissionregistration/v1/validatingadmissionpolicy.go b/apis/admissionregistration/v1/validatingadmissionpolicy.go index a8b7121..67769ec 100644 --- a/apis/admissionregistration/v1/validatingadmissionpolicy.go +++ b/apis/admissionregistration/v1/validatingadmissionpolicy.go @@ -18,124 +18,35 @@ package v1 import ( admissionregistrationv1 "k8s.io/api/admissionregistration/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die:object=true,apiVersion=admissionregistration.k8s.io/v1,kind=ValidatingAdmissionPolicy type _ = admissionregistrationv1.ValidatingAdmissionPolicy // +die +// +die:field:name=ParamKind,die=ParamKindDie,pointer=true +// +die:field:name=MatchConstraints,die=MatchResourcesDie,pointer=true +// +die:field:name=Validations,die=ValidationDie,listType=atomic +// +die:field:name=AuditAnnotations,die=AuditAnnotationDie,listType=atomic +// +die:field:name=MatchConditions,die=MatchConditionDie,listType=map +// +die:field:name=Variables,die=VariableDie,listType=map type _ = admissionregistrationv1.ValidatingAdmissionPolicySpec -func (d *ValidatingAdmissionPolicySpecDie) ParamKindDie(fn func(d *ParamKindDie)) *ValidatingAdmissionPolicySpecDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { - d := ParamKindBlank.DieImmutable(false).DieFeedPtr(r.ParamKind) - fn(d) - r.ParamKind = d.DieReleasePtr() - }) -} - -func (d *ValidatingAdmissionPolicySpecDie) MatchConstraintsDie(fn func(d *MatchResourcesDie)) *ValidatingAdmissionPolicySpecDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { - d := MatchResourcesBlank.DieImmutable(false).DieFeedPtr(r.MatchConstraints) - fn(d) - r.MatchConstraints = d.DieReleasePtr() - }) -} - -func (d *ValidatingAdmissionPolicySpecDie) ValidationsDie(validations ...*ValidationDie) *ValidatingAdmissionPolicySpecDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { - r.Validations = make([]admissionregistrationv1.Validation, len(validations)) - for i := range validations { - r.Validations[i] = validations[i].DieRelease() - } - }) -} - -func (d *ValidatingAdmissionPolicySpecDie) AuditAnnotationsDie(annotations ...*AuditAnnotationDie) *ValidatingAdmissionPolicySpecDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { - r.AuditAnnotations = make([]admissionregistrationv1.AuditAnnotation, len(annotations)) - for i := range annotations { - r.AuditAnnotations[i] = annotations[i].DieRelease() - } - }) -} - -func (d *ValidatingAdmissionPolicySpecDie) MatchConditionDie(name string, fn func(d *MatchConditionDie)) *ValidatingAdmissionPolicySpecDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { - for i := range r.MatchConditions { - if name == r.MatchConditions[i].Name { - d := MatchConditionBlank.DieImmutable(false).DieFeed(r.MatchConditions[i]) - fn(d) - r.MatchConditions[i] = d.DieRelease() - return - } - } - - d := MatchConditionBlank.DieImmutable(false).DieFeed(admissionregistrationv1.MatchCondition{Name: name}) - fn(d) - r.MatchConditions = append(r.MatchConditions, d.DieRelease()) - }) -} - +// deprecated: use VariableDie instead func (d *ValidatingAdmissionPolicySpecDie) VariablesDie(name string, fn func(d *VariableDie)) *ValidatingAdmissionPolicySpecDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { - for i := range r.Variables { - if name == r.Variables[i].Name { - d := VariableBlank.DieImmutable(false).DieFeed(r.Variables[i]) - fn(d) - r.Variables[i] = d.DieRelease() - return - } - } - - d := VariableBlank.DieImmutable(false).DieFeed(admissionregistrationv1.Variable{Name: name}) - fn(d) - r.Variables = append(r.Variables, d.DieRelease()) - }) + return d.VariableDie(name, fn) } // +die type _ = admissionregistrationv1.ParamKind // +die +// +die:field:name=NamespaceSelector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=ObjectSelector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=ResourceRules,die=NamedRuleWithOperationsDie,listType=atomic +// +die:field:name=ExcludeResourceRules,die=NamedRuleWithOperationsDie,listType=atomic type _ = admissionregistrationv1.MatchResources -func (d *MatchResourcesDie) NamespaceSelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *MatchResourcesDie { - return d.DieStamp(func(r *admissionregistrationv1.MatchResources) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NamespaceSelector) - fn(d) - r.NamespaceSelector = d.DieReleasePtr() - }) -} - -func (d *MatchResourcesDie) ObjectSelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *MatchResourcesDie { - return d.DieStamp(func(r *admissionregistrationv1.MatchResources) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.ObjectSelector) - fn(d) - r.ObjectSelector = d.DieReleasePtr() - }) -} - -func (d *MatchResourcesDie) ResourceRulesDie(rules ...*NamedRuleWithOperationsDie) *MatchResourcesDie { - return d.DieStamp(func(r *admissionregistrationv1.MatchResources) { - r.ResourceRules = make([]admissionregistrationv1.NamedRuleWithOperations, len(rules)) - for i := range rules { - r.ResourceRules[i] = rules[i].DieRelease() - } - }) -} - -func (d *MatchResourcesDie) ExcludeResourceRulesDie(rules ...*NamedRuleWithOperationsDie) *MatchResourcesDie { - return d.DieStamp(func(r *admissionregistrationv1.MatchResources) { - r.ExcludeResourceRules = make([]admissionregistrationv1.NamedRuleWithOperations, len(rules)) - for i := range rules { - r.ExcludeResourceRules[i] = rules[i].DieRelease() - } - }) -} - // +die type _ = admissionregistrationv1.NamedRuleWithOperations @@ -185,36 +96,13 @@ type _ = admissionregistrationv1.AuditAnnotation type _ = admissionregistrationv1.Variable // +die +// +die:field:name=TypeChecking,die=TypeCheckingDie,pointer=true +// +die:field:name=Conditions,package=_/meta/v1,die=ConditionDie,listType=atomic type _ = admissionregistrationv1.ValidatingAdmissionPolicyStatus -func (d *ValidatingAdmissionPolicyStatusDie) TypeCheckingDie(fn func(d *TypeCheckingDie)) *ValidatingAdmissionPolicyStatusDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicyStatus) { - d := TypeCheckingBlank.DieImmutable(false).DieFeedPtr(r.TypeChecking) - fn(d) - r.TypeChecking = d.DieReleasePtr() - }) -} - -func (d *ValidatingAdmissionPolicyStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *ValidatingAdmissionPolicyStatusDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicyStatus) { - r.Conditions = make([]metav1.Condition, len(conditions)) - for i := range conditions { - r.Conditions[i] = conditions[i].DieRelease() - } - }) -} - // +die +// +die:field:name=ExpressionWarnings,die=ExpressionWarningDie,listType=atomic type _ = admissionregistrationv1.TypeChecking -func (d *TypeCheckingDie) ExpressionWarningsDie(warnings ...*ExpressionWarningDie) *TypeCheckingDie { - return d.DieStamp(func(r *admissionregistrationv1.TypeChecking) { - r.ExpressionWarnings = make([]admissionregistrationv1.ExpressionWarning, len(warnings)) - for i := range warnings { - r.ExpressionWarnings[i] = warnings[i].DieRelease() - } - }) -} - // +die type _ = admissionregistrationv1.ExpressionWarning diff --git a/apis/admissionregistration/v1/validatingadmissionpolicybinding.go b/apis/admissionregistration/v1/validatingadmissionpolicybinding.go index 1292cae..cf9c726 100644 --- a/apis/admissionregistration/v1/validatingadmissionpolicybinding.go +++ b/apis/admissionregistration/v1/validatingadmissionpolicybinding.go @@ -18,38 +18,16 @@ package v1 import ( admissionregistrationv1 "k8s.io/api/admissionregistration/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die:object=true,apiVersion=admissionregistration.k8s.io/v1,kind=ValidatingAdmissionPolicyBinding type _ = admissionregistrationv1.ValidatingAdmissionPolicyBinding // +die +// +die:field:name=ParamRef,die=ParamRefDie,pointer=true +// +die:field:name=MatchResources,die=MatchResourcesDie,pointer=true type _ = admissionregistrationv1.ValidatingAdmissionPolicyBindingSpec -func (d *ValidatingAdmissionPolicyBindingSpecDie) ParamRefDie(fn func(d *ParamRefDie)) *ValidatingAdmissionPolicyBindingSpecDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicyBindingSpec) { - d := ParamRefBlank.DieImmutable(false).DieFeedPtr(r.ParamRef) - fn(d) - r.ParamRef = d.DieReleasePtr() - }) -} - -func (d *ValidatingAdmissionPolicyBindingSpecDie) MatchResourcesDie(fn func(d *MatchResourcesDie)) *ValidatingAdmissionPolicyBindingSpecDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicyBindingSpec) { - d := MatchResourcesBlank.DieImmutable(false).DieFeedPtr(r.MatchResources) - fn(d) - r.MatchResources = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Selector,package=_/meta/v1,die=LabelSelectorDie,pointer=true type _ = admissionregistrationv1.ParamRef - -func (d *ParamRefDie) SelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *ParamRefDie { - return d.DieStamp(func(r *admissionregistrationv1.ParamRef) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) - fn(d) - r.Selector = d.DieReleasePtr() - }) -} diff --git a/apis/admissionregistration/v1/validatingwebhookconfiguration.go b/apis/admissionregistration/v1/validatingwebhookconfiguration.go index c010f18..8bc5363 100644 --- a/apis/admissionregistration/v1/validatingwebhookconfiguration.go +++ b/apis/admissionregistration/v1/validatingwebhookconfiguration.go @@ -18,78 +18,16 @@ package v1 import ( admissionregistrationv1 "k8s.io/api/admissionregistration/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die:object=true,apiVersion=admissionregistration.k8s.io/v1,kind=ValidatingWebhookConfiguration +// +die:field:name=Webhooks,die=ValidatingWebhookDie,listType=map type _ = admissionregistrationv1.ValidatingWebhookConfiguration -func (d *ValidatingWebhookConfigurationDie) WebhookDie(name string, fn func(d *ValidatingWebhookDie)) *ValidatingWebhookConfigurationDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhookConfiguration) { - for i := range r.Webhooks { - if name == r.Webhooks[i].Name { - d := ValidatingWebhookBlank.DieImmutable(false).DieFeed(r.Webhooks[i]) - fn(d) - r.Webhooks[i] = d.DieRelease() - return - } - } - - d := ValidatingWebhookBlank.DieImmutable(false).DieFeed(admissionregistrationv1.ValidatingWebhook{Name: name}) - fn(d) - r.Webhooks = append(r.Webhooks, d.DieRelease()) - }) -} - // +die +// +die:field:name=ClientConfig,die=WebhookClientConfigDie +// +die:field:name=NamespaceSelector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=ObjectSelector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=Rules,die=RuleWithOperationsDie,listType=atomic +// +die:field:name=MatchConditions,die=MatchConditionDie,listType=map type _ = admissionregistrationv1.ValidatingWebhook - -func (d *ValidatingWebhookDie) ClientConfigDie(fn func(d *WebhookClientConfigDie)) *ValidatingWebhookDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhook) { - d := WebhookClientConfigBlank.DieImmutable(false).DieFeed(r.ClientConfig) - fn(d) - r.ClientConfig = d.DieRelease() - }) -} - -func (d *ValidatingWebhookDie) RulesDie(rules ...*RuleWithOperationsDie) *ValidatingWebhookDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhook) { - r.Rules = make([]admissionregistrationv1.RuleWithOperations, len(rules)) - for i := range rules { - r.Rules[i] = rules[i].DieRelease() - } - }) -} - -func (d *ValidatingWebhookDie) NamespaceSelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *ValidatingWebhookDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhook) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NamespaceSelector) - fn(d) - r.NamespaceSelector = d.DieReleasePtr() - }) -} - -func (d *ValidatingWebhookDie) ObjectSelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *ValidatingWebhookDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhook) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.ObjectSelector) - fn(d) - r.ObjectSelector = d.DieReleasePtr() - }) -} - -func (d *ValidatingWebhookDie) MatchConditionDie(name string, fn func(d *MatchConditionDie)) *ValidatingWebhookDie { - return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhook) { - for i := range r.MatchConditions { - if name == r.MatchConditions[i].Name { - d := MatchConditionBlank.DieImmutable(false).DieFeed(r.MatchConditions[i]) - fn(d) - r.MatchConditions[i] = d.DieRelease() - return - } - } - - d := MatchConditionBlank.DieImmutable(false).DieFeed(admissionregistrationv1.MatchCondition{Name: name}) - fn(d) - r.MatchConditions = append(r.MatchConditions, d.DieRelease()) - }) -} diff --git a/apis/admissionregistration/v1/zz_generated.die.go b/apis/admissionregistration/v1/zz_generated.die.go index a5a09d9..d361318 100644 --- a/apis/admissionregistration/v1/zz_generated.die.go +++ b/apis/admissionregistration/v1/zz_generated.die.go @@ -267,6 +267,21 @@ func (d *WebhookClientConfigDie) DiePatch(patchType types.PatchType) ([]byte, er return patch.Create(d.seal, d.r, patchType) } +// ServiceDie mutates Service as a die. +// +// `service` is a reference to the service for this webhook. Either +// +// `service` or `url` must be specified. +// +// If the webhook is running within the cluster, then you should use `service`. +func (d *WebhookClientConfigDie) ServiceDie(fn func(d *ServiceReferenceDie)) *WebhookClientConfigDie { + return d.DieStamp(func(r *admissionregistrationv1.WebhookClientConfig) { + d := ServiceReferenceBlank.DieImmutable(false).DieFeedPtr(r.Service) + fn(d) + r.Service = d.DieReleasePtr() + }) +} + // `url` gives the location of the webhook, in standard URL form // // (`scheme://host:port/path`). Exactly one of `url` or `service` @@ -1747,6 +1762,26 @@ func (d *MutatingWebhookConfigurationDie) MetadataDie(fn func(d *metav1.ObjectMe }) } +// WebhookDie mutates a single item in Webhooks matched by the nested field Name, appending a new item if no match is found. +// +// Webhooks is a list of webhooks and the affected resources and operations. +func (d *MutatingWebhookConfigurationDie) WebhookDie(v string, fn func(d *MutatingWebhookDie)) *MutatingWebhookConfigurationDie { + return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhookConfiguration) { + for i := range r.Webhooks { + if v == r.Webhooks[i].Name { + d := MutatingWebhookBlank.DieImmutable(false).DieFeed(r.Webhooks[i]) + fn(d) + r.Webhooks[i] = d.DieRelease() + return + } + } + + d := MutatingWebhookBlank.DieImmutable(false).DieFeed(admissionregistrationv1.MutatingWebhook{Name: v}) + fn(d) + r.Webhooks = append(r.Webhooks, d.DieRelease()) + }) +} + // Webhooks is a list of webhooks and the affected resources and operations. func (d *MutatingWebhookConfigurationDie) Webhooks(v ...admissionregistrationv1.MutatingWebhook) *MutatingWebhookConfigurationDie { return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhookConfiguration) { @@ -1982,6 +2017,197 @@ func (d *MutatingWebhookDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// ClientConfigDie mutates ClientConfig as a die. +// +// ClientConfig defines how to communicate with the hook. +// +// Required +func (d *MutatingWebhookDie) ClientConfigDie(fn func(d *WebhookClientConfigDie)) *MutatingWebhookDie { + return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhook) { + d := WebhookClientConfigBlank.DieImmutable(false).DieFeed(r.ClientConfig) + fn(d) + r.ClientConfig = d.DieRelease() + }) +} + +// NamespaceSelectorDie mutates NamespaceSelector as a die. +// +// # NamespaceSelector decides whether to run the webhook on an object based +// +// on whether the namespace for that object matches the selector. If the +// +// object itself is a namespace, the matching is performed on +// +// object.metadata.labels. If the object is another cluster scoped resource, +// +// it never skips the webhook. +// +// # For example, to run the webhook on any objects whose namespace is not +// +// associated with "runlevel" of "0" or "1"; you will set the selector as +// +// follows: +// +// "namespaceSelector": { +// +// "matchExpressions": [ +// +// { +// +// "key": "runlevel", +// +// "operator": "NotIn", +// +// "values": [ +// +// "0", +// +// "1" +// +// ] +// +// } +// +// ] +// +// } +// +// # If instead you want to only run the webhook on any objects whose +// +// namespace is associated with the "environment" of "prod" or "staging"; +// +// you will set the selector as follows: +// +// "namespaceSelector": { +// +// "matchExpressions": [ +// +// { +// +// "key": "environment", +// +// "operator": "In", +// +// "values": [ +// +// "prod", +// +// "staging" +// +// ] +// +// } +// +// ] +// +// } +// +// # See +// +// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ +// +// for more examples of label selectors. +// +// Default to the empty LabelSelector, which matches everything. +func (d *MutatingWebhookDie) NamespaceSelectorDie(fn func(d *metav1.LabelSelectorDie)) *MutatingWebhookDie { + return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhook) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NamespaceSelector) + fn(d) + r.NamespaceSelector = d.DieReleasePtr() + }) +} + +// ObjectSelectorDie mutates ObjectSelector as a die. +// +// # ObjectSelector decides whether to run the webhook based on if the +// +// object has matching labels. objectSelector is evaluated against both +// +// the oldObject and newObject that would be sent to the webhook, and +// +// is considered to match if either object matches the selector. A null +// +// object (oldObject in the case of create, or newObject in the case of +// +// delete) or an object that cannot have labels (like a +// +// # DeploymentRollback or a PodProxyOptions object) is not considered to +// +// match. +// +// # Use the object selector only if the webhook is opt-in, because end +// +// users may skip the admission webhook by setting the labels. +// +// Default to the empty LabelSelector, which matches everything. +func (d *MutatingWebhookDie) ObjectSelectorDie(fn func(d *metav1.LabelSelectorDie)) *MutatingWebhookDie { + return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhook) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.ObjectSelector) + fn(d) + r.ObjectSelector = d.DieReleasePtr() + }) +} + +// RulesDie replaces Rules by collecting the released value from each die passed. +// +// Rules describes what operations on what resources/subresources the webhook cares about. +// +// The webhook cares about an operation if it matches _any_ Rule. +// +// # However, in order to prevent ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks +// +// from putting the cluster in a state which cannot be recovered from without completely +// +// disabling the plugin, ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks are never called +// +// on admission requests for ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects. +func (d *MutatingWebhookDie) RulesDie(v ...*RuleWithOperationsDie) *MutatingWebhookDie { + return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhook) { + r.Rules = make([]admissionregistrationv1.RuleWithOperations, len(v)) + for i := range v { + r.Rules[i] = v[i].DieRelease() + } + }) +} + +// MatchConditionDie mutates a single item in MatchConditions matched by the nested field Name, appending a new item if no match is found. +// +// # MatchConditions is a list of conditions that must be met for a request to be sent to this +// +// webhook. Match conditions filter requests that have already been matched by the rules, +// +// namespaceSelector, and objectSelector. An empty list of matchConditions matches all requests. +// +// There are a maximum of 64 match conditions allowed. +// +// The exact matching logic is (in order): +// +// 1. If ANY matchCondition evaluates to FALSE, the webhook is skipped. +// +// 2. If ALL matchConditions evaluate to TRUE, the webhook is called. +// +// 3. If any matchCondition evaluates to an error (but none are FALSE): +// +// - If failurePolicy=Fail, reject the request +// +// - If failurePolicy=Ignore, the error is ignored and the webhook is skipped +func (d *MutatingWebhookDie) MatchConditionDie(v string, fn func(d *MatchConditionDie)) *MutatingWebhookDie { + return d.DieStamp(func(r *admissionregistrationv1.MutatingWebhook) { + for i := range r.MatchConditions { + if v == r.MatchConditions[i].Name { + d := MatchConditionBlank.DieImmutable(false).DieFeed(r.MatchConditions[i]) + fn(d) + r.MatchConditions[i] = d.DieRelease() + return + } + } + + d := MatchConditionBlank.DieImmutable(false).DieFeed(admissionregistrationv1.MatchCondition{Name: v}) + fn(d) + r.MatchConditions = append(r.MatchConditions, d.DieRelease()) + }) +} + // The name of the admission webhook. // // # Name should be fully qualified, e.g., imagepolicy.kubernetes.io, where @@ -2863,6 +3089,148 @@ func (d *ValidatingAdmissionPolicySpecDie) DiePatch(patchType types.PatchType) ( return patch.Create(d.seal, d.r, patchType) } +// ParamKindDie mutates ParamKind as a die. +// +// ParamKind specifies the kind of resources used to parameterize this policy. +// +// If absent, there are no parameters for this policy and the param CEL variable will not be provided to validation expressions. +// +// If ParamKind refers to a non-existent kind, this policy definition is mis-configured and the FailurePolicy is applied. +// +// If paramKind is specified but paramRef is unset in ValidatingAdmissionPolicyBinding, the params variable will be null. +func (d *ValidatingAdmissionPolicySpecDie) ParamKindDie(fn func(d *ParamKindDie)) *ValidatingAdmissionPolicySpecDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { + d := ParamKindBlank.DieImmutable(false).DieFeedPtr(r.ParamKind) + fn(d) + r.ParamKind = d.DieReleasePtr() + }) +} + +// MatchConstraintsDie mutates MatchConstraints as a die. +// +// MatchConstraints specifies what resources this policy is designed to validate. +// +// The AdmissionPolicy cares about a request if it matches _all_ Constraints. +// +// # However, in order to prevent clusters from being put into an unstable state that cannot be recovered from via the API +// +// ValidatingAdmissionPolicy cannot match ValidatingAdmissionPolicy and ValidatingAdmissionPolicyBinding. +// +// Required. +func (d *ValidatingAdmissionPolicySpecDie) MatchConstraintsDie(fn func(d *MatchResourcesDie)) *ValidatingAdmissionPolicySpecDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { + d := MatchResourcesBlank.DieImmutable(false).DieFeedPtr(r.MatchConstraints) + fn(d) + r.MatchConstraints = d.DieReleasePtr() + }) +} + +// ValidationsDie replaces Validations by collecting the released value from each die passed. +// +// Validations contain CEL expressions which is used to apply the validation. +// +// Validations and AuditAnnotations may not both be empty; a minimum of one Validations or AuditAnnotations is +// +// required. +func (d *ValidatingAdmissionPolicySpecDie) ValidationsDie(v ...*ValidationDie) *ValidatingAdmissionPolicySpecDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { + r.Validations = make([]admissionregistrationv1.Validation, len(v)) + for i := range v { + r.Validations[i] = v[i].DieRelease() + } + }) +} + +// AuditAnnotationsDie replaces AuditAnnotations by collecting the released value from each die passed. +// +// auditAnnotations contains CEL expressions which are used to produce audit +// +// annotations for the audit event of the API request. +// +// validations and auditAnnotations may not both be empty; a least one of validations or auditAnnotations is +// +// required. +func (d *ValidatingAdmissionPolicySpecDie) AuditAnnotationsDie(v ...*AuditAnnotationDie) *ValidatingAdmissionPolicySpecDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { + r.AuditAnnotations = make([]admissionregistrationv1.AuditAnnotation, len(v)) + for i := range v { + r.AuditAnnotations[i] = v[i].DieRelease() + } + }) +} + +// MatchConditionDie mutates a single item in MatchConditions matched by the nested field Name, appending a new item if no match is found. +// +// MatchConditions is a list of conditions that must be met for a request to be validated. +// +// Match conditions filter requests that have already been matched by the rules, +// +// namespaceSelector, and objectSelector. An empty list of matchConditions matches all requests. +// +// There are a maximum of 64 match conditions allowed. +// +// # If a parameter object is provided, it can be accessed via the `params` handle in the same +// +// manner as validation expressions. +// +// The exact matching logic is (in order): +// +// 1. If ANY matchCondition evaluates to FALSE, the policy is skipped. +// +// 2. If ALL matchConditions evaluate to TRUE, the policy is evaluated. +// +// 3. If any matchCondition evaluates to an error (but none are FALSE): +// +// - If failurePolicy=Fail, reject the request +// +// - If failurePolicy=Ignore, the policy is skipped +func (d *ValidatingAdmissionPolicySpecDie) MatchConditionDie(v string, fn func(d *MatchConditionDie)) *ValidatingAdmissionPolicySpecDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { + for i := range r.MatchConditions { + if v == r.MatchConditions[i].Name { + d := MatchConditionBlank.DieImmutable(false).DieFeed(r.MatchConditions[i]) + fn(d) + r.MatchConditions[i] = d.DieRelease() + return + } + } + + d := MatchConditionBlank.DieImmutable(false).DieFeed(admissionregistrationv1.MatchCondition{Name: v}) + fn(d) + r.MatchConditions = append(r.MatchConditions, d.DieRelease()) + }) +} + +// VariableDie mutates a single item in Variables matched by the nested field Name, appending a new item if no match is found. +// +// Variables contain definitions of variables that can be used in composition of other expressions. +// +// Each variable is defined as a named CEL expression. +// +// # The variables defined here will be available under `variables` in other expressions of the policy +// +// except MatchConditions because MatchConditions are evaluated before the rest of the policy. +// +// The expression of a variable can refer to other variables defined earlier in the list but not those after. +// +// Thus, Variables must be sorted by the order of first appearance and acyclic. +func (d *ValidatingAdmissionPolicySpecDie) VariableDie(v string, fn func(d *VariableDie)) *ValidatingAdmissionPolicySpecDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicySpec) { + for i := range r.Variables { + if v == r.Variables[i].Name { + d := VariableBlank.DieImmutable(false).DieFeed(r.Variables[i]) + fn(d) + r.Variables[i] = d.DieRelease() + return + } + } + + d := VariableBlank.DieImmutable(false).DieFeed(admissionregistrationv1.Variable{Name: v}) + fn(d) + r.Variables = append(r.Variables, d.DieRelease()) + }) +} + // ParamKind specifies the kind of resources used to parameterize this policy. // // If absent, there are no parameters for this policy and the param CEL variable will not be provided to validation expressions. @@ -3455,9 +3823,155 @@ func (d *MatchResourcesDie) DieDiff(opts ...cmp.Option) string { return cmp.Diff(d.seal, d.r, opts...) } -// DiePatch generates a patch between the current value of the die and the sealed value. -func (d *MatchResourcesDie) DiePatch(patchType types.PatchType) ([]byte, error) { - return patch.Create(d.seal, d.r, patchType) +// DiePatch generates a patch between the current value of the die and the sealed value. +func (d *MatchResourcesDie) DiePatch(patchType types.PatchType) ([]byte, error) { + return patch.Create(d.seal, d.r, patchType) +} + +// NamespaceSelectorDie mutates NamespaceSelector as a die. +// +// # NamespaceSelector decides whether to run the admission control policy on an object based +// +// on whether the namespace for that object matches the selector. If the +// +// object itself is a namespace, the matching is performed on +// +// object.metadata.labels. If the object is another cluster scoped resource, +// +// it never skips the policy. +// +// # For example, to run the webhook on any objects whose namespace is not +// +// associated with "runlevel" of "0" or "1"; you will set the selector as +// +// follows: +// +// "namespaceSelector": { +// +// "matchExpressions": [ +// +// { +// +// "key": "runlevel", +// +// "operator": "NotIn", +// +// "values": [ +// +// "0", +// +// "1" +// +// ] +// +// } +// +// ] +// +// } +// +// # If instead you want to only run the policy on any objects whose +// +// namespace is associated with the "environment" of "prod" or "staging"; +// +// you will set the selector as follows: +// +// "namespaceSelector": { +// +// "matchExpressions": [ +// +// { +// +// "key": "environment", +// +// "operator": "In", +// +// "values": [ +// +// "prod", +// +// "staging" +// +// ] +// +// } +// +// ] +// +// } +// +// # See +// +// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ +// +// for more examples of label selectors. +// +// Default to the empty LabelSelector, which matches everything. +func (d *MatchResourcesDie) NamespaceSelectorDie(fn func(d *metav1.LabelSelectorDie)) *MatchResourcesDie { + return d.DieStamp(func(r *admissionregistrationv1.MatchResources) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NamespaceSelector) + fn(d) + r.NamespaceSelector = d.DieReleasePtr() + }) +} + +// ObjectSelectorDie mutates ObjectSelector as a die. +// +// # ObjectSelector decides whether to run the validation based on if the +// +// object has matching labels. objectSelector is evaluated against both +// +// the oldObject and newObject that would be sent to the cel validation, and +// +// is considered to match if either object matches the selector. A null +// +// object (oldObject in the case of create, or newObject in the case of +// +// delete) or an object that cannot have labels (like a +// +// # DeploymentRollback or a PodProxyOptions object) is not considered to +// +// match. +// +// # Use the object selector only if the webhook is opt-in, because end +// +// users may skip the admission webhook by setting the labels. +// +// Default to the empty LabelSelector, which matches everything. +func (d *MatchResourcesDie) ObjectSelectorDie(fn func(d *metav1.LabelSelectorDie)) *MatchResourcesDie { + return d.DieStamp(func(r *admissionregistrationv1.MatchResources) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.ObjectSelector) + fn(d) + r.ObjectSelector = d.DieReleasePtr() + }) +} + +// ResourceRulesDie replaces ResourceRules by collecting the released value from each die passed. +// +// ResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy matches. +// +// The policy cares about an operation if it matches _any_ Rule. +func (d *MatchResourcesDie) ResourceRulesDie(v ...*NamedRuleWithOperationsDie) *MatchResourcesDie { + return d.DieStamp(func(r *admissionregistrationv1.MatchResources) { + r.ResourceRules = make([]admissionregistrationv1.NamedRuleWithOperations, len(v)) + for i := range v { + r.ResourceRules[i] = v[i].DieRelease() + } + }) +} + +// ExcludeResourceRulesDie replaces ExcludeResourceRules by collecting the released value from each die passed. +// +// ExcludeResourceRules describes what operations on what resources/subresources the ValidatingAdmissionPolicy should not care about. +// +// The exclude rules take precedence over include rules (if a resource matches both, it is excluded) +func (d *MatchResourcesDie) ExcludeResourceRulesDie(v ...*NamedRuleWithOperationsDie) *MatchResourcesDie { + return d.DieStamp(func(r *admissionregistrationv1.MatchResources) { + r.ExcludeResourceRules = make([]admissionregistrationv1.NamedRuleWithOperations, len(v)) + for i := range v { + r.ExcludeResourceRules[i] = v[i].DieRelease() + } + }) } // NamespaceSelector decides whether to run the admission control policy on an object based @@ -4989,6 +5503,31 @@ func (d *ValidatingAdmissionPolicyStatusDie) DiePatch(patchType types.PatchType) return patch.Create(d.seal, d.r, patchType) } +// TypeCheckingDie mutates TypeChecking as a die. +// +// The results of type checking for each expression. +// +// Presence of this field indicates the completion of the type checking. +func (d *ValidatingAdmissionPolicyStatusDie) TypeCheckingDie(fn func(d *TypeCheckingDie)) *ValidatingAdmissionPolicyStatusDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicyStatus) { + d := TypeCheckingBlank.DieImmutable(false).DieFeedPtr(r.TypeChecking) + fn(d) + r.TypeChecking = d.DieReleasePtr() + }) +} + +// ConditionsDie replaces Conditions by collecting the released value from each die passed. +// +// The conditions represent the latest available observations of a policy's current state. +func (d *ValidatingAdmissionPolicyStatusDie) ConditionsDie(v ...*metav1.ConditionDie) *ValidatingAdmissionPolicyStatusDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicyStatus) { + r.Conditions = make([]apismetav1.Condition, len(v)) + for i := range v { + r.Conditions[i] = v[i].DieRelease() + } + }) +} + // The generation observed by the controller. func (d *ValidatingAdmissionPolicyStatusDie) ObservedGeneration(v int64) *ValidatingAdmissionPolicyStatusDie { return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicyStatus) { @@ -5240,6 +5779,18 @@ func (d *TypeCheckingDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ExpressionWarningsDie replaces ExpressionWarnings by collecting the released value from each die passed. +// +// The type checking warnings for each expression. +func (d *TypeCheckingDie) ExpressionWarningsDie(v ...*ExpressionWarningDie) *TypeCheckingDie { + return d.DieStamp(func(r *admissionregistrationv1.TypeChecking) { + r.ExpressionWarnings = make([]admissionregistrationv1.ExpressionWarning, len(v)) + for i := range v { + r.ExpressionWarnings[i] = v[i].DieRelease() + } + }) +} + // The type checking warnings for each expression. func (d *TypeCheckingDie) ExpressionWarnings(v ...admissionregistrationv1.ExpressionWarning) *TypeCheckingDie { return d.DieStamp(func(r *admissionregistrationv1.TypeChecking) { @@ -6064,6 +6615,42 @@ func (d *ValidatingAdmissionPolicyBindingSpecDie) DiePatch(patchType types.Patch return patch.Create(d.seal, d.r, patchType) } +// ParamRefDie mutates ParamRef as a die. +// +// paramRef specifies the parameter resource used to configure the admission control policy. +// +// It should point to a resource of the type specified in ParamKind of the bound ValidatingAdmissionPolicy. +// +// If the policy specifies a ParamKind and the resource referred to by ParamRef does not exist, this binding is considered mis-configured and the FailurePolicy of the ValidatingAdmissionPolicy applied. +// +// If the policy does not specify a ParamKind then this field is ignored, and the rules are evaluated without a param. +func (d *ValidatingAdmissionPolicyBindingSpecDie) ParamRefDie(fn func(d *ParamRefDie)) *ValidatingAdmissionPolicyBindingSpecDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicyBindingSpec) { + d := ParamRefBlank.DieImmutable(false).DieFeedPtr(r.ParamRef) + fn(d) + r.ParamRef = d.DieReleasePtr() + }) +} + +// MatchResourcesDie mutates MatchResources as a die. +// +// MatchResources declares what resources match this binding and will be validated by it. +// +// Note that this is intersected with the policy's matchConstraints, so only requests that are matched by the policy can be selected by this. +// +// # If this is unset, all resources matched by the policy are validated by this binding +// +// When resourceRules is unset, it does not constrain resource matching. If a resource is matched by the other fields of this object, it will be validated. +// +// Note that this is differs from ValidatingAdmissionPolicy matchConstraints, where resourceRules are required. +func (d *ValidatingAdmissionPolicyBindingSpecDie) MatchResourcesDie(fn func(d *MatchResourcesDie)) *ValidatingAdmissionPolicyBindingSpecDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingAdmissionPolicyBindingSpec) { + d := MatchResourcesBlank.DieImmutable(false).DieFeedPtr(r.MatchResources) + fn(d) + r.MatchResources = d.DieReleasePtr() + }) +} + // PolicyName references a ValidatingAdmissionPolicy name which the ValidatingAdmissionPolicyBinding binds to. // // # If the referenced resource does not exist, this binding is considered invalid and will be ignored @@ -6396,6 +6983,27 @@ func (d *ParamRefDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// SelectorDie mutates Selector as a die. +// +// selector can be used to match multiple param objects based on their labels. +// +// Supply selector: {} to match all resources of the ParamKind. +// +// # If multiple params are found, they are all evaluated with the policy expressions +// +// and the results are ANDed together. +// +// # One of `name` or `selector` must be set, but `name` and `selector` are +// +// mutually exclusive properties. If one is set, the other must be unset. +func (d *ParamRefDie) SelectorDie(fn func(d *metav1.LabelSelectorDie)) *ParamRefDie { + return d.DieStamp(func(r *admissionregistrationv1.ParamRef) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) + fn(d) + r.Selector = d.DieReleasePtr() + }) +} + // name is the name of the resource being referenced. // // # One of `name` or `selector` must be set, but `name` and `selector` are @@ -6801,6 +7409,26 @@ func (d *ValidatingWebhookConfigurationDie) MetadataDie(fn func(d *metav1.Object }) } +// WebhookDie mutates a single item in Webhooks matched by the nested field Name, appending a new item if no match is found. +// +// Webhooks is a list of webhooks and the affected resources and operations. +func (d *ValidatingWebhookConfigurationDie) WebhookDie(v string, fn func(d *ValidatingWebhookDie)) *ValidatingWebhookConfigurationDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhookConfiguration) { + for i := range r.Webhooks { + if v == r.Webhooks[i].Name { + d := ValidatingWebhookBlank.DieImmutable(false).DieFeed(r.Webhooks[i]) + fn(d) + r.Webhooks[i] = d.DieRelease() + return + } + } + + d := ValidatingWebhookBlank.DieImmutable(false).DieFeed(admissionregistrationv1.ValidatingWebhook{Name: v}) + fn(d) + r.Webhooks = append(r.Webhooks, d.DieRelease()) + }) +} + // Webhooks is a list of webhooks and the affected resources and operations. func (d *ValidatingWebhookConfigurationDie) Webhooks(v ...admissionregistrationv1.ValidatingWebhook) *ValidatingWebhookConfigurationDie { return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhookConfiguration) { @@ -7036,6 +7664,197 @@ func (d *ValidatingWebhookDie) DiePatch(patchType types.PatchType) ([]byte, erro return patch.Create(d.seal, d.r, patchType) } +// ClientConfigDie mutates ClientConfig as a die. +// +// ClientConfig defines how to communicate with the hook. +// +// Required +func (d *ValidatingWebhookDie) ClientConfigDie(fn func(d *WebhookClientConfigDie)) *ValidatingWebhookDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhook) { + d := WebhookClientConfigBlank.DieImmutable(false).DieFeed(r.ClientConfig) + fn(d) + r.ClientConfig = d.DieRelease() + }) +} + +// NamespaceSelectorDie mutates NamespaceSelector as a die. +// +// # NamespaceSelector decides whether to run the webhook on an object based +// +// on whether the namespace for that object matches the selector. If the +// +// object itself is a namespace, the matching is performed on +// +// object.metadata.labels. If the object is another cluster scoped resource, +// +// it never skips the webhook. +// +// # For example, to run the webhook on any objects whose namespace is not +// +// associated with "runlevel" of "0" or "1"; you will set the selector as +// +// follows: +// +// "namespaceSelector": { +// +// "matchExpressions": [ +// +// { +// +// "key": "runlevel", +// +// "operator": "NotIn", +// +// "values": [ +// +// "0", +// +// "1" +// +// ] +// +// } +// +// ] +// +// } +// +// # If instead you want to only run the webhook on any objects whose +// +// namespace is associated with the "environment" of "prod" or "staging"; +// +// you will set the selector as follows: +// +// "namespaceSelector": { +// +// "matchExpressions": [ +// +// { +// +// "key": "environment", +// +// "operator": "In", +// +// "values": [ +// +// "prod", +// +// "staging" +// +// ] +// +// } +// +// ] +// +// } +// +// # See +// +// https://kubernetes.io/docs/concepts/overview/working-with-objects/labels +// +// for more examples of label selectors. +// +// Default to the empty LabelSelector, which matches everything. +func (d *ValidatingWebhookDie) NamespaceSelectorDie(fn func(d *metav1.LabelSelectorDie)) *ValidatingWebhookDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhook) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NamespaceSelector) + fn(d) + r.NamespaceSelector = d.DieReleasePtr() + }) +} + +// ObjectSelectorDie mutates ObjectSelector as a die. +// +// # ObjectSelector decides whether to run the webhook based on if the +// +// object has matching labels. objectSelector is evaluated against both +// +// the oldObject and newObject that would be sent to the webhook, and +// +// is considered to match if either object matches the selector. A null +// +// object (oldObject in the case of create, or newObject in the case of +// +// delete) or an object that cannot have labels (like a +// +// # DeploymentRollback or a PodProxyOptions object) is not considered to +// +// match. +// +// # Use the object selector only if the webhook is opt-in, because end +// +// users may skip the admission webhook by setting the labels. +// +// Default to the empty LabelSelector, which matches everything. +func (d *ValidatingWebhookDie) ObjectSelectorDie(fn func(d *metav1.LabelSelectorDie)) *ValidatingWebhookDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhook) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.ObjectSelector) + fn(d) + r.ObjectSelector = d.DieReleasePtr() + }) +} + +// RulesDie replaces Rules by collecting the released value from each die passed. +// +// Rules describes what operations on what resources/subresources the webhook cares about. +// +// The webhook cares about an operation if it matches _any_ Rule. +// +// # However, in order to prevent ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks +// +// from putting the cluster in a state which cannot be recovered from without completely +// +// disabling the plugin, ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks are never called +// +// on admission requests for ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects. +func (d *ValidatingWebhookDie) RulesDie(v ...*RuleWithOperationsDie) *ValidatingWebhookDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhook) { + r.Rules = make([]admissionregistrationv1.RuleWithOperations, len(v)) + for i := range v { + r.Rules[i] = v[i].DieRelease() + } + }) +} + +// MatchConditionDie mutates a single item in MatchConditions matched by the nested field Name, appending a new item if no match is found. +// +// # MatchConditions is a list of conditions that must be met for a request to be sent to this +// +// webhook. Match conditions filter requests that have already been matched by the rules, +// +// namespaceSelector, and objectSelector. An empty list of matchConditions matches all requests. +// +// There are a maximum of 64 match conditions allowed. +// +// The exact matching logic is (in order): +// +// 1. If ANY matchCondition evaluates to FALSE, the webhook is skipped. +// +// 2. If ALL matchConditions evaluate to TRUE, the webhook is called. +// +// 3. If any matchCondition evaluates to an error (but none are FALSE): +// +// - If failurePolicy=Fail, reject the request +// +// - If failurePolicy=Ignore, the error is ignored and the webhook is skipped +func (d *ValidatingWebhookDie) MatchConditionDie(v string, fn func(d *MatchConditionDie)) *ValidatingWebhookDie { + return d.DieStamp(func(r *admissionregistrationv1.ValidatingWebhook) { + for i := range r.MatchConditions { + if v == r.MatchConditions[i].Name { + d := MatchConditionBlank.DieImmutable(false).DieFeed(r.MatchConditions[i]) + fn(d) + r.MatchConditions[i] = d.DieRelease() + return + } + } + + d := MatchConditionBlank.DieImmutable(false).DieFeed(admissionregistrationv1.MatchCondition{Name: v}) + fn(d) + r.MatchConditions = append(r.MatchConditions, d.DieRelease()) + }) +} + // The name of the admission webhook. // // # Name should be fully qualified, e.g., imagepolicy.kubernetes.io, where diff --git a/apis/apiextensions/v1/customresourcedefinition.go b/apis/apiextensions/v1/customresourcedefinition.go index 277e6e5..cda7729 100644 --- a/apis/apiextensions/v1/customresourcedefinition.go +++ b/apis/apiextensions/v1/customresourcedefinition.go @@ -25,100 +25,25 @@ import ( type _ = apiextensionsv1.CustomResourceDefinition // +die +// +die:field:name=Names,die=CustomResourceDefinitionNamesDie +// +die:field:name=Conversion,die=CustomResourceConversionDie,pointer=true +// +die:field:name=Versions,die=CustomResourceDefinitionVersionDie,listType=map type _ = apiextensionsv1.CustomResourceDefinitionSpec -func (d *CustomResourceDefinitionSpecDie) NamesDie(fn func(d *CustomResourceDefinitionNamesDie)) *CustomResourceDefinitionSpecDie { - return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionSpec) { - d := CustomResourceDefinitionNamesBlank.DieImmutable(false).DieFeed(r.Names) - fn(d) - r.Names = d.DieRelease() - }) -} - -func (d *CustomResourceDefinitionSpecDie) VersionDie(name string, fn func(d *CustomResourceDefinitionVersionDie)) *CustomResourceDefinitionSpecDie { - return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionSpec) { - for i := range r.Versions { - if name == r.Versions[i].Name { - d := CustomResourceDefinitionVersionBlank.DieImmutable(false).DieFeed(r.Versions[i]) - fn(d) - r.Versions[i] = d.DieRelease() - return - } - } - - d := CustomResourceDefinitionVersionBlank.DieImmutable(false).DieFeed(apiextensionsv1.CustomResourceDefinitionVersion{Name: name}) - fn(d) - r.Versions = append(r.Versions, d.DieRelease()) - }) -} - -func (d *CustomResourceDefinitionSpecDie) ConversionDie(fn func(d *CustomResourceConversionDie)) *CustomResourceDefinitionSpecDie { - return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionSpec) { - d := CustomResourceConversionBlank.DieImmutable(false).DieFeedPtr(r.Conversion) - fn(d) - r.Conversion = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Schema,die=CustomResourceValidationDie,pointer=true +// +die:field:name=Subresources,die=CustomResourceSubresourcesDie,pointer=true +// +die:field:name=AdditionalPrinterColumns,die=CustomResourceColumnDefinitionDie,listType=map +// +die:field:name=SelectableFields,die=SelectableFieldDie,listType=atomic type _ apiextensionsv1.CustomResourceDefinitionVersion -func (d *CustomResourceDefinitionVersionDie) SchemaDie(fn func(d *CustomResourceValidationDie)) *CustomResourceDefinitionVersionDie { - return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionVersion) { - d := CustomResourceValidationBlank.DieImmutable(false).DieFeedPtr(r.Schema) - fn(d) - r.Schema = d.DieReleasePtr() - }) -} - -func (d *CustomResourceDefinitionVersionDie) SubresourcesDie(fn func(d *CustomResourceSubresourcesDie)) *CustomResourceDefinitionVersionDie { - return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionVersion) { - d := CustomResourceSubresourcesBlank.DieImmutable(false).DieFeedPtr(r.Subresources) - fn(d) - r.Subresources = d.DieReleasePtr() - }) -} - -func (d *CustomResourceDefinitionVersionDie) AdditionalPrinterColumnDie(name string, fn func(d *CustomResourceColumnDefinitionDie)) *CustomResourceDefinitionVersionDie { - return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionVersion) { - for i := range r.AdditionalPrinterColumns { - if name == r.AdditionalPrinterColumns[i].Name { - d := CustomResourceColumnDefinitionBlank.DieImmutable(false).DieFeed(r.AdditionalPrinterColumns[i]) - fn(d) - r.AdditionalPrinterColumns[i] = d.DieRelease() - return - } - } - - d := CustomResourceColumnDefinitionBlank.DieImmutable(false).DieFeed(apiextensionsv1.CustomResourceColumnDefinition{Name: name}) - fn(d) - r.AdditionalPrinterColumns = append(r.AdditionalPrinterColumns, d.DieRelease()) - }) -} - -func (d *CustomResourceDefinitionVersionDie) SelectableFieldsDie(fields ...*SelectableFieldDie) *CustomResourceDefinitionVersionDie { - return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionVersion) { - r.SelectableFields = make([]apiextensionsv1.SelectableField, len(fields)) - for i := range fields { - r.SelectableFields[i] = fields[i].DieRelease() - } - }) -} - // +die type _ apiextensionsv1.CustomResourceValidation // +die +// +die:field:name=Scale,die=CustomResourceSubresourceScaleDie,pointer=true type _ apiextensionsv1.CustomResourceSubresources -func (d *CustomResourceSubresourcesDie) ScaleDie(fn func(d *CustomResourceSubresourceScaleDie)) *CustomResourceSubresourcesDie { - return d.DieStamp(func(r *apiextensionsv1.CustomResourceSubresources) { - d := CustomResourceSubresourceScaleBlank.DieImmutable(false).DieFeedPtr(r.Scale) - fn(d) - r.Scale = d.DieReleasePtr() - }) -} - // +die type _ apiextensionsv1.CustomResourceSubresourceScale @@ -126,38 +51,17 @@ type _ apiextensionsv1.CustomResourceSubresourceScale type _ apiextensionsv1.CustomResourceColumnDefinition // +die +// +die:field:name=Webhook,die=WebhookConversionDie,pointer=true type _ apiextensionsv1.CustomResourceConversion -func (d *CustomResourceConversionDie) WebhookDie(fn func(d *WebhookConversionDie)) *CustomResourceConversionDie { - return d.DieStamp(func(r *apiextensionsv1.CustomResourceConversion) { - d := WebhookConversionBlank.DieImmutable(false).DieFeedPtr(r.Webhook) - fn(d) - r.Webhook = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=ClientConfig,die=WebhookClientConfigDie,pointer=true type _ apiextensionsv1.WebhookConversion -func (d *WebhookConversionDie) ClientConfigDie(fn func(d *WebhookClientConfigDie)) *WebhookConversionDie { - return d.DieStamp(func(r *apiextensionsv1.WebhookConversion) { - d := WebhookClientConfigBlank.DieImmutable(false).DieFeedPtr(r.ClientConfig) - fn(d) - r.ClientConfig = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Service,die=ServiceReferenceDie,pointer=true type _ apiextensionsv1.WebhookClientConfig -func (d *WebhookClientConfigDie) ServiceDie(fn func(d *ServiceReferenceDie)) *WebhookClientConfigDie { - return d.DieStamp(func(r *apiextensionsv1.WebhookClientConfig) { - d := ServiceReferenceBlank.DieImmutable(false).DieFeedPtr(r.Service) - fn(d) - r.Service = d.DieReleasePtr() - }) -} - // +die type _ apiextensionsv1.ServiceReference @@ -165,6 +69,7 @@ type _ apiextensionsv1.ServiceReference type _ apiextensionsv1.SelectableField // +die +// +die:field:name=AcceptedNames,die=CustomResourceDefinitionNamesDie type _ = apiextensionsv1.CustomResourceDefinitionStatus func (d *CustomResourceDefinitionStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *CustomResourceDefinitionStatusDie { @@ -183,13 +88,5 @@ func (d *CustomResourceDefinitionStatusDie) ConditionsDie(conditions ...*diemeta }) } -func (d *CustomResourceDefinitionStatusDie) AcceptedNamesDie(fn func(d *CustomResourceDefinitionNamesDie)) *CustomResourceDefinitionStatusDie { - return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionStatus) { - d := CustomResourceDefinitionNamesBlank.DieImmutable(false).DieFeed(r.AcceptedNames) - fn(d) - r.AcceptedNames = d.DieRelease() - }) -} - // +die type _ = apiextensionsv1.CustomResourceDefinitionNames diff --git a/apis/apiextensions/v1/zz_generated.die.go b/apis/apiextensions/v1/zz_generated.die.go index 6d263c8..36ec63d 100644 --- a/apis/apiextensions/v1/zz_generated.die.go +++ b/apis/apiextensions/v1/zz_generated.die.go @@ -622,6 +622,62 @@ func (d *CustomResourceDefinitionSpecDie) DiePatch(patchType types.PatchType) ([ return patch.Create(d.seal, d.r, patchType) } +// NamesDie mutates Names as a die. +// +// names specify the resource and kind names for the custom resource. +func (d *CustomResourceDefinitionSpecDie) NamesDie(fn func(d *CustomResourceDefinitionNamesDie)) *CustomResourceDefinitionSpecDie { + return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionSpec) { + d := CustomResourceDefinitionNamesBlank.DieImmutable(false).DieFeed(r.Names) + fn(d) + r.Names = d.DieRelease() + }) +} + +// ConversionDie mutates Conversion as a die. +// +// conversion defines conversion settings for the CRD. +func (d *CustomResourceDefinitionSpecDie) ConversionDie(fn func(d *CustomResourceConversionDie)) *CustomResourceDefinitionSpecDie { + return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionSpec) { + d := CustomResourceConversionBlank.DieImmutable(false).DieFeedPtr(r.Conversion) + fn(d) + r.Conversion = d.DieReleasePtr() + }) +} + +// VersionDie mutates a single item in Versions matched by the nested field Name, appending a new item if no match is found. +// +// versions is the list of all API versions of the defined custom resource. +// +// Version names are used to compute the order in which served versions are listed in API discovery. +// +// If the version string is "kube-like", it will sort above non "kube-like" version strings, which are ordered +// +// lexicographically. "Kube-like" versions start with a "v", then are followed by a number (the major version), +// +// then optionally the string "alpha" or "beta" and another number (the minor version). These are sorted first +// +// by GA > beta > alpha (where GA is a version with no suffix such as beta or alpha), and then by comparing +// +// major version, then minor version. An example sorted list of versions: +// +// v10, v2, v1, v11beta2, v10beta3, v3beta1, v12alpha1, v11alpha2, foo1, foo10. +func (d *CustomResourceDefinitionSpecDie) VersionDie(v string, fn func(d *CustomResourceDefinitionVersionDie)) *CustomResourceDefinitionSpecDie { + return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionSpec) { + for i := range r.Versions { + if v == r.Versions[i].Name { + d := CustomResourceDefinitionVersionBlank.DieImmutable(false).DieFeed(r.Versions[i]) + fn(d) + r.Versions[i] = d.DieRelease() + return + } + } + + d := CustomResourceDefinitionVersionBlank.DieImmutable(false).DieFeed(apiextensionsv1.CustomResourceDefinitionVersion{Name: v}) + fn(d) + r.Versions = append(r.Versions, d.DieRelease()) + }) +} + // group is the API group of the defined custom resource. // // The custom resources are served under `/apis//...`. @@ -920,6 +976,68 @@ func (d *CustomResourceDefinitionVersionDie) DiePatch(patchType types.PatchType) return patch.Create(d.seal, d.r, patchType) } +// SchemaDie mutates Schema as a die. +// +// schema describes the schema used for validation, pruning, and defaulting of this version of the custom resource. +func (d *CustomResourceDefinitionVersionDie) SchemaDie(fn func(d *CustomResourceValidationDie)) *CustomResourceDefinitionVersionDie { + return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionVersion) { + d := CustomResourceValidationBlank.DieImmutable(false).DieFeedPtr(r.Schema) + fn(d) + r.Schema = d.DieReleasePtr() + }) +} + +// SubresourcesDie mutates Subresources as a die. +// +// subresources specify what subresources this version of the defined custom resource have. +func (d *CustomResourceDefinitionVersionDie) SubresourcesDie(fn func(d *CustomResourceSubresourcesDie)) *CustomResourceDefinitionVersionDie { + return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionVersion) { + d := CustomResourceSubresourcesBlank.DieImmutable(false).DieFeedPtr(r.Subresources) + fn(d) + r.Subresources = d.DieReleasePtr() + }) +} + +// AdditionalPrinterColumnDie mutates a single item in AdditionalPrinterColumns matched by the nested field Name, appending a new item if no match is found. +// +// additionalPrinterColumns specifies additional columns returned in Table output. +// +// See https://kubernetes.io/docs/reference/using-api/api-concepts/#receiving-resources-as-tables for details. +// +// If no columns are specified, a single column displaying the age of the custom resource is used. +func (d *CustomResourceDefinitionVersionDie) AdditionalPrinterColumnDie(v string, fn func(d *CustomResourceColumnDefinitionDie)) *CustomResourceDefinitionVersionDie { + return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionVersion) { + for i := range r.AdditionalPrinterColumns { + if v == r.AdditionalPrinterColumns[i].Name { + d := CustomResourceColumnDefinitionBlank.DieImmutable(false).DieFeed(r.AdditionalPrinterColumns[i]) + fn(d) + r.AdditionalPrinterColumns[i] = d.DieRelease() + return + } + } + + d := CustomResourceColumnDefinitionBlank.DieImmutable(false).DieFeed(apiextensionsv1.CustomResourceColumnDefinition{Name: v}) + fn(d) + r.AdditionalPrinterColumns = append(r.AdditionalPrinterColumns, d.DieRelease()) + }) +} + +// SelectableFieldsDie replaces SelectableFields by collecting the released value from each die passed. +// +// selectableFields specifies paths to fields that may be used as field selectors. +// +// A maximum of 8 selectable fields are allowed. +// +// See https://kubernetes.io/docs/concepts/overview/working-with-objects/field-selectors +func (d *CustomResourceDefinitionVersionDie) SelectableFieldsDie(v ...*SelectableFieldDie) *CustomResourceDefinitionVersionDie { + return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionVersion) { + r.SelectableFields = make([]apiextensionsv1.SelectableField, len(v)) + for i := range v { + r.SelectableFields[i] = v[i].DieRelease() + } + }) +} + // name is the version name, e.g. “v1”, “v2beta1”, etc. // // The custom resources are served under this version at `/apis///...` if `served` is true. @@ -1468,6 +1586,17 @@ func (d *CustomResourceSubresourcesDie) DiePatch(patchType types.PatchType) ([]b return patch.Create(d.seal, d.r, patchType) } +// ScaleDie mutates Scale as a die. +// +// scale indicates the custom resource should serve a `/scale` subresource that returns an `autoscaling/v1` Scale object. +func (d *CustomResourceSubresourcesDie) ScaleDie(fn func(d *CustomResourceSubresourceScaleDie)) *CustomResourceSubresourcesDie { + return d.DieStamp(func(r *apiextensionsv1.CustomResourceSubresources) { + d := CustomResourceSubresourceScaleBlank.DieImmutable(false).DieFeedPtr(r.Scale) + fn(d) + r.Scale = d.DieReleasePtr() + }) +} + // status indicates the custom resource should serve a `/status` subresource. // // When enabled: @@ -2277,6 +2406,17 @@ func (d *CustomResourceConversionDie) DiePatch(patchType types.PatchType) ([]byt return patch.Create(d.seal, d.r, patchType) } +// WebhookDie mutates Webhook as a die. +// +// webhook describes how to call the conversion webhook. Required when `strategy` is set to `"Webhook"`. +func (d *CustomResourceConversionDie) WebhookDie(fn func(d *WebhookConversionDie)) *CustomResourceConversionDie { + return d.DieStamp(func(r *apiextensionsv1.CustomResourceConversion) { + d := WebhookConversionBlank.DieImmutable(false).DieFeedPtr(r.Webhook) + fn(d) + r.Webhook = d.DieReleasePtr() + }) +} + // strategy specifies how custom resources are converted between versions. Allowed values are: // // - `"None"`: The converter only change the apiVersion and would not touch any other field in the custom resource. @@ -2525,6 +2665,17 @@ func (d *WebhookConversionDie) DiePatch(patchType types.PatchType) ([]byte, erro return patch.Create(d.seal, d.r, patchType) } +// ClientConfigDie mutates ClientConfig as a die. +// +// clientConfig is the instructions for how to call the webhook if strategy is `Webhook`. +func (d *WebhookConversionDie) ClientConfigDie(fn func(d *WebhookClientConfigDie)) *WebhookConversionDie { + return d.DieStamp(func(r *apiextensionsv1.WebhookConversion) { + d := WebhookClientConfigBlank.DieImmutable(false).DieFeedPtr(r.ClientConfig) + fn(d) + r.ClientConfig = d.DieReleasePtr() + }) +} + // clientConfig is the instructions for how to call the webhook if strategy is `Webhook`. func (d *WebhookConversionDie) ClientConfig(v *apiextensionsv1.WebhookClientConfig) *WebhookConversionDie { return d.DieStamp(func(r *apiextensionsv1.WebhookConversion) { @@ -2777,6 +2928,21 @@ func (d *WebhookClientConfigDie) DiePatch(patchType types.PatchType) ([]byte, er return patch.Create(d.seal, d.r, patchType) } +// ServiceDie mutates Service as a die. +// +// service is a reference to the service for this webhook. Either +// +// service or url must be specified. +// +// If the webhook is running within the cluster, then you should use `service`. +func (d *WebhookClientConfigDie) ServiceDie(fn func(d *ServiceReferenceDie)) *WebhookClientConfigDie { + return d.DieStamp(func(r *apiextensionsv1.WebhookClientConfig) { + d := ServiceReferenceBlank.DieImmutable(false).DieFeedPtr(r.Service) + fn(d) + r.Service = d.DieReleasePtr() + }) +} + // url gives the location of the webhook, in standard URL form // // (`scheme://host:port/path`). Exactly one of `url` or `service` @@ -3583,6 +3749,19 @@ func (d *CustomResourceDefinitionStatusDie) DiePatch(patchType types.PatchType) return patch.Create(d.seal, d.r, patchType) } +// AcceptedNamesDie mutates AcceptedNames as a die. +// +// acceptedNames are the names that are actually being used to serve discovery. +// +// They may be different than the names in spec. +func (d *CustomResourceDefinitionStatusDie) AcceptedNamesDie(fn func(d *CustomResourceDefinitionNamesDie)) *CustomResourceDefinitionStatusDie { + return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionStatus) { + d := CustomResourceDefinitionNamesBlank.DieImmutable(false).DieFeed(r.AcceptedNames) + fn(d) + r.AcceptedNames = d.DieRelease() + }) +} + // conditions indicate state for particular aspects of a CustomResourceDefinition func (d *CustomResourceDefinitionStatusDie) Conditions(v ...apiextensionsv1.CustomResourceDefinitionCondition) *CustomResourceDefinitionStatusDie { return d.DieStamp(func(r *apiextensionsv1.CustomResourceDefinitionStatus) { diff --git a/apis/apiregistration/v1/apiservice.go b/apis/apiregistration/v1/apiservice.go index c8bcb2f..a71be86 100644 --- a/apis/apiregistration/v1/apiservice.go +++ b/apis/apiregistration/v1/apiservice.go @@ -25,16 +25,9 @@ import ( type _ = apiregistrationv1.APIService // +die +// +die:field:name=Service,die=ServiceReferenceDie,pointer=true type _ = apiregistrationv1.APIServiceSpec -func (d *APIServiceSpecDie) TargetDie(fn func(d *ServiceReferenceDie)) *APIServiceSpecDie { - return d.DieStamp(func(r *apiregistrationv1.APIServiceSpec) { - d := ServiceReferenceBlank.DieImmutable(false).DieFeedPtr(r.Service) - fn(d) - r.Service = d.DieReleasePtr() - }) -} - // +die type _ = apiregistrationv1.ServiceReference diff --git a/apis/apiregistration/v1/zz_generated.die.go b/apis/apiregistration/v1/zz_generated.die.go index d519bc1..21451da 100644 --- a/apis/apiregistration/v1/zz_generated.die.go +++ b/apis/apiregistration/v1/zz_generated.die.go @@ -622,6 +622,23 @@ func (d *APIServiceSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// ServiceDie mutates Service as a die. +// +// Service is a reference to the service for this API server. It must communicate +// +// on port 443. +// +// If the Service is nil, that means the handling for the API groupversion is handled locally on this server. +// +// The call will simply delegate to the normal handler chain to be fulfilled. +func (d *APIServiceSpecDie) ServiceDie(fn func(d *ServiceReferenceDie)) *APIServiceSpecDie { + return d.DieStamp(func(r *apiregistration.APIServiceSpec) { + d := ServiceReferenceBlank.DieImmutable(false).DieFeedPtr(r.Service) + fn(d) + r.Service = d.DieReleasePtr() + }) +} + // Service is a reference to the service for this API server. It must communicate // // on port 443. diff --git a/apis/apiserver/flowcontrol/v1beta1/flowschema.go b/apis/apiserver/flowcontrol/v1beta1/flowschema.go index 8077d00..50753ea 100644 --- a/apis/apiserver/flowcontrol/v1beta1/flowschema.go +++ b/apis/apiserver/flowcontrol/v1beta1/flowschema.go @@ -25,33 +25,11 @@ import ( type _ = flowcontrolv1beta1.FlowSchema // +die +// +die:field:name=PriorityLevelConfiguration,die=PriorityLevelConfigurationReferenceDie +// +die:field:name=DistinguisherMethod,die=FlowDistinguisherMethodDie,pointer=true +// +die:field:name=Rules,die=PolicyRulesWithSubjectsDie,listType=atomic type _ = flowcontrolv1beta1.FlowSchemaSpec -func (d *FlowSchemaSpecDie) PriorityLevelConfigurationDie(fn func(d *PriorityLevelConfigurationReferenceDie)) *FlowSchemaSpecDie { - return d.DieStamp(func(r *flowcontrolv1beta1.FlowSchemaSpec) { - d := PriorityLevelConfigurationReferenceBlank.DieImmutable(false).DieFeed(r.PriorityLevelConfiguration) - fn(d) - r.PriorityLevelConfiguration = d.DieRelease() - }) -} - -func (d *FlowSchemaSpecDie) DistinguisherMethodDie(fn func(d *FlowDistinguisherMethodDie)) *FlowSchemaSpecDie { - return d.DieStamp(func(r *flowcontrolv1beta1.FlowSchemaSpec) { - d := FlowDistinguisherMethodBlank.DieImmutable(false).DieFeedPtr(r.DistinguisherMethod) - fn(d) - r.DistinguisherMethod = d.DieReleasePtr() - }) -} - -func (d *FlowSchemaSpecDie) RulesDie(rules ...*PolicyRulesWithSubjectsDie) *FlowSchemaSpecDie { - return d.DieStamp(func(r *flowcontrolv1beta1.FlowSchemaSpec) { - r.Rules = make([]flowcontrolv1beta1.PolicyRulesWithSubjects, len(rules)) - for i := range rules { - r.Rules[i] = rules[i].DieRelease() - } - }) -} - // +die type _ = flowcontrolv1beta1.FlowSchemaStatus @@ -78,33 +56,14 @@ type _ = flowcontrolv1beta1.PriorityLevelConfigurationReference type _ = flowcontrolv1beta1.FlowDistinguisherMethod // +die +// +die:field:name=Subjects,die=SubjectDie,listType=atomic +// +die:field:name=ResourceRules,die=ResourcePolicyRuleDie,listType=atomic +// +die:field:name=NonResourceRules,die=NonResourcePolicyRuleDie,listType=atomic type _ = flowcontrolv1beta1.PolicyRulesWithSubjects -func (d *PolicyRulesWithSubjectsDie) SubjectsDie(subjects ...*SubjectDie) *PolicyRulesWithSubjectsDie { - return d.DieStamp(func(r *flowcontrolv1beta1.PolicyRulesWithSubjects) { - r.Subjects = make([]flowcontrolv1beta1.Subject, len(subjects)) - for i := range subjects { - r.Subjects[i] = subjects[i].DieRelease() - } - }) -} - -func (d *PolicyRulesWithSubjectsDie) ResourceRulesDie(rules ...*ResourcePolicyRuleDie) *PolicyRulesWithSubjectsDie { - return d.DieStamp(func(r *flowcontrolv1beta1.PolicyRulesWithSubjects) { - r.ResourceRules = make([]flowcontrolv1beta1.ResourcePolicyRule, len(rules)) - for i := range rules { - r.ResourceRules[i] = rules[i].DieRelease() - } - }) -} - +// deprecated: use NonResourceRulesDie func (d *PolicyRulesWithSubjectsDie) NonResourcePolicyRuleDie(rules ...*NonResourcePolicyRuleDie) *PolicyRulesWithSubjectsDie { - return d.DieStamp(func(r *flowcontrolv1beta1.PolicyRulesWithSubjects) { - r.NonResourceRules = make([]flowcontrolv1beta1.NonResourcePolicyRule, len(rules)) - for i := range rules { - r.NonResourceRules[i] = rules[i].DieRelease() - } - }) + return d.NonResourceRulesDie(rules...) } // +die diff --git a/apis/apiserver/flowcontrol/v1beta1/prioritylevelconfiguration.go b/apis/apiserver/flowcontrol/v1beta1/prioritylevelconfiguration.go index a1b93ee..be1f872 100644 --- a/apis/apiserver/flowcontrol/v1beta1/prioritylevelconfiguration.go +++ b/apis/apiserver/flowcontrol/v1beta1/prioritylevelconfiguration.go @@ -25,46 +25,18 @@ import ( type _ = flowcontrolv1beta1.PriorityLevelConfiguration // +die +// +die:field:name=Limited,die=LimitedPriorityLevelConfigurationDie,pointer=true +// +die:field:name=Exempt,die=ExemptPriorityLevelConfigurationDie,pointer=true type _ = flowcontrolv1beta1.PriorityLevelConfigurationSpec -func (d *PriorityLevelConfigurationSpecDie) LimitedDie(fn func(d *LimitedPriorityLevelConfigurationDie)) *PriorityLevelConfigurationSpecDie { - return d.DieStamp(func(r *flowcontrolv1beta1.PriorityLevelConfigurationSpec) { - d := LimitedPriorityLevelConfigurationBlank.DieImmutable(false).DieFeedPtr(r.Limited) - fn(d) - r.Limited = d.DieReleasePtr() - }) -} - -func (d *PriorityLevelConfigurationSpecDie) ExemptDie(fn func(d *ExemptPriorityLevelConfigurationDie)) *PriorityLevelConfigurationSpecDie { - return d.DieStamp(func(r *flowcontrolv1beta1.PriorityLevelConfigurationSpec) { - d := ExemptPriorityLevelConfigurationBlank.DieImmutable(false).DieFeedPtr(r.Exempt) - fn(d) - r.Exempt = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=LimitResponse,die=LimitResponseDie type _ = flowcontrolv1beta1.LimitedPriorityLevelConfiguration -func (d *LimitedPriorityLevelConfigurationDie) LimitResponseDie(fn func(d *LimitResponseDie)) *LimitedPriorityLevelConfigurationDie { - return d.DieStamp(func(r *flowcontrolv1beta1.LimitedPriorityLevelConfiguration) { - d := LimitResponseBlank.DieImmutable(false).DieFeed(r.LimitResponse) - fn(d) - r.LimitResponse = d.DieRelease() - }) -} - // +die +// +die:field:name=Queuing,die=QueuingConfigurationDie,pointer=true type _ = flowcontrolv1beta1.LimitResponse -func (d *LimitResponseDie) QueuingDie(fn func(d *QueuingConfigurationDie)) *LimitResponseDie { - return d.DieStamp(func(r *flowcontrolv1beta1.LimitResponse) { - d := QueuingConfigurationBlank.DieImmutable(false).DieFeedPtr(r.Queuing) - fn(d) - r.Queuing = d.DieReleasePtr() - }) -} - // +die type _ = flowcontrolv1beta1.ExemptPriorityLevelConfiguration diff --git a/apis/apiserver/flowcontrol/v1beta1/zz_generated.die.go b/apis/apiserver/flowcontrol/v1beta1/zz_generated.die.go index 5ba9fe7..369f3f3 100644 --- a/apis/apiserver/flowcontrol/v1beta1/zz_generated.die.go +++ b/apis/apiserver/flowcontrol/v1beta1/zz_generated.die.go @@ -626,6 +626,50 @@ func (d *FlowSchemaSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// PriorityLevelConfigurationDie mutates PriorityLevelConfiguration as a die. +// +// `priorityLevelConfiguration` should reference a PriorityLevelConfiguration in the cluster. If the reference cannot +// +// be resolved, the FlowSchema will be ignored and marked as invalid in its status. +// +// Required. +func (d *FlowSchemaSpecDie) PriorityLevelConfigurationDie(fn func(d *PriorityLevelConfigurationReferenceDie)) *FlowSchemaSpecDie { + return d.DieStamp(func(r *flowcontrolv1beta1.FlowSchemaSpec) { + d := PriorityLevelConfigurationReferenceBlank.DieImmutable(false).DieFeed(r.PriorityLevelConfiguration) + fn(d) + r.PriorityLevelConfiguration = d.DieRelease() + }) +} + +// DistinguisherMethodDie mutates DistinguisherMethod as a die. +// +// `distinguisherMethod` defines how to compute the flow distinguisher for requests that match this schema. +// +// `nil` specifies that the distinguisher is disabled and thus will always be the empty string. +func (d *FlowSchemaSpecDie) DistinguisherMethodDie(fn func(d *FlowDistinguisherMethodDie)) *FlowSchemaSpecDie { + return d.DieStamp(func(r *flowcontrolv1beta1.FlowSchemaSpec) { + d := FlowDistinguisherMethodBlank.DieImmutable(false).DieFeedPtr(r.DistinguisherMethod) + fn(d) + r.DistinguisherMethod = d.DieReleasePtr() + }) +} + +// RulesDie replaces Rules by collecting the released value from each die passed. +// +// `rules` describes which requests will match this flow schema. This FlowSchema matches a request if and only if +// +// at least one member of rules matches the request. +// +// if it is an empty slice, there will be no requests matching the FlowSchema. +func (d *FlowSchemaSpecDie) RulesDie(v ...*PolicyRulesWithSubjectsDie) *FlowSchemaSpecDie { + return d.DieStamp(func(r *flowcontrolv1beta1.FlowSchemaSpec) { + r.Rules = make([]flowcontrolv1beta1.PolicyRulesWithSubjects, len(v)) + for i := range v { + r.Rules[i] = v[i].DieRelease() + } + }) +} + // `priorityLevelConfiguration` should reference a PriorityLevelConfiguration in the cluster. If the reference cannot // // be resolved, the FlowSchema will be ignored and marked as invalid in its status. @@ -1609,6 +1653,54 @@ func (d *PolicyRulesWithSubjectsDie) DiePatch(patchType types.PatchType) ([]byte return patch.Create(d.seal, d.r, patchType) } +// SubjectsDie replaces Subjects by collecting the released value from each die passed. +// +// subjects is the list of normal user, serviceaccount, or group that this rule cares about. +// +// There must be at least one member in this slice. +// +// A slice that includes both the system:authenticated and system:unauthenticated user groups matches every request. +// +// Required. +func (d *PolicyRulesWithSubjectsDie) SubjectsDie(v ...*SubjectDie) *PolicyRulesWithSubjectsDie { + return d.DieStamp(func(r *flowcontrolv1beta1.PolicyRulesWithSubjects) { + r.Subjects = make([]flowcontrolv1beta1.Subject, len(v)) + for i := range v { + r.Subjects[i] = v[i].DieRelease() + } + }) +} + +// ResourceRulesDie replaces ResourceRules by collecting the released value from each die passed. +// +// `resourceRules` is a slice of ResourcePolicyRules that identify matching requests according to their verb and the +// +// target resource. +// +// At least one of `resourceRules` and `nonResourceRules` has to be non-empty. +func (d *PolicyRulesWithSubjectsDie) ResourceRulesDie(v ...*ResourcePolicyRuleDie) *PolicyRulesWithSubjectsDie { + return d.DieStamp(func(r *flowcontrolv1beta1.PolicyRulesWithSubjects) { + r.ResourceRules = make([]flowcontrolv1beta1.ResourcePolicyRule, len(v)) + for i := range v { + r.ResourceRules[i] = v[i].DieRelease() + } + }) +} + +// NonResourceRulesDie replaces NonResourceRules by collecting the released value from each die passed. +// +// `nonResourceRules` is a list of NonResourcePolicyRules that identify matching requests according to their verb +// +// and the target non-resource URL. +func (d *PolicyRulesWithSubjectsDie) NonResourceRulesDie(v ...*NonResourcePolicyRuleDie) *PolicyRulesWithSubjectsDie { + return d.DieStamp(func(r *flowcontrolv1beta1.PolicyRulesWithSubjects) { + r.NonResourceRules = make([]flowcontrolv1beta1.NonResourcePolicyRule, len(v)) + for i := range v { + r.NonResourceRules[i] = v[i].DieRelease() + } + }) +} + // subjects is the list of normal user, serviceaccount, or group that this rule cares about. // // There must be at least one member in this slice. @@ -3774,6 +3866,38 @@ func (d *PriorityLevelConfigurationSpecDie) DiePatch(patchType types.PatchType) return patch.Create(d.seal, d.r, patchType) } +// LimitedDie mutates Limited as a die. +// +// `limited` specifies how requests are handled for a Limited priority level. +// +// This field must be non-empty if and only if `type` is `"Limited"`. +func (d *PriorityLevelConfigurationSpecDie) LimitedDie(fn func(d *LimitedPriorityLevelConfigurationDie)) *PriorityLevelConfigurationSpecDie { + return d.DieStamp(func(r *flowcontrolv1beta1.PriorityLevelConfigurationSpec) { + d := LimitedPriorityLevelConfigurationBlank.DieImmutable(false).DieFeedPtr(r.Limited) + fn(d) + r.Limited = d.DieReleasePtr() + }) +} + +// ExemptDie mutates Exempt as a die. +// +// `exempt` specifies how requests are handled for an exempt priority level. +// +// This field MUST be empty if `type` is `"Limited"`. +// +// This field MAY be non-empty if `type` is `"Exempt"`. +// +// If empty and `type` is `"Exempt"` then the default values +// +// for `ExemptPriorityLevelConfiguration` apply. +func (d *PriorityLevelConfigurationSpecDie) ExemptDie(fn func(d *ExemptPriorityLevelConfigurationDie)) *PriorityLevelConfigurationSpecDie { + return d.DieStamp(func(r *flowcontrolv1beta1.PriorityLevelConfigurationSpec) { + d := ExemptPriorityLevelConfigurationBlank.DieImmutable(false).DieFeedPtr(r.Exempt) + fn(d) + r.Exempt = d.DieReleasePtr() + }) +} + // `type` indicates whether this priority level is subject to // // limitation on request execution. A value of `"Exempt"` means @@ -4049,6 +4173,17 @@ func (d *LimitedPriorityLevelConfigurationDie) DiePatch(patchType types.PatchTyp return patch.Create(d.seal, d.r, patchType) } +// LimitResponseDie mutates LimitResponse as a die. +// +// `limitResponse` indicates what to do with requests that can not be executed right now +func (d *LimitedPriorityLevelConfigurationDie) LimitResponseDie(fn func(d *LimitResponseDie)) *LimitedPriorityLevelConfigurationDie { + return d.DieStamp(func(r *flowcontrolv1beta1.LimitedPriorityLevelConfiguration) { + d := LimitResponseBlank.DieImmutable(false).DieFeed(r.LimitResponse) + fn(d) + r.LimitResponse = d.DieRelease() + }) +} + // `assuredConcurrencyShares` (ACS) configures the execution // // limit, which is a limit on the number of requests of this @@ -4363,6 +4498,19 @@ func (d *LimitResponseDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// QueuingDie mutates Queuing as a die. +// +// `queuing` holds the configuration parameters for queuing. +// +// This field may be non-empty only if `type` is `"Queue"`. +func (d *LimitResponseDie) QueuingDie(fn func(d *QueuingConfigurationDie)) *LimitResponseDie { + return d.DieStamp(func(r *flowcontrolv1beta1.LimitResponse) { + d := QueuingConfigurationBlank.DieImmutable(false).DieFeedPtr(r.Queuing) + fn(d) + r.Queuing = d.DieReleasePtr() + }) +} + // `type` is "Queue" or "Reject". // // "Queue" means that requests that can not be executed upon arrival diff --git a/apis/apps/v1/daemonset.go b/apis/apps/v1/daemonset.go index a067a93..c50ca7c 100644 --- a/apis/apps/v1/daemonset.go +++ b/apis/apps/v1/daemonset.go @@ -19,7 +19,6 @@ package v1 import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" - diecorev1 "reconciler.io/dies/apis/core/v1" diemetav1 "reconciler.io/dies/apis/meta/v1" ) @@ -27,32 +26,11 @@ import ( type _ = appsv1.DaemonSet // +die +// +die:field:name=Selector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=Template,package=_/core/v1,die=PodTemplateSpecDie +// +die:field:name=UpdateStrategy,die=DaemonSetUpdateStrategyDie type _ = appsv1.DaemonSetSpec -func (d *DaemonSetSpecDie) SelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *DaemonSetSpecDie { - return d.DieStamp(func(r *appsv1.DaemonSetSpec) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) - fn(d) - r.Selector = d.DieReleasePtr() - }) -} - -func (d *DaemonSetSpecDie) TemplateDie(fn func(d *diecorev1.PodTemplateSpecDie)) *DaemonSetSpecDie { - return d.DieStamp(func(r *appsv1.DaemonSetSpec) { - d := diecorev1.PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) - fn(d) - r.Template = d.DieRelease() - }) -} - -func (d *DaemonSetSpecDie) UpdateStrategyDie(fn func(d *DaemonSetUpdateStrategyDie)) *DaemonSetSpecDie { - return d.DieStamp(func(r *appsv1.DaemonSetSpec) { - d := DaemonSetUpdateStrategyBlank.DieImmutable(false).DieFeed(r.UpdateStrategy) - fn(d) - r.UpdateStrategy = d.DieRelease() - }) -} - // +die type _ = appsv1.DaemonSetUpdateStrategy diff --git a/apis/apps/v1/deployment.go b/apis/apps/v1/deployment.go index 51ff170..e02a390 100644 --- a/apis/apps/v1/deployment.go +++ b/apis/apps/v1/deployment.go @@ -19,7 +19,6 @@ package v1 import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" - diecorev1 "reconciler.io/dies/apis/core/v1" diemetav1 "reconciler.io/dies/apis/meta/v1" ) @@ -27,32 +26,11 @@ import ( type _ = appsv1.Deployment // +die +// +die:field:name=Selector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=Template,package=_/core/v1,die=PodTemplateSpecDie +// +die:field:name=Strategy,die=DeploymentStrategyDie type _ = appsv1.DeploymentSpec -func (d *DeploymentSpecDie) SelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *DeploymentSpecDie { - return d.DieStamp(func(r *appsv1.DeploymentSpec) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) - fn(d) - r.Selector = d.DieReleasePtr() - }) -} - -func (d *DeploymentSpecDie) TemplateDie(fn func(d *diecorev1.PodTemplateSpecDie)) *DeploymentSpecDie { - return d.DieStamp(func(r *appsv1.DeploymentSpec) { - d := diecorev1.PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) - fn(d) - r.Template = d.DieRelease() - }) -} - -func (d *DeploymentSpecDie) StrategyDie(fn func(d *DeploymentStrategyDie)) *DeploymentSpecDie { - return d.DieStamp(func(r *appsv1.DeploymentSpec) { - d := DeploymentStrategyBlank.DieImmutable(false).DieFeed(r.Strategy) - fn(d) - r.Strategy = d.DieRelease() - }) -} - // +die type _ = appsv1.DeploymentStrategy diff --git a/apis/apps/v1/replicaset.go b/apis/apps/v1/replicaset.go index e199f76..62c380e 100644 --- a/apis/apps/v1/replicaset.go +++ b/apis/apps/v1/replicaset.go @@ -19,7 +19,6 @@ package v1 import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" - diecorev1 "reconciler.io/dies/apis/core/v1" diemetav1 "reconciler.io/dies/apis/meta/v1" ) @@ -27,24 +26,10 @@ import ( type _ = appsv1.ReplicaSet // +die +// +die:field:name=Selector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=Template,package=_/core/v1,die=PodTemplateSpecDie type _ = appsv1.ReplicaSetSpec -func (d *ReplicaSetSpecDie) SelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *ReplicaSetSpecDie { - return d.DieStamp(func(r *appsv1.ReplicaSetSpec) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) - fn(d) - r.Selector = d.DieReleasePtr() - }) -} - -func (d *ReplicaSetSpecDie) TemplateDie(fn func(d *diecorev1.PodTemplateSpecDie)) *ReplicaSetSpecDie { - return d.DieStamp(func(r *appsv1.ReplicaSetSpec) { - d := diecorev1.PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) - fn(d) - r.Template = d.DieRelease() - }) -} - // +die type _ = appsv1.ReplicaSetStatus diff --git a/apis/apps/v1/statefulset.go b/apis/apps/v1/statefulset.go index c35aa1d..5d420f3 100644 --- a/apis/apps/v1/statefulset.go +++ b/apis/apps/v1/statefulset.go @@ -19,7 +19,6 @@ package v1 import ( appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" - diecorev1 "reconciler.io/dies/apis/core/v1" diemetav1 "reconciler.io/dies/apis/meta/v1" ) @@ -27,57 +26,14 @@ import ( type _ = appsv1.StatefulSet // +die +// +die:field:name=Selector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=Template,package=_/core/v1,die=PodTemplateSpecDie +// +die:field:name=UpdateStrategy,die=StatefulSetUpdateStrategyDie +// +die:field:name=PersistentVolumeClaimRetentionPolicy,die=StatefulSetPersistentVolumeClaimRetentionPolicyDie,pointer=true +// +die:field:name=Ordinals,die=StatefulSetOrdinalsDie,pointer=true +// +die:field:name=VolumeClaimTemplates,package=_/core/v1,die=PersistentVolumeClaimDie,listType=atomic type _ = appsv1.StatefulSetSpec -func (d *StatefulSetSpecDie) SelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *StatefulSetSpecDie { - return d.DieStamp(func(r *appsv1.StatefulSetSpec) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) - fn(d) - r.Selector = d.DieReleasePtr() - }) -} - -func (d *StatefulSetSpecDie) TemplateDie(fn func(d *diecorev1.PodTemplateSpecDie)) *StatefulSetSpecDie { - return d.DieStamp(func(r *appsv1.StatefulSetSpec) { - d := diecorev1.PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) - fn(d) - r.Template = d.DieRelease() - }) -} - -func (d *StatefulSetSpecDie) VolumeClaimTemplatesDie(volumeClaimTemplates ...*diecorev1.PersistentVolumeClaimDie) *StatefulSetSpecDie { - return d.DieStamp(func(r *appsv1.StatefulSetSpec) { - r.VolumeClaimTemplates = make([]corev1.PersistentVolumeClaim, len(volumeClaimTemplates)) - for i, v := range volumeClaimTemplates { - r.VolumeClaimTemplates[i] = v.DieRelease() - } - }) -} - -func (d *StatefulSetSpecDie) UpdateStrategyDie(fn func(d *StatefulSetUpdateStrategyDie)) *StatefulSetSpecDie { - return d.DieStamp(func(r *appsv1.StatefulSetSpec) { - d := StatefulSetUpdateStrategyBlank.DieImmutable(false).DieFeed(r.UpdateStrategy) - fn(d) - r.UpdateStrategy = d.DieRelease() - }) -} - -func (d *StatefulSetSpecDie) PersistentVolumeClaimRetentionPolicyDie(fn func(d *StatefulSetPersistentVolumeClaimRetentionPolicyDie)) *StatefulSetSpecDie { - return d.DieStamp(func(r *appsv1.StatefulSetSpec) { - d := StatefulSetPersistentVolumeClaimRetentionPolicyBlank.DieImmutable(false).DieFeedPtr(r.PersistentVolumeClaimRetentionPolicy) - fn(d) - r.PersistentVolumeClaimRetentionPolicy = d.DieReleasePtr() - }) -} - -func (d *StatefulSetSpecDie) OrdinalsDie(fn func(d *StatefulSetOrdinalsDie)) *StatefulSetSpecDie { - return d.DieStamp(func(r *appsv1.StatefulSetSpec) { - d := StatefulSetOrdinalsBlank.DieImmutable(false).DieFeedPtr(r.Ordinals) - fn(d) - r.Ordinals = d.DieReleasePtr() - }) -} - // +die type _ = appsv1.StatefulSetUpdateStrategy diff --git a/apis/apps/v1/zz_generated.die.go b/apis/apps/v1/zz_generated.die.go index 4dc52cc..3055598 100644 --- a/apis/apps/v1/zz_generated.die.go +++ b/apis/apps/v1/zz_generated.die.go @@ -25,7 +25,7 @@ import ( fmtx "fmt" cmp "github.com/google/go-cmp/cmp" appsv1 "k8s.io/api/apps/v1" - corev1 "k8s.io/api/core/v1" + apicorev1 "k8s.io/api/core/v1" apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" unstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" runtime "k8s.io/apimachinery/pkg/runtime" @@ -35,6 +35,7 @@ import ( json "k8s.io/apimachinery/pkg/util/json" jsonpath "k8s.io/client-go/util/jsonpath" osx "os" + corev1 "reconciler.io/dies/apis/core/v1" metav1 "reconciler.io/dies/apis/meta/v1" patch "reconciler.io/dies/patch" reflectx "reflect" @@ -971,6 +972,55 @@ func (d *DaemonSetSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// SelectorDie mutates Selector as a die. +// +// A label query over pods that are managed by the daemon set. +// +// Must match in order to be controlled. +// +// It must match the pod template's labels. +// +// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors +func (d *DaemonSetSpecDie) SelectorDie(fn func(d *metav1.LabelSelectorDie)) *DaemonSetSpecDie { + return d.DieStamp(func(r *appsv1.DaemonSetSpec) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) + fn(d) + r.Selector = d.DieReleasePtr() + }) +} + +// TemplateDie mutates Template as a die. +// +// An object that describes the pod that will be created. +// +// # The DaemonSet will create exactly one copy of this pod on every node +// +// that matches the template's node selector (or on every node if no node +// +// selector is specified). +// +// The only allowed template.spec.restartPolicy value is "Always". +// +// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template +func (d *DaemonSetSpecDie) TemplateDie(fn func(d *corev1.PodTemplateSpecDie)) *DaemonSetSpecDie { + return d.DieStamp(func(r *appsv1.DaemonSetSpec) { + d := corev1.PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) + fn(d) + r.Template = d.DieRelease() + }) +} + +// UpdateStrategyDie mutates UpdateStrategy as a die. +// +// An update strategy to replace existing DaemonSet pods with new pods. +func (d *DaemonSetSpecDie) UpdateStrategyDie(fn func(d *DaemonSetUpdateStrategyDie)) *DaemonSetSpecDie { + return d.DieStamp(func(r *appsv1.DaemonSetSpec) { + d := DaemonSetUpdateStrategyBlank.DieImmutable(false).DieFeed(r.UpdateStrategy) + fn(d) + r.UpdateStrategy = d.DieRelease() + }) +} + // A label query over pods that are managed by the daemon set. // // Must match in order to be controlled. @@ -995,7 +1045,7 @@ func (d *DaemonSetSpecDie) Selector(v *apismetav1.LabelSelector) *DaemonSetSpecD // The only allowed template.spec.restartPolicy value is "Always". // // More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template -func (d *DaemonSetSpecDie) Template(v corev1.PodTemplateSpec) *DaemonSetSpecDie { +func (d *DaemonSetSpecDie) Template(v apicorev1.PodTemplateSpec) *DaemonSetSpecDie { return d.DieStamp(func(r *appsv1.DaemonSetSpec) { r.Template = v }) @@ -2651,6 +2701,45 @@ func (d *DeploymentSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// SelectorDie mutates Selector as a die. +// +// Label selector for pods. Existing ReplicaSets whose pods are +// +// selected by this will be the ones affected by this deployment. +// +// It must match the pod template's labels. +func (d *DeploymentSpecDie) SelectorDie(fn func(d *metav1.LabelSelectorDie)) *DeploymentSpecDie { + return d.DieStamp(func(r *appsv1.DeploymentSpec) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) + fn(d) + r.Selector = d.DieReleasePtr() + }) +} + +// TemplateDie mutates Template as a die. +// +// Template describes the pods that will be created. +// +// The only allowed template.spec.restartPolicy value is "Always". +func (d *DeploymentSpecDie) TemplateDie(fn func(d *corev1.PodTemplateSpecDie)) *DeploymentSpecDie { + return d.DieStamp(func(r *appsv1.DeploymentSpec) { + d := corev1.PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) + fn(d) + r.Template = d.DieRelease() + }) +} + +// StrategyDie mutates Strategy as a die. +// +// The deployment strategy to use to replace existing pods with new ones. +func (d *DeploymentSpecDie) StrategyDie(fn func(d *DeploymentStrategyDie)) *DeploymentSpecDie { + return d.DieStamp(func(r *appsv1.DeploymentSpec) { + d := DeploymentStrategyBlank.DieImmutable(false).DieFeed(r.Strategy) + fn(d) + r.Strategy = d.DieRelease() + }) +} + // Number of desired pods. This is a pointer to distinguish between explicit // // zero and not specified. Defaults to 1. @@ -2674,7 +2763,7 @@ func (d *DeploymentSpecDie) Selector(v *apismetav1.LabelSelector) *DeploymentSpe // Template describes the pods that will be created. // // The only allowed template.spec.restartPolicy value is "Always". -func (d *DeploymentSpecDie) Template(v corev1.PodTemplateSpec) *DeploymentSpecDie { +func (d *DeploymentSpecDie) Template(v apicorev1.PodTemplateSpec) *DeploymentSpecDie { return d.DieStamp(func(r *appsv1.DeploymentSpec) { r.Template = v }) @@ -4262,6 +4351,38 @@ func (d *ReplicaSetSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// SelectorDie mutates Selector as a die. +// +// Selector is a label query over pods that should match the replica count. +// +// Label keys and values that must match in order to be controlled by this replica set. +// +// It must match the pod template's labels. +// +// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors +func (d *ReplicaSetSpecDie) SelectorDie(fn func(d *metav1.LabelSelectorDie)) *ReplicaSetSpecDie { + return d.DieStamp(func(r *appsv1.ReplicaSetSpec) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) + fn(d) + r.Selector = d.DieReleasePtr() + }) +} + +// TemplateDie mutates Template as a die. +// +// # Template is the object that describes the pod that will be created if +// +// insufficient replicas are detected. +// +// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template +func (d *ReplicaSetSpecDie) TemplateDie(fn func(d *corev1.PodTemplateSpecDie)) *ReplicaSetSpecDie { + return d.DieStamp(func(r *appsv1.ReplicaSetSpec) { + d := corev1.PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) + fn(d) + r.Template = d.DieRelease() + }) +} + // Replicas is the number of desired replicas. // // This is a pointer to distinguish between explicit zero and unspecified. @@ -4304,7 +4425,7 @@ func (d *ReplicaSetSpecDie) Selector(v *apismetav1.LabelSelector) *ReplicaSetSpe // insufficient replicas are detected. // // More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template -func (d *ReplicaSetSpecDie) Template(v corev1.PodTemplateSpec) *ReplicaSetSpecDie { +func (d *ReplicaSetSpecDie) Template(v apicorev1.PodTemplateSpec) *ReplicaSetSpecDie { return d.DieStamp(func(r *appsv1.ReplicaSetSpec) { r.Template = v }) @@ -5167,6 +5288,125 @@ func (d *StatefulSetSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// SelectorDie mutates Selector as a die. +// +// selector is a label query over pods that should match the replica count. +// +// It must match the pod template's labels. +// +// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors +func (d *StatefulSetSpecDie) SelectorDie(fn func(d *metav1.LabelSelectorDie)) *StatefulSetSpecDie { + return d.DieStamp(func(r *appsv1.StatefulSetSpec) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) + fn(d) + r.Selector = d.DieReleasePtr() + }) +} + +// TemplateDie mutates Template as a die. +// +// template is the object that describes the pod that will be created if +// +// insufficient replicas are detected. Each pod stamped out by the StatefulSet +// +// will fulfill this Template, but have a unique identity from the rest +// +// of the StatefulSet. Each pod will be named with the format +// +// -. For example, a pod in a StatefulSet named +// +// "web" with index number "3" would be named "web-3". +// +// The only allowed template.spec.restartPolicy value is "Always". +func (d *StatefulSetSpecDie) TemplateDie(fn func(d *corev1.PodTemplateSpecDie)) *StatefulSetSpecDie { + return d.DieStamp(func(r *appsv1.StatefulSetSpec) { + d := corev1.PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) + fn(d) + r.Template = d.DieRelease() + }) +} + +// UpdateStrategyDie mutates UpdateStrategy as a die. +// +// updateStrategy indicates the StatefulSetUpdateStrategy that will be +// +// employed to update Pods in the StatefulSet when a revision is made to +// +// Template. +func (d *StatefulSetSpecDie) UpdateStrategyDie(fn func(d *StatefulSetUpdateStrategyDie)) *StatefulSetSpecDie { + return d.DieStamp(func(r *appsv1.StatefulSetSpec) { + d := StatefulSetUpdateStrategyBlank.DieImmutable(false).DieFeed(r.UpdateStrategy) + fn(d) + r.UpdateStrategy = d.DieRelease() + }) +} + +// PersistentVolumeClaimRetentionPolicyDie mutates PersistentVolumeClaimRetentionPolicy as a die. +// +// persistentVolumeClaimRetentionPolicy describes the lifecycle of persistent +// +// volume claims created from volumeClaimTemplates. By default, all persistent +// +// volume claims are created as needed and retained until manually deleted. This +// +// policy allows the lifecycle to be altered, for example by deleting persistent +// +// volume claims when their stateful set is deleted, or when their pod is scaled +// +// down. This requires the StatefulSetAutoDeletePVC feature gate to be enabled, +// +// which is alpha. +optional +func (d *StatefulSetSpecDie) PersistentVolumeClaimRetentionPolicyDie(fn func(d *StatefulSetPersistentVolumeClaimRetentionPolicyDie)) *StatefulSetSpecDie { + return d.DieStamp(func(r *appsv1.StatefulSetSpec) { + d := StatefulSetPersistentVolumeClaimRetentionPolicyBlank.DieImmutable(false).DieFeedPtr(r.PersistentVolumeClaimRetentionPolicy) + fn(d) + r.PersistentVolumeClaimRetentionPolicy = d.DieReleasePtr() + }) +} + +// OrdinalsDie mutates Ordinals as a die. +// +// ordinals controls the numbering of replica indices in a StatefulSet. The +// +// default ordinals behavior assigns a "0" index to the first replica and +// +// increments the index by one for each additional replica requested. Using +// +// the ordinals field requires the StatefulSetStartOrdinal feature gate to be +// +// enabled, which is beta. +func (d *StatefulSetSpecDie) OrdinalsDie(fn func(d *StatefulSetOrdinalsDie)) *StatefulSetSpecDie { + return d.DieStamp(func(r *appsv1.StatefulSetSpec) { + d := StatefulSetOrdinalsBlank.DieImmutable(false).DieFeedPtr(r.Ordinals) + fn(d) + r.Ordinals = d.DieReleasePtr() + }) +} + +// VolumeClaimTemplatesDie replaces VolumeClaimTemplates by collecting the released value from each die passed. +// +// volumeClaimTemplates is a list of claims that pods are allowed to reference. +// +// # The StatefulSet controller is responsible for mapping network identities to +// +// claims in a way that maintains the identity of a pod. Every claim in +// +// this list must have at least one matching (by name) volumeMount in one +// +// container in the template. A claim in this list takes precedence over +// +// any volumes in the template, with the same name. +// +// TODO: Define the behavior if a claim already exists with the same name. +func (d *StatefulSetSpecDie) VolumeClaimTemplatesDie(v ...*corev1.PersistentVolumeClaimDie) *StatefulSetSpecDie { + return d.DieStamp(func(r *appsv1.StatefulSetSpec) { + r.VolumeClaimTemplates = make([]apicorev1.PersistentVolumeClaim, len(v)) + for i := range v { + r.VolumeClaimTemplates[i] = v[i].DieRelease() + } + }) +} + // replicas is the desired number of replicas of the given Template. // // # These are replicas in the sense that they are instantiations of the @@ -5206,7 +5446,7 @@ func (d *StatefulSetSpecDie) Selector(v *apismetav1.LabelSelector) *StatefulSetS // "web" with index number "3" would be named "web-3". // // The only allowed template.spec.restartPolicy value is "Always". -func (d *StatefulSetSpecDie) Template(v corev1.PodTemplateSpec) *StatefulSetSpecDie { +func (d *StatefulSetSpecDie) Template(v apicorev1.PodTemplateSpec) *StatefulSetSpecDie { return d.DieStamp(func(r *appsv1.StatefulSetSpec) { r.Template = v }) @@ -5225,7 +5465,7 @@ func (d *StatefulSetSpecDie) Template(v corev1.PodTemplateSpec) *StatefulSetSpec // any volumes in the template, with the same name. // // TODO: Define the behavior if a claim already exists with the same name. -func (d *StatefulSetSpecDie) VolumeClaimTemplates(v ...corev1.PersistentVolumeClaim) *StatefulSetSpecDie { +func (d *StatefulSetSpecDie) VolumeClaimTemplates(v ...apicorev1.PersistentVolumeClaim) *StatefulSetSpecDie { return d.DieStamp(func(r *appsv1.StatefulSetSpec) { r.VolumeClaimTemplates = v }) diff --git a/apis/authentication/v1/selfsubjectreview.go b/apis/authentication/v1/selfsubjectreview.go index 2923d8e..5b48b6d 100644 --- a/apis/authentication/v1/selfsubjectreview.go +++ b/apis/authentication/v1/selfsubjectreview.go @@ -24,16 +24,9 @@ import ( type _ = authenticationv1.SelfSubjectReview // +die +// +die:field:name=UserInfo,die=UserInfoDie type _ = authenticationv1.SelfSubjectReviewStatus -func (d *SelfSubjectReviewStatusDie) UserInfoDie(fn func(d *UserInfoDie)) *SelfSubjectReviewStatusDie { - return d.DieStamp(func(r *authenticationv1.SelfSubjectReviewStatus) { - d := UserInfoBlank.DieImmutable(false).DieFeed(r.UserInfo) - fn(d) - r.UserInfo = d.DieRelease() - }) -} - // +die:ignore={Extra} type _ = authenticationv1.UserInfo diff --git a/apis/authentication/v1/tokenreview.go b/apis/authentication/v1/tokenreview.go index f4b0d6e..99a76db 100644 --- a/apis/authentication/v1/tokenreview.go +++ b/apis/authentication/v1/tokenreview.go @@ -24,16 +24,9 @@ import ( type _ = authenticationv1.TokenReview // +die +// +die:field:name=BoundObjectRef,die=BoundObjectReferenceDie,pointer=true type _ = authenticationv1.TokenRequestSpec -func (d *TokenRequestSpecDie) BoundObjectRefDie(fn func(d *BoundObjectReferenceDie)) *TokenRequestSpecDie { - return d.DieStamp(func(r *authenticationv1.TokenRequestSpec) { - d := BoundObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.BoundObjectRef) - fn(d) - r.BoundObjectRef = d.DieReleasePtr() - }) -} - // +die type _ = authenticationv1.BoundObjectReference diff --git a/apis/authentication/v1/zz_generated.die.go b/apis/authentication/v1/zz_generated.die.go index 017a81d..d5f133a 100644 --- a/apis/authentication/v1/zz_generated.die.go +++ b/apis/authentication/v1/zz_generated.die.go @@ -606,6 +606,17 @@ func (d *SelfSubjectReviewStatusDie) DiePatch(patchType types.PatchType) ([]byte return patch.Create(d.seal, d.r, patchType) } +// UserInfoDie mutates UserInfo as a die. +// +// User attributes of the user making this request. +func (d *SelfSubjectReviewStatusDie) UserInfoDie(fn func(d *UserInfoDie)) *SelfSubjectReviewStatusDie { + return d.DieStamp(func(r *authenticationv1.SelfSubjectReviewStatus) { + d := UserInfoBlank.DieImmutable(false).DieFeed(r.UserInfo) + fn(d) + r.UserInfo = d.DieRelease() + }) +} + // User attributes of the user making this request. func (d *SelfSubjectReviewStatusDie) UserInfo(v authenticationv1.UserInfo) *SelfSubjectReviewStatusDie { return d.DieStamp(func(r *authenticationv1.SelfSubjectReviewStatus) { @@ -1431,6 +1442,25 @@ func (d *TokenRequestSpecDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// BoundObjectRefDie mutates BoundObjectRef as a die. +// +// BoundObjectRef is a reference to an object that the token will be bound to. +// +// The token will only be valid for as long as the bound object exists. +// +// NOTE: The API server's TokenReview endpoint will validate the +// +// BoundObjectRef, but other audiences may not. Keep ExpirationSeconds +// +// small if you want prompt revocation. +func (d *TokenRequestSpecDie) BoundObjectRefDie(fn func(d *BoundObjectReferenceDie)) *TokenRequestSpecDie { + return d.DieStamp(func(r *authenticationv1.TokenRequestSpec) { + d := BoundObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.BoundObjectRef) + fn(d) + r.BoundObjectRef = d.DieReleasePtr() + }) +} + // Audiences are the intendend audiences of the token. A recipient of a // // token must identify themself with an identifier in the list of diff --git a/apis/authorization/rbac/v1/clusterrole.go b/apis/authorization/rbac/v1/clusterrole.go index cde3f71..3ec9a14 100644 --- a/apis/authorization/rbac/v1/clusterrole.go +++ b/apis/authorization/rbac/v1/clusterrole.go @@ -18,44 +18,19 @@ package v1 import ( rbacv1 "k8s.io/api/rbac/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die:object=true,apiVersion=rbac.authorization.k8s.io/v1,kind=ClusterRole +// +die:field:name=AggregationRule,die=AggregationRuleDie,pointer=true +// +die:field:name=Rules,die=PolicyRuleDie,listType=atomic type _ = rbacv1.ClusterRole -func (d *ClusterRoleDie) RulesDie(rules ...*PolicyRuleDie) *ClusterRoleDie { - return d.DieStamp(func(r *rbacv1.ClusterRole) { - r.Rules = make([]rbacv1.PolicyRule, len(rules)) - for i := range rules { - r.Rules[i] = rules[i].DieRelease() - } - }) -} - func (d *ClusterRoleDie) AddRuleDie(rule *PolicyRuleDie) *ClusterRoleDie { return d.DieStamp(func(r *rbacv1.ClusterRole) { r.Rules = append(r.Rules, rule.DieRelease()) }) } -func (d *ClusterRoleDie) AggregationRuleDie(fn func(d *AggregationRuleDie)) *ClusterRoleDie { - return d.DieStamp(func(r *rbacv1.ClusterRole) { - d := AggregationRuleBlank.DieImmutable(false).DieFeedPtr(r.AggregationRule) - fn(d) - r.AggregationRule = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=ClusterRoleSelectors,package=_/meta/v1,die=LabelSelectorDie,listType=atomic type _ = rbacv1.AggregationRule - -func (d *AggregationRuleDie) ClusterRoleSelectorsDie(selectors ...*diemetav1.LabelSelectorDie) *AggregationRuleDie { - return d.DieStamp(func(r *rbacv1.AggregationRule) { - r.ClusterRoleSelectors = make([]metav1.LabelSelector, len(selectors)) - for i := range selectors { - r.ClusterRoleSelectors[i] = selectors[i].DieRelease() - } - }) -} diff --git a/apis/authorization/rbac/v1/clusterrolebinding.go b/apis/authorization/rbac/v1/clusterrolebinding.go index 33f78e0..89103a1 100644 --- a/apis/authorization/rbac/v1/clusterrolebinding.go +++ b/apis/authorization/rbac/v1/clusterrolebinding.go @@ -21,21 +21,6 @@ import ( ) // +die:object=true,apiVersion=rbac.authorization.k8s.io/v1,kind=ClusterRoleBinding +// +die:field:name=RoleRef,die=RoleRefDie +// +die:field:name=Subjects,die=SubjectDie,listType=atomic type _ = rbacv1.ClusterRoleBinding - -func (d *ClusterRoleBindingDie) SubjectsDie(subjects ...*SubjectDie) *ClusterRoleBindingDie { - return d.DieStamp(func(r *rbacv1.ClusterRoleBinding) { - r.Subjects = make([]rbacv1.Subject, len(subjects)) - for i := range subjects { - r.Subjects[i] = subjects[i].DieRelease() - } - }) -} - -func (d *ClusterRoleBindingDie) RoleRefDie(fn func(d *RoleRefDie)) *ClusterRoleBindingDie { - return d.DieStamp(func(r *rbacv1.ClusterRoleBinding) { - d := RoleRefBlank.DieImmutable(false).DieFeed(r.RoleRef) - fn(d) - r.RoleRef = d.DieRelease() - }) -} diff --git a/apis/authorization/rbac/v1/role.go b/apis/authorization/rbac/v1/role.go index e368e96..c73c02c 100644 --- a/apis/authorization/rbac/v1/role.go +++ b/apis/authorization/rbac/v1/role.go @@ -21,17 +21,9 @@ import ( ) // +die:object=true,apiVersion=rbac.authorization.k8s.io/v1,kind=Role +// +die:field:name=Rules,die=PolicyRuleDie,listType=atomic type _ = rbacv1.Role -func (d *RoleDie) RulesDie(rules ...*PolicyRuleDie) *RoleDie { - return d.DieStamp(func(r *rbacv1.Role) { - r.Rules = make([]rbacv1.PolicyRule, len(rules)) - for i := range rules { - r.Rules[i] = rules[i].DieRelease() - } - }) -} - func (d *RoleDie) AddRuleDie(rule *PolicyRuleDie) *RoleDie { return d.DieStamp(func(r *rbacv1.Role) { r.Rules = append(r.Rules, rule.DieRelease()) diff --git a/apis/authorization/rbac/v1/rolebinding.go b/apis/authorization/rbac/v1/rolebinding.go index 5a12176..b0e3b70 100644 --- a/apis/authorization/rbac/v1/rolebinding.go +++ b/apis/authorization/rbac/v1/rolebinding.go @@ -21,25 +21,10 @@ import ( ) // +die:object=true,apiVersion=rbac.authorization.k8s.io/v1,kind=RoleBinding +// +die:field:name=RoleRef,die=RoleRefDie +// +die:field:name=Subjects,die=SubjectDie,listType=atomic type _ = rbacv1.RoleBinding -func (d *RoleBindingDie) SubjectsDie(subjects ...*SubjectDie) *RoleBindingDie { - return d.DieStamp(func(r *rbacv1.RoleBinding) { - r.Subjects = make([]rbacv1.Subject, len(subjects)) - for i := range subjects { - r.Subjects[i] = subjects[i].DieRelease() - } - }) -} - -func (d *RoleBindingDie) RoleRefDie(fn func(d *RoleRefDie)) *RoleBindingDie { - return d.DieStamp(func(r *rbacv1.RoleBinding) { - d := RoleRefBlank.DieImmutable(false).DieFeed(r.RoleRef) - fn(d) - r.RoleRef = d.DieRelease() - }) -} - // +die type _ = rbacv1.Subject diff --git a/apis/authorization/rbac/v1/zz_generated.die.go b/apis/authorization/rbac/v1/zz_generated.die.go index 0517b96..e8a5ece 100644 --- a/apis/authorization/rbac/v1/zz_generated.die.go +++ b/apis/authorization/rbac/v1/zz_generated.die.go @@ -362,6 +362,33 @@ func (d *ClusterRoleDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *ClusterR }) } +// AggregationRuleDie mutates AggregationRule as a die. +// +// AggregationRule is an optional field that describes how to build the Rules for this ClusterRole. +// +// # If AggregationRule is set, then the Rules are controller managed and direct changes to Rules will be +// +// stomped by the controller. +func (d *ClusterRoleDie) AggregationRuleDie(fn func(d *AggregationRuleDie)) *ClusterRoleDie { + return d.DieStamp(func(r *rbacv1.ClusterRole) { + d := AggregationRuleBlank.DieImmutable(false).DieFeedPtr(r.AggregationRule) + fn(d) + r.AggregationRule = d.DieReleasePtr() + }) +} + +// RulesDie replaces Rules by collecting the released value from each die passed. +// +// Rules holds all the PolicyRules for this ClusterRole +func (d *ClusterRoleDie) RulesDie(v ...*PolicyRuleDie) *ClusterRoleDie { + return d.DieStamp(func(r *rbacv1.ClusterRole) { + r.Rules = make([]rbacv1.PolicyRule, len(v)) + for i := range v { + r.Rules[i] = v[i].DieRelease() + } + }) +} + // Rules holds all the PolicyRules for this ClusterRole func (d *ClusterRoleDie) Rules(v ...rbacv1.PolicyRule) *ClusterRoleDie { return d.DieStamp(func(r *rbacv1.ClusterRole) { @@ -608,6 +635,20 @@ func (d *AggregationRuleDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// ClusterRoleSelectorsDie replaces ClusterRoleSelectors by collecting the released value from each die passed. +// +// ClusterRoleSelectors holds a list of selectors which will be used to find ClusterRoles and create the rules. +// +// If any of the selectors match, then the ClusterRole's permissions will be added +func (d *AggregationRuleDie) ClusterRoleSelectorsDie(v ...*metav1.LabelSelectorDie) *AggregationRuleDie { + return d.DieStamp(func(r *rbacv1.AggregationRule) { + r.ClusterRoleSelectors = make([]apismetav1.LabelSelector, len(v)) + for i := range v { + r.ClusterRoleSelectors[i] = v[i].DieRelease() + } + }) +} + // ClusterRoleSelectors holds a list of selectors which will be used to find ClusterRoles and create the rules. // // If any of the selectors match, then the ClusterRole's permissions will be added @@ -940,6 +981,33 @@ func (d *ClusterRoleBindingDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *C }) } +// RoleRefDie mutates RoleRef as a die. +// +// RoleRef can only reference a ClusterRole in the global namespace. +// +// If the RoleRef cannot be resolved, the Authorizer must return an error. +// +// This field is immutable. +func (d *ClusterRoleBindingDie) RoleRefDie(fn func(d *RoleRefDie)) *ClusterRoleBindingDie { + return d.DieStamp(func(r *rbacv1.ClusterRoleBinding) { + d := RoleRefBlank.DieImmutable(false).DieFeed(r.RoleRef) + fn(d) + r.RoleRef = d.DieRelease() + }) +} + +// SubjectsDie replaces Subjects by collecting the released value from each die passed. +// +// Subjects holds references to the objects the role applies to. +func (d *ClusterRoleBindingDie) SubjectsDie(v ...*SubjectDie) *ClusterRoleBindingDie { + return d.DieStamp(func(r *rbacv1.ClusterRoleBinding) { + r.Subjects = make([]rbacv1.Subject, len(v)) + for i := range v { + r.Subjects[i] = v[i].DieRelease() + } + }) +} + // Subjects holds references to the objects the role applies to. func (d *ClusterRoleBindingDie) Subjects(v ...rbacv1.Subject) *ClusterRoleBindingDie { return d.DieStamp(func(r *rbacv1.ClusterRoleBinding) { @@ -1281,6 +1349,18 @@ func (d *RoleDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *RoleDie { }) } +// RulesDie replaces Rules by collecting the released value from each die passed. +// +// Rules holds all the PolicyRules for this Role +func (d *RoleDie) RulesDie(v ...*PolicyRuleDie) *RoleDie { + return d.DieStamp(func(r *rbacv1.Role) { + r.Rules = make([]rbacv1.PolicyRule, len(v)) + for i := range v { + r.Rules[i] = v[i].DieRelease() + } + }) +} + // Rules holds all the PolicyRules for this Role func (d *RoleDie) Rules(v ...rbacv1.PolicyRule) *RoleDie { return d.DieStamp(func(r *rbacv1.Role) { @@ -1880,6 +1960,33 @@ func (d *RoleBindingDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *RoleBind }) } +// RoleRefDie mutates RoleRef as a die. +// +// RoleRef can reference a Role in the current namespace or a ClusterRole in the global namespace. +// +// If the RoleRef cannot be resolved, the Authorizer must return an error. +// +// This field is immutable. +func (d *RoleBindingDie) RoleRefDie(fn func(d *RoleRefDie)) *RoleBindingDie { + return d.DieStamp(func(r *rbacv1.RoleBinding) { + d := RoleRefBlank.DieImmutable(false).DieFeed(r.RoleRef) + fn(d) + r.RoleRef = d.DieRelease() + }) +} + +// SubjectsDie replaces Subjects by collecting the released value from each die passed. +// +// Subjects holds references to the objects the role applies to. +func (d *RoleBindingDie) SubjectsDie(v ...*SubjectDie) *RoleBindingDie { + return d.DieStamp(func(r *rbacv1.RoleBinding) { + r.Subjects = make([]rbacv1.Subject, len(v)) + for i := range v { + r.Subjects[i] = v[i].DieRelease() + } + }) +} + // Subjects holds references to the objects the role applies to. func (d *RoleBindingDie) Subjects(v ...rbacv1.Subject) *RoleBindingDie { return d.DieStamp(func(r *rbacv1.RoleBinding) { diff --git a/apis/authorization/v1/selfsubjectaccessreview.go b/apis/authorization/v1/selfsubjectaccessreview.go index c8fc20f..3644e79 100644 --- a/apis/authorization/v1/selfsubjectaccessreview.go +++ b/apis/authorization/v1/selfsubjectaccessreview.go @@ -24,20 +24,6 @@ import ( type _ = authorizationv1.SelfSubjectAccessReview // +die +// +die:field:name=ResourceAttributes,die=ResourceAttributesDie,pointer=true +// +die:field:name=NonResourceAttributes,die=NonResourceAttributesDie,pointer=true type _ = authorizationv1.SelfSubjectAccessReviewSpec - -func (d *SelfSubjectAccessReviewSpecDie) ResourceAttributesDie(fn func(d *ResourceAttributesDie)) *SelfSubjectAccessReviewSpecDie { - return d.DieStamp(func(r *authorizationv1.SelfSubjectAccessReviewSpec) { - d := ResourceAttributesBlank.DieImmutable(false).DieFeedPtr(r.ResourceAttributes) - fn(d) - r.ResourceAttributes = d.DieReleasePtr() - }) -} - -func (d *SelfSubjectAccessReviewSpecDie) NonResourceAttributesDie(fn func(d *NonResourceAttributesDie)) *SelfSubjectAccessReviewSpecDie { - return d.DieStamp(func(r *authorizationv1.SelfSubjectAccessReviewSpec) { - d := NonResourceAttributesBlank.DieImmutable(false).DieFeedPtr(r.NonResourceAttributes) - fn(d) - r.NonResourceAttributes = d.DieReleasePtr() - }) -} diff --git a/apis/authorization/v1/selfsubjectrulesreview.go b/apis/authorization/v1/selfsubjectrulesreview.go index 17b5b28..b323235 100644 --- a/apis/authorization/v1/selfsubjectrulesreview.go +++ b/apis/authorization/v1/selfsubjectrulesreview.go @@ -27,26 +27,10 @@ type _ = authorizationv1.SelfSubjectRulesReview type _ = authorizationv1.SelfSubjectRulesReviewSpec // +die +// +die:field:name=ResourceRules,die=ResourceRuleDie,listType=atomic +// +die:field:name=NonResourceRules,die=NonResourceRuleDie,listType=atomic type _ = authorizationv1.SubjectRulesReviewStatus -func (d *SubjectRulesReviewStatusDie) ResourceRulesDie(rules ...*ResourceRuleDie) *SubjectRulesReviewStatusDie { - return d.DieStamp(func(r *authorizationv1.SubjectRulesReviewStatus) { - r.ResourceRules = make([]authorizationv1.ResourceRule, len(rules)) - for i := range rules { - r.ResourceRules[i] = rules[i].DieRelease() - } - }) -} - -func (d *SubjectRulesReviewStatusDie) NonResourceRulesDie(rules ...*NonResourceRuleDie) *SubjectRulesReviewStatusDie { - return d.DieStamp(func(r *authorizationv1.SubjectRulesReviewStatus) { - r.NonResourceRules = make([]authorizationv1.NonResourceRule, len(rules)) - for i := range rules { - r.NonResourceRules[i] = rules[i].DieRelease() - } - }) -} - // +die type _ = authorizationv1.ResourceRule diff --git a/apis/authorization/v1/subjectaccessreview.go b/apis/authorization/v1/subjectaccessreview.go index 1efef55..a239a1f 100644 --- a/apis/authorization/v1/subjectaccessreview.go +++ b/apis/authorization/v1/subjectaccessreview.go @@ -26,24 +26,10 @@ type _ = authorizationv1.SubjectAccessReview // TODO(scothis) fix import for maps with struct values, ignore the 'Extra' field until then // +die:ignore={Extra} +// +die:field:name=ResourceAttributes,die=ResourceAttributesDie,pointer=true +// +die:field:name=NonResourceAttributes,die=NonResourceAttributesDie,pointer=true type _ = authorizationv1.SubjectAccessReviewSpec -func (d *SubjectAccessReviewSpecDie) ResourceAttributesDie(fn func(d *ResourceAttributesDie)) *SubjectAccessReviewSpecDie { - return d.DieStamp(func(r *authorizationv1.SubjectAccessReviewSpec) { - d := ResourceAttributesBlank.DieImmutable(false).DieFeedPtr(r.ResourceAttributes) - fn(d) - r.ResourceAttributes = d.DieReleasePtr() - }) -} - -func (d *SubjectAccessReviewSpecDie) NonResourceAttributesDie(fn func(d *NonResourceAttributesDie)) *SubjectAccessReviewSpecDie { - return d.DieStamp(func(r *authorizationv1.SubjectAccessReviewSpec) { - d := NonResourceAttributesBlank.DieImmutable(false).DieFeedPtr(r.NonResourceAttributes) - fn(d) - r.NonResourceAttributes = d.DieReleasePtr() - }) -} - // Extra corresponds to the user.Info.GetExtra() method from the authenticator. Since that is input to the authorizer it needs a reflection here. func (d *SubjectAccessReviewSpecDie) Extra(v map[string]authorizationv1.ExtraValue) *SubjectAccessReviewSpecDie { return d.DieStamp(func(r *authorizationv1.SubjectAccessReviewSpec) { diff --git a/apis/authorization/v1/zz_generated.die.go b/apis/authorization/v1/zz_generated.die.go index 531c256..1869769 100644 --- a/apis/authorization/v1/zz_generated.die.go +++ b/apis/authorization/v1/zz_generated.die.go @@ -961,6 +961,28 @@ func (d *SelfSubjectAccessReviewSpecDie) DiePatch(patchType types.PatchType) ([] return patch.Create(d.seal, d.r, patchType) } +// ResourceAttributesDie mutates ResourceAttributes as a die. +// +// ResourceAuthorizationAttributes describes information for a resource access request +func (d *SelfSubjectAccessReviewSpecDie) ResourceAttributesDie(fn func(d *ResourceAttributesDie)) *SelfSubjectAccessReviewSpecDie { + return d.DieStamp(func(r *authorizationv1.SelfSubjectAccessReviewSpec) { + d := ResourceAttributesBlank.DieImmutable(false).DieFeedPtr(r.ResourceAttributes) + fn(d) + r.ResourceAttributes = d.DieReleasePtr() + }) +} + +// NonResourceAttributesDie mutates NonResourceAttributes as a die. +// +// NonResourceAttributes describes information for a non-resource access request +func (d *SelfSubjectAccessReviewSpecDie) NonResourceAttributesDie(fn func(d *NonResourceAttributesDie)) *SelfSubjectAccessReviewSpecDie { + return d.DieStamp(func(r *authorizationv1.SelfSubjectAccessReviewSpec) { + d := NonResourceAttributesBlank.DieImmutable(false).DieFeedPtr(r.NonResourceAttributes) + fn(d) + r.NonResourceAttributes = d.DieReleasePtr() + }) +} + // ResourceAuthorizationAttributes describes information for a resource access request func (d *SelfSubjectAccessReviewSpecDie) ResourceAttributes(v *authorizationv1.ResourceAttributes) *SelfSubjectAccessReviewSpecDie { return d.DieStamp(func(r *authorizationv1.SelfSubjectAccessReviewSpec) { @@ -1793,6 +1815,34 @@ func (d *SubjectRulesReviewStatusDie) DiePatch(patchType types.PatchType) ([]byt return patch.Create(d.seal, d.r, patchType) } +// ResourceRulesDie replaces ResourceRules by collecting the released value from each die passed. +// +// ResourceRules is the list of actions the subject is allowed to perform on resources. +// +// The list ordering isn't significant, may contain duplicates, and possibly be incomplete. +func (d *SubjectRulesReviewStatusDie) ResourceRulesDie(v ...*ResourceRuleDie) *SubjectRulesReviewStatusDie { + return d.DieStamp(func(r *authorizationv1.SubjectRulesReviewStatus) { + r.ResourceRules = make([]authorizationv1.ResourceRule, len(v)) + for i := range v { + r.ResourceRules[i] = v[i].DieRelease() + } + }) +} + +// NonResourceRulesDie replaces NonResourceRules by collecting the released value from each die passed. +// +// NonResourceRules is the list of actions the subject is allowed to perform on non-resources. +// +// The list ordering isn't significant, may contain duplicates, and possibly be incomplete. +func (d *SubjectRulesReviewStatusDie) NonResourceRulesDie(v ...*NonResourceRuleDie) *SubjectRulesReviewStatusDie { + return d.DieStamp(func(r *authorizationv1.SubjectRulesReviewStatus) { + r.NonResourceRules = make([]authorizationv1.NonResourceRule, len(v)) + for i := range v { + r.NonResourceRules[i] = v[i].DieRelease() + } + }) +} + // ResourceRules is the list of actions the subject is allowed to perform on resources. // // The list ordering isn't significant, may contain duplicates, and possibly be incomplete. @@ -2918,6 +2968,28 @@ func (d *SubjectAccessReviewSpecDie) DiePatch(patchType types.PatchType) ([]byte return patch.Create(d.seal, d.r, patchType) } +// ResourceAttributesDie mutates ResourceAttributes as a die. +// +// ResourceAuthorizationAttributes describes information for a resource access request +func (d *SubjectAccessReviewSpecDie) ResourceAttributesDie(fn func(d *ResourceAttributesDie)) *SubjectAccessReviewSpecDie { + return d.DieStamp(func(r *authorizationv1.SubjectAccessReviewSpec) { + d := ResourceAttributesBlank.DieImmutable(false).DieFeedPtr(r.ResourceAttributes) + fn(d) + r.ResourceAttributes = d.DieReleasePtr() + }) +} + +// NonResourceAttributesDie mutates NonResourceAttributes as a die. +// +// NonResourceAttributes describes information for a non-resource access request +func (d *SubjectAccessReviewSpecDie) NonResourceAttributesDie(fn func(d *NonResourceAttributesDie)) *SubjectAccessReviewSpecDie { + return d.DieStamp(func(r *authorizationv1.SubjectAccessReviewSpec) { + d := NonResourceAttributesBlank.DieImmutable(false).DieFeedPtr(r.NonResourceAttributes) + fn(d) + r.NonResourceAttributes = d.DieReleasePtr() + }) +} + // ResourceAuthorizationAttributes describes information for a resource access request func (d *SubjectAccessReviewSpecDie) ResourceAttributes(v *authorizationv1.ResourceAttributes) *SubjectAccessReviewSpecDie { return d.DieStamp(func(r *authorizationv1.SubjectAccessReviewSpec) { diff --git a/apis/autoscaling/v1/horizontalpodautoscaler.go b/apis/autoscaling/v1/horizontalpodautoscaler.go index 538e2d8..2f24307 100644 --- a/apis/autoscaling/v1/horizontalpodautoscaler.go +++ b/apis/autoscaling/v1/horizontalpodautoscaler.go @@ -24,16 +24,9 @@ import ( type _ = autoscalingv1.HorizontalPodAutoscaler // +die +// +die:field:name=ScaleTargetRef,die=CrossVersionObjectReferenceDie type _ = autoscalingv1.HorizontalPodAutoscalerSpec -func (d *HorizontalPodAutoscalerSpecDie) ScaleTargetRefDie(fn func(d *CrossVersionObjectReferenceDie)) *HorizontalPodAutoscalerSpecDie { - return d.DieStamp(func(r *autoscalingv1.HorizontalPodAutoscalerSpec) { - d := CrossVersionObjectReferenceBlank.DieImmutable(false).DieFeed(r.ScaleTargetRef) - fn(d) - r.ScaleTargetRef = d.DieRelease() - }) -} - // +die type _ = autoscalingv1.CrossVersionObjectReference diff --git a/apis/autoscaling/v1/zz_generated.die.go b/apis/autoscaling/v1/zz_generated.die.go index e1a0719..6556718 100644 --- a/apis/autoscaling/v1/zz_generated.die.go +++ b/apis/autoscaling/v1/zz_generated.die.go @@ -622,6 +622,19 @@ func (d *HorizontalPodAutoscalerSpecDie) DiePatch(patchType types.PatchType) ([] return patch.Create(d.seal, d.r, patchType) } +// ScaleTargetRefDie mutates ScaleTargetRef as a die. +// +// reference to scaled resource; horizontal pod autoscaler will learn the current resource consumption +// +// and will set the desired number of pods by using its Scale subresource. +func (d *HorizontalPodAutoscalerSpecDie) ScaleTargetRefDie(fn func(d *CrossVersionObjectReferenceDie)) *HorizontalPodAutoscalerSpecDie { + return d.DieStamp(func(r *autoscalingv1.HorizontalPodAutoscalerSpec) { + d := CrossVersionObjectReferenceBlank.DieImmutable(false).DieFeed(r.ScaleTargetRef) + fn(d) + r.ScaleTargetRef = d.DieRelease() + }) +} + // reference to scaled resource; horizontal pod autoscaler will learn the current resource consumption // // and will set the desired number of pods by using its Scale subresource. diff --git a/apis/autoscaling/v2/horizontalpodautoscaler.go b/apis/autoscaling/v2/horizontalpodautoscaler.go index 844eeb4..aac164b 100644 --- a/apis/autoscaling/v2/horizontalpodautoscaler.go +++ b/apis/autoscaling/v2/horizontalpodautoscaler.go @@ -26,226 +26,69 @@ import ( type _ = autoscalingv2.HorizontalPodAutoscaler // +die +// +die:field:name=ScaleTargetRef,die=CrossVersionObjectReferenceDie +// +die:field:name=Behavior,die=HorizontalPodAutoscalerBehaviorDie,pointer=true +// +die:field:name=Metrics,die=MetricSpecDie,listType=atomic type _ = autoscalingv2.HorizontalPodAutoscalerSpec -func (d *HorizontalPodAutoscalerSpecDie) ScaleTargetRefDie(fn func(d *CrossVersionObjectReferenceDie)) *HorizontalPodAutoscalerSpecDie { - return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerSpec) { - d := CrossVersionObjectReferenceBlank.DieImmutable(false).DieFeed(r.ScaleTargetRef) - fn(d) - r.ScaleTargetRef = d.DieRelease() - }) -} - -func (d *HorizontalPodAutoscalerSpecDie) ConditionsDie(metrics ...*MetricSpecDie) *HorizontalPodAutoscalerSpecDie { - return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerSpec) { - r.Metrics = make([]autoscalingv2.MetricSpec, len(metrics)) - for i := range metrics { - r.Metrics[i] = metrics[i].DieRelease() - } - }) -} - -func (d *HorizontalPodAutoscalerSpecDie) BehaviorDie(fn func(d *HorizontalPodAutoscalerBehaviorDie)) *HorizontalPodAutoscalerSpecDie { - return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerSpec) { - d := HorizontalPodAutoscalerBehaviorBlank.DieImmutable(false).DieFeedPtr(r.Behavior) - fn(d) - r.Behavior = d.DieReleasePtr() - }) -} - // +die type _ = autoscalingv2.CrossVersionObjectReference // +die +// +die:field:name=Object,die=ObjectMetricSourceDie,pointer=true +// +die:field:name=Pods,die=PodsMetricSourceDie,pointer=true +// +die:field:name=Resource,die=ResourceMetricSourceDie,pointer=true +// +die:field:name=ContainerResource,die=ContainerResourceMetricSourceDie,pointer=true +// +die:field:name=External,die=ExternalMetricSourceDie,pointer=true type _ = autoscalingv2.MetricSpec -func (d *MetricSpecDie) BehaviorDie(fn func(d *ObjectMetricSourceDie)) *MetricSpecDie { - return d.DieStamp(func(r *autoscalingv2.MetricSpec) { - d := ObjectMetricSourceBlank.DieImmutable(false).DieFeedPtr(r.Object) - fn(d) - r.Object = d.DieReleasePtr() - }) -} - -func (d *MetricSpecDie) PodsDie(fn func(d *PodsMetricSourceDie)) *MetricSpecDie { - return d.DieStamp(func(r *autoscalingv2.MetricSpec) { - d := PodsMetricSourceBlank.DieImmutable(false).DieFeedPtr(r.Pods) - fn(d) - r.Pods = d.DieReleasePtr() - }) -} - -func (d *MetricSpecDie) ResourceDie(fn func(d *ResourceMetricSourceDie)) *MetricSpecDie { - return d.DieStamp(func(r *autoscalingv2.MetricSpec) { - d := ResourceMetricSourceBlank.DieImmutable(false).DieFeedPtr(r.Resource) - fn(d) - r.Resource = d.DieReleasePtr() - }) -} - -func (d *MetricSpecDie) ContainerResourceDie(fn func(d *ContainerResourceMetricSourceDie)) *MetricSpecDie { - return d.DieStamp(func(r *autoscalingv2.MetricSpec) { - d := ContainerResourceMetricSourceBlank.DieImmutable(false).DieFeedPtr(r.ContainerResource) - fn(d) - r.ContainerResource = d.DieReleasePtr() - }) -} - -func (d *MetricSpecDie) ExternalDie(fn func(d *ExternalMetricSourceDie)) *MetricSpecDie { - return d.DieStamp(func(r *autoscalingv2.MetricSpec) { - d := ExternalMetricSourceBlank.DieImmutable(false).DieFeedPtr(r.External) - fn(d) - r.External = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=DescribedObject,die=CrossVersionObjectReferenceDie +// +die:field:name=Target,die=MetricTargetDie +// +die:field:name=Metric,die=MetricIdentifierDie type _ = autoscalingv2.ObjectMetricSource -func (d *ObjectMetricSourceDie) DescribedObjectDie(fn func(d *CrossVersionObjectReferenceDie)) *ObjectMetricSourceDie { - return d.DieStamp(func(r *autoscalingv2.ObjectMetricSource) { - d := CrossVersionObjectReferenceBlank.DieImmutable(false).DieFeed(r.DescribedObject) - fn(d) - r.DescribedObject = d.DieRelease() - }) -} - -func (d *ObjectMetricSourceDie) TargetDie(fn func(d *MetricTargetDie)) *ObjectMetricSourceDie { - return d.DieStamp(func(r *autoscalingv2.ObjectMetricSource) { - d := MetricTargetBlank.DieImmutable(false).DieFeed(r.Target) - fn(d) - r.Target = d.DieRelease() - }) -} - -func (d *ObjectMetricSourceDie) MetricDie(fn func(d *MetricIdentifierDie)) *ObjectMetricSourceDie { - return d.DieStamp(func(r *autoscalingv2.ObjectMetricSource) { - d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) - fn(d) - r.Metric = d.DieRelease() - }) -} - // +die type _ = autoscalingv2.MetricTarget // +die +// +die:field:name=Selector,package=_/meta/v1,die=LabelSelectorDie,pointer=true type _ = autoscalingv2.MetricIdentifier -func (d *MetricIdentifierDie) SelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *MetricIdentifierDie { - return d.DieStamp(func(r *autoscalingv2.MetricIdentifier) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) - fn(d) - r.Selector = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Metric,die=MetricIdentifierDie +// +die:field:name=Target,die=MetricTargetDie type _ = autoscalingv2.PodsMetricSource -func (d *PodsMetricSourceDie) MetricDie(fn func(d *MetricIdentifierDie)) *PodsMetricSourceDie { - return d.DieStamp(func(r *autoscalingv2.PodsMetricSource) { - d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) - fn(d) - r.Metric = d.DieRelease() - }) -} - -func (d *PodsMetricSourceDie) TargetDie(fn func(d *MetricTargetDie)) *PodsMetricSourceDie { - return d.DieStamp(func(r *autoscalingv2.PodsMetricSource) { - d := MetricTargetBlank.DieImmutable(false).DieFeed(r.Target) - fn(d) - r.Target = d.DieRelease() - }) -} - // +die +// +die:field:name=Target,die=MetricTargetDie type _ = autoscalingv2.ResourceMetricSource -func (d *ResourceMetricSourceDie) TargetDie(fn func(d *MetricTargetDie)) *ResourceMetricSourceDie { - return d.DieStamp(func(r *autoscalingv2.ResourceMetricSource) { - d := MetricTargetBlank.DieImmutable(false).DieFeed(r.Target) - fn(d) - r.Target = d.DieRelease() - }) -} - // +die +// +die:field:name=Target,die=MetricTargetDie type _ = autoscalingv2.ContainerResourceMetricSource -func (d *ContainerResourceMetricSourceDie) TargetDie(fn func(d *MetricTargetDie)) *ContainerResourceMetricSourceDie { - return d.DieStamp(func(r *autoscalingv2.ContainerResourceMetricSource) { - d := MetricTargetBlank.DieImmutable(false).DieFeed(r.Target) - fn(d) - r.Target = d.DieRelease() - }) -} - // +die +// +die:field:name=Metric,die=MetricIdentifierDie +// +die:field:name=Target,die=MetricTargetDie type _ = autoscalingv2.ExternalMetricSource -func (d *ExternalMetricSourceDie) MetricDie(fn func(d *MetricIdentifierDie)) *ExternalMetricSourceDie { - return d.DieStamp(func(r *autoscalingv2.ExternalMetricSource) { - d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) - fn(d) - r.Metric = d.DieRelease() - }) -} - -func (d *ExternalMetricSourceDie) TargetDie(fn func(d *MetricTargetDie)) *ExternalMetricSourceDie { - return d.DieStamp(func(r *autoscalingv2.ExternalMetricSource) { - d := MetricTargetBlank.DieImmutable(false).DieFeed(r.Target) - fn(d) - r.Target = d.DieRelease() - }) -} - // +die +// +die:field:name=ScaleUp,die=HPAScalingRulesDie,pointer=true +// +die:field:name=ScaleDown,die=HPAScalingRulesDie,pointer=true type _ = autoscalingv2.HorizontalPodAutoscalerBehavior -func (d *HorizontalPodAutoscalerBehaviorDie) ScaleUpDie(fn func(d *HPAScalingRulesDie)) *HorizontalPodAutoscalerBehaviorDie { - return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerBehavior) { - d := HPAScalingRulesBlank.DieImmutable(false).DieFeedPtr(r.ScaleUp) - fn(d) - r.ScaleUp = d.DieReleasePtr() - }) -} - -func (d *HorizontalPodAutoscalerBehaviorDie) ScaleDownDie(fn func(d *HPAScalingRulesDie)) *HorizontalPodAutoscalerBehaviorDie { - return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerBehavior) { - d := HPAScalingRulesBlank.DieImmutable(false).DieFeedPtr(r.ScaleDown) - fn(d) - r.ScaleDown = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Policies,die=HPAScalingPolicyDie,listType=atomic type _ = autoscalingv2.HPAScalingRules -func (d *HPAScalingRulesDie) PoliciesDie(policies ...*HPAScalingPolicyDie) *HPAScalingRulesDie { - return d.DieStamp(func(r *autoscalingv2.HPAScalingRules) { - r.Policies = make([]autoscalingv2.HPAScalingPolicy, len(policies)) - for i := range policies { - r.Policies[i] = policies[i].DieRelease() - } - }) -} - // +die type _ = autoscalingv2.HPAScalingPolicy // +die +// +die:field:name=CurrentMetrics,die=MetricStatusDie,listType=atomic type _ = autoscalingv2.HorizontalPodAutoscalerStatus -func (d *HorizontalPodAutoscalerStatusDie) CurrentMetricsDie(metrics ...*MetricStatusDie) *HorizontalPodAutoscalerStatusDie { - return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerStatus) { - r.CurrentMetrics = make([]autoscalingv2.MetricStatus, len(metrics)) - for i := range metrics { - r.CurrentMetrics[i] = metrics[i].DieRelease() - } - }) -} - func (d *HorizontalPodAutoscalerStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *HorizontalPodAutoscalerStatusDie { return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerStatus) { r.Conditions = make([]autoscalingv2.HorizontalPodAutoscalerCondition, len(conditions)) @@ -263,134 +106,36 @@ func (d *HorizontalPodAutoscalerStatusDie) ConditionsDie(conditions ...*diemetav } // +die +// +die:field:name=Object,die=ObjectMetricStatusDie,pointer=true +// +die:field:name=Pods,die=PodsMetricStatusDie,pointer=true +// +die:field:name=Resource,die=ResourceMetricStatusDie,pointer=true +// +die:field:name=ContainerResource,die=ContainerResourceMetricStatusDie,pointer=true +// +die:field:name=External,die=ExternalMetricStatusDie,pointer=true type _ = autoscalingv2.MetricStatus -func (d *MetricStatusDie) ObjectDie(fn func(d *ObjectMetricStatusDie)) *MetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.MetricStatus) { - d := ObjectMetricStatusBlank.DieImmutable(false).DieFeedPtr(r.Object) - fn(d) - r.Object = d.DieReleasePtr() - }) -} - -func (d *MetricStatusDie) PodDie(fn func(d *PodsMetricStatusDie)) *MetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.MetricStatus) { - d := PodsMetricStatusBlank.DieImmutable(false).DieFeedPtr(r.Pods) - fn(d) - r.Pods = d.DieReleasePtr() - }) -} - -func (d *MetricStatusDie) ResourceDie(fn func(d *ResourceMetricStatusDie)) *MetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.MetricStatus) { - d := ResourceMetricStatusBlank.DieImmutable(false).DieFeedPtr(r.Resource) - fn(d) - r.Resource = d.DieReleasePtr() - }) -} - -func (d *MetricStatusDie) ContainerResourceDie(fn func(d *ContainerResourceMetricStatusDie)) *MetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.MetricStatus) { - d := ContainerResourceMetricStatusBlank.DieImmutable(false).DieFeedPtr(r.ContainerResource) - fn(d) - r.ContainerResource = d.DieReleasePtr() - }) -} - -func (d *MetricStatusDie) ExternalDie(fn func(d *ExternalMetricStatusDie)) *MetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.MetricStatus) { - d := ExternalMetricStatusBlank.DieImmutable(false).DieFeedPtr(r.External) - fn(d) - r.External = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Metric,die=MetricIdentifierDie +// +die:field:name=Current,die=MetricValueStatusDie +// +die:field:name=DescribedObject,die=CrossVersionObjectReferenceDie type _ = autoscalingv2.ObjectMetricStatus -func (d *ObjectMetricStatusDie) MetricDie(fn func(d *MetricIdentifierDie)) *ObjectMetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.ObjectMetricStatus) { - d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) - fn(d) - r.Metric = d.DieRelease() - }) -} - -func (d *ObjectMetricStatusDie) CurrentDie(fn func(d *MetricValueStatusDie)) *ObjectMetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.ObjectMetricStatus) { - d := MetricValueStatusBlank.DieImmutable(false).DieFeed(r.Current) - fn(d) - r.Current = d.DieRelease() - }) -} - -func (d *ObjectMetricStatusDie) DescribedObjectDie(fn func(d *CrossVersionObjectReferenceDie)) *ObjectMetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.ObjectMetricStatus) { - d := CrossVersionObjectReferenceBlank.DieImmutable(false).DieFeed(r.DescribedObject) - fn(d) - r.DescribedObject = d.DieRelease() - }) -} - // +die type _ = autoscalingv2.MetricValueStatus // +die +// +die:field:name=Metric,die=MetricIdentifierDie +// +die:field:name=Current,die=MetricValueStatusDie type _ = autoscalingv2.PodsMetricStatus -func (d *PodsMetricStatusDie) MetricDie(fn func(d *MetricIdentifierDie)) *PodsMetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.PodsMetricStatus) { - d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) - fn(d) - r.Metric = d.DieRelease() - }) -} - -func (d *PodsMetricStatusDie) CurrentDie(fn func(d *MetricValueStatusDie)) *PodsMetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.PodsMetricStatus) { - d := MetricValueStatusBlank.DieImmutable(false).DieFeed(r.Current) - fn(d) - r.Current = d.DieRelease() - }) -} - // +die +// +die:field:name=Current,die=MetricValueStatusDie type _ = autoscalingv2.ResourceMetricStatus -func (d *ResourceMetricStatusDie) CurrentDie(fn func(d *MetricValueStatusDie)) *ResourceMetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.ResourceMetricStatus) { - d := MetricValueStatusBlank.DieImmutable(false).DieFeed(r.Current) - fn(d) - r.Current = d.DieRelease() - }) -} - // +die +// +die:field:name=Current,die=MetricValueStatusDie type _ = autoscalingv2.ContainerResourceMetricStatus -func (d *ContainerResourceMetricStatusDie) CurrentDie(fn func(d *MetricValueStatusDie)) *ContainerResourceMetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.ContainerResourceMetricStatus) { - d := MetricValueStatusBlank.DieImmutable(false).DieFeed(r.Current) - fn(d) - r.Current = d.DieRelease() - }) -} - // +die +// +die:field:name=Metric,die=MetricIdentifierDie +// +die:field:name=Current,die=MetricValueStatusDie type _ = autoscalingv2.ExternalMetricStatus - -func (d *ExternalMetricStatusDie) MetricDie(fn func(d *MetricIdentifierDie)) *ExternalMetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.ExternalMetricStatus) { - d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) - fn(d) - r.Metric = d.DieRelease() - }) -} - -func (d *ExternalMetricStatusDie) CurrentDie(fn func(d *MetricValueStatusDie)) *ExternalMetricStatusDie { - return d.DieStamp(func(r *autoscalingv2.ExternalMetricStatus) { - d := MetricValueStatusBlank.DieImmutable(false).DieFeed(r.Current) - fn(d) - r.Current = d.DieRelease() - }) -} diff --git a/apis/autoscaling/v2/zz_generated.die.go b/apis/autoscaling/v2/zz_generated.die.go index b83a944..3468139 100644 --- a/apis/autoscaling/v2/zz_generated.die.go +++ b/apis/autoscaling/v2/zz_generated.die.go @@ -626,6 +626,60 @@ func (d *HorizontalPodAutoscalerSpecDie) DiePatch(patchType types.PatchType) ([] return patch.Create(d.seal, d.r, patchType) } +// ScaleTargetRefDie mutates ScaleTargetRef as a die. +// +// scaleTargetRef points to the target resource to scale, and is used to the pods for which metrics +// +// should be collected, as well as to actually change the replica count. +func (d *HorizontalPodAutoscalerSpecDie) ScaleTargetRefDie(fn func(d *CrossVersionObjectReferenceDie)) *HorizontalPodAutoscalerSpecDie { + return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerSpec) { + d := CrossVersionObjectReferenceBlank.DieImmutable(false).DieFeed(r.ScaleTargetRef) + fn(d) + r.ScaleTargetRef = d.DieRelease() + }) +} + +// BehaviorDie mutates Behavior as a die. +// +// behavior configures the scaling behavior of the target +// +// in both Up and Down directions (scaleUp and scaleDown fields respectively). +// +// If not set, the default HPAScalingRules for scale up and scale down are used. +func (d *HorizontalPodAutoscalerSpecDie) BehaviorDie(fn func(d *HorizontalPodAutoscalerBehaviorDie)) *HorizontalPodAutoscalerSpecDie { + return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerSpec) { + d := HorizontalPodAutoscalerBehaviorBlank.DieImmutable(false).DieFeedPtr(r.Behavior) + fn(d) + r.Behavior = d.DieReleasePtr() + }) +} + +// MetricsDie replaces Metrics by collecting the released value from each die passed. +// +// metrics contains the specifications for which to use to calculate the +// +// desired replica count (the maximum replica count across all metrics will +// +// be used). The desired replica count is calculated multiplying the +// +// ratio between the target value and the current value by the current +// +// number of pods. Ergo, metrics used must decrease as the pod count is +// +// increased, and vice-versa. See the individual metric source types for +// +// more information about how each type of metric must respond. +// +// If not set, the default metric will be set to 80% average CPU utilization. +func (d *HorizontalPodAutoscalerSpecDie) MetricsDie(v ...*MetricSpecDie) *HorizontalPodAutoscalerSpecDie { + return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerSpec) { + r.Metrics = make([]autoscalingv2.MetricSpec, len(v)) + for i := range v { + r.Metrics[i] = v[i].DieRelease() + } + }) +} + // scaleTargetRef points to the target resource to scale, and is used to the pods for which metrics // // should be collected, as well as to actually change the replica count. @@ -1168,6 +1222,93 @@ func (d *MetricSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ObjectDie mutates Object as a die. +// +// object refers to a metric describing a single kubernetes object +// +// (for example, hits-per-second on an Ingress object). +func (d *MetricSpecDie) ObjectDie(fn func(d *ObjectMetricSourceDie)) *MetricSpecDie { + return d.DieStamp(func(r *autoscalingv2.MetricSpec) { + d := ObjectMetricSourceBlank.DieImmutable(false).DieFeedPtr(r.Object) + fn(d) + r.Object = d.DieReleasePtr() + }) +} + +// PodsDie mutates Pods as a die. +// +// pods refers to a metric describing each pod in the current scale target +// +// (for example, transactions-processed-per-second). The values will be +// +// averaged together before being compared to the target value. +func (d *MetricSpecDie) PodsDie(fn func(d *PodsMetricSourceDie)) *MetricSpecDie { + return d.DieStamp(func(r *autoscalingv2.MetricSpec) { + d := PodsMetricSourceBlank.DieImmutable(false).DieFeedPtr(r.Pods) + fn(d) + r.Pods = d.DieReleasePtr() + }) +} + +// ResourceDie mutates Resource as a die. +// +// resource refers to a resource metric (such as those specified in +// +// requests and limits) known to Kubernetes describing each pod in the +// +// current scale target (e.g. CPU or memory). Such metrics are built in to +// +// # Kubernetes, and have special scaling options on top of those available +// +// to normal per-pod metrics using the "pods" source. +func (d *MetricSpecDie) ResourceDie(fn func(d *ResourceMetricSourceDie)) *MetricSpecDie { + return d.DieStamp(func(r *autoscalingv2.MetricSpec) { + d := ResourceMetricSourceBlank.DieImmutable(false).DieFeedPtr(r.Resource) + fn(d) + r.Resource = d.DieReleasePtr() + }) +} + +// ContainerResourceDie mutates ContainerResource as a die. +// +// containerResource refers to a resource metric (such as those specified in +// +// requests and limits) known to Kubernetes describing a single container in +// +// each pod of the current scale target (e.g. CPU or memory). Such metrics are +// +// built in to Kubernetes, and have special scaling options on top of those +// +// available to normal per-pod metrics using the "pods" source. +// +// This is an alpha feature and can be enabled by the HPAContainerMetrics feature flag. +func (d *MetricSpecDie) ContainerResourceDie(fn func(d *ContainerResourceMetricSourceDie)) *MetricSpecDie { + return d.DieStamp(func(r *autoscalingv2.MetricSpec) { + d := ContainerResourceMetricSourceBlank.DieImmutable(false).DieFeedPtr(r.ContainerResource) + fn(d) + r.ContainerResource = d.DieReleasePtr() + }) +} + +// ExternalDie mutates External as a die. +// +// external refers to a global metric that is not associated +// +// with any Kubernetes object. It allows autoscaling based on information +// +// coming from components running outside of cluster +// +// (for example length of queue in cloud messaging service, or +// +// QPS from loadbalancer running outside of cluster). +func (d *MetricSpecDie) ExternalDie(fn func(d *ExternalMetricSourceDie)) *MetricSpecDie { + return d.DieStamp(func(r *autoscalingv2.MetricSpec) { + d := ExternalMetricSourceBlank.DieImmutable(false).DieFeedPtr(r.External) + fn(d) + r.External = d.DieReleasePtr() + }) +} + // type is the type of metric source. It should be one of "ContainerResource", "External", // // "Object", "Pods" or "Resource", each mapping to a matching field in the object. @@ -1476,6 +1617,39 @@ func (d *ObjectMetricSourceDie) DiePatch(patchType types.PatchType) ([]byte, err return patch.Create(d.seal, d.r, patchType) } +// DescribedObjectDie mutates DescribedObject as a die. +// +// describedObject specifies the descriptions of a object,such as kind,name apiVersion +func (d *ObjectMetricSourceDie) DescribedObjectDie(fn func(d *CrossVersionObjectReferenceDie)) *ObjectMetricSourceDie { + return d.DieStamp(func(r *autoscalingv2.ObjectMetricSource) { + d := CrossVersionObjectReferenceBlank.DieImmutable(false).DieFeed(r.DescribedObject) + fn(d) + r.DescribedObject = d.DieRelease() + }) +} + +// TargetDie mutates Target as a die. +// +// target specifies the target value for the given metric +func (d *ObjectMetricSourceDie) TargetDie(fn func(d *MetricTargetDie)) *ObjectMetricSourceDie { + return d.DieStamp(func(r *autoscalingv2.ObjectMetricSource) { + d := MetricTargetBlank.DieImmutable(false).DieFeed(r.Target) + fn(d) + r.Target = d.DieRelease() + }) +} + +// MetricDie mutates Metric as a die. +// +// metric identifies the target metric by name and selector +func (d *ObjectMetricSourceDie) MetricDie(fn func(d *MetricIdentifierDie)) *ObjectMetricSourceDie { + return d.DieStamp(func(r *autoscalingv2.ObjectMetricSource) { + d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) + fn(d) + r.Metric = d.DieRelease() + }) +} + // describedObject specifies the descriptions of a object,such as kind,name apiVersion func (d *ObjectMetricSourceDie) DescribedObject(v autoscalingv2.CrossVersionObjectReference) *ObjectMetricSourceDie { return d.DieStamp(func(r *autoscalingv2.ObjectMetricSource) { @@ -2007,6 +2181,21 @@ func (d *MetricIdentifierDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// SelectorDie mutates Selector as a die. +// +// selector is the string-encoded form of a standard kubernetes label selector for the given metric +// +// When set, it is passed as an additional parameter to the metrics server for more specific metrics scoping. +// +// When unset, just the metricName will be used to gather metrics. +func (d *MetricIdentifierDie) SelectorDie(fn func(d *v1.LabelSelectorDie)) *MetricIdentifierDie { + return d.DieStamp(func(r *autoscalingv2.MetricIdentifier) { + d := v1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) + fn(d) + r.Selector = d.DieReleasePtr() + }) +} + // name is the name of the given metric func (d *MetricIdentifierDie) Name(v string) *MetricIdentifierDie { return d.DieStamp(func(r *autoscalingv2.MetricIdentifier) { @@ -2253,6 +2442,28 @@ func (d *PodsMetricSourceDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// MetricDie mutates Metric as a die. +// +// metric identifies the target metric by name and selector +func (d *PodsMetricSourceDie) MetricDie(fn func(d *MetricIdentifierDie)) *PodsMetricSourceDie { + return d.DieStamp(func(r *autoscalingv2.PodsMetricSource) { + d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) + fn(d) + r.Metric = d.DieRelease() + }) +} + +// TargetDie mutates Target as a die. +// +// target specifies the target value for the given metric +func (d *PodsMetricSourceDie) TargetDie(fn func(d *MetricTargetDie)) *PodsMetricSourceDie { + return d.DieStamp(func(r *autoscalingv2.PodsMetricSource) { + d := MetricTargetBlank.DieImmutable(false).DieFeed(r.Target) + fn(d) + r.Target = d.DieRelease() + }) +} + // metric identifies the target metric by name and selector func (d *PodsMetricSourceDie) Metric(v autoscalingv2.MetricIdentifier) *PodsMetricSourceDie { return d.DieStamp(func(r *autoscalingv2.PodsMetricSource) { @@ -2495,6 +2706,17 @@ func (d *ResourceMetricSourceDie) DiePatch(patchType types.PatchType) ([]byte, e return patch.Create(d.seal, d.r, patchType) } +// TargetDie mutates Target as a die. +// +// target specifies the target value for the given metric +func (d *ResourceMetricSourceDie) TargetDie(fn func(d *MetricTargetDie)) *ResourceMetricSourceDie { + return d.DieStamp(func(r *autoscalingv2.ResourceMetricSource) { + d := MetricTargetBlank.DieImmutable(false).DieFeed(r.Target) + fn(d) + r.Target = d.DieRelease() + }) +} + // name is the name of the resource in question. func (d *ResourceMetricSourceDie) Name(v corev1.ResourceName) *ResourceMetricSourceDie { return d.DieStamp(func(r *autoscalingv2.ResourceMetricSource) { @@ -2737,6 +2959,17 @@ func (d *ContainerResourceMetricSourceDie) DiePatch(patchType types.PatchType) ( return patch.Create(d.seal, d.r, patchType) } +// TargetDie mutates Target as a die. +// +// target specifies the target value for the given metric +func (d *ContainerResourceMetricSourceDie) TargetDie(fn func(d *MetricTargetDie)) *ContainerResourceMetricSourceDie { + return d.DieStamp(func(r *autoscalingv2.ContainerResourceMetricSource) { + d := MetricTargetBlank.DieImmutable(false).DieFeed(r.Target) + fn(d) + r.Target = d.DieRelease() + }) +} + // name is the name of the resource in question. func (d *ContainerResourceMetricSourceDie) Name(v corev1.ResourceName) *ContainerResourceMetricSourceDie { return d.DieStamp(func(r *autoscalingv2.ContainerResourceMetricSource) { @@ -2986,6 +3219,28 @@ func (d *ExternalMetricSourceDie) DiePatch(patchType types.PatchType) ([]byte, e return patch.Create(d.seal, d.r, patchType) } +// MetricDie mutates Metric as a die. +// +// metric identifies the target metric by name and selector +func (d *ExternalMetricSourceDie) MetricDie(fn func(d *MetricIdentifierDie)) *ExternalMetricSourceDie { + return d.DieStamp(func(r *autoscalingv2.ExternalMetricSource) { + d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) + fn(d) + r.Metric = d.DieRelease() + }) +} + +// TargetDie mutates Target as a die. +// +// target specifies the target value for the given metric +func (d *ExternalMetricSourceDie) TargetDie(fn func(d *MetricTargetDie)) *ExternalMetricSourceDie { + return d.DieStamp(func(r *autoscalingv2.ExternalMetricSource) { + d := MetricTargetBlank.DieImmutable(false).DieFeed(r.Target) + fn(d) + r.Target = d.DieRelease() + }) +} + // metric identifies the target metric by name and selector func (d *ExternalMetricSourceDie) Metric(v autoscalingv2.MetricIdentifier) *ExternalMetricSourceDie { return d.DieStamp(func(r *autoscalingv2.ExternalMetricSource) { @@ -3228,6 +3483,42 @@ func (d *HorizontalPodAutoscalerBehaviorDie) DiePatch(patchType types.PatchType) return patch.Create(d.seal, d.r, patchType) } +// ScaleUpDie mutates ScaleUp as a die. +// +// scaleUp is scaling policy for scaling Up. +// +// If not set, the default value is the higher of: +// +// * increase no more than 4 pods per 60 seconds +// +// * double the number of pods per 60 seconds +// +// No stabilization is used. +func (d *HorizontalPodAutoscalerBehaviorDie) ScaleUpDie(fn func(d *HPAScalingRulesDie)) *HorizontalPodAutoscalerBehaviorDie { + return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerBehavior) { + d := HPAScalingRulesBlank.DieImmutable(false).DieFeedPtr(r.ScaleUp) + fn(d) + r.ScaleUp = d.DieReleasePtr() + }) +} + +// ScaleDownDie mutates ScaleDown as a die. +// +// scaleDown is scaling policy for scaling Down. +// +// # If not set, the default value is to allow to scale down to minReplicas pods, with a +// +// 300 second stabilization window (i.e., the highest recommendation for +// +// the last 300sec is used). +func (d *HorizontalPodAutoscalerBehaviorDie) ScaleDownDie(fn func(d *HPAScalingRulesDie)) *HorizontalPodAutoscalerBehaviorDie { + return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerBehavior) { + d := HPAScalingRulesBlank.DieImmutable(false).DieFeedPtr(r.ScaleDown) + fn(d) + r.ScaleDown = d.DieReleasePtr() + }) +} + // scaleUp is scaling policy for scaling Up. // // If not set, the default value is the higher of: @@ -3484,6 +3775,20 @@ func (d *HPAScalingRulesDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// PoliciesDie replaces Policies by collecting the released value from each die passed. +// +// policies is a list of potential scaling polices which can be used during scaling. +// +// At least one policy must be specified, otherwise the HPAScalingRules will be discarded as invalid +func (d *HPAScalingRulesDie) PoliciesDie(v ...*HPAScalingPolicyDie) *HPAScalingRulesDie { + return d.DieStamp(func(r *autoscalingv2.HPAScalingRules) { + r.Policies = make([]autoscalingv2.HPAScalingPolicy, len(v)) + for i := range v { + r.Policies[i] = v[i].DieRelease() + } + }) +} + // stabilizationWindowSeconds is the number of seconds for which past recommendations should be // // considered while scaling up or scaling down. @@ -4000,6 +4305,18 @@ func (d *HorizontalPodAutoscalerStatusDie) DiePatch(patchType types.PatchType) ( return patch.Create(d.seal, d.r, patchType) } +// CurrentMetricsDie replaces CurrentMetrics by collecting the released value from each die passed. +// +// currentMetrics is the last read state of the metrics used by this autoscaler. +func (d *HorizontalPodAutoscalerStatusDie) CurrentMetricsDie(v ...*MetricStatusDie) *HorizontalPodAutoscalerStatusDie { + return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerStatus) { + r.CurrentMetrics = make([]autoscalingv2.MetricStatus, len(v)) + for i := range v { + r.CurrentMetrics[i] = v[i].DieRelease() + } + }) +} + // observedGeneration is the most recent generation observed by this autoscaler. func (d *HorizontalPodAutoscalerStatusDie) ObservedGeneration(v *int64) *HorizontalPodAutoscalerStatusDie { return d.DieStamp(func(r *autoscalingv2.HorizontalPodAutoscalerStatus) { @@ -4278,6 +4595,91 @@ func (d *MetricStatusDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ObjectDie mutates Object as a die. +// +// object refers to a metric describing a single kubernetes object +// +// (for example, hits-per-second on an Ingress object). +func (d *MetricStatusDie) ObjectDie(fn func(d *ObjectMetricStatusDie)) *MetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.MetricStatus) { + d := ObjectMetricStatusBlank.DieImmutable(false).DieFeedPtr(r.Object) + fn(d) + r.Object = d.DieReleasePtr() + }) +} + +// PodsDie mutates Pods as a die. +// +// pods refers to a metric describing each pod in the current scale target +// +// (for example, transactions-processed-per-second). The values will be +// +// averaged together before being compared to the target value. +func (d *MetricStatusDie) PodsDie(fn func(d *PodsMetricStatusDie)) *MetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.MetricStatus) { + d := PodsMetricStatusBlank.DieImmutable(false).DieFeedPtr(r.Pods) + fn(d) + r.Pods = d.DieReleasePtr() + }) +} + +// ResourceDie mutates Resource as a die. +// +// resource refers to a resource metric (such as those specified in +// +// requests and limits) known to Kubernetes describing each pod in the +// +// current scale target (e.g. CPU or memory). Such metrics are built in to +// +// # Kubernetes, and have special scaling options on top of those available +// +// to normal per-pod metrics using the "pods" source. +func (d *MetricStatusDie) ResourceDie(fn func(d *ResourceMetricStatusDie)) *MetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.MetricStatus) { + d := ResourceMetricStatusBlank.DieImmutable(false).DieFeedPtr(r.Resource) + fn(d) + r.Resource = d.DieReleasePtr() + }) +} + +// ContainerResourceDie mutates ContainerResource as a die. +// +// container resource refers to a resource metric (such as those specified in +// +// requests and limits) known to Kubernetes describing a single container in each pod in the +// +// current scale target (e.g. CPU or memory). Such metrics are built in to +// +// # Kubernetes, and have special scaling options on top of those available +// +// to normal per-pod metrics using the "pods" source. +func (d *MetricStatusDie) ContainerResourceDie(fn func(d *ContainerResourceMetricStatusDie)) *MetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.MetricStatus) { + d := ContainerResourceMetricStatusBlank.DieImmutable(false).DieFeedPtr(r.ContainerResource) + fn(d) + r.ContainerResource = d.DieReleasePtr() + }) +} + +// ExternalDie mutates External as a die. +// +// external refers to a global metric that is not associated +// +// with any Kubernetes object. It allows autoscaling based on information +// +// coming from components running outside of cluster +// +// (for example length of queue in cloud messaging service, or +// +// QPS from loadbalancer running outside of cluster). +func (d *MetricStatusDie) ExternalDie(fn func(d *ExternalMetricStatusDie)) *MetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.MetricStatus) { + d := ExternalMetricStatusBlank.DieImmutable(false).DieFeedPtr(r.External) + fn(d) + r.External = d.DieReleasePtr() + }) +} + // type is the type of metric source. It will be one of "ContainerResource", "External", // // "Object", "Pods" or "Resource", each corresponds to a matching field in the object. @@ -4584,6 +4986,39 @@ func (d *ObjectMetricStatusDie) DiePatch(patchType types.PatchType) ([]byte, err return patch.Create(d.seal, d.r, patchType) } +// MetricDie mutates Metric as a die. +// +// metric identifies the target metric by name and selector +func (d *ObjectMetricStatusDie) MetricDie(fn func(d *MetricIdentifierDie)) *ObjectMetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.ObjectMetricStatus) { + d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) + fn(d) + r.Metric = d.DieRelease() + }) +} + +// CurrentDie mutates Current as a die. +// +// current contains the current value for the given metric +func (d *ObjectMetricStatusDie) CurrentDie(fn func(d *MetricValueStatusDie)) *ObjectMetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.ObjectMetricStatus) { + d := MetricValueStatusBlank.DieImmutable(false).DieFeed(r.Current) + fn(d) + r.Current = d.DieRelease() + }) +} + +// DescribedObjectDie mutates DescribedObject as a die. +// +// DescribedObject specifies the descriptions of a object,such as kind,name apiVersion +func (d *ObjectMetricStatusDie) DescribedObjectDie(fn func(d *CrossVersionObjectReferenceDie)) *ObjectMetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.ObjectMetricStatus) { + d := CrossVersionObjectReferenceBlank.DieImmutable(false).DieFeed(r.DescribedObject) + fn(d) + r.DescribedObject = d.DieRelease() + }) +} + // metric identifies the target metric by name and selector func (d *ObjectMetricStatusDie) Metric(v autoscalingv2.MetricIdentifier) *ObjectMetricStatusDie { return d.DieStamp(func(r *autoscalingv2.ObjectMetricStatus) { @@ -5106,6 +5541,28 @@ func (d *PodsMetricStatusDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// MetricDie mutates Metric as a die. +// +// metric identifies the target metric by name and selector +func (d *PodsMetricStatusDie) MetricDie(fn func(d *MetricIdentifierDie)) *PodsMetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.PodsMetricStatus) { + d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) + fn(d) + r.Metric = d.DieRelease() + }) +} + +// CurrentDie mutates Current as a die. +// +// current contains the current value for the given metric +func (d *PodsMetricStatusDie) CurrentDie(fn func(d *MetricValueStatusDie)) *PodsMetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.PodsMetricStatus) { + d := MetricValueStatusBlank.DieImmutable(false).DieFeed(r.Current) + fn(d) + r.Current = d.DieRelease() + }) +} + // metric identifies the target metric by name and selector func (d *PodsMetricStatusDie) Metric(v autoscalingv2.MetricIdentifier) *PodsMetricStatusDie { return d.DieStamp(func(r *autoscalingv2.PodsMetricStatus) { @@ -5348,6 +5805,17 @@ func (d *ResourceMetricStatusDie) DiePatch(patchType types.PatchType) ([]byte, e return patch.Create(d.seal, d.r, patchType) } +// CurrentDie mutates Current as a die. +// +// current contains the current value for the given metric +func (d *ResourceMetricStatusDie) CurrentDie(fn func(d *MetricValueStatusDie)) *ResourceMetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.ResourceMetricStatus) { + d := MetricValueStatusBlank.DieImmutable(false).DieFeed(r.Current) + fn(d) + r.Current = d.DieRelease() + }) +} + // name is the name of the resource in question. func (d *ResourceMetricStatusDie) Name(v corev1.ResourceName) *ResourceMetricStatusDie { return d.DieStamp(func(r *autoscalingv2.ResourceMetricStatus) { @@ -5590,6 +6058,17 @@ func (d *ContainerResourceMetricStatusDie) DiePatch(patchType types.PatchType) ( return patch.Create(d.seal, d.r, patchType) } +// CurrentDie mutates Current as a die. +// +// current contains the current value for the given metric +func (d *ContainerResourceMetricStatusDie) CurrentDie(fn func(d *MetricValueStatusDie)) *ContainerResourceMetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.ContainerResourceMetricStatus) { + d := MetricValueStatusBlank.DieImmutable(false).DieFeed(r.Current) + fn(d) + r.Current = d.DieRelease() + }) +} + // name is the name of the resource in question. func (d *ContainerResourceMetricStatusDie) Name(v corev1.ResourceName) *ContainerResourceMetricStatusDie { return d.DieStamp(func(r *autoscalingv2.ContainerResourceMetricStatus) { @@ -5839,6 +6318,28 @@ func (d *ExternalMetricStatusDie) DiePatch(patchType types.PatchType) ([]byte, e return patch.Create(d.seal, d.r, patchType) } +// MetricDie mutates Metric as a die. +// +// metric identifies the target metric by name and selector +func (d *ExternalMetricStatusDie) MetricDie(fn func(d *MetricIdentifierDie)) *ExternalMetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.ExternalMetricStatus) { + d := MetricIdentifierBlank.DieImmutable(false).DieFeed(r.Metric) + fn(d) + r.Metric = d.DieRelease() + }) +} + +// CurrentDie mutates Current as a die. +// +// current contains the current value for the given metric +func (d *ExternalMetricStatusDie) CurrentDie(fn func(d *MetricValueStatusDie)) *ExternalMetricStatusDie { + return d.DieStamp(func(r *autoscalingv2.ExternalMetricStatus) { + d := MetricValueStatusBlank.DieImmutable(false).DieFeed(r.Current) + fn(d) + r.Current = d.DieRelease() + }) +} + // metric identifies the target metric by name and selector func (d *ExternalMetricStatusDie) Metric(v autoscalingv2.MetricIdentifier) *ExternalMetricStatusDie { return d.DieStamp(func(r *autoscalingv2.ExternalMetricStatus) { diff --git a/apis/batch/v1/job.go b/apis/batch/v1/job.go index e9e7eeb..2c1fa0b 100644 --- a/apis/batch/v1/job.go +++ b/apis/batch/v1/job.go @@ -19,7 +19,6 @@ package v1 import ( batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" - diecorev1 "reconciler.io/dies/apis/core/v1" diemetav1 "reconciler.io/dies/apis/meta/v1" ) @@ -27,72 +26,21 @@ import ( type _ = batchv1.Job // +die +// +die:field:name=PodFailurePolicy,die=PodFailurePolicyDie,pointer=true +// +die:field:name=SuccessPolicy,die=SuccessPolicyDie,pointer=true +// +die:field:name=Selector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=Template,package=_/core/v1,die=PodTemplateSpecDie type _ = batchv1.JobSpec -func (d *JobSpecDie) PodFailurePolicyDie(fn func(d *PodFailurePolicyDie)) *JobSpecDie { - return d.DieStamp(func(r *batchv1.JobSpec) { - d := PodFailurePolicyBlank.DieImmutable(false).DieFeedPtr(r.PodFailurePolicy) - fn(d) - r.PodFailurePolicy = d.DieReleasePtr() - }) -} - -func (d *JobSpecDie) SuccessPolicyDie(fn func(d *SuccessPolicyDie)) *JobSpecDie { - return d.DieStamp(func(r *batchv1.JobSpec) { - d := SuccessPolicyBlank.DieImmutable(false).DieFeedPtr(r.SuccessPolicy) - fn(d) - r.SuccessPolicy = d.DieReleasePtr() - }) -} - -func (d *JobSpecDie) SelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *JobSpecDie { - return d.DieStamp(func(r *batchv1.JobSpec) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) - fn(d) - r.Selector = d.DieReleasePtr() - }) -} - -func (d *JobSpecDie) TemplateDie(fn func(d *diecorev1.PodTemplateSpecDie)) *JobSpecDie { - return d.DieStamp(func(r *batchv1.JobSpec) { - d := diecorev1.PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) - fn(d) - r.Template = d.DieRelease() - }) -} - // +die +// +die:field:name=Rules,die=PodFailurePolicyRuleDie,listType=atomic type _ = batchv1.PodFailurePolicy -func (d *PodFailurePolicyDie) RulesDie(rules ...*PodFailurePolicyRuleDie) *PodFailurePolicyDie { - return d.DieStamp(func(r *batchv1.PodFailurePolicy) { - r.Rules = make([]batchv1.PodFailurePolicyRule, len(rules)) - for i := range rules { - r.Rules[i] = rules[i].DieRelease() - } - }) -} - // +die +// +die:field:name=OnExitCodes,die=PodFailurePolicyOnExitCodesRequirementDie,pointer=true +// +die:field:name=OnPodConditions,die=PodFailurePolicyOnPodConditionsPatternDie,listType=atomic type _ = batchv1.PodFailurePolicyRule -func (d *PodFailurePolicyRuleDie) OnExitCodesDie(fn func(d *PodFailurePolicyOnExitCodesRequirementDie)) *PodFailurePolicyRuleDie { - return d.DieStamp(func(r *batchv1.PodFailurePolicyRule) { - d := PodFailurePolicyOnExitCodesRequirementBlank.DieImmutable(false).DieFeedPtr(r.OnExitCodes) - fn(d) - r.OnExitCodes = d.DieReleasePtr() - }) -} - -func (d *PodFailurePolicyRuleDie) OnPodConditionsDie(patterns ...*PodFailurePolicyOnPodConditionsPatternDie) *PodFailurePolicyRuleDie { - return d.DieStamp(func(r *batchv1.PodFailurePolicyRule) { - r.OnPodConditions = make([]batchv1.PodFailurePolicyOnPodConditionsPattern, len(patterns)) - for i := range patterns { - r.OnPodConditions[i] = patterns[i].DieRelease() - } - }) -} - // +die type _ = batchv1.PodFailurePolicyOnExitCodesRequirement @@ -100,21 +48,14 @@ type _ = batchv1.PodFailurePolicyOnExitCodesRequirement type _ = batchv1.PodFailurePolicyOnPodConditionsPattern // +die +// +die:field:name=Rules,die=SuccessPolicyRuleDie,listType=atomic type _ = batchv1.SuccessPolicy -func (d *SuccessPolicyDie) RulesDie(rules ...*SuccessPolicyRuleDie) *SuccessPolicyDie { - return d.DieStamp(func(r *batchv1.SuccessPolicy) { - r.Rules = make([]batchv1.SuccessPolicyRule, len(rules)) - for i := range rules { - r.Rules[i] = rules[i].DieRelease() - } - }) -} - // +die type _ = batchv1.SuccessPolicyRule // +die +// +die:field:name=UncountedTerminatedPods,die=UncountedTerminatedPodsDie,pointer=true type _ = batchv1.JobStatus func (d *JobStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *JobStatusDie { @@ -133,13 +74,5 @@ func (d *JobStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *Job }) } -func (d *JobStatusDie) UncountedTerminatedPodsDie(fn func(d *UncountedTerminatedPodsDie)) *JobStatusDie { - return d.DieStamp(func(r *batchv1.JobStatus) { - d := UncountedTerminatedPodsBlank.DieImmutable(false).DieFeedPtr(r.UncountedTerminatedPods) - fn(d) - r.UncountedTerminatedPods = d.DieReleasePtr() - }) -} - // +die type _ = batchv1.UncountedTerminatedPods diff --git a/apis/batch/v1/zz_generated.die.go b/apis/batch/v1/zz_generated.die.go index 3ae923d..e4aa410 100644 --- a/apis/batch/v1/zz_generated.die.go +++ b/apis/batch/v1/zz_generated.die.go @@ -34,6 +34,7 @@ import ( json "k8s.io/apimachinery/pkg/util/json" jsonpath "k8s.io/client-go/util/jsonpath" osx "os" + apiscorev1 "reconciler.io/dies/apis/core/v1" metav1 "reconciler.io/dies/apis/meta/v1" patch "reconciler.io/dies/patch" reflectx "reflect" @@ -1551,6 +1552,86 @@ func (d *JobSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// PodFailurePolicyDie mutates PodFailurePolicy as a die. +// +// Specifies the policy of handling failed pods. In particular, it allows to +// +// specify the set of actions and conditions which need to be +// +// satisfied to take the associated action. +// +// If empty, the default behaviour applies - the counter of failed pods, +// +// represented by the jobs's .status.failed field, is incremented and it is +// +// checked against the backoffLimit. This field cannot be used in combination +// +// with restartPolicy=OnFailure. +// +// This field is beta-level. It can be used when the `JobPodFailurePolicy` +// +// feature gate is enabled (enabled by default). +func (d *JobSpecDie) PodFailurePolicyDie(fn func(d *PodFailurePolicyDie)) *JobSpecDie { + return d.DieStamp(func(r *batchv1.JobSpec) { + d := PodFailurePolicyBlank.DieImmutable(false).DieFeedPtr(r.PodFailurePolicy) + fn(d) + r.PodFailurePolicy = d.DieReleasePtr() + }) +} + +// SuccessPolicyDie mutates SuccessPolicy as a die. +// +// successPolicy specifies the policy when the Job can be declared as succeeded. +// +// # If empty, the default behavior applies - the Job is declared as succeeded +// +// only when the number of succeeded pods equals to the completions. +// +// When the field is specified, it must be immutable and works only for the Indexed Jobs. +// +// Once the Job meets the SuccessPolicy, the lingering pods are terminated. +// +// This field is alpha-level. To use this field, you must enable the +// +// `JobSuccessPolicy` feature gate (disabled by default). +func (d *JobSpecDie) SuccessPolicyDie(fn func(d *SuccessPolicyDie)) *JobSpecDie { + return d.DieStamp(func(r *batchv1.JobSpec) { + d := SuccessPolicyBlank.DieImmutable(false).DieFeedPtr(r.SuccessPolicy) + fn(d) + r.SuccessPolicy = d.DieReleasePtr() + }) +} + +// SelectorDie mutates Selector as a die. +// +// A label query over pods that should match the pod count. +// +// Normally, the system sets this field for you. +// +// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#label-selectors +func (d *JobSpecDie) SelectorDie(fn func(d *metav1.LabelSelectorDie)) *JobSpecDie { + return d.DieStamp(func(r *batchv1.JobSpec) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) + fn(d) + r.Selector = d.DieReleasePtr() + }) +} + +// TemplateDie mutates Template as a die. +// +// Describes the pod that will be created when executing a job. +// +// The only allowed template.spec.restartPolicy values are "Never" or "OnFailure". +// +// More info: https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/ +func (d *JobSpecDie) TemplateDie(fn func(d *apiscorev1.PodTemplateSpecDie)) *JobSpecDie { + return d.DieStamp(func(r *batchv1.JobSpec) { + d := apiscorev1.PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) + fn(d) + r.Template = d.DieRelease() + }) +} + // Specifies the maximum desired number of pods the job should // // run at any given time. The actual number of pods running in steady state will @@ -2101,6 +2182,26 @@ func (d *PodFailurePolicyDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// RulesDie replaces Rules by collecting the released value from each die passed. +// +// A list of pod failure policy rules. The rules are evaluated in order. +// +// Once a rule matches a Pod failure, the remaining of the rules are ignored. +// +// # When no rule matches the Pod failure, the default handling applies - the +// +// counter of pod failures is incremented and it is checked against +// +// the backoffLimit. At most 20 elements are allowed. +func (d *PodFailurePolicyDie) RulesDie(v ...*PodFailurePolicyRuleDie) *PodFailurePolicyDie { + return d.DieStamp(func(r *batchv1.PodFailurePolicy) { + r.Rules = make([]batchv1.PodFailurePolicyRule, len(v)) + for i := range v { + r.Rules[i] = v[i].DieRelease() + } + }) +} + // A list of pod failure policy rules. The rules are evaluated in order. // // Once a rule matches a Pod failure, the remaining of the rules are ignored. @@ -2344,6 +2445,33 @@ func (d *PodFailurePolicyRuleDie) DiePatch(patchType types.PatchType) ([]byte, e return patch.Create(d.seal, d.r, patchType) } +// OnExitCodesDie mutates OnExitCodes as a die. +// +// Represents the requirement on the container exit codes. +func (d *PodFailurePolicyRuleDie) OnExitCodesDie(fn func(d *PodFailurePolicyOnExitCodesRequirementDie)) *PodFailurePolicyRuleDie { + return d.DieStamp(func(r *batchv1.PodFailurePolicyRule) { + d := PodFailurePolicyOnExitCodesRequirementBlank.DieImmutable(false).DieFeedPtr(r.OnExitCodes) + fn(d) + r.OnExitCodes = d.DieReleasePtr() + }) +} + +// OnPodConditionsDie replaces OnPodConditions by collecting the released value from each die passed. +// +// Represents the requirement on the pod conditions. The requirement is represented +// +// as a list of pod condition patterns. The requirement is satisfied if at +// +// least one pattern matches an actual pod condition. At most 20 elements are allowed. +func (d *PodFailurePolicyRuleDie) OnPodConditionsDie(v ...*PodFailurePolicyOnPodConditionsPatternDie) *PodFailurePolicyRuleDie { + return d.DieStamp(func(r *batchv1.PodFailurePolicyRule) { + r.OnPodConditions = make([]batchv1.PodFailurePolicyOnPodConditionsPattern, len(v)) + for i := range v { + r.OnPodConditions[i] = v[i].DieRelease() + } + }) +} + // Specifies the action taken on a pod failure when the requirements are satisfied. // // Possible values are: @@ -3154,6 +3282,28 @@ func (d *SuccessPolicyDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// RulesDie replaces Rules by collecting the released value from each die passed. +// +// rules represents the list of alternative rules for the declaring the Jobs +// +// as successful before `.status.succeeded >= .spec.completions`. Once any of the rules are met, +// +// the "SucceededCriteriaMet" condition is added, and the lingering pods are removed. +// +// The terminal state for such a Job has the "Complete" condition. +// +// Additionally, these rules are evaluated in order; Once the Job meets one of the rules, +// +// other rules are ignored. At most 20 elements are allowed. +func (d *SuccessPolicyDie) RulesDie(v ...*SuccessPolicyRuleDie) *SuccessPolicyDie { + return d.DieStamp(func(r *batchv1.SuccessPolicy) { + r.Rules = make([]batchv1.SuccessPolicyRule, len(v)) + for i := range v { + r.Rules[i] = v[i].DieRelease() + } + }) +} + // rules represents the list of alternative rules for the declaring the Jobs // // as successful before `.status.succeeded >= .spec.completions`. Once any of the rules are met, @@ -3679,6 +3829,39 @@ func (d *JobStatusDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// UncountedTerminatedPodsDie mutates UncountedTerminatedPods as a die. +// +// uncountedTerminatedPods holds the UIDs of Pods that have terminated but +// +// the job controller hasn't yet accounted for in the status counters. +// +// The job controller creates pods with a finalizer. When a pod terminates +// +// (succeeded or failed), the controller does three steps to account for it +// +// in the job status: +// +// 1. Add the pod UID to the arrays in this field. +// +// 2. Remove the pod finalizer. +// +// 3. Remove the pod UID from the arrays while increasing the corresponding +// +// counter. +// +// # Old jobs might not be tracked using this field, in which case the field +// +// remains null. +// +// The structure is empty for finished jobs. +func (d *JobStatusDie) UncountedTerminatedPodsDie(fn func(d *UncountedTerminatedPodsDie)) *JobStatusDie { + return d.DieStamp(func(r *batchv1.JobStatus) { + d := UncountedTerminatedPodsBlank.DieImmutable(false).DieFeedPtr(r.UncountedTerminatedPods) + fn(d) + r.UncountedTerminatedPods = d.DieReleasePtr() + }) +} + // The latest available observations of an object's current state. When a Job // // fails, one of the conditions will have type "Failed" and status true. When diff --git a/apis/core/v1/binding.go b/apis/core/v1/binding.go index fe1c073..9d721ac 100644 --- a/apis/core/v1/binding.go +++ b/apis/core/v1/binding.go @@ -21,12 +21,5 @@ import ( ) // +die:object=true,apiVersion=v1,kind=Binding +// +die:field:name=Target,die=ObjectReferenceDie type _ = corev1.Binding - -func (d *BindingDie) TargetDie(fn func(d *ObjectReferenceDie)) *BindingDie { - return d.DieStamp(func(r *corev1.Binding) { - d := ObjectReferenceBlank.DieImmutable(false).DieFeed(r.Target) - fn(d) - r.Target = d.DieRelease() - }) -} diff --git a/apis/core/v1/common.go b/apis/core/v1/common.go index 9001c3a..396d3d7 100644 --- a/apis/core/v1/common.go +++ b/apis/core/v1/common.go @@ -36,16 +36,8 @@ type _ = corev1.TypedObjectReference type _ = corev1.SecretReference // +die +// +die:field:name=MatchLabelExpressions,die=TopologySelectorLabelRequirementDie,listType=atomic type _ = corev1.TopologySelectorTerm -func (d *TopologySelectorTermDie) MatchLabelExpressionsDie(requirements ...*TopologySelectorLabelRequirementDie) *TopologySelectorTermDie { - return d.DieStamp(func(r *corev1.TopologySelectorTerm) { - r.MatchLabelExpressions = make([]corev1.TopologySelectorLabelRequirement, len(requirements)) - for i := range requirements { - r.MatchLabelExpressions[i] = requirements[i].DieRelease() - } - }) -} - // +die type _ = corev1.TopologySelectorLabelRequirement diff --git a/apis/core/v1/container.go b/apis/core/v1/container.go index 490a93e..23ee471 100644 --- a/apis/core/v1/container.go +++ b/apis/core/v1/container.go @@ -21,172 +21,28 @@ import ( ) // +die +// +die:field:name=Resources,die=ResourceRequirementsDie +// +die:field:name=LivenessProbe,die=ProbeDie,pointer=true +// +die:field:name=ReadinessProbe,die=ProbeDie,pointer=true +// +die:field:name=StartupProbe,die=ProbeDie,pointer=true +// +die:field:name=Lifecycle,die=LifecycleDie,pointer=true +// +die:field:name=SecurityContext,die=SecurityContextDie,pointer=true +// +die:field:name=Ports,die=ContainerPortDie,listType=atomic +// +die:field:name=EnvFrom,die=EnvFromSourceDie,listType=map,listMapKey=Prefix +// +die:field:name=Env,die=EnvVarDie,listType=map +// +die:field:name=ResizePolicy,die=ContainerResizePolicyDie,listType=map,listMapKey=ResourceName,listMapKeyPackage=k8s.io/api/core/v1,listMapKeyType=ResourceName +// +die:field:name=VolumeMounts,die=VolumeMountDie,listType=map +// +die:field:name=VolumeDevices,die=VolumeDeviceDie,listType=map type _ = corev1.Container -func (d *ContainerDie) PortsDie(ports ...*ContainerPortDie) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - r.Ports = make([]corev1.ContainerPort, len(ports)) - for i := range ports { - r.Ports[i] = ports[i].DieRelease() - } - }) -} - -func (d *ContainerDie) EnvFromDie(prefix string, fn func(d *EnvFromSourceDie)) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - for i := range r.EnvFrom { - if prefix == r.EnvFrom[i].Prefix { - d := EnvFromSourceBlank.DieImmutable(false).DieFeed(r.EnvFrom[i]) - fn(d) - r.EnvFrom[i] = d.DieRelease() - return - } - } - - d := EnvFromSourceBlank.DieImmutable(false).DieFeed(corev1.EnvFromSource{Prefix: prefix}) - fn(d) - r.EnvFrom = append(r.EnvFrom, d.DieRelease()) - }) -} - -func (d *ContainerDie) EnvDie(name string, fn func(d *EnvVarDie)) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - for i := range r.Env { - if name == r.Env[i].Name { - d := EnvVarBlank.DieImmutable(false).DieFeed(r.Env[i]) - fn(d) - r.Env[i] = d.DieRelease() - return - } - } - - d := EnvVarBlank.DieImmutable(false).DieFeed(corev1.EnvVar{Name: name}) - fn(d) - r.Env = append(r.Env, d.DieRelease()) - }) -} - -func (d *ContainerDie) ResourcesDie(fn func(d *ResourceRequirementsDie)) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - d := ResourceRequirementsBlank.DieImmutable(false).DieFeed(r.Resources) - fn(d) - r.Resources = d.DieRelease() - }) -} - -func (d *ContainerDie) ResizePolicyDie(name corev1.ResourceName, fn func(d *ContainerResizePolicyDie)) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - for i := range r.ResizePolicy { - if name == r.ResizePolicy[i].ResourceName { - d := ContainerResizePolicyBlank.DieImmutable(false).DieFeed(r.ResizePolicy[i]) - fn(d) - r.ResizePolicy[i] = d.DieRelease() - return - } - } - - d := ContainerResizePolicyBlank.DieImmutable(false).DieFeed(corev1.ContainerResizePolicy{ResourceName: name}) - fn(d) - r.ResizePolicy = append(r.ResizePolicy, d.DieRelease()) - }) -} - -func (d *ContainerDie) VolumeMountDie(name string, fn func(d *VolumeMountDie)) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - for i := range r.VolumeMounts { - if name == r.VolumeMounts[i].Name { - d := VolumeMountBlank.DieImmutable(false).DieFeed(r.VolumeMounts[i]) - fn(d) - r.VolumeMounts[i] = d.DieRelease() - return - } - } - - d := VolumeMountBlank.DieImmutable(false).DieFeed(corev1.VolumeMount{Name: name}) - fn(d) - r.VolumeMounts = append(r.VolumeMounts, d.DieRelease()) - }) -} - -func (d *ContainerDie) VolumeDeviceDie(name string, fn func(d *VolumeDeviceDie)) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - for i := range r.VolumeDevices { - if name == r.VolumeDevices[i].Name { - d := VolumeDeviceBlank.DieImmutable(false).DieFeed(r.VolumeDevices[i]) - fn(d) - r.VolumeDevices[i] = d.DieRelease() - return - } - } - - d := VolumeDeviceBlank.DieImmutable(false).DieFeed(corev1.VolumeDevice{Name: name}) - fn(d) - r.VolumeDevices = append(r.VolumeDevices, d.DieRelease()) - }) -} - -func (d *ContainerDie) LivenessProbeDie(fn func(d *ProbeDie)) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - d := ProbeBlank.DieImmutable(false).DieFeedPtr(r.LivenessProbe) - fn(d) - r.LivenessProbe = d.DieReleasePtr() - }) -} - -func (d *ContainerDie) ReadinessProbeDie(fn func(d *ProbeDie)) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - d := ProbeBlank.DieImmutable(false).DieFeedPtr(r.ReadinessProbe) - fn(d) - r.ReadinessProbe = d.DieReleasePtr() - }) -} - -func (d *ContainerDie) StartupProbeDie(fn func(d *ProbeDie)) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - d := ProbeBlank.DieImmutable(false).DieFeedPtr(r.StartupProbe) - fn(d) - r.StartupProbe = d.DieReleasePtr() - }) -} - -func (d *ContainerDie) LifecycleDie(fn func(d *LifecycleDie)) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - d := LifecycleBlank.DieImmutable(false).DieFeedPtr(r.Lifecycle) - fn(d) - r.Lifecycle = d.DieReleasePtr() - }) -} - -func (d *ContainerDie) SecurityContextDie(fn func(d *SecurityContextDie)) *ContainerDie { - return d.DieStamp(func(r *corev1.Container) { - d := SecurityContextBlank.DieImmutable(false).DieFeedPtr(r.SecurityContext) - fn(d) - r.SecurityContext = d.DieReleasePtr() - }) -} - // +die type _ = corev1.ContainerPort // +die +// +die:field:name=ConfigMapRef,die=ConfigMapEnvSourceDie,pointer=true +// +die:field:name=SecretRef,die=SecretEnvSourceDie,pointer=true type _ = corev1.EnvFromSource -func (d *EnvFromSourceDie) ConfigMapRefDie(fn func(d *ConfigMapEnvSourceDie)) *EnvFromSourceDie { - return d.DieStamp(func(r *corev1.EnvFromSource) { - d := ConfigMapEnvSourceBlank.DieImmutable(false).DieFeedPtr(r.ConfigMapRef) - fn(d) - r.ConfigMapRef = d.DieReleasePtr() - }) -} - -func (d *EnvFromSourceDie) SecretRefDie(fn func(d *SecretEnvSourceDie)) *EnvFromSourceDie { - return d.DieStamp(func(r *corev1.EnvFromSource) { - d := SecretEnvSourceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die type _ = corev1.ConfigMapEnvSource @@ -206,51 +62,16 @@ func (d *SecretEnvSourceDie) Name(v string) *SecretEnvSourceDie { } // +die +// +die:field:name=ValueFrom,die=EnvVarSourceDie,pointer=true type _ = corev1.EnvVar -func (d *EnvVarDie) ValueFromDie(fn func(d *EnvVarSourceDie)) *EnvVarDie { - return d.DieStamp(func(r *corev1.EnvVar) { - d := EnvVarSourceBlank.DieImmutable(false).DieFeedPtr(r.ValueFrom) - fn(d) - r.ValueFrom = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=FieldRef,die=ObjectFieldSelectorDie,pointer=true +// +die:field:name=ResourceFieldRef,die=ResourceFieldSelectorDie,pointer=true +// +die:field:name=ConfigMapKeyRef,die=ConfigMapKeySelectorDie,pointer=true +// +die:field:name=SecretKeyRef,die=SecretKeySelectorDie,pointer=true type _ = corev1.EnvVarSource -func (d *EnvVarSourceDie) FieldRefDie(fn func(d *ObjectFieldSelectorDie)) *EnvVarSourceDie { - return d.DieStamp(func(r *corev1.EnvVarSource) { - d := ObjectFieldSelectorBlank.DieImmutable(false).DieFeedPtr(r.FieldRef) - fn(d) - r.FieldRef = d.DieReleasePtr() - }) -} - -func (d *EnvVarSourceDie) ResourceFieldRefDie(fn func(d *ResourceFieldSelectorDie)) *EnvVarSourceDie { - return d.DieStamp(func(r *corev1.EnvVarSource) { - d := ResourceFieldSelectorBlank.DieImmutable(false).DieFeedPtr(r.ResourceFieldRef) - fn(d) - r.ResourceFieldRef = d.DieReleasePtr() - }) -} - -func (d *EnvVarSourceDie) ConfigMapKeyRefDie(fn func(d *ConfigMapKeySelectorDie)) *EnvVarSourceDie { - return d.DieStamp(func(r *corev1.EnvVarSource) { - d := ConfigMapKeySelectorBlank.DieImmutable(false).DieFeedPtr(r.ConfigMapKeyRef) - fn(d) - r.ConfigMapKeyRef = d.DieReleasePtr() - }) -} - -func (d *EnvVarSourceDie) SecretKeyRefDie(fn func(d *SecretKeySelectorDie)) *EnvVarSourceDie { - return d.DieStamp(func(r *corev1.EnvVarSource) { - d := SecretKeySelectorBlank.DieImmutable(false).DieFeedPtr(r.SecretKeyRef) - fn(d) - r.SecretKeyRef = d.DieReleasePtr() - }) -} - // +die type _ = corev1.ObjectFieldSelector @@ -276,17 +97,10 @@ func (d *SecretKeySelectorDie) Name(v string) *SecretKeySelectorDie { } // +die +// +die:field:name=Claims,die=ResourceClaimDie,listType=atomic +// +die:field:name=Claims,die=ResourceClaimDie,listType=map type _ = corev1.ResourceRequirements -func (d *ResourceRequirementsDie) ClaimsDie(claims ...*ResourceClaimDie) *ResourceRequirementsDie { - return d.DieStamp(func(r *corev1.ResourceRequirements) { - r.Claims = make([]corev1.ResourceClaim, len(claims)) - for i := range claims { - r.Claims[i] = claims[i].DieRelease() - } - }) -} - // +die type _ = corev1.ResourceClaim @@ -300,16 +114,9 @@ type _ = corev1.VolumeMount type _ = corev1.VolumeDevice // +die +// +die:field:name=ProbeHandler,die=ProbeHandlerDie type _ = corev1.Probe -func (d *ProbeDie) ProbeHandlerDie(fn func(d *ProbeHandlerDie)) *ProbeDie { - return d.DieStamp(func(r *corev1.Probe) { - d := ProbeHandlerBlank.DieImmutable(false).DieFeed(r.ProbeHandler) - fn(d) - r.ProbeHandler = d.DieRelease() - }) -} - func (d *ProbeDie) ExecDie(fn func(d *ExecActionDie)) *ProbeDie { return d.DieStamp(func(r *corev1.Probe) { d := ExecActionBlank.DieImmutable(false).DieFeedPtr(r.Exec) @@ -341,109 +148,31 @@ func (d *ProbeDie) TCPSocketDie(fn func(d *TCPSocketActionDie)) *ProbeDie { } // +die +// +die:field:name=PostStart,die=LifecycleHandlerDie,pointer=true +// +die:field:name=PreStop,die=LifecycleHandlerDie,pointer=true type _ = corev1.Lifecycle -func (d *LifecycleDie) PostStartDie(fn func(d *LifecycleHandlerDie)) *LifecycleDie { - return d.DieStamp(func(r *corev1.Lifecycle) { - d := LifecycleHandlerBlank.DieImmutable(false).DieFeedPtr(r.PostStart) - fn(d) - r.PostStart = d.DieReleasePtr() - }) -} - -func (d *LifecycleDie) PreStopDie(fn func(d *LifecycleHandlerDie)) *LifecycleDie { - return d.DieStamp(func(r *corev1.Lifecycle) { - d := LifecycleHandlerBlank.DieImmutable(false).DieFeedPtr(r.PreStop) - fn(d) - r.PreStop = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Exec,die=ExecActionDie,pointer=true +// +die:field:name=HTTPGet,die=HTTPGetActionDie,pointer=true +// +die:field:name=TCPSocket,die=TCPSocketActionDie,pointer=true +// +die:field:name=Sleep,die=SleepActionDie,pointer=true type _ = corev1.LifecycleHandler -func (d *LifecycleHandlerDie) ExecDie(fn func(d *ExecActionDie)) *LifecycleHandlerDie { - return d.DieStamp(func(r *corev1.LifecycleHandler) { - d := ExecActionBlank.DieImmutable(false).DieFeedPtr(r.Exec) - fn(d) - r.Exec = d.DieReleasePtr() - }) -} - -func (d *LifecycleHandlerDie) HTTPGetDie(fn func(d *HTTPGetActionDie)) *LifecycleHandlerDie { - return d.DieStamp(func(r *corev1.LifecycleHandler) { - d := HTTPGetActionBlank.DieImmutable(false).DieFeedPtr(r.HTTPGet) - fn(d) - r.HTTPGet = d.DieReleasePtr() - }) -} - -func (d *LifecycleHandlerDie) TCPSocketDie(fn func(d *TCPSocketActionDie)) *LifecycleHandlerDie { - return d.DieStamp(func(r *corev1.LifecycleHandler) { - d := TCPSocketActionBlank.DieImmutable(false).DieFeedPtr(r.TCPSocket) - fn(d) - r.TCPSocket = d.DieReleasePtr() - }) -} - -func (d *LifecycleHandlerDie) SleepDie(fn func(d *SleepActionDie)) *LifecycleHandlerDie { - return d.DieStamp(func(r *corev1.LifecycleHandler) { - d := SleepActionBlank.DieImmutable(false).DieFeedPtr(r.Sleep) - fn(d) - r.Sleep = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Exec,die=ExecActionDie,pointer=true +// +die:field:name=HTTPGet,die=HTTPGetActionDie,pointer=true +// +die:field:name=TCPSocket,die=TCPSocketActionDie,pointer=true +// +die:field:name=GRPC,die=GRPCActionDie,pointer=true type _ = corev1.ProbeHandler -func (d *ProbeHandlerDie) ExecDie(fn func(d *ExecActionDie)) *ProbeHandlerDie { - return d.DieStamp(func(r *corev1.ProbeHandler) { - d := ExecActionBlank.DieImmutable(false).DieFeedPtr(r.Exec) - fn(d) - r.Exec = d.DieReleasePtr() - }) -} - -func (d *ProbeHandlerDie) HTTPGetDie(fn func(d *HTTPGetActionDie)) *ProbeHandlerDie { - return d.DieStamp(func(r *corev1.ProbeHandler) { - d := HTTPGetActionBlank.DieImmutable(false).DieFeedPtr(r.HTTPGet) - fn(d) - r.HTTPGet = d.DieReleasePtr() - }) -} - -func (d *ProbeHandlerDie) TCPSocketDie(fn func(d *TCPSocketActionDie)) *ProbeHandlerDie { - return d.DieStamp(func(r *corev1.ProbeHandler) { - d := TCPSocketActionBlank.DieImmutable(false).DieFeedPtr(r.TCPSocket) - fn(d) - r.TCPSocket = d.DieReleasePtr() - }) -} - -func (d *ProbeHandlerDie) GRPCDie(fn func(d *GRPCActionDie)) *ProbeHandlerDie { - return d.DieStamp(func(r *corev1.ProbeHandler) { - d := GRPCActionBlank.DieImmutable(false).DieFeedPtr(r.GRPC) - fn(d) - r.GRPC = d.DieReleasePtr() - }) -} - // +die type _ = corev1.ExecAction // +die +// +die:field:name=HTTPHeaders,die=HTTPHeaderDie,listType=atomic type _ = corev1.HTTPGetAction -func (d *HTTPGetActionDie) HTTPHeadersDie(headers ...*HTTPHeaderDie) *HTTPGetActionDie { - return d.DieStamp(func(r *corev1.HTTPGetAction) { - r.HTTPHeaders = make([]corev1.HTTPHeader, len(headers)) - for i := range headers { - r.HTTPHeaders[i] = headers[i].DieRelease() - } - }) -} - // +die type _ = corev1.HTTPHeader @@ -457,48 +186,13 @@ type _ = corev1.GRPCAction type _ = corev1.SleepAction // +die +// +die:field:name=Capabilities,die=CapabilitiesDie,pointer=true +// +die:field:name=SELinuxOptions,die=SELinuxOptionsDie,pointer=true +// +die:field:name=WindowsOptions,die=WindowsSecurityContextOptionsDie,pointer=true +// +die:field:name=SeccompProfile,die=SeccompProfileDie,pointer=true +// +die:field:name=AppArmorProfile,die=AppArmorProfileDie,pointer=true type _ = corev1.SecurityContext -func (d *SecurityContextDie) CapabilitiesDie(fn func(d *CapabilitiesDie)) *SecurityContextDie { - return d.DieStamp(func(r *corev1.SecurityContext) { - d := CapabilitiesBlank.DieImmutable(false).DieFeedPtr(r.Capabilities) - fn(d) - r.Capabilities = d.DieReleasePtr() - }) -} - -func (d *SecurityContextDie) SELinuxOptionsDie(fn func(d *SELinuxOptionsDie)) *SecurityContextDie { - return d.DieStamp(func(r *corev1.SecurityContext) { - d := SELinuxOptionsBlank.DieImmutable(false).DieFeedPtr(r.SELinuxOptions) - fn(d) - r.SELinuxOptions = d.DieReleasePtr() - }) -} - -func (d *SecurityContextDie) WindowsOptionsDie(fn func(d *WindowsSecurityContextOptionsDie)) *SecurityContextDie { - return d.DieStamp(func(r *corev1.SecurityContext) { - d := WindowsSecurityContextOptionsBlank.DieImmutable(false).DieFeedPtr(r.WindowsOptions) - fn(d) - r.WindowsOptions = d.DieReleasePtr() - }) -} - -func (d *SecurityContextDie) SeccompProfileDie(fn func(d *SeccompProfileDie)) *SecurityContextDie { - return d.DieStamp(func(r *corev1.SecurityContext) { - d := SeccompProfileBlank.DieImmutable(false).DieFeedPtr(r.SeccompProfile) - fn(d) - r.SeccompProfile = d.DieReleasePtr() - }) -} - -func (d *SecurityContextDie) AppArmorProfileDie(fn func(d *AppArmorProfileDie)) *SecurityContextDie { - return d.DieStamp(func(r *corev1.SecurityContext) { - d := AppArmorProfileBlank.DieImmutable(false).DieFeedPtr(r.AppArmorProfile) - fn(d) - r.AppArmorProfile = d.DieReleasePtr() - }) -} - // +die type _ = corev1.Capabilities @@ -515,76 +209,18 @@ type _ = corev1.SeccompProfile type _ = corev1.AppArmorProfile // +die +// +die:field:name=State,die=ContainerStateDie +// +die:field:name=LastTerminationState,die=ContainerStateDie +// +die:field:name=Resources,die=ResourceRequirementsDie,pointer=true +// +die:field:name=VolumeMounts,die=VolumeMountStatusDie,listType=map type _ = corev1.ContainerStatus -func (d *ContainerStatusDie) StateDie(fn func(d *ContainerStateDie)) *ContainerStatusDie { - return d.DieStamp(func(r *corev1.ContainerStatus) { - d := ContainerStateBlank.DieImmutable(false).DieFeed(r.State) - fn(d) - r.State = d.DieRelease() - }) -} - -func (d *ContainerStatusDie) LastTerminationStateDie(fn func(d *ContainerStateDie)) *ContainerStatusDie { - return d.DieStamp(func(r *corev1.ContainerStatus) { - d := ContainerStateBlank.DieImmutable(false).DieFeed(r.LastTerminationState) - fn(d) - r.LastTerminationState = d.DieRelease() - }) -} - -func (d *ContainerStatusDie) ResourcesDie(fn func(d *ResourceRequirementsDie)) *ContainerStatusDie { - return d.DieStamp(func(r *corev1.ContainerStatus) { - d := ResourceRequirementsBlank.DieImmutable(false).DieFeedPtr(r.Resources) - fn(d) - r.Resources = d.DieReleasePtr() - }) -} - -func (d *ContainerStatusDie) VolumeMountDie(name string, fn func(d *VolumeMountStatusDie)) *ContainerStatusDie { - return d.DieStamp(func(r *corev1.ContainerStatus) { - for i := range r.VolumeMounts { - if name == r.VolumeMounts[i].Name { - d := VolumeMountStatusBlank.DieImmutable(false).DieFeed(r.VolumeMounts[i]) - fn(d) - r.VolumeMounts[i] = d.DieRelease() - return - } - } - - d := VolumeMountStatusBlank.DieImmutable(false).DieFeed(corev1.VolumeMountStatus{Name: name}) - fn(d) - r.VolumeMounts = append(r.VolumeMounts, d.DieRelease()) - }) -} - // +die +// +die:field:name=Waiting,die=ContainerStateWaitingDie,pointer=true +// +die:field:name=Running,die=ContainerStateRunningDie,pointer=true +// +die:field:name=Terminated,die=ContainerStateTerminatedDie,pointer=true type _ = corev1.ContainerState -func (d *ContainerStateDie) WaitingDie(fn func(d *ContainerStateWaitingDie)) *ContainerStateDie { - return d.DieStamp(func(r *corev1.ContainerState) { - d := ContainerStateWaitingBlank.DieImmutable(false).DieFeedPtr(r.Waiting) - fn(d) - r.Waiting = d.DieReleasePtr() - }) -} - -func (d *ContainerStateDie) RunningDie(fn func(d *ContainerStateRunningDie)) *ContainerStateDie { - return d.DieStamp(func(r *corev1.ContainerState) { - d := ContainerStateRunningBlank.DieImmutable(false).DieFeedPtr(r.Running) - fn(d) - r.Running = d.DieReleasePtr() - }) -} - -func (d *ContainerStateDie) TerminatedDie(fn func(d *ContainerStateTerminatedDie)) *ContainerStateDie { - return d.DieStamp(func(r *corev1.ContainerState) { - d := ContainerStateTerminatedBlank.DieImmutable(false).DieFeedPtr(r.Terminated) - fn(d) - r.Terminated = d.DieReleasePtr() - }) -} - // +die type _ = corev1.ContainerStateWaiting diff --git a/apis/core/v1/endpoints.go b/apis/core/v1/endpoints.go index 2e63891..1055cc9 100644 --- a/apis/core/v1/endpoints.go +++ b/apis/core/v1/endpoints.go @@ -21,57 +21,18 @@ import ( ) // +die:object=true,apiVersion=v1,kind=Endpoints +// +die:field:name=Subsets,die=EndpointSubsetDie,listType=atomic type _ = corev1.Endpoints -func (d *EndpointsDie) SubsetsDie(subsets ...*EndpointSubsetDie) *EndpointsDie { - return d.DieStamp(func(r *corev1.Endpoints) { - r.Subsets = make([]corev1.EndpointSubset, len(subsets)) - for i := range subsets { - r.Subsets[i] = subsets[i].DieRelease() - } - }) -} - // +die +// +die:field:name=Addresses,die=EndpointAddressDie,listType=atomic +// +die:field:name=NotReadyAddresses,die=EndpointAddressDie,listType=atomic +// +die:field:name=Ports,die=EndpointPortDie,listType=atomic type _ = corev1.EndpointSubset -func (d *EndpointSubsetDie) AddressesDie(addresses ...*EndpointAddressDie) *EndpointSubsetDie { - return d.DieStamp(func(r *corev1.EndpointSubset) { - r.Addresses = make([]corev1.EndpointAddress, len(addresses)) - for i := range addresses { - r.Addresses[i] = addresses[i].DieRelease() - } - }) -} - -func (d *EndpointSubsetDie) NotReadyAddressesDie(addresses ...*EndpointAddressDie) *EndpointSubsetDie { - return d.DieStamp(func(r *corev1.EndpointSubset) { - r.NotReadyAddresses = make([]corev1.EndpointAddress, len(addresses)) - for i := range addresses { - r.NotReadyAddresses[i] = addresses[i].DieRelease() - } - }) -} - -func (d *EndpointSubsetDie) PortsDie(ports ...*EndpointPortDie) *EndpointSubsetDie { - return d.DieStamp(func(r *corev1.EndpointSubset) { - r.Ports = make([]corev1.EndpointPort, len(ports)) - for i := range ports { - r.Ports[i] = ports[i].DieRelease() - } - }) -} - // +die +// +die:field:name=TargetRef,die=ObjectReferenceDie,pointer=true type _ = corev1.EndpointAddress -func (d *EndpointAddressDie) TargetRefDie(fn func(d *ObjectReferenceDie)) *EndpointAddressDie { - return d.DieStamp(func(r *corev1.EndpointAddress) { - d := ObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.TargetRef) - fn(d) - r.TargetRef = d.DieReleasePtr() - }) -} - // +die type _ = corev1.EndpointPort diff --git a/apis/core/v1/event.go b/apis/core/v1/event.go index 07bd614..06ceb88 100644 --- a/apis/core/v1/event.go +++ b/apis/core/v1/event.go @@ -21,40 +21,12 @@ import ( ) // +die:object=true,apiVersion=v1,kind=Event +// +die:field:name=InvolvedObject,die=ObjectReferenceDie +// +die:field:name=Source,die=EventSourceDie +// +die:field:name=Series,die=EventSeriesDie,pointer=true +// +die:field:name=Related,die=ObjectReferenceDie,pointer=true type _ = corev1.Event -func (d *EventDie) InvolvedObjectDie(fn func(d *ObjectReferenceDie)) *EventDie { - return d.DieStamp(func(r *corev1.Event) { - d := ObjectReferenceBlank.DieImmutable(false).DieFeed(r.InvolvedObject) - fn(d) - r.InvolvedObject = d.DieRelease() - }) -} - -func (d *EventDie) SourceDie(fn func(d *EventSourceDie)) *EventDie { - return d.DieStamp(func(r *corev1.Event) { - d := EventSourceBlank.DieImmutable(false).DieFeed(r.Source) - fn(d) - r.Source = d.DieRelease() - }) -} - -func (d *EventDie) SeriesDie(fn func(d *EventSeriesDie)) *EventDie { - return d.DieStamp(func(r *corev1.Event) { - d := EventSeriesBlank.DieImmutable(false).DieFeedPtr(r.Series) - fn(d) - r.Series = d.DieReleasePtr() - }) -} - -func (d *EventDie) RelatedDie(fn func(d *ObjectReferenceDie)) *EventDie { - return d.DieStamp(func(r *corev1.Event) { - d := ObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.Related) - fn(d) - r.Related = d.DieReleasePtr() - }) -} - // +die type _ = corev1.EventSource diff --git a/apis/core/v1/limitrange.go b/apis/core/v1/limitrange.go index dad415f..4504373 100644 --- a/apis/core/v1/limitrange.go +++ b/apis/core/v1/limitrange.go @@ -24,16 +24,8 @@ import ( type _ = corev1.LimitRange // +die +// +die:field:name=Limits,die=LimitRangeItemDie,listType=atomic type _ = corev1.LimitRangeSpec -func (d *LimitRangeSpecDie) LimitsDie(limits ...*LimitRangeItemDie) *LimitRangeSpecDie { - return d.DieStamp(func(r *corev1.LimitRangeSpec) { - r.Limits = make([]corev1.LimitRangeItem, len(limits)) - for i := range r.Limits { - r.Limits[i] = limits[i].DieRelease() - } - }) -} - // +die type _ = corev1.LimitRangeItem diff --git a/apis/core/v1/node.go b/apis/core/v1/node.go index 3d6de22..901c595 100644 --- a/apis/core/v1/node.go +++ b/apis/core/v1/node.go @@ -25,51 +25,28 @@ import ( type _ = corev1.Node // +die +// +die:field:name=ConfigSource,die=NodeConfigSourceDie,pointer=true +// +die:field:name=Taints,die=TaintDie,listType=map,listMapKey=Key type _ = corev1.NodeSpec -func (d *NodeSpecDie) TaintDie(key string, fn func(d *TaintDie)) *NodeSpecDie { - return d.DieStamp(func(r *corev1.NodeSpec) { - for i := range r.Taints { - if key == r.Taints[i].Key { - d := TaintBlank.DieImmutable(false).DieFeed(r.Taints[i]) - fn(d) - r.Taints[i] = d.DieRelease() - return - } - } - - d := TaintBlank.DieImmutable(false).DieFeed(corev1.Taint{Key: key}) - fn(d) - r.Taints = append(r.Taints, d.DieRelease()) - }) -} - -func (d *NodeSpecDie) ConfigSourceDie(fn func(d *NodeConfigSourceDie)) *NodeSpecDie { - return d.DieStamp(func(r *corev1.NodeSpec) { - d := NodeConfigSourceBlank.DieImmutable(false).DieFeedPtr(r.ConfigSource) - fn(d) - r.ConfigSource = d.DieReleasePtr() - }) -} - // +die type _ = corev1.Taint // +die +// +die:field:name=ConfigMap,die=ConfigMapNodeConfigSourceDie,pointer=true type _ = corev1.NodeConfigSource -func (d *NodeConfigSourceDie) ConfigMapDie(fn func(d *ConfigMapNodeConfigSourceDie)) *NodeConfigSourceDie { - return d.DieStamp(func(r *corev1.NodeConfigSource) { - d := ConfigMapNodeConfigSourceBlank.DieImmutable(false).DieFeedPtr(r.ConfigMap) - fn(d) - r.ConfigMap = d.DieReleasePtr() - }) -} - // +die type _ = corev1.ConfigMapNodeConfigSource // +die +// +die:field:name=DaemonEndpoints,die=NodeDaemonEndpointsDie +// +die:field:name=NodeInfo,die=NodeSystemInfoDie +// +die:field:name=Config,die=NodeConfigStatusDie,pointer=true +// +die:field:name=Addresses,die=NodeAddressDie,listType=atomic +// +die:field:name=Images,die=ContainerImageDie,listType=atomic +// +die:field:name=VolumesAttached,method=VolumeAttachedDie,die=AttachedVolumeDie,listType=map,listMapKeyPackage=k8s.io/api/core/v1,listMapKeyType=UniqueVolumeName +// +die:field:name=RuntimeHandlers,die=NodeRuntimeHandlerDie,listType=atomic type _ = corev1.NodeStatus func (d *NodeStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *NodeStatusDie { @@ -88,88 +65,18 @@ func (d *NodeStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *No }) } +// deprecated: use AddressesDie func (d *NodeStatusDie) AddresssDie(addresses ...*NodeAddressDie) *NodeStatusDie { - return d.DieStamp(func(r *corev1.NodeStatus) { - r.Addresses = make([]corev1.NodeAddress, len(addresses)) - for i := range addresses { - r.Addresses[i] = addresses[i].DieRelease() - } - }) -} - -func (d *NodeStatusDie) DaemonEndpointsDie(fn func(d *NodeDaemonEndpointsDie)) *NodeStatusDie { - return d.DieStamp(func(r *corev1.NodeStatus) { - d := NodeDaemonEndpointsBlank.DieImmutable(false).DieFeed(r.DaemonEndpoints) - fn(d) - r.DaemonEndpoints = d.DieRelease() - }) -} - -func (d *NodeStatusDie) NodeInfoDie(fn func(d *NodeSystemInfoDie)) *NodeStatusDie { - return d.DieStamp(func(r *corev1.NodeStatus) { - d := NodeSystemInfoBlank.DieImmutable(false).DieFeed(r.NodeInfo) - fn(d) - r.NodeInfo = d.DieRelease() - }) -} - -func (d *NodeStatusDie) ImagesDie(images ...*ContainerImageDie) *NodeStatusDie { - return d.DieStamp(func(r *corev1.NodeStatus) { - r.Images = make([]corev1.ContainerImage, len(images)) - for i := range images { - r.Images[i] = images[i].DieRelease() - } - }) -} - -func (d *NodeStatusDie) VolumeAttachedDie(name corev1.UniqueVolumeName, fn func(d *AttachedVolumeDie)) *NodeStatusDie { - return d.DieStamp(func(r *corev1.NodeStatus) { - for i := range r.VolumesAttached { - if name == r.VolumesAttached[i].Name { - d := AttachedVolumeBlank.DieImmutable(false).DieFeed(r.VolumesAttached[i]) - fn(d) - r.VolumesAttached[i] = d.DieRelease() - return - } - } - - d := AttachedVolumeBlank.DieImmutable(false).DieFeed(corev1.AttachedVolume{Name: name}) - fn(d) - r.VolumesAttached = append(r.VolumesAttached, d.DieRelease()) - }) -} - -func (d *NodeStatusDie) ConfigDie(fn func(d *NodeConfigStatusDie)) *NodeStatusDie { - return d.DieStamp(func(r *corev1.NodeStatus) { - d := NodeConfigStatusBlank.DieImmutable(false).DieFeedPtr(r.Config) - fn(d) - r.Config = d.DieReleasePtr() - }) -} - -func (d *NodeStatusDie) RuntimeHandlersDie(handlers ...*NodeRuntimeHandlerDie) *NodeStatusDie { - return d.DieStamp(func(r *corev1.NodeStatus) { - r.RuntimeHandlers = make([]corev1.NodeRuntimeHandler, len(handlers)) - for i := range handlers { - r.RuntimeHandlers[i] = handlers[i].DieRelease() - } - }) + return d.AddressesDie(addresses...) } // +die type _ = corev1.NodeAddress // +die +// +die:field:name=KubeletEndpoint,die=DaemonEndpointDie type _ = corev1.NodeDaemonEndpoints -func (d *NodeDaemonEndpointsDie) KubeletEndpointDie(fn func(d *DaemonEndpointDie)) *NodeDaemonEndpointsDie { - return d.DieStamp(func(r *corev1.NodeDaemonEndpoints) { - d := DaemonEndpointBlank.DieImmutable(false).DieFeed(r.KubeletEndpoint) - fn(d) - r.KubeletEndpoint = d.DieRelease() - }) -} - // +die type _ = corev1.DaemonEndpoint @@ -183,42 +90,14 @@ type _ = corev1.ContainerImage type _ = corev1.AttachedVolume // +die +// +die:field:name=Assigned,die=NodeConfigSourceDie,pointer=true +// +die:field:name=Active,die=NodeConfigSourceDie,pointer=true +// +die:field:name=LastKnownGood,die=NodeConfigSourceDie,pointer=true type _ = corev1.NodeConfigStatus -func (d *NodeConfigStatusDie) AssignedDie(fn func(d *NodeConfigSourceDie)) *NodeConfigStatusDie { - return d.DieStamp(func(r *corev1.NodeConfigStatus) { - d := NodeConfigSourceBlank.DieImmutable(false).DieFeedPtr(r.Assigned) - fn(d) - r.Assigned = d.DieReleasePtr() - }) -} - -func (d *NodeConfigStatusDie) ActiveDie(fn func(d *NodeConfigSourceDie)) *NodeConfigStatusDie { - return d.DieStamp(func(r *corev1.NodeConfigStatus) { - d := NodeConfigSourceBlank.DieImmutable(false).DieFeedPtr(r.Active) - fn(d) - r.Active = d.DieReleasePtr() - }) -} - -func (d *NodeConfigStatusDie) LastKnownGoodDie(fn func(d *NodeConfigSourceDie)) *NodeConfigStatusDie { - return d.DieStamp(func(r *corev1.NodeConfigStatus) { - d := NodeConfigSourceBlank.DieImmutable(false).DieFeedPtr(r.LastKnownGood) - fn(d) - r.LastKnownGood = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Features,die=NodeRuntimeHandlerFeaturesDie,pointer=true type _ = corev1.NodeRuntimeHandler -func (d *NodeRuntimeHandlerDie) FeaturesDie(fn func(d *NodeRuntimeHandlerFeaturesDie)) *NodeRuntimeHandlerDie { - return d.DieStamp(func(r *corev1.NodeRuntimeHandler) { - d := NodeRuntimeHandlerFeaturesBlank.DieImmutable(false).DieFeedPtr(r.Features) - fn(d) - r.Features = d.DieReleasePtr() - }) -} - // +die type _ = corev1.NodeRuntimeHandlerFeatures diff --git a/apis/core/v1/persistantvolume.go b/apis/core/v1/persistantvolume.go index 109f293..b8a45c7 100644 --- a/apis/core/v1/persistantvolume.go +++ b/apis/core/v1/persistantvolume.go @@ -24,6 +24,7 @@ import ( type _ = corev1.PersistentVolume // +die +// +die:field:name=NodeAffinity,die=VolumeNodeAffinityDie,pointer=true type _ = corev1.PersistentVolumeSpec func (d *PersistentVolumeSpecDie) GCEPersistentDiskDie(fn func(d *GCEPersistentDiskVolumeSourceDie)) *PersistentVolumeSpecDie { @@ -254,14 +255,6 @@ func (d *PersistentVolumeSpecDie) ClaimRefDie(fn func(d *ObjectReferenceDie)) *P }) } -func (d *PersistentVolumeSpecDie) NodeAffinityDie(fn func(d *VolumeNodeAffinityDie)) *PersistentVolumeSpecDie { - return d.DieStamp(func(r *corev1.PersistentVolumeSpec) { - d := VolumeNodeAffinityBlank.DieImmutable(false).DieFeedPtr(r.NodeAffinity) - fn(d) - r.NodeAffinity = d.DieReleasePtr() - }) -} - // +die type _ = corev1.PersistentVolumeStatus @@ -269,89 +262,45 @@ type _ = corev1.PersistentVolumeStatus type _ = corev1.GlusterfsPersistentVolumeSource // +die +// +die:field:name=SecretRef,die=SecretReferenceDie,pointer=true type _ = corev1.RBDPersistentVolumeSource -func (d *RBDPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *RBDPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.RBDPersistentVolumeSource) { - d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=SecretRef,die=SecretReferenceDie,pointer=true type _ = corev1.ISCSIPersistentVolumeSource -func (d *ISCSIPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *ISCSIPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.ISCSIPersistentVolumeSource) { - d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=SecretRef,die=SecretReferenceDie,pointer=true type _ = corev1.CinderPersistentVolumeSource -func (d *CinderPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *CinderPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.CinderPersistentVolumeSource) { - d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=SecretRef,die=SecretReferenceDie,pointer=true type _ = corev1.CephFSPersistentVolumeSource -func (d *CephFSPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *CephFSPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.CephFSPersistentVolumeSource) { - d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=SecretRef,die=SecretReferenceDie,pointer=true type _ = corev1.FlexPersistentVolumeSource -func (d *FlexPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *FlexPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.FlexPersistentVolumeSource) { - d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die type _ = corev1.AzureFilePersistentVolumeSource // +die +// +die:field:name=SecretRef,die=SecretReferenceDie,pointer=true type _ = corev1.ScaleIOPersistentVolumeSource -func (d *ScaleIOPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *ScaleIOPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.ScaleIOPersistentVolumeSource) { - d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die type _ = corev1.LocalVolumeSource // +die +// +die:field:name=SecretRef,die=ObjectReferenceDie,pointer=true type _ = corev1.StorageOSPersistentVolumeSource -func (d *StorageOSPersistentVolumeSourceDie) SecretRefDie(fn func(d *ObjectReferenceDie)) *StorageOSPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.StorageOSPersistentVolumeSource) { - d := ObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=ControllerPublishSecretRef,die=SecretReferenceDie,pointer=true +// +die:field:name=NodeStageSecretRef,die=SecretReferenceDie,pointer=true +// +die:field:name=NodePublishSecretRef,die=SecretReferenceDie,pointer=true +// +die:field:name=ControllerExpandSecretRef,die=SecretReferenceDie,pointer=true +// +die:field:name=NodeExpandSecretRef,die=SecretReferenceDie,pointer=true type _ = corev1.CSIPersistentVolumeSource func (d *CSIPersistentVolumeSourceDie) AddVolumeAttributes(key, value string) *CSIPersistentVolumeSourceDie { @@ -363,104 +312,22 @@ func (d *CSIPersistentVolumeSourceDie) AddVolumeAttributes(key, value string) *C }) } -func (d *CSIPersistentVolumeSourceDie) ControllerPublishSecretRefDie(fn func(d *SecretReferenceDie)) *CSIPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.CSIPersistentVolumeSource) { - d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.ControllerPublishSecretRef) - fn(d) - r.ControllerPublishSecretRef = d.DieReleasePtr() - }) -} - -func (d *CSIPersistentVolumeSourceDie) NodeStageSecretRefDie(fn func(d *SecretReferenceDie)) *CSIPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.CSIPersistentVolumeSource) { - d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.NodeStageSecretRef) - fn(d) - r.NodeStageSecretRef = d.DieReleasePtr() - }) -} - -func (d *CSIPersistentVolumeSourceDie) NodePublishSecretRefDie(fn func(d *SecretReferenceDie)) *CSIPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.CSIPersistentVolumeSource) { - d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.NodePublishSecretRef) - fn(d) - r.NodePublishSecretRef = d.DieReleasePtr() - }) -} - -func (d *CSIPersistentVolumeSourceDie) ControllerExpandSecretRefDie(fn func(d *SecretReferenceDie)) *CSIPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.CSIPersistentVolumeSource) { - d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.ControllerExpandSecretRef) - fn(d) - r.ControllerExpandSecretRef = d.DieReleasePtr() - }) -} - -func (d *CSIPersistentVolumeSourceDie) NodeExpandSecretRefDie(fn func(d *SecretReferenceDie)) *CSIPersistentVolumeSourceDie { - return d.DieStamp(func(r *corev1.CSIPersistentVolumeSource) { - d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.NodeExpandSecretRef) - fn(d) - r.NodeExpandSecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Required,die=NodeSelectorDie,pointer=true type _ = corev1.VolumeNodeAffinity -func (d *VolumeNodeAffinityDie) RequiredDie(fn func(d *NodeSelectorDie)) *VolumeNodeAffinityDie { - return d.DieStamp(func(r *corev1.VolumeNodeAffinity) { - d := NodeSelectorBlank.DieImmutable(false).DieFeedPtr(r.Required) - fn(d) - r.Required = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=NodeSelectorTerms,die=NodeSelectorTermDie,listType=atomic type _ = corev1.NodeSelector -func (d *NodeSelectorDie) NodeSelectorTermsDie(terms ...*NodeSelectorTermDie) *NodeSelectorDie { - return d.DieStamp(func(r *corev1.NodeSelector) { - r.NodeSelectorTerms = make([]corev1.NodeSelectorTerm, len(terms)) - for i := range terms { - r.NodeSelectorTerms[i] = terms[i].DieRelease() - } - }) -} - // +die +// +die:field:name=MatchExpressions,die=NodeSelectorRequirementDie,listMapKey=Key +// +die:field:name=MatchFields,die=NodeSelectorRequirementDie,listMapKey=Key type _ = corev1.NodeSelectorTerm -func (d *NodeSelectorTermDie) MatchExpressionDie(key string, fn func(d *NodeSelectorRequirementDie)) *NodeSelectorTermDie { - return d.DieStamp(func(r *corev1.NodeSelectorTerm) { - for i := range r.MatchExpressions { - if key == r.MatchExpressions[i].Key { - d := NodeSelectorRequirementBlank.DieImmutable(false).DieFeed(r.MatchExpressions[i]) - fn(d) - r.MatchExpressions[i] = d.DieRelease() - return - } - } - - d := NodeSelectorRequirementBlank.DieImmutable(false).DieFeed(corev1.NodeSelectorRequirement{Key: key}) - fn(d) - r.MatchExpressions = append(r.MatchExpressions, d.DieRelease()) - }) -} - +// deprecated: use MatchFieldDie func (d *NodeSelectorTermDie) MatchFieldsDie(key string, fn func(d *NodeSelectorRequirementDie)) *NodeSelectorTermDie { - return d.DieStamp(func(r *corev1.NodeSelectorTerm) { - for i := range r.MatchFields { - if key == r.MatchFields[i].Key { - d := NodeSelectorRequirementBlank.DieImmutable(false).DieFeed(r.MatchFields[i]) - fn(d) - r.MatchFields[i] = d.DieRelease() - return - } - } - - d := NodeSelectorRequirementBlank.DieImmutable(false).DieFeed(corev1.NodeSelectorRequirement{Key: key}) - fn(d) - r.MatchFields = append(r.MatchFields, d.DieRelease()) - }) + return d.MatchFieldDie(key, fn) } // +die diff --git a/apis/core/v1/persistantvolumeclaim.go b/apis/core/v1/persistantvolumeclaim.go index 092d521..3168a62 100644 --- a/apis/core/v1/persistantvolumeclaim.go +++ b/apis/core/v1/persistantvolumeclaim.go @@ -25,44 +25,17 @@ import ( type _ = corev1.PersistentVolumeClaim // +die +// +die:field:name=Selector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=Resources,die=VolumeResourceRequirementsDie +// +die:field:name=DataSource,die=TypedLocalObjectReferenceDie,pointer=true +// +die:field:name=DataSourceRef,die=TypedObjectReferenceDie,pointer=true type _ = corev1.PersistentVolumeClaimSpec -func (d *PersistentVolumeClaimSpecDie) SelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *PersistentVolumeClaimSpecDie { - return d.DieStamp(func(r *corev1.PersistentVolumeClaimSpec) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) - fn(d) - r.Selector = d.DieReleasePtr() - }) -} - -func (d *PersistentVolumeClaimSpecDie) ResourcesDie(fn func(d *VolumeResourceRequirementsDie)) *PersistentVolumeClaimSpecDie { - return d.DieStamp(func(r *corev1.PersistentVolumeClaimSpec) { - d := VolumeResourceRequirementsBlank.DieImmutable(false).DieFeed(r.Resources) - fn(d) - r.Resources = d.DieRelease() - }) -} - -func (d *PersistentVolumeClaimSpecDie) DataSourceDie(fn func(d *TypedLocalObjectReferenceDie)) *PersistentVolumeClaimSpecDie { - return d.DieStamp(func(r *corev1.PersistentVolumeClaimSpec) { - d := TypedLocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.DataSource) - fn(d) - r.DataSource = d.DieReleasePtr() - }) -} - -func (d *PersistentVolumeClaimSpecDie) DataSourceRefDie(fn func(d *TypedObjectReferenceDie)) *PersistentVolumeClaimSpecDie { - return d.DieStamp(func(r *corev1.PersistentVolumeClaimSpec) { - d := TypedObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.DataSourceRef) - fn(d) - r.DataSourceRef = d.DieReleasePtr() - }) -} - // +die type _ = corev1.VolumeResourceRequirements // +die:ignore={AllocatedResourceStatuses} +// +die:field:name=ModifyVolumeStatus,die=ModifyVolumeStatusDie,pointer=true type _ = corev1.PersistentVolumeClaimStatus func (d *PersistentVolumeClaimStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *PersistentVolumeClaimStatusDie { @@ -134,32 +107,10 @@ func (d *PersistentVolumeClaimStatusDie) AddAllocatedResourceStatus(name corev1. }) } -func (d *PersistentVolumeClaimStatusDie) ModifyVolumeStatusDie(fn func(d *ModifyVolumeStatusDie)) *PersistentVolumeClaimStatusDie { - return d.DieStamp(func(r *corev1.PersistentVolumeClaimStatus) { - d := ModifyVolumeStatusBlank.DieImmutable(false).DieFeedPtr(r.ModifyVolumeStatus) - fn(d) - r.ModifyVolumeStatus = d.DieReleasePtr() - }) -} - // +die type _ corev1.ModifyVolumeStatus // +die +// +die:field:name=ObjectMeta,package=_/meta/v1,die=ObjectMetaDie +// +die:field:name=Spec,die=PersistentVolumeClaimSpecDie type _ corev1.PersistentVolumeClaimTemplate - -func (d *PersistentVolumeClaimTemplateDie) MetadataDie(fn func(d *diemetav1.ObjectMetaDie)) *PersistentVolumeClaimTemplateDie { - return d.DieStamp(func(r *corev1.PersistentVolumeClaimTemplate) { - d := diemetav1.ObjectMetaBlank.DieImmutable(false).DieFeed(r.ObjectMeta) - fn(d) - r.ObjectMeta = d.DieRelease() - }) -} - -func (d *PersistentVolumeClaimTemplateDie) SpecDie(fn func(d *PersistentVolumeClaimSpecDie)) *PersistentVolumeClaimTemplateDie { - return d.DieStamp(func(r *corev1.PersistentVolumeClaimTemplate) { - d := PersistentVolumeClaimSpecBlank.DieImmutable(false).DieFeed(r.Spec) - fn(d) - r.Spec = d.DieRelease() - }) -} diff --git a/apis/core/v1/pod.go b/apis/core/v1/pod.go index c164d41..6283e93 100644 --- a/apis/core/v1/pod.go +++ b/apis/core/v1/pod.go @@ -25,213 +25,38 @@ import ( type _ = corev1.Pod // +die +// +die:field:name=SecurityContext,die=PodSecurityContextDie,pointer=true +// +die:field:name=DNSConfig,die=PodDNSConfigDie,pointer=true +// +die:field:name=OS,die=PodOSDie,pointer=true +// +die:field:name=Volumes,die=VolumeDie,listType=map +// +die:field:name=InitContainers,die=ContainerDie,listType=map +// +die:field:name=Containers,die=ContainerDie,listType=map +// +die:field:name=Tolerations,die=TolerationDie,listMapKey=Key +// +die:field:name=HostAliases,die=HostAliasDie,listType=atomic +// +die:field:name=ReadinessGates,die=PodReadinessGateDie,listType=atomic +// +die:field:name=TopologySpreadConstraints,die=TopologySpreadConstraintDie,listMapKey=TopologyKey +// +die:field:name=SchedulingGates,die=PodSchedulingGateDie,listType=atomic +// +die:field:name=ResourceClaims,die=PodResourceClaimDie,listType=atomic type _ = corev1.PodSpec -func (d *PodSpecDie) VolumeDie(name string, fn func(d *VolumeDie)) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - for i := range r.Volumes { - if name == r.Volumes[i].Name { - d := VolumeBlank.DieImmutable(false).DieFeed(r.Volumes[i]) - fn(d) - r.Volumes[i] = d.DieRelease() - return - } - } - - d := VolumeBlank.DieImmutable(false).DieFeed(corev1.Volume{Name: name}) - fn(d) - r.Volumes = append(r.Volumes, d.DieRelease()) - }) -} - -func (d *PodSpecDie) InitContainerDie(name string, fn func(d *ContainerDie)) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - for i := range r.InitContainers { - if name == r.InitContainers[i].Name { - d := ContainerBlank.DieImmutable(false).DieFeed(r.InitContainers[i]) - fn(d) - r.InitContainers[i] = d.DieRelease() - return - } - } - - d := ContainerBlank.DieImmutable(false).DieFeed(corev1.Container{Name: name}) - fn(d) - r.InitContainers = append(r.InitContainers, d.DieRelease()) - }) -} - -func (d *PodSpecDie) ContainerDie(name string, fn func(d *ContainerDie)) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - for i := range r.Containers { - if name == r.Containers[i].Name { - d := ContainerBlank.DieImmutable(false).DieFeed(r.Containers[i]) - fn(d) - r.Containers[i] = d.DieRelease() - return - } - } - - d := ContainerBlank.DieImmutable(false).DieFeed(corev1.Container{Name: name}) - fn(d) - r.Containers = append(r.Containers, d.DieRelease()) - }) -} - -func (d *PodSpecDie) SecurityContextDie(fn func(d *PodSecurityContextDie)) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - d := PodSecurityContextBlank.DieImmutable(false).DieFeedPtr(r.SecurityContext) - fn(d) - r.SecurityContext = d.DieReleasePtr() - }) -} - -func (d *PodSpecDie) TolerationDie(key string, fn func(d *TolerationDie)) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - for i := range r.Tolerations { - if key == r.Tolerations[i].Key { - d := TolerationBlank.DieImmutable(false).DieFeed(r.Tolerations[i]) - fn(d) - r.Tolerations[i] = d.DieRelease() - return - } - } - - d := TolerationBlank.DieImmutable(false).DieFeed(corev1.Toleration{Key: key}) - fn(d) - r.Tolerations = append(r.Tolerations, d.DieRelease()) - }) -} - -func (d *PodSpecDie) HostAliasesDie(hosts ...*HostAliasDie) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - r.HostAliases = make([]corev1.HostAlias, len(hosts)) - for i := range hosts { - r.HostAliases[i] = hosts[i].DieRelease() - } - }) -} - -func (d *PodSpecDie) DNSConfigDie(fn func(d *PodDNSConfigDie)) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - d := PodDNSConfigBlank.DieImmutable(false).DieFeedPtr(r.DNSConfig) - fn(d) - r.DNSConfig = d.DieReleasePtr() - }) -} - -func (d *PodSpecDie) ReadinessGatesDie(gates ...*PodReadinessGateDie) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - r.ReadinessGates = make([]corev1.PodReadinessGate, len(gates)) - for i := range gates { - r.ReadinessGates[i] = gates[i].DieRelease() - } - }) -} - -func (d *PodSpecDie) TopologySpreadConstraintDie(topologyKey string, fn func(d *TopologySpreadConstraintDie)) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - for i := range r.TopologySpreadConstraints { - if topologyKey == r.TopologySpreadConstraints[i].TopologyKey { - d := TopologySpreadConstraintBlank.DieImmutable(false).DieFeed(r.TopologySpreadConstraints[i]) - fn(d) - r.TopologySpreadConstraints[i] = d.DieRelease() - return - } - } - - d := TopologySpreadConstraintBlank.DieImmutable(false).DieFeed(corev1.TopologySpreadConstraint{TopologyKey: topologyKey}) - fn(d) - r.TopologySpreadConstraints = append(r.TopologySpreadConstraints, d.DieRelease()) - }) -} - -func (d *PodSpecDie) OSDie(fn func(d *PodOSDie)) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - d := PodOSBlank.DieImmutable(false).DieFeedPtr(r.OS) - fn(d) - r.OS = d.DieReleasePtr() - }) -} - -func (d *PodSpecDie) SchedulingGatesDie(gates ...*PodSchedulingGateDie) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - r.SchedulingGates = make([]corev1.PodSchedulingGate, len(gates)) - for i := range gates { - r.SchedulingGates[i] = gates[i].DieRelease() - } - }) -} - -func (d *PodSpecDie) ResourceClaimsDie(gates ...*PodResourceClaimDie) *PodSpecDie { - return d.DieStamp(func(r *corev1.PodSpec) { - r.ResourceClaims = make([]corev1.PodResourceClaim, len(gates)) - for i := range gates { - r.ResourceClaims[i] = gates[i].DieRelease() - } - }) -} - // +die type _ = corev1.PodSchedulingGate // +die +// +die:field:name=Source,die=ClaimSourceDie type _ = corev1.PodResourceClaim -func (d *PodResourceClaimDie) SourceDie(fn func(d *ClaimSourceDie)) *PodResourceClaimDie { - return d.DieStamp(func(r *corev1.PodResourceClaim) { - d := ClaimSourceBlank.DieImmutable(false).DieFeed(r.Source) - fn(d) - r.Source = d.DieRelease() - }) -} - // +die type _ = corev1.ClaimSource // +die -type _ = corev1.PodSecurityContext - -func (d *PodSecurityContextDie) SELinuxOptionsDie(fn func(d *SELinuxOptionsDie)) *PodSecurityContextDie { - return d.DieStamp(func(r *corev1.PodSecurityContext) { - d := SELinuxOptionsBlank.DieImmutable(false).DieFeedPtr(r.SELinuxOptions) - fn(d) - r.SELinuxOptions = d.DieReleasePtr() - }) -} - -func (d *PodSecurityContextDie) WindowsOptionsDie(fn func(d *WindowsSecurityContextOptionsDie)) *PodSecurityContextDie { - return d.DieStamp(func(r *corev1.PodSecurityContext) { - d := WindowsSecurityContextOptionsBlank.DieImmutable(false).DieFeedPtr(r.WindowsOptions) - fn(d) - r.WindowsOptions = d.DieReleasePtr() - }) -} +// +die:field:name=SELinuxOptions,die=SELinuxOptionsDie,pointer=true +// +die:field:name=WindowsOptions,die=WindowsSecurityContextOptionsDie,pointer=true +// +die:field:name=AppArmorProfile,die=AppArmorProfileDie,pointer=true +// +die:field:name=Sysctls,die=SysctlDie,listType=atomic +// +die:field:name=SeccompProfile,die=SeccompProfileDie,pointer=true -func (d *PodSecurityContextDie) SysctlsDie(sysctls ...*SysctlDie) *PodSecurityContextDie { - return d.DieStamp(func(r *corev1.PodSecurityContext) { - r.Sysctls = make([]corev1.Sysctl, len(sysctls)) - for i := range sysctls { - r.Sysctls[i] = sysctls[i].DieRelease() - } - }) -} - -func (d *PodSecurityContextDie) SeccompProfileDie(fn func(d *SeccompProfileDie)) *PodSecurityContextDie { - return d.DieStamp(func(r *corev1.PodSecurityContext) { - d := SeccompProfileBlank.DieImmutable(false).DieFeedPtr(r.SeccompProfile) - fn(d) - r.SeccompProfile = d.DieReleasePtr() - }) -} - -func (d *PodSecurityContextDie) AppArmorProfileDie(fn func(d *AppArmorProfileDie)) *PodSecurityContextDie { - return d.DieStamp(func(r *corev1.PodSecurityContext) { - d := AppArmorProfileBlank.DieImmutable(false).DieFeedPtr(r.AppArmorProfile) - fn(d) - r.AppArmorProfile = d.DieReleasePtr() - }) -} +type _ = corev1.PodSecurityContext // +die type _ = corev1.Sysctl @@ -243,17 +68,9 @@ type _ = corev1.Toleration type _ = corev1.HostAlias // +die +// +die:field:name=Options,die=PodDNSConfigOptionDie,listType=atomic type _ = corev1.PodDNSConfig -func (d *PodDNSConfigDie) OptionsDie(options ...*PodDNSConfigOptionDie) *PodDNSConfigDie { - return d.DieStamp(func(r *corev1.PodDNSConfig) { - r.Options = make([]corev1.PodDNSConfigOption, len(options)) - for i := range options { - r.Options[i] = options[i].DieRelease() - } - }) -} - // +die type _ = corev1.PodDNSConfigOption @@ -261,20 +78,16 @@ type _ = corev1.PodDNSConfigOption type _ = corev1.PodReadinessGate // +die +// +die:field:name=LabelSelector,package=_/meta/v1,die=LabelSelectorDie,pointer=true type _ = corev1.TopologySpreadConstraint -func (d *TopologySpreadConstraintDie) LabelSelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *TopologySpreadConstraintDie { - return d.DieStamp(func(r *corev1.TopologySpreadConstraint) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.LabelSelector) - fn(d) - r.LabelSelector = d.DieReleasePtr() - }) -} - // +die type _ = corev1.PodOS // +die +// +die:field:name=InitContainerStatuses,method=InitContainerStatusDie,die=ContainerStatusDie,listType=map +// +die:field:name=ContainerStatuses,method=ContainerStatusDie,die=ContainerStatusDie,listType=map +// +die:field:name=EphemeralContainerStatuses,method=EphemeralContainerStatusDie,die=ContainerStatusDie,listType=map type _ = corev1.PodStatus func (d *PodStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *PodStatusDie { @@ -292,54 +105,3 @@ func (d *PodStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *Pod } }) } - -func (d *PodStatusDie) InitContainerStatusDie(name string, fn func(d *ContainerStatusDie)) *PodStatusDie { - return d.DieStamp(func(r *corev1.PodStatus) { - for i := range r.InitContainerStatuses { - if name == r.InitContainerStatuses[i].Name { - d := ContainerStatusBlank.DieImmutable(false).DieFeed(r.InitContainerStatuses[i]) - fn(d) - r.InitContainerStatuses[i] = d.DieRelease() - return - } - } - - d := ContainerStatusBlank.DieImmutable(false).DieFeed(corev1.ContainerStatus{Name: name}) - fn(d) - r.InitContainerStatuses = append(r.InitContainerStatuses, d.DieRelease()) - }) -} - -func (d *PodStatusDie) ContainerStatusDie(name string, fn func(d *ContainerStatusDie)) *PodStatusDie { - return d.DieStamp(func(r *corev1.PodStatus) { - for i := range r.ContainerStatuses { - if name == r.ContainerStatuses[i].Name { - d := ContainerStatusBlank.DieImmutable(false).DieFeed(r.ContainerStatuses[i]) - fn(d) - r.ContainerStatuses[i] = d.DieRelease() - return - } - } - - d := ContainerStatusBlank.DieImmutable(false).DieFeed(corev1.ContainerStatus{Name: name}) - fn(d) - r.ContainerStatuses = append(r.ContainerStatuses, d.DieRelease()) - }) -} - -func (d *PodStatusDie) EphemeralContainerStatusDie(name string, fn func(d *ContainerStatusDie)) *PodStatusDie { - return d.DieStamp(func(r *corev1.PodStatus) { - for i := range r.EphemeralContainerStatuses { - if name == r.EphemeralContainerStatuses[i].Name { - d := ContainerStatusBlank.DieImmutable(false).DieFeed(r.EphemeralContainerStatuses[i]) - fn(d) - r.EphemeralContainerStatuses[i] = d.DieRelease() - return - } - } - - d := ContainerStatusBlank.DieImmutable(false).DieFeed(corev1.ContainerStatus{Name: name}) - fn(d) - r.EphemeralContainerStatuses = append(r.EphemeralContainerStatuses, d.DieRelease()) - }) -} diff --git a/apis/core/v1/podtemplate.go b/apis/core/v1/podtemplate.go index ef65fbe..62c7c63 100644 --- a/apis/core/v1/podtemplate.go +++ b/apis/core/v1/podtemplate.go @@ -18,35 +18,13 @@ package v1 import ( corev1 "k8s.io/api/core/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die:object=true,spec=- +// +die:field:name=Template,die=PodTemplateSpecDie type _ = corev1.PodTemplate -func (d *PodTemplateDie) TemplateDie(fn func(d *PodTemplateSpecDie)) *PodTemplateDie { - return d.DieStamp(func(r *corev1.PodTemplate) { - d := PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) - fn(d) - r.Template = d.DieRelease() - }) -} - // +die +// +die:field:name=ObjectMeta,method=MetadataDie,package=_/meta/v1,die=ObjectMetaDie +// +die:field:name=Spec,die=PodSpecDie type _ = corev1.PodTemplateSpec - -func (d *PodTemplateSpecDie) MetadataDie(fn func(d *diemetav1.ObjectMetaDie)) *PodTemplateSpecDie { - return d.DieStamp(func(r *corev1.PodTemplateSpec) { - d := diemetav1.ObjectMetaBlank.DieImmutable(false).DieFeed(r.ObjectMeta) - fn(d) - r.ObjectMeta = d.DieRelease() - }) -} - -func (d *PodTemplateSpecDie) SpecDie(fn func(d *PodSpecDie)) *PodTemplateSpecDie { - return d.DieStamp(func(r *corev1.PodTemplateSpec) { - d := PodSpecBlank.DieImmutable(false).DieFeed(r.Spec) - fn(d) - r.Spec = d.DieRelease() - }) -} diff --git a/apis/core/v1/replicationcontroller.go b/apis/core/v1/replicationcontroller.go index 920802d..d76e621 100644 --- a/apis/core/v1/replicationcontroller.go +++ b/apis/core/v1/replicationcontroller.go @@ -25,16 +25,9 @@ import ( type _ = corev1.ReplicationController // +die +// +die:field:name=Template,die=PodTemplateSpecDie,pointer=true type _ = corev1.ReplicationControllerSpec -func (d *ReplicationControllerSpecDie) TemplateDie(fn func(d *PodTemplateSpecDie)) *ReplicationControllerSpecDie { - return d.DieStamp(func(r *corev1.ReplicationControllerSpec) { - d := PodTemplateSpecBlank.DieImmutable(false).DieFeedPtr(r.Template) - fn(d) - r.Template = d.DieReleasePtr() - }) -} - // +die type _ = corev1.ReplicationControllerStatus diff --git a/apis/core/v1/resourcequota.go b/apis/core/v1/resourcequota.go index c8e5e84..c345b96 100644 --- a/apis/core/v1/resourcequota.go +++ b/apis/core/v1/resourcequota.go @@ -24,36 +24,13 @@ import ( type _ = corev1.ResourceQuota // +die +// +die:field:name=ScopeSelector,die=ScopeSelectorDie,pointer=true type _ = corev1.ResourceQuotaSpec -func (d *ResourceQuotaSpecDie) ScopeSelectorDie(fn func(d *ScopeSelectorDie)) *ResourceQuotaSpecDie { - return d.DieStamp(func(r *corev1.ResourceQuotaSpec) { - d := ScopeSelectorBlank.DieImmutable(false).DieFeedPtr(r.ScopeSelector) - fn(d) - r.ScopeSelector = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=MatchExpressions,die=ScopedResourceSelectorRequirementDie,listType=map,listMapKey=ScopeName,listMapKeyPackage=k8s.io/api/core/v1,listMapKeyType=ResourceQuotaScope type _ = corev1.ScopeSelector -func (d *ScopeSelectorDie) MatchExpressionDie(scope corev1.ResourceQuotaScope, fn func(d *ScopedResourceSelectorRequirementDie)) *ScopeSelectorDie { - return d.DieStamp(func(r *corev1.ScopeSelector) { - for i := range r.MatchExpressions { - if scope == r.MatchExpressions[i].ScopeName { - d := ScopedResourceSelectorRequirementBlank.DieImmutable(false).DieFeed(r.MatchExpressions[i]) - fn(d) - r.MatchExpressions[i] = d.DieRelease() - return - } - } - - d := ScopedResourceSelectorRequirementBlank.DieImmutable(false).DieFeed(corev1.ScopedResourceSelectorRequirement{ScopeName: scope}) - fn(d) - r.MatchExpressions = append(r.MatchExpressions, d.DieRelease()) - }) -} - // +die type _ = corev1.ScopedResourceSelectorRequirement diff --git a/apis/core/v1/service.go b/apis/core/v1/service.go index 4cb6493..d3b2965 100644 --- a/apis/core/v1/service.go +++ b/apis/core/v1/service.go @@ -26,6 +26,7 @@ import ( type _ = corev1.Service // +die +// +die:field:name=SessionAffinityConfig,die=SessionAffinityConfigDie,pointer=true type _ = corev1.ServiceSpec func (d *ServiceSpecDie) PortDie(protocol corev1.Protocol, port int32, fn func(d *ServicePortDie)) *ServiceSpecDie { @@ -54,42 +55,20 @@ func (d *ServiceSpecDie) AddSelector(key, value string) *ServiceSpecDie { }) } -func (d *ServiceSpecDie) SessionAffinityConfigDie(fn func(d *SessionAffinityConfigDie)) *ServiceSpecDie { - return d.DieStamp(func(r *corev1.ServiceSpec) { - d := SessionAffinityConfigBlank.DieImmutable(false).DieFeedPtr(r.SessionAffinityConfig) - fn(d) - r.SessionAffinityConfig = d.DieReleasePtr() - }) -} - // +die type _ = corev1.ServicePort // +die +// +die:field:name=ClientIP,die=ClientIPConfigDie,pointer=true type _ = corev1.SessionAffinityConfig -func (d *SessionAffinityConfigDie) ClientIPDie(fn func(d *ClientIPConfigDie)) *SessionAffinityConfigDie { - return d.DieStamp(func(r *corev1.SessionAffinityConfig) { - d := ClientIPConfigBlank.DieImmutable(false).DieFeedPtr(r.ClientIP) - fn(d) - r.ClientIP = d.DieReleasePtr() - }) -} - // +die type _ = corev1.ClientIPConfig // +die +// +die:field:name=LoadBalancer,die=LoadBalancerStatusDie type _ = corev1.ServiceStatus -func (d *ServiceStatusDie) LoadBalancerDie(fn func(d *LoadBalancerStatusDie)) *ServiceStatusDie { - return d.DieStamp(func(r *corev1.ServiceStatus) { - d := LoadBalancerStatusBlank.DieImmutable(false).DieFeed(r.LoadBalancer) - fn(d) - r.LoadBalancer = d.DieRelease() - }) -} - func (d *ServiceStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *ServiceStatusDie { return d.DieStamp(func(r *corev1.ServiceStatus) { r.Conditions = make([]metav1.Condition, len(conditions)) @@ -100,28 +79,17 @@ func (d *ServiceStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) } // +die +// +die:field:name=Ingress,die=LoadBalancerIngressDie,listType=atomic type _ = corev1.LoadBalancerStatus +// deprecated: use IngressDie func (d *LoadBalancerStatusDie) LoadBalancerDie(ingress ...*LoadBalancerIngressDie) *LoadBalancerStatusDie { - return d.DieStamp(func(r *corev1.LoadBalancerStatus) { - r.Ingress = make([]corev1.LoadBalancerIngress, len(ingress)) - for i := range ingress { - r.Ingress[i] = ingress[i].DieRelease() - } - }) + return d.IngressDie(ingress...) } // +die +// +die:field:name=Ports,die=PortStatusDie,listType=atomic type _ = corev1.LoadBalancerIngress -func (d *LoadBalancerIngressDie) PortsDie(ports ...*PortStatusDie) *LoadBalancerIngressDie { - return d.DieStamp(func(r *corev1.LoadBalancerIngress) { - r.Ports = make([]corev1.PortStatus, len(ports)) - for i := range ports { - r.Ports[i] = ports[i].DieRelease() - } - }) -} - // +die type _ = corev1.PortStatus diff --git a/apis/core/v1/serviceaccount.go b/apis/core/v1/serviceaccount.go index 6683ae7..24ad4db 100644 --- a/apis/core/v1/serviceaccount.go +++ b/apis/core/v1/serviceaccount.go @@ -21,22 +21,6 @@ import ( ) // +die:object=true,apiVersion=v1,kind=ServiceAccount +// +die:field:name=Secrets,die=ObjectReferenceDie,listType=atomic +// +die:field:name=ImagePullSecrets,die=LocalObjectReferenceDie,listType=atomic type _ = corev1.ServiceAccount - -func (d *ServiceAccountDie) SecretsDie(secrets ...*ObjectReferenceDie) *ServiceAccountDie { - return d.DieStamp(func(r *corev1.ServiceAccount) { - r.Secrets = make([]corev1.ObjectReference, len(secrets)) - for i := range secrets { - r.Secrets[i] = secrets[i].DieRelease() - } - }) -} - -func (d *ServiceAccountDie) ImagePullSecretsDie(secrets ...*LocalObjectReferenceDie) *ServiceAccountDie { - return d.DieStamp(func(r *corev1.ServiceAccount) { - r.ImagePullSecrets = make([]corev1.LocalObjectReference, len(secrets)) - for i := range secrets { - r.ImagePullSecrets[i] = secrets[i].DieRelease() - } - }) -} diff --git a/apis/core/v1/volume.go b/apis/core/v1/volume.go index 9432e8c..4e561c0 100644 --- a/apis/core/v1/volume.go +++ b/apis/core/v1/volume.go @@ -18,7 +18,6 @@ package v1 import ( corev1 "k8s.io/api/core/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die @@ -330,39 +329,16 @@ type _ = corev1.AWSElasticBlockStoreVolumeSource type _ = corev1.GitRepoVolumeSource // +die +// +die:field:name=Items,die=KeyToPathDie,listMapKey=Key type _ = corev1.SecretVolumeSource -func (d *SecretVolumeSourceDie) ItemDie(key string, fn func(d *KeyToPathDie)) *SecretVolumeSourceDie { - return d.DieStamp(func(r *corev1.SecretVolumeSource) { - for i := range r.Items { - if key == r.Items[i].Key { - d := KeyToPathBlank.DieImmutable(false).DieFeed(r.Items[i]) - fn(d) - r.Items[i] = d.DieRelease() - return - } - } - - d := KeyToPathBlank.DieImmutable(false).DieFeed(corev1.KeyToPath{Key: key}) - fn(d) - r.Items = append(r.Items, d.DieRelease()) - }) -} - // +die type _ = corev1.NFSVolumeSource // +die +// +die:field:name=SecretRef,die=LocalObjectReferenceDie,pointer=true type _ = corev1.ISCSIVolumeSource -func (d *ISCSIVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *ISCSIVolumeSourceDie { - return d.DieStamp(func(r *corev1.ISCSIVolumeSource) { - d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die type _ = corev1.GlusterfsVolumeSource @@ -370,91 +346,33 @@ type _ = corev1.GlusterfsVolumeSource type _ = corev1.PersistentVolumeClaimVolumeSource // +die +// +die:field:name=SecretRef,die=LocalObjectReferenceDie,pointer=true type _ = corev1.RBDVolumeSource -func (d *RBDVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *RBDVolumeSourceDie { - return d.DieStamp(func(r *corev1.RBDVolumeSource) { - d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=SecretRef,die=LocalObjectReferenceDie,pointer=true type _ = corev1.FlexVolumeSource -func (d *FlexVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *FlexVolumeSourceDie { - return d.DieStamp(func(r *corev1.FlexVolumeSource) { - d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=SecretRef,die=LocalObjectReferenceDie,pointer=true type _ = corev1.CinderVolumeSource -func (d *CinderVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *CinderVolumeSourceDie { - return d.DieStamp(func(r *corev1.CinderVolumeSource) { - d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=SecretRef,die=LocalObjectReferenceDie,pointer=true type _ = corev1.CephFSVolumeSource -func (d *CephFSVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *CephFSVolumeSourceDie { - return d.DieStamp(func(r *corev1.CephFSVolumeSource) { - d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die type _ = corev1.FlockerVolumeSource // +die +// +die:field:name=Items,die=DownwardAPIVolumeFileDie,listMapKey=Path type _ = corev1.DownwardAPIVolumeSource -func (d *DownwardAPIVolumeSourceDie) ItemDie(path string, fn func(d *DownwardAPIVolumeFileDie)) *DownwardAPIVolumeSourceDie { - return d.DieStamp(func(r *corev1.DownwardAPIVolumeSource) { - for i := range r.Items { - if path == r.Items[i].Path { - d := DownwardAPIVolumeFileBlank.DieImmutable(false).DieFeed(r.Items[i]) - fn(d) - r.Items[i] = d.DieRelease() - return - } - } - - d := DownwardAPIVolumeFileBlank.DieImmutable(false).DieFeed(corev1.DownwardAPIVolumeFile{Path: path}) - fn(d) - r.Items = append(r.Items, d.DieRelease()) - }) -} - // +die +// +die:field:name=FieldRef,die=ObjectFieldSelectorDie,pointer=true +// +die:field:name=ResourceFieldRef,die=ResourceFieldSelectorDie,pointer=true type _ = corev1.DownwardAPIVolumeFile -func (d *DownwardAPIVolumeFileDie) FieldRefDie(fn func(d *ObjectFieldSelectorDie)) *DownwardAPIVolumeFileDie { - return d.DieStamp(func(r *corev1.DownwardAPIVolumeFile) { - d := ObjectFieldSelectorBlank.DieImmutable(false).DieFeedPtr(r.FieldRef) - fn(d) - r.FieldRef = d.DieReleasePtr() - }) -} - -func (d *DownwardAPIVolumeFileDie) ResourceFieldRefDie(fn func(d *ResourceFieldSelectorDie)) *DownwardAPIVolumeFileDie { - return d.DieStamp(func(r *corev1.DownwardAPIVolumeFile) { - d := ResourceFieldSelectorBlank.DieImmutable(false).DieFeedPtr(r.ResourceFieldRef) - fn(d) - r.ResourceFieldRef = d.DieReleasePtr() - }) -} - // +die type _ = corev1.FCVolumeSource @@ -462,6 +380,7 @@ type _ = corev1.FCVolumeSource type _ = corev1.AzureFileVolumeSource // +die +// +die:field:name=Items,die=KeyToPathDie,listMapKey=Key type _ = corev1.ConfigMapVolumeSource func (d *ConfigMapVolumeSourceDie) Name(v string) *ConfigMapVolumeSourceDie { @@ -470,23 +389,6 @@ func (d *ConfigMapVolumeSourceDie) Name(v string) *ConfigMapVolumeSourceDie { }) } -func (d *ConfigMapVolumeSourceDie) ItemDie(key string, fn func(d *KeyToPathDie)) *ConfigMapVolumeSourceDie { - return d.DieStamp(func(r *corev1.ConfigMapVolumeSource) { - for i := range r.Items { - if key == r.Items[i].Key { - d := KeyToPathBlank.DieImmutable(false).DieFeed(r.Items[i]) - fn(d) - r.Items[i] = d.DieRelease() - return - } - } - - d := KeyToPathBlank.DieImmutable(false).DieFeed(corev1.KeyToPath{Key: key}) - fn(d) - r.Items = append(r.Items, d.DieRelease()) - }) -} - // +die type _ = corev1.VsphereVirtualDiskVolumeSource @@ -500,61 +402,19 @@ type _ = corev1.AzureDiskVolumeSource type _ = corev1.PhotonPersistentDiskVolumeSource // +die +// +die:field:name=Sources,die=VolumeProjectionDie,listType=atomic type _ = corev1.ProjectedVolumeSource -func (d *ProjectedVolumeSourceDie) SourcesDie(sources ...*VolumeProjectionDie) *ProjectedVolumeSourceDie { - return d.DieStamp(func(r *corev1.ProjectedVolumeSource) { - r.Sources = make([]corev1.VolumeProjection, len(sources)) - for i := range sources { - r.Sources[i] = sources[i].DieRelease() - } - }) -} - // +die +// +die:field:name=Secret,die=SecretProjectionDie,pointer=true +// +die:field:name=DownwardAPI,die=DownwardAPIProjectionDie,pointer=true +// +die:field:name=ConfigMap,die=ConfigMapProjectionDie,pointer=true +// +die:field:name=ServiceAccountToken,die=ServiceAccountTokenProjectionDie,pointer=true +// +die:field:name=ClusterTrustBundle,die=ClusterTrustBundleProjectionDie,pointer=true type _ = corev1.VolumeProjection -func (d *VolumeProjectionDie) SecretDie(fn func(d *SecretProjectionDie)) *VolumeProjectionDie { - return d.DieStamp(func(r *corev1.VolumeProjection) { - d := SecretProjectionBlank.DieImmutable(false).DieFeedPtr(r.Secret) - fn(d) - r.Secret = d.DieReleasePtr() - }) -} - -func (d *VolumeProjectionDie) DownwardAPIDie(fn func(d *DownwardAPIProjectionDie)) *VolumeProjectionDie { - return d.DieStamp(func(r *corev1.VolumeProjection) { - d := DownwardAPIProjectionBlank.DieImmutable(false).DieFeedPtr(r.DownwardAPI) - fn(d) - r.DownwardAPI = d.DieReleasePtr() - }) -} - -func (d *VolumeProjectionDie) ConfigMapDie(fn func(d *ConfigMapProjectionDie)) *VolumeProjectionDie { - return d.DieStamp(func(r *corev1.VolumeProjection) { - d := ConfigMapProjectionBlank.DieImmutable(false).DieFeedPtr(r.ConfigMap) - fn(d) - r.ConfigMap = d.DieReleasePtr() - }) -} - -func (d *VolumeProjectionDie) ServiceAccountTokenDie(fn func(d *ServiceAccountTokenProjectionDie)) *VolumeProjectionDie { - return d.DieStamp(func(r *corev1.VolumeProjection) { - d := ServiceAccountTokenProjectionBlank.DieImmutable(false).DieFeedPtr(r.ServiceAccountToken) - fn(d) - r.ServiceAccountToken = d.DieReleasePtr() - }) -} - -func (d *VolumeProjectionDie) ClusterTrustBundleDie(fn func(d *ClusterTrustBundleProjectionDie)) *VolumeProjectionDie { - return d.DieStamp(func(r *corev1.VolumeProjection) { - d := ClusterTrustBundleProjectionBlank.DieImmutable(false).DieFeedPtr(r.ClusterTrustBundle) - fn(d) - r.ClusterTrustBundle = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Items,die=KeyToPathDie,listMapKey=Key type _ = corev1.SecretProjection func (d *SecretProjectionDie) Name(v string) *SecretProjectionDie { @@ -563,44 +423,12 @@ func (d *SecretProjectionDie) Name(v string) *SecretProjectionDie { }) } -func (d *SecretProjectionDie) ItemDie(key string, fn func(d *KeyToPathDie)) *SecretProjectionDie { - return d.DieStamp(func(r *corev1.SecretProjection) { - for i := range r.Items { - if key == r.Items[i].Key { - d := KeyToPathBlank.DieImmutable(false).DieFeed(r.Items[i]) - fn(d) - r.Items[i] = d.DieRelease() - return - } - } - - d := KeyToPathBlank.DieImmutable(false).DieFeed(corev1.KeyToPath{Key: key}) - fn(d) - r.Items = append(r.Items, d.DieRelease()) - }) -} - // +die +// +die:field:name=Items,die=DownwardAPIVolumeFileDie,listMapKey=Path type _ = corev1.DownwardAPIProjection -func (d *DownwardAPIProjectionDie) ItemDie(path string, fn func(d *DownwardAPIVolumeFileDie)) *DownwardAPIProjectionDie { - return d.DieStamp(func(r *corev1.DownwardAPIProjection) { - for i := range r.Items { - if path == r.Items[i].Path { - d := DownwardAPIVolumeFileBlank.DieImmutable(false).DieFeed(r.Items[i]) - fn(d) - r.Items[i] = d.DieRelease() - return - } - } - - d := DownwardAPIVolumeFileBlank.DieImmutable(false).DieFeed(corev1.DownwardAPIVolumeFile{Path: path}) - fn(d) - r.Items = append(r.Items, d.DieRelease()) - }) -} - // +die +// +die:field:name=Items,die=KeyToPathDie,listMapKey=Key type _ = corev1.ConfigMapProjection func (d *ConfigMapProjectionDie) Name(v string) *ConfigMapProjectionDie { @@ -609,63 +437,26 @@ func (d *ConfigMapProjectionDie) Name(v string) *ConfigMapProjectionDie { }) } -func (d *ConfigMapProjectionDie) ItemDie(key string, fn func(d *KeyToPathDie)) *ConfigMapProjectionDie { - return d.DieStamp(func(r *corev1.ConfigMapProjection) { - for i := range r.Items { - if key == r.Items[i].Key { - d := KeyToPathBlank.DieImmutable(false).DieFeed(r.Items[i]) - fn(d) - r.Items[i] = d.DieRelease() - return - } - } - - d := KeyToPathBlank.DieImmutable(false).DieFeed(corev1.KeyToPath{Key: key}) - fn(d) - r.Items = append(r.Items, d.DieRelease()) - }) -} - // +die type _ = corev1.ServiceAccountTokenProjection // +die +// +die:field:name=LabelSelector,package=_/meta/v1,die=LabelSelectorDie,pointer=true type _ = corev1.ClusterTrustBundleProjection -func (d *ClusterTrustBundleProjectionDie) LabelSelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *ClusterTrustBundleProjectionDie { - return d.DieStamp(func(r *corev1.ClusterTrustBundleProjection) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.LabelSelector) - fn(d) - r.LabelSelector = d.DieReleasePtr() - }) -} - // +die type _ = corev1.PortworxVolumeSource // +die +// +die:field:name=SecretRef,die=LocalObjectReferenceDie,pointer=true type _ = corev1.ScaleIOVolumeSource -func (d *ScaleIOVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *ScaleIOVolumeSourceDie { - return d.DieStamp(func(r *corev1.ScaleIOVolumeSource) { - d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=SecretRef,die=LocalObjectReferenceDie,pointer=true type _ = corev1.StorageOSVolumeSource -func (d *StorageOSVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *StorageOSVolumeSourceDie { - return d.DieStamp(func(r *corev1.StorageOSVolumeSource) { - d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) - fn(d) - r.SecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=NodePublishSecretRef,die=LocalObjectReferenceDie,pointer=true type _ = corev1.CSIVolumeSource func (d *CSIVolumeSourceDie) VolumeAttribute(key, value string) *CSIVolumeSourceDie { @@ -674,24 +465,9 @@ func (d *CSIVolumeSourceDie) VolumeAttribute(key, value string) *CSIVolumeSource }) } -func (d *CSIVolumeSourceDie) NodePublishSecretRefDie(fn func(d *LocalObjectReferenceDie)) *CSIVolumeSourceDie { - return d.DieStamp(func(r *corev1.CSIVolumeSource) { - d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.NodePublishSecretRef) - fn(d) - r.NodePublishSecretRef = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=VolumeClaimTemplate,die=PersistentVolumeClaimTemplateDie,pointer=true type _ = corev1.EphemeralVolumeSource -func (d *EphemeralVolumeSourceDie) VolumeClaimTemplateDie(fn func(d *PersistentVolumeClaimTemplateDie)) *EphemeralVolumeSourceDie { - return d.DieStamp(func(r *corev1.EphemeralVolumeSource) { - d := PersistentVolumeClaimTemplateBlank.DieImmutable(false).DieFeedPtr(r.VolumeClaimTemplate) - fn(d) - r.VolumeClaimTemplate = d.DieReleasePtr() - }) -} - // +die type _ = corev1.KeyToPath diff --git a/apis/core/v1/zz_generated.die.go b/apis/core/v1/zz_generated.die.go index 696a72e..3ad02e3 100644 --- a/apis/core/v1/zz_generated.die.go +++ b/apis/core/v1/zz_generated.die.go @@ -364,6 +364,17 @@ func (d *BindingDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *BindingDie { }) } +// TargetDie mutates Target as a die. +// +// The target object that you want to bind to the standard object. +func (d *BindingDie) TargetDie(fn func(d *ObjectReferenceDie)) *BindingDie { + return d.DieStamp(func(r *corev1.Binding) { + d := ObjectReferenceBlank.DieImmutable(false).DieFeed(r.Target) + fn(d) + r.Target = d.DieRelease() + }) +} + // The target object that you want to bind to the standard object. func (d *BindingDie) Target(v corev1.ObjectReference) *BindingDie { return d.DieStamp(func(r *corev1.Binding) { @@ -1898,6 +1909,18 @@ func (d *TopologySelectorTermDie) DiePatch(patchType types.PatchType) ([]byte, e return patch.Create(d.seal, d.r, patchType) } +// MatchLabelExpressionsDie replaces MatchLabelExpressions by collecting the released value from each die passed. +// +// A list of topology selector requirements by labels. +func (d *TopologySelectorTermDie) MatchLabelExpressionsDie(v ...*TopologySelectorLabelRequirementDie) *TopologySelectorTermDie { + return d.DieStamp(func(r *corev1.TopologySelectorTerm) { + r.MatchLabelExpressions = make([]corev1.TopologySelectorLabelRequirement, len(v)) + for i := range v { + r.MatchLabelExpressions[i] = v[i].DieRelease() + } + }) +} + // A list of topology selector requirements by labels. func (d *TopologySelectorTermDie) MatchLabelExpressions(v ...corev1.TopologySelectorLabelRequirement) *TopologySelectorTermDie { return d.DieStamp(func(r *corev1.TopologySelectorTerm) { @@ -3043,6 +3066,244 @@ func (d *ContainerDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ResourcesDie mutates Resources as a die. +// +// Compute Resources required by this container. +// +// Cannot be updated. +// +// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ +func (d *ContainerDie) ResourcesDie(fn func(d *ResourceRequirementsDie)) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + d := ResourceRequirementsBlank.DieImmutable(false).DieFeed(r.Resources) + fn(d) + r.Resources = d.DieRelease() + }) +} + +// LivenessProbeDie mutates LivenessProbe as a die. +// +// Periodic probe of container liveness. +// +// Container will be restarted if the probe fails. +// +// Cannot be updated. +// +// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes +func (d *ContainerDie) LivenessProbeDie(fn func(d *ProbeDie)) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + d := ProbeBlank.DieImmutable(false).DieFeedPtr(r.LivenessProbe) + fn(d) + r.LivenessProbe = d.DieReleasePtr() + }) +} + +// ReadinessProbeDie mutates ReadinessProbe as a die. +// +// Periodic probe of container service readiness. +// +// Container will be removed from service endpoints if the probe fails. +// +// Cannot be updated. +// +// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes +func (d *ContainerDie) ReadinessProbeDie(fn func(d *ProbeDie)) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + d := ProbeBlank.DieImmutable(false).DieFeedPtr(r.ReadinessProbe) + fn(d) + r.ReadinessProbe = d.DieReleasePtr() + }) +} + +// StartupProbeDie mutates StartupProbe as a die. +// +// StartupProbe indicates that the Pod has successfully initialized. +// +// If specified, no other probes are executed until this completes successfully. +// +// If this probe fails, the Pod will be restarted, just as if the livenessProbe failed. +// +// This can be used to provide different probe parameters at the beginning of a Pod's lifecycle, +// +// when it might take a long time to load data or warm a cache, than during steady-state operation. +// +// This cannot be updated. +// +// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#container-probes +func (d *ContainerDie) StartupProbeDie(fn func(d *ProbeDie)) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + d := ProbeBlank.DieImmutable(false).DieFeedPtr(r.StartupProbe) + fn(d) + r.StartupProbe = d.DieReleasePtr() + }) +} + +// LifecycleDie mutates Lifecycle as a die. +// +// Actions that the management system should take in response to container lifecycle events. +// +// Cannot be updated. +func (d *ContainerDie) LifecycleDie(fn func(d *LifecycleDie)) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + d := LifecycleBlank.DieImmutable(false).DieFeedPtr(r.Lifecycle) + fn(d) + r.Lifecycle = d.DieReleasePtr() + }) +} + +// SecurityContextDie mutates SecurityContext as a die. +// +// SecurityContext defines the security options the container should be run with. +// +// If set, the fields of SecurityContext override the equivalent fields of PodSecurityContext. +// +// More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ +func (d *ContainerDie) SecurityContextDie(fn func(d *SecurityContextDie)) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + d := SecurityContextBlank.DieImmutable(false).DieFeedPtr(r.SecurityContext) + fn(d) + r.SecurityContext = d.DieReleasePtr() + }) +} + +// PortsDie replaces Ports by collecting the released value from each die passed. +// +// List of ports to expose from the container. Not specifying a port here +// +// DOES NOT prevent that port from being exposed. Any port which is +// +// listening on the default "0.0.0.0" address inside a container will be +// +// accessible from the network. +// +// Modifying this array with strategic merge patch may corrupt the data. +// +// For more information See https://github.com/kubernetes/kubernetes/issues/108255. +// +// Cannot be updated. +func (d *ContainerDie) PortsDie(v ...*ContainerPortDie) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + r.Ports = make([]corev1.ContainerPort, len(v)) + for i := range v { + r.Ports[i] = v[i].DieRelease() + } + }) +} + +// EnvFromDie mutates a single item in EnvFrom matched by the nested field Prefix, appending a new item if no match is found. +// +// List of sources to populate environment variables in the container. +// +// The keys defined within a source must be a C_IDENTIFIER. All invalid keys +// +// will be reported as an event when the container is starting. When a key exists in multiple +// +// sources, the value associated with the last source will take precedence. +// +// Values defined by an Env with a duplicate key will take precedence. +// +// Cannot be updated. +func (d *ContainerDie) EnvFromDie(v string, fn func(d *EnvFromSourceDie)) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + for i := range r.EnvFrom { + if v == r.EnvFrom[i].Prefix { + d := EnvFromSourceBlank.DieImmutable(false).DieFeed(r.EnvFrom[i]) + fn(d) + r.EnvFrom[i] = d.DieRelease() + return + } + } + + d := EnvFromSourceBlank.DieImmutable(false).DieFeed(corev1.EnvFromSource{Prefix: v}) + fn(d) + r.EnvFrom = append(r.EnvFrom, d.DieRelease()) + }) +} + +// EnvDie mutates a single item in Env matched by the nested field Name, appending a new item if no match is found. +// +// List of environment variables to set in the container. +// +// Cannot be updated. +func (d *ContainerDie) EnvDie(v string, fn func(d *EnvVarDie)) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + for i := range r.Env { + if v == r.Env[i].Name { + d := EnvVarBlank.DieImmutable(false).DieFeed(r.Env[i]) + fn(d) + r.Env[i] = d.DieRelease() + return + } + } + + d := EnvVarBlank.DieImmutable(false).DieFeed(corev1.EnvVar{Name: v}) + fn(d) + r.Env = append(r.Env, d.DieRelease()) + }) +} + +// ResizePolicyDie mutates a single item in ResizePolicy matched by the nested field ResourceName, appending a new item if no match is found. +// +// Resources resize policy for the container. +func (d *ContainerDie) ResizePolicyDie(v corev1.ResourceName, fn func(d *ContainerResizePolicyDie)) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + for i := range r.ResizePolicy { + if v == r.ResizePolicy[i].ResourceName { + d := ContainerResizePolicyBlank.DieImmutable(false).DieFeed(r.ResizePolicy[i]) + fn(d) + r.ResizePolicy[i] = d.DieRelease() + return + } + } + + d := ContainerResizePolicyBlank.DieImmutable(false).DieFeed(corev1.ContainerResizePolicy{ResourceName: v}) + fn(d) + r.ResizePolicy = append(r.ResizePolicy, d.DieRelease()) + }) +} + +// VolumeMountDie mutates a single item in VolumeMounts matched by the nested field Name, appending a new item if no match is found. +// +// Pod volumes to mount into the container's filesystem. +// +// Cannot be updated. +func (d *ContainerDie) VolumeMountDie(v string, fn func(d *VolumeMountDie)) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + for i := range r.VolumeMounts { + if v == r.VolumeMounts[i].Name { + d := VolumeMountBlank.DieImmutable(false).DieFeed(r.VolumeMounts[i]) + fn(d) + r.VolumeMounts[i] = d.DieRelease() + return + } + } + + d := VolumeMountBlank.DieImmutable(false).DieFeed(corev1.VolumeMount{Name: v}) + fn(d) + r.VolumeMounts = append(r.VolumeMounts, d.DieRelease()) + }) +} + +// VolumeDeviceDie mutates a single item in VolumeDevices matched by the nested field Name, appending a new item if no match is found. +// +// volumeDevices is the list of block devices to be used by the container. +func (d *ContainerDie) VolumeDeviceDie(v string, fn func(d *VolumeDeviceDie)) *ContainerDie { + return d.DieStamp(func(r *corev1.Container) { + for i := range r.VolumeDevices { + if v == r.VolumeDevices[i].Name { + d := VolumeDeviceBlank.DieImmutable(false).DieFeed(r.VolumeDevices[i]) + fn(d) + r.VolumeDevices[i] = d.DieRelease() + return + } + } + + d := VolumeDeviceBlank.DieImmutable(false).DieFeed(corev1.VolumeDevice{Name: v}) + fn(d) + r.VolumeDevices = append(r.VolumeDevices, d.DieRelease()) + }) +} + // Name of the container specified as a DNS_LABEL. // // Each container in a pod must have a unique name (DNS_LABEL). @@ -3898,6 +4159,28 @@ func (d *EnvFromSourceDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ConfigMapRefDie mutates ConfigMapRef as a die. +// +// The ConfigMap to select from +func (d *EnvFromSourceDie) ConfigMapRefDie(fn func(d *ConfigMapEnvSourceDie)) *EnvFromSourceDie { + return d.DieStamp(func(r *corev1.EnvFromSource) { + d := ConfigMapEnvSourceBlank.DieImmutable(false).DieFeedPtr(r.ConfigMapRef) + fn(d) + r.ConfigMapRef = d.DieReleasePtr() + }) +} + +// SecretRefDie mutates SecretRef as a die. +// +// The Secret to select from +func (d *EnvFromSourceDie) SecretRefDie(fn func(d *SecretEnvSourceDie)) *EnvFromSourceDie { + return d.DieStamp(func(r *corev1.EnvFromSource) { + d := SecretEnvSourceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // An optional identifier to prepend to each key in the ConfigMap. Must be a C_IDENTIFIER. func (d *EnvFromSourceDie) Prefix(v string) *EnvFromSourceDie { return d.DieStamp(func(r *corev1.EnvFromSource) { @@ -4631,6 +4914,17 @@ func (d *EnvVarDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ValueFromDie mutates ValueFrom as a die. +// +// Source for the environment variable's value. Cannot be used if value is not empty. +func (d *EnvVarDie) ValueFromDie(fn func(d *EnvVarSourceDie)) *EnvVarDie { + return d.DieStamp(func(r *corev1.EnvVar) { + d := EnvVarSourceBlank.DieImmutable(false).DieFeedPtr(r.ValueFrom) + fn(d) + r.ValueFrom = d.DieReleasePtr() + }) +} + // Name of the environment variable. Must be a C_IDENTIFIER. func (d *EnvVarDie) Name(v string) *EnvVarDie { return d.DieStamp(func(r *corev1.EnvVar) { @@ -4896,6 +5190,54 @@ func (d *EnvVarSourceDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// FieldRefDie mutates FieldRef as a die. +// +// Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, +// +// spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs. +func (d *EnvVarSourceDie) FieldRefDie(fn func(d *ObjectFieldSelectorDie)) *EnvVarSourceDie { + return d.DieStamp(func(r *corev1.EnvVarSource) { + d := ObjectFieldSelectorBlank.DieImmutable(false).DieFeedPtr(r.FieldRef) + fn(d) + r.FieldRef = d.DieReleasePtr() + }) +} + +// ResourceFieldRefDie mutates ResourceFieldRef as a die. +// +// Selects a resource of the container: only resources limits and requests +// +// (limits.cpu, limits.memory, limits.ephemeral-storage, requests.cpu, requests.memory and requests.ephemeral-storage) are currently supported. +func (d *EnvVarSourceDie) ResourceFieldRefDie(fn func(d *ResourceFieldSelectorDie)) *EnvVarSourceDie { + return d.DieStamp(func(r *corev1.EnvVarSource) { + d := ResourceFieldSelectorBlank.DieImmutable(false).DieFeedPtr(r.ResourceFieldRef) + fn(d) + r.ResourceFieldRef = d.DieReleasePtr() + }) +} + +// ConfigMapKeyRefDie mutates ConfigMapKeyRef as a die. +// +// Selects a key of a ConfigMap. +func (d *EnvVarSourceDie) ConfigMapKeyRefDie(fn func(d *ConfigMapKeySelectorDie)) *EnvVarSourceDie { + return d.DieStamp(func(r *corev1.EnvVarSource) { + d := ConfigMapKeySelectorBlank.DieImmutable(false).DieFeedPtr(r.ConfigMapKeyRef) + fn(d) + r.ConfigMapKeyRef = d.DieReleasePtr() + }) +} + +// SecretKeyRefDie mutates SecretKeyRef as a die. +// +// Selects a key of a secret in the pod's namespace +func (d *EnvVarSourceDie) SecretKeyRefDie(fn func(d *SecretKeySelectorDie)) *EnvVarSourceDie { + return d.DieStamp(func(r *corev1.EnvVarSource) { + d := SecretKeySelectorBlank.DieImmutable(false).DieFeedPtr(r.SecretKeyRef) + fn(d) + r.SecretKeyRef = d.DieReleasePtr() + }) +} + // Selects a field of the pod: supports metadata.name, metadata.namespace, `metadata.labels['']`, `metadata.annotations['']`, // // spec.nodeName, spec.serviceAccountName, status.hostIP, status.podIP, status.podIPs. @@ -6153,6 +6495,54 @@ func (d *ResourceRequirementsDie) DiePatch(patchType types.PatchType) ([]byte, e return patch.Create(d.seal, d.r, patchType) } +// ClaimsDie replaces Claims by collecting the released value from each die passed. +// +// Claims lists the names of resources, defined in spec.resourceClaims, +// +// that are used by this container. +// +// # This is an alpha field and requires enabling the +// +// DynamicResourceAllocation feature gate. +// +// This field is immutable. It can only be set for containers. +func (d *ResourceRequirementsDie) ClaimsDie(v ...*ResourceClaimDie) *ResourceRequirementsDie { + return d.DieStamp(func(r *corev1.ResourceRequirements) { + r.Claims = make([]corev1.ResourceClaim, len(v)) + for i := range v { + r.Claims[i] = v[i].DieRelease() + } + }) +} + +// ClaimDie mutates a single item in Claims matched by the nested field Name, appending a new item if no match is found. +// +// Claims lists the names of resources, defined in spec.resourceClaims, +// +// that are used by this container. +// +// # This is an alpha field and requires enabling the +// +// DynamicResourceAllocation feature gate. +// +// This field is immutable. It can only be set for containers. +func (d *ResourceRequirementsDie) ClaimDie(v string, fn func(d *ResourceClaimDie)) *ResourceRequirementsDie { + return d.DieStamp(func(r *corev1.ResourceRequirements) { + for i := range r.Claims { + if v == r.Claims[i].Name { + d := ResourceClaimBlank.DieImmutable(false).DieFeed(r.Claims[i]) + fn(d) + r.Claims[i] = d.DieRelease() + return + } + } + + d := ResourceClaimBlank.DieImmutable(false).DieFeed(corev1.ResourceClaim{Name: v}) + fn(d) + r.Claims = append(r.Claims, d.DieRelease()) + }) +} + // Limits describes the maximum amount of compute resources allowed. // // More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ @@ -7522,6 +7912,17 @@ func (d *ProbeDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ProbeHandlerDie mutates ProbeHandler as a die. +// +// The action taken to determine the health of a container +func (d *ProbeDie) ProbeHandlerDie(fn func(d *ProbeHandlerDie)) *ProbeDie { + return d.DieStamp(func(r *corev1.Probe) { + d := ProbeHandlerBlank.DieImmutable(false).DieFeed(r.ProbeHandler) + fn(d) + r.ProbeHandler = d.DieRelease() + }) +} + // The action taken to determine the health of a container func (d *ProbeDie) ProbeHandler(v corev1.ProbeHandler) *ProbeDie { return d.DieStamp(func(r *corev1.Probe) { @@ -7829,6 +8230,50 @@ func (d *LifecycleDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// PostStartDie mutates PostStart as a die. +// +// PostStart is called immediately after a container is created. If the handler fails, +// +// the container is terminated and restarted according to its restart policy. +// +// Other management of the container blocks until the hook completes. +// +// More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks +func (d *LifecycleDie) PostStartDie(fn func(d *LifecycleHandlerDie)) *LifecycleDie { + return d.DieStamp(func(r *corev1.Lifecycle) { + d := LifecycleHandlerBlank.DieImmutable(false).DieFeedPtr(r.PostStart) + fn(d) + r.PostStart = d.DieReleasePtr() + }) +} + +// PreStopDie mutates PreStop as a die. +// +// # PreStop is called immediately before a container is terminated due to an +// +// API request or management event such as liveness/startup probe failure, +// +// preemption, resource contention, etc. The handler is not called if the +// +// container crashes or exits. The Pod's termination grace period countdown begins before the +// +// PreStop hook is executed. Regardless of the outcome of the handler, the +// +// container will eventually terminate within the Pod's termination grace +// +// period (unless delayed by finalizers). Other management of the container blocks until the hook completes +// +// or until the termination grace period is reached. +// +// More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks +func (d *LifecycleDie) PreStopDie(fn func(d *LifecycleHandlerDie)) *LifecycleDie { + return d.DieStamp(func(r *corev1.Lifecycle) { + d := LifecycleHandlerBlank.DieImmutable(false).DieFeedPtr(r.PreStop) + fn(d) + r.PreStop = d.DieReleasePtr() + }) +} + // PostStart is called immediately after a container is created. If the handler fails, // // the container is terminated and restarted according to its restart policy. @@ -8093,6 +8538,54 @@ func (d *LifecycleHandlerDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// ExecDie mutates Exec as a die. +// +// Exec specifies the action to take. +func (d *LifecycleHandlerDie) ExecDie(fn func(d *ExecActionDie)) *LifecycleHandlerDie { + return d.DieStamp(func(r *corev1.LifecycleHandler) { + d := ExecActionBlank.DieImmutable(false).DieFeedPtr(r.Exec) + fn(d) + r.Exec = d.DieReleasePtr() + }) +} + +// HTTPGetDie mutates HTTPGet as a die. +// +// HTTPGet specifies the http request to perform. +func (d *LifecycleHandlerDie) HTTPGetDie(fn func(d *HTTPGetActionDie)) *LifecycleHandlerDie { + return d.DieStamp(func(r *corev1.LifecycleHandler) { + d := HTTPGetActionBlank.DieImmutable(false).DieFeedPtr(r.HTTPGet) + fn(d) + r.HTTPGet = d.DieReleasePtr() + }) +} + +// TCPSocketDie mutates TCPSocket as a die. +// +// Deprecated. TCPSocket is NOT supported as a LifecycleHandler and kept +// +// for the backward compatibility. There are no validation of this field and +// +// lifecycle hooks will fail in runtime when tcp handler is specified. +func (d *LifecycleHandlerDie) TCPSocketDie(fn func(d *TCPSocketActionDie)) *LifecycleHandlerDie { + return d.DieStamp(func(r *corev1.LifecycleHandler) { + d := TCPSocketActionBlank.DieImmutable(false).DieFeedPtr(r.TCPSocket) + fn(d) + r.TCPSocket = d.DieReleasePtr() + }) +} + +// SleepDie mutates Sleep as a die. +// +// Sleep represents the duration that the container should sleep before being terminated. +func (d *LifecycleHandlerDie) SleepDie(fn func(d *SleepActionDie)) *LifecycleHandlerDie { + return d.DieStamp(func(r *corev1.LifecycleHandler) { + d := SleepActionBlank.DieImmutable(false).DieFeedPtr(r.Sleep) + fn(d) + r.Sleep = d.DieReleasePtr() + }) +} + // Exec specifies the action to take. func (d *LifecycleHandlerDie) Exec(v *corev1.ExecAction) *LifecycleHandlerDie { return d.DieStamp(func(r *corev1.LifecycleHandler) { @@ -8353,6 +8846,50 @@ func (d *ProbeHandlerDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ExecDie mutates Exec as a die. +// +// Exec specifies the action to take. +func (d *ProbeHandlerDie) ExecDie(fn func(d *ExecActionDie)) *ProbeHandlerDie { + return d.DieStamp(func(r *corev1.ProbeHandler) { + d := ExecActionBlank.DieImmutable(false).DieFeedPtr(r.Exec) + fn(d) + r.Exec = d.DieReleasePtr() + }) +} + +// HTTPGetDie mutates HTTPGet as a die. +// +// HTTPGet specifies the http request to perform. +func (d *ProbeHandlerDie) HTTPGetDie(fn func(d *HTTPGetActionDie)) *ProbeHandlerDie { + return d.DieStamp(func(r *corev1.ProbeHandler) { + d := HTTPGetActionBlank.DieImmutable(false).DieFeedPtr(r.HTTPGet) + fn(d) + r.HTTPGet = d.DieReleasePtr() + }) +} + +// TCPSocketDie mutates TCPSocket as a die. +// +// TCPSocket specifies an action involving a TCP port. +func (d *ProbeHandlerDie) TCPSocketDie(fn func(d *TCPSocketActionDie)) *ProbeHandlerDie { + return d.DieStamp(func(r *corev1.ProbeHandler) { + d := TCPSocketActionBlank.DieImmutable(false).DieFeedPtr(r.TCPSocket) + fn(d) + r.TCPSocket = d.DieReleasePtr() + }) +} + +// GRPCDie mutates GRPC as a die. +// +// GRPC specifies an action involving a GRPC port. +func (d *ProbeHandlerDie) GRPCDie(fn func(d *GRPCActionDie)) *ProbeHandlerDie { + return d.DieStamp(func(r *corev1.ProbeHandler) { + d := GRPCActionBlank.DieImmutable(false).DieFeedPtr(r.GRPC) + fn(d) + r.GRPC = d.DieReleasePtr() + }) +} + // Exec specifies the action to take. func (d *ProbeHandlerDie) Exec(v *corev1.ExecAction) *ProbeHandlerDie { return d.DieStamp(func(r *corev1.ProbeHandler) { @@ -8852,6 +9389,18 @@ func (d *HTTPGetActionDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// HTTPHeadersDie replaces HTTPHeaders by collecting the released value from each die passed. +// +// Custom headers to set in the request. HTTP allows repeated headers. +func (d *HTTPGetActionDie) HTTPHeadersDie(v ...*HTTPHeaderDie) *HTTPGetActionDie { + return d.DieStamp(func(r *corev1.HTTPGetAction) { + r.HTTPHeaders = make([]corev1.HTTPHeader, len(v)) + for i := range v { + r.HTTPHeaders[i] = v[i].DieRelease() + } + }) +} + // Path to access on the HTTP server. func (d *HTTPGetActionDie) Path(v string) *HTTPGetActionDie { return d.DieStamp(func(r *corev1.HTTPGetAction) { @@ -10150,6 +10699,89 @@ func (d *SecurityContextDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// CapabilitiesDie mutates Capabilities as a die. +// +// The capabilities to add/drop when running containers. +// +// Defaults to the default set of capabilities granted by the container runtime. +// +// Note that this field cannot be set when spec.os.name is windows. +func (d *SecurityContextDie) CapabilitiesDie(fn func(d *CapabilitiesDie)) *SecurityContextDie { + return d.DieStamp(func(r *corev1.SecurityContext) { + d := CapabilitiesBlank.DieImmutable(false).DieFeedPtr(r.Capabilities) + fn(d) + r.Capabilities = d.DieReleasePtr() + }) +} + +// SELinuxOptionsDie mutates SELinuxOptions as a die. +// +// The SELinux context to be applied to the container. +// +// # If unspecified, the container runtime will allocate a random SELinux context for each +// +// container. May also be set in PodSecurityContext. If set in both SecurityContext and +// +// PodSecurityContext, the value specified in SecurityContext takes precedence. +// +// Note that this field cannot be set when spec.os.name is windows. +func (d *SecurityContextDie) SELinuxOptionsDie(fn func(d *SELinuxOptionsDie)) *SecurityContextDie { + return d.DieStamp(func(r *corev1.SecurityContext) { + d := SELinuxOptionsBlank.DieImmutable(false).DieFeedPtr(r.SELinuxOptions) + fn(d) + r.SELinuxOptions = d.DieReleasePtr() + }) +} + +// WindowsOptionsDie mutates WindowsOptions as a die. +// +// The Windows specific settings applied to all containers. +// +// If unspecified, the options from the PodSecurityContext will be used. +// +// If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. +// +// Note that this field cannot be set when spec.os.name is linux. +func (d *SecurityContextDie) WindowsOptionsDie(fn func(d *WindowsSecurityContextOptionsDie)) *SecurityContextDie { + return d.DieStamp(func(r *corev1.SecurityContext) { + d := WindowsSecurityContextOptionsBlank.DieImmutable(false).DieFeedPtr(r.WindowsOptions) + fn(d) + r.WindowsOptions = d.DieReleasePtr() + }) +} + +// SeccompProfileDie mutates SeccompProfile as a die. +// +// The seccomp options to use by this container. If seccomp options are +// +// provided at both the pod & container level, the container options +// +// override the pod options. +// +// Note that this field cannot be set when spec.os.name is windows. +func (d *SecurityContextDie) SeccompProfileDie(fn func(d *SeccompProfileDie)) *SecurityContextDie { + return d.DieStamp(func(r *corev1.SecurityContext) { + d := SeccompProfileBlank.DieImmutable(false).DieFeedPtr(r.SeccompProfile) + fn(d) + r.SeccompProfile = d.DieReleasePtr() + }) +} + +// AppArmorProfileDie mutates AppArmorProfile as a die. +// +// appArmorProfile is the AppArmor options to use by this container. If set, this profile +// +// overrides the pod's appArmorProfile. +// +// Note that this field cannot be set when spec.os.name is windows. +func (d *SecurityContextDie) AppArmorProfileDie(fn func(d *AppArmorProfileDie)) *SecurityContextDie { + return d.DieStamp(func(r *corev1.SecurityContext) { + d := AppArmorProfileBlank.DieImmutable(false).DieFeedPtr(r.AppArmorProfile) + fn(d) + r.AppArmorProfile = d.DieReleasePtr() + }) +} + // The capabilities to add/drop when running containers. // // Defaults to the default set of capabilities granted by the container runtime. @@ -11828,6 +12460,65 @@ func (d *ContainerStatusDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// StateDie mutates State as a die. +// +// State holds details about the container's current condition. +func (d *ContainerStatusDie) StateDie(fn func(d *ContainerStateDie)) *ContainerStatusDie { + return d.DieStamp(func(r *corev1.ContainerStatus) { + d := ContainerStateBlank.DieImmutable(false).DieFeed(r.State) + fn(d) + r.State = d.DieRelease() + }) +} + +// LastTerminationStateDie mutates LastTerminationState as a die. +// +// # LastTerminationState holds the last termination state of the container to +// +// help debug container crashes and restarts. This field is not +// +// populated if the container is still running and RestartCount is 0. +func (d *ContainerStatusDie) LastTerminationStateDie(fn func(d *ContainerStateDie)) *ContainerStatusDie { + return d.DieStamp(func(r *corev1.ContainerStatus) { + d := ContainerStateBlank.DieImmutable(false).DieFeed(r.LastTerminationState) + fn(d) + r.LastTerminationState = d.DieRelease() + }) +} + +// ResourcesDie mutates Resources as a die. +// +// # Resources represents the compute resource requests and limits that have been successfully +// +// enacted on the running container after it has been started or has been successfully resized. +func (d *ContainerStatusDie) ResourcesDie(fn func(d *ResourceRequirementsDie)) *ContainerStatusDie { + return d.DieStamp(func(r *corev1.ContainerStatus) { + d := ResourceRequirementsBlank.DieImmutable(false).DieFeedPtr(r.Resources) + fn(d) + r.Resources = d.DieReleasePtr() + }) +} + +// VolumeMountDie mutates a single item in VolumeMounts matched by the nested field Name, appending a new item if no match is found. +// +// Status of volume mounts. +func (d *ContainerStatusDie) VolumeMountDie(v string, fn func(d *VolumeMountStatusDie)) *ContainerStatusDie { + return d.DieStamp(func(r *corev1.ContainerStatus) { + for i := range r.VolumeMounts { + if v == r.VolumeMounts[i].Name { + d := VolumeMountStatusBlank.DieImmutable(false).DieFeed(r.VolumeMounts[i]) + fn(d) + r.VolumeMounts[i] = d.DieRelease() + return + } + } + + d := VolumeMountStatusBlank.DieImmutable(false).DieFeed(corev1.VolumeMountStatus{Name: v}) + fn(d) + r.VolumeMounts = append(r.VolumeMounts, d.DieRelease()) + }) +} + // Name is a DNS_LABEL representing the unique name of the container. // // Each container in a pod must have a unique name across all container types. @@ -12226,6 +12917,39 @@ func (d *ContainerStateDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// WaitingDie mutates Waiting as a die. +// +// Details about a waiting container +func (d *ContainerStateDie) WaitingDie(fn func(d *ContainerStateWaitingDie)) *ContainerStateDie { + return d.DieStamp(func(r *corev1.ContainerState) { + d := ContainerStateWaitingBlank.DieImmutable(false).DieFeedPtr(r.Waiting) + fn(d) + r.Waiting = d.DieReleasePtr() + }) +} + +// RunningDie mutates Running as a die. +// +// Details about a running container +func (d *ContainerStateDie) RunningDie(fn func(d *ContainerStateRunningDie)) *ContainerStateDie { + return d.DieStamp(func(r *corev1.ContainerState) { + d := ContainerStateRunningBlank.DieImmutable(false).DieFeedPtr(r.Running) + fn(d) + r.Running = d.DieReleasePtr() + }) +} + +// TerminatedDie mutates Terminated as a die. +// +// Details about a terminated container +func (d *ContainerStateDie) TerminatedDie(fn func(d *ContainerStateTerminatedDie)) *ContainerStateDie { + return d.DieStamp(func(r *corev1.ContainerState) { + d := ContainerStateTerminatedBlank.DieImmutable(false).DieFeedPtr(r.Terminated) + fn(d) + r.Terminated = d.DieReleasePtr() + }) +} + // Details about a waiting container func (d *ContainerStateDie) Waiting(v *corev1.ContainerStateWaiting) *ContainerStateDie { return d.DieStamp(func(r *corev1.ContainerState) { @@ -13584,6 +14308,30 @@ func (d *EndpointsDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *EndpointsD }) } +// SubsetsDie replaces Subsets by collecting the released value from each die passed. +// +// The set of all endpoints is the union of all subsets. Addresses are placed into +// +// subsets according to the IPs they share. A single address with multiple ports, +// +// some of which are ready and some of which are not (because they come from +// +// different containers) will result in the address being displayed in different +// +// subsets for the different ports. No address will appear in both Addresses and +// +// NotReadyAddresses in the same subset. +// +// Sets of addresses and ports that comprise a service. +func (d *EndpointsDie) SubsetsDie(v ...*EndpointSubsetDie) *EndpointsDie { + return d.DieStamp(func(r *corev1.Endpoints) { + r.Subsets = make([]corev1.EndpointSubset, len(v)) + for i := range v { + r.Subsets[i] = v[i].DieRelease() + } + }) +} + // The set of all endpoints is the union of all subsets. Addresses are placed into // // subsets according to the IPs they share. A single address with multiple ports, @@ -13831,6 +14579,48 @@ func (d *EndpointSubsetDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// AddressesDie replaces Addresses by collecting the released value from each die passed. +// +// IP addresses which offer the related ports that are marked as ready. These endpoints +// +// should be considered safe for load balancers and clients to utilize. +func (d *EndpointSubsetDie) AddressesDie(v ...*EndpointAddressDie) *EndpointSubsetDie { + return d.DieStamp(func(r *corev1.EndpointSubset) { + r.Addresses = make([]corev1.EndpointAddress, len(v)) + for i := range v { + r.Addresses[i] = v[i].DieRelease() + } + }) +} + +// NotReadyAddressesDie replaces NotReadyAddresses by collecting the released value from each die passed. +// +// # IP addresses which offer the related ports but are not currently marked as ready +// +// because they have not yet finished starting, have recently failed a readiness check, +// +// or have recently failed a liveness check. +func (d *EndpointSubsetDie) NotReadyAddressesDie(v ...*EndpointAddressDie) *EndpointSubsetDie { + return d.DieStamp(func(r *corev1.EndpointSubset) { + r.NotReadyAddresses = make([]corev1.EndpointAddress, len(v)) + for i := range v { + r.NotReadyAddresses[i] = v[i].DieRelease() + } + }) +} + +// PortsDie replaces Ports by collecting the released value from each die passed. +// +// Port numbers available on the related IP addresses. +func (d *EndpointSubsetDie) PortsDie(v ...*EndpointPortDie) *EndpointSubsetDie { + return d.DieStamp(func(r *corev1.EndpointSubset) { + r.Ports = make([]corev1.EndpointPort, len(v)) + for i := range v { + r.Ports[i] = v[i].DieRelease() + } + }) +} + // IP addresses which offer the related ports that are marked as ready. These endpoints // // should be considered safe for load balancers and clients to utilize. @@ -14086,6 +14876,17 @@ func (d *EndpointAddressDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// TargetRefDie mutates TargetRef as a die. +// +// Reference to object providing the endpoint. +func (d *EndpointAddressDie) TargetRefDie(fn func(d *ObjectReferenceDie)) *EndpointAddressDie { + return d.DieStamp(func(r *corev1.EndpointAddress) { + d := ObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.TargetRef) + fn(d) + r.TargetRef = d.DieReleasePtr() + }) +} + // The IP of this endpoint. // // May not be loopback (127.0.0.0/8 or ::1), link-local (169.254.0.0/16 or fe80::/10), @@ -14729,6 +15530,50 @@ func (d *EventDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *EventDie { }) } +// InvolvedObjectDie mutates InvolvedObject as a die. +// +// The object that this event is about. +func (d *EventDie) InvolvedObjectDie(fn func(d *ObjectReferenceDie)) *EventDie { + return d.DieStamp(func(r *corev1.Event) { + d := ObjectReferenceBlank.DieImmutable(false).DieFeed(r.InvolvedObject) + fn(d) + r.InvolvedObject = d.DieRelease() + }) +} + +// SourceDie mutates Source as a die. +// +// The component reporting this event. Should be a short machine understandable string. +func (d *EventDie) SourceDie(fn func(d *EventSourceDie)) *EventDie { + return d.DieStamp(func(r *corev1.Event) { + d := EventSourceBlank.DieImmutable(false).DieFeed(r.Source) + fn(d) + r.Source = d.DieRelease() + }) +} + +// SeriesDie mutates Series as a die. +// +// Data about the Event series this event represents or nil if it's a singleton Event. +func (d *EventDie) SeriesDie(fn func(d *EventSeriesDie)) *EventDie { + return d.DieStamp(func(r *corev1.Event) { + d := EventSeriesBlank.DieImmutable(false).DieFeedPtr(r.Series) + fn(d) + r.Series = d.DieReleasePtr() + }) +} + +// RelatedDie mutates Related as a die. +// +// Optional secondary object for more complex actions. +func (d *EventDie) RelatedDie(fn func(d *ObjectReferenceDie)) *EventDie { + return d.DieStamp(func(r *corev1.Event) { + d := ObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.Related) + fn(d) + r.Related = d.DieReleasePtr() + }) +} + // The object that this event is about. func (d *EventDie) InvolvedObject(v corev1.ObjectReference) *EventDie { return d.DieStamp(func(r *corev1.Event) { @@ -15886,6 +16731,18 @@ func (d *LimitRangeSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// LimitsDie replaces Limits by collecting the released value from each die passed. +// +// Limits is the list of LimitRangeItem objects that are enforced. +func (d *LimitRangeSpecDie) LimitsDie(v ...*LimitRangeItemDie) *LimitRangeSpecDie { + return d.DieStamp(func(r *corev1.LimitRangeSpec) { + r.Limits = make([]corev1.LimitRangeItem, len(v)) + for i := range v { + r.Limits[i] = v[i].DieRelease() + } + }) +} + // Limits is the list of LimitRangeItem objects that are enforced. func (d *LimitRangeSpecDie) Limits(v ...corev1.LimitRangeItem) *LimitRangeSpecDie { return d.DieStamp(func(r *corev1.LimitRangeSpec) { @@ -17694,6 +18551,37 @@ func (d *NodeSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ConfigSourceDie mutates ConfigSource as a die. +// +// Deprecated: Previously used to specify the source of the node's configuration for the DynamicKubeletConfig feature. This feature is removed. +func (d *NodeSpecDie) ConfigSourceDie(fn func(d *NodeConfigSourceDie)) *NodeSpecDie { + return d.DieStamp(func(r *corev1.NodeSpec) { + d := NodeConfigSourceBlank.DieImmutable(false).DieFeedPtr(r.ConfigSource) + fn(d) + r.ConfigSource = d.DieReleasePtr() + }) +} + +// TaintDie mutates a single item in Taints matched by the nested field Key, appending a new item if no match is found. +// +// If specified, the node's taints. +func (d *NodeSpecDie) TaintDie(v string, fn func(d *TaintDie)) *NodeSpecDie { + return d.DieStamp(func(r *corev1.NodeSpec) { + for i := range r.Taints { + if v == r.Taints[i].Key { + d := TaintBlank.DieImmutable(false).DieFeed(r.Taints[i]) + fn(d) + r.Taints[i] = d.DieRelease() + return + } + } + + d := TaintBlank.DieImmutable(false).DieFeed(corev1.Taint{Key: v}) + fn(d) + r.Taints = append(r.Taints, d.DieRelease()) + }) +} + // PodCIDR represents the pod IP range assigned to the node. func (d *NodeSpecDie) PodCIDR(v string) *NodeSpecDie { return d.DieStamp(func(r *corev1.NodeSpec) { @@ -18241,6 +19129,17 @@ func (d *NodeConfigSourceDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// ConfigMapDie mutates ConfigMap as a die. +// +// ConfigMap is a reference to a Node's ConfigMap +func (d *NodeConfigSourceDie) ConfigMapDie(fn func(d *ConfigMapNodeConfigSourceDie)) *NodeConfigSourceDie { + return d.DieStamp(func(r *corev1.NodeConfigSource) { + d := ConfigMapNodeConfigSourceBlank.DieImmutable(false).DieFeedPtr(r.ConfigMap) + fn(d) + r.ConfigMap = d.DieReleasePtr() + }) +} + // ConfigMap is a reference to a Node's ConfigMap func (d *NodeConfigSourceDie) ConfigMap(v *corev1.ConfigMapNodeConfigSource) *NodeConfigSourceDie { return d.DieStamp(func(r *corev1.NodeConfigSource) { @@ -18749,6 +19648,115 @@ func (d *NodeStatusDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// DaemonEndpointsDie mutates DaemonEndpoints as a die. +// +// Endpoints of daemons running on the Node. +func (d *NodeStatusDie) DaemonEndpointsDie(fn func(d *NodeDaemonEndpointsDie)) *NodeStatusDie { + return d.DieStamp(func(r *corev1.NodeStatus) { + d := NodeDaemonEndpointsBlank.DieImmutable(false).DieFeed(r.DaemonEndpoints) + fn(d) + r.DaemonEndpoints = d.DieRelease() + }) +} + +// NodeInfoDie mutates NodeInfo as a die. +// +// Set of ids/uuids to uniquely identify the node. +// +// More info: https://kubernetes.io/docs/concepts/nodes/node/#info +func (d *NodeStatusDie) NodeInfoDie(fn func(d *NodeSystemInfoDie)) *NodeStatusDie { + return d.DieStamp(func(r *corev1.NodeStatus) { + d := NodeSystemInfoBlank.DieImmutable(false).DieFeed(r.NodeInfo) + fn(d) + r.NodeInfo = d.DieRelease() + }) +} + +// ConfigDie mutates Config as a die. +// +// Status of the config assigned to the node via the dynamic Kubelet config feature. +func (d *NodeStatusDie) ConfigDie(fn func(d *NodeConfigStatusDie)) *NodeStatusDie { + return d.DieStamp(func(r *corev1.NodeStatus) { + d := NodeConfigStatusBlank.DieImmutable(false).DieFeedPtr(r.Config) + fn(d) + r.Config = d.DieReleasePtr() + }) +} + +// AddressesDie replaces Addresses by collecting the released value from each die passed. +// +// List of addresses reachable to the node. +// +// Queried from cloud provider, if available. +// +// More info: https://kubernetes.io/docs/concepts/nodes/node/#addresses +// +// Note: This field is declared as mergeable, but the merge key is not sufficiently +// +// unique, which can cause data corruption when it is merged. Callers should instead +// +// use a full-replacement patch. See https://pr.k8s.io/79391 for an example. +// +// # Consumers should assume that addresses can change during the +// +// lifetime of a Node. However, there are some exceptions where this may not +// +// be possible, such as Pods that inherit a Node's address in its own status or +// +// consumers of the downward API (status.hostIP). +func (d *NodeStatusDie) AddressesDie(v ...*NodeAddressDie) *NodeStatusDie { + return d.DieStamp(func(r *corev1.NodeStatus) { + r.Addresses = make([]corev1.NodeAddress, len(v)) + for i := range v { + r.Addresses[i] = v[i].DieRelease() + } + }) +} + +// ImagesDie replaces Images by collecting the released value from each die passed. +// +// List of container images on this node +func (d *NodeStatusDie) ImagesDie(v ...*ContainerImageDie) *NodeStatusDie { + return d.DieStamp(func(r *corev1.NodeStatus) { + r.Images = make([]corev1.ContainerImage, len(v)) + for i := range v { + r.Images[i] = v[i].DieRelease() + } + }) +} + +// VolumeAttachedDie mutates a single item in VolumesAttached matched by the nested field Name, appending a new item if no match is found. +// +// List of volumes that are attached to the node. +func (d *NodeStatusDie) VolumeAttachedDie(v corev1.UniqueVolumeName, fn func(d *AttachedVolumeDie)) *NodeStatusDie { + return d.DieStamp(func(r *corev1.NodeStatus) { + for i := range r.VolumesAttached { + if v == r.VolumesAttached[i].Name { + d := AttachedVolumeBlank.DieImmutable(false).DieFeed(r.VolumesAttached[i]) + fn(d) + r.VolumesAttached[i] = d.DieRelease() + return + } + } + + d := AttachedVolumeBlank.DieImmutable(false).DieFeed(corev1.AttachedVolume{Name: v}) + fn(d) + r.VolumesAttached = append(r.VolumesAttached, d.DieRelease()) + }) +} + +// RuntimeHandlersDie replaces RuntimeHandlers by collecting the released value from each die passed. +// +// The available runtime handlers. +func (d *NodeStatusDie) RuntimeHandlersDie(v ...*NodeRuntimeHandlerDie) *NodeStatusDie { + return d.DieStamp(func(r *corev1.NodeStatus) { + r.RuntimeHandlers = make([]corev1.NodeRuntimeHandler, len(v)) + for i := range v { + r.RuntimeHandlers[i] = v[i].DieRelease() + } + }) +} + // Capacity represents the total resources of a node. // // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#capacity @@ -19381,6 +20389,17 @@ func (d *NodeDaemonEndpointsDie) DiePatch(patchType types.PatchType) ([]byte, er return patch.Create(d.seal, d.r, patchType) } +// KubeletEndpointDie mutates KubeletEndpoint as a die. +// +// Endpoint on which Kubelet is listening. +func (d *NodeDaemonEndpointsDie) KubeletEndpointDie(fn func(d *DaemonEndpointDie)) *NodeDaemonEndpointsDie { + return d.DieStamp(func(r *corev1.NodeDaemonEndpoints) { + d := DaemonEndpointBlank.DieImmutable(false).DieFeed(r.KubeletEndpoint) + fn(d) + r.KubeletEndpoint = d.DieRelease() + }) +} + // Endpoint on which Kubelet is listening. func (d *NodeDaemonEndpointsDie) KubeletEndpoint(v corev1.DaemonEndpoint) *NodeDaemonEndpointsDie { return d.DieStamp(func(r *corev1.NodeDaemonEndpoints) { @@ -20643,6 +21662,79 @@ func (d *NodeConfigStatusDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// AssignedDie mutates Assigned as a die. +// +// Assigned reports the checkpointed config the node will try to use. +// +// # When Node.Spec.ConfigSource is updated, the node checkpoints the associated +// +// config payload to local disk, along with a record indicating intended +// +// config. The node refers to this record to choose its config checkpoint, and +// +// reports this record in Assigned. Assigned only updates in the status after +// +// the record has been checkpointed to disk. When the Kubelet is restarted, +// +// it tries to make the Assigned config the Active config by loading and +// +// validating the checkpointed payload identified by Assigned. +func (d *NodeConfigStatusDie) AssignedDie(fn func(d *NodeConfigSourceDie)) *NodeConfigStatusDie { + return d.DieStamp(func(r *corev1.NodeConfigStatus) { + d := NodeConfigSourceBlank.DieImmutable(false).DieFeedPtr(r.Assigned) + fn(d) + r.Assigned = d.DieReleasePtr() + }) +} + +// ActiveDie mutates Active as a die. +// +// Active reports the checkpointed config the node is actively using. +// +// Active will represent either the current version of the Assigned config, +// +// or the current LastKnownGood config, depending on whether attempting to use the +// +// Assigned config results in an error. +func (d *NodeConfigStatusDie) ActiveDie(fn func(d *NodeConfigSourceDie)) *NodeConfigStatusDie { + return d.DieStamp(func(r *corev1.NodeConfigStatus) { + d := NodeConfigSourceBlank.DieImmutable(false).DieFeedPtr(r.Active) + fn(d) + r.Active = d.DieReleasePtr() + }) +} + +// LastKnownGoodDie mutates LastKnownGood as a die. +// +// # LastKnownGood reports the checkpointed config the node will fall back to +// +// when it encounters an error attempting to use the Assigned config. +// +// # The Assigned config becomes the LastKnownGood config when the node determines +// +// that the Assigned config is stable and correct. +// +// # This is currently implemented as a 10-minute soak period starting when the local +// +// record of Assigned config is updated. If the Assigned config is Active at the end +// +// of this period, it becomes the LastKnownGood. Note that if Spec.ConfigSource is +// +// reset to nil (use local defaults), the LastKnownGood is also immediately reset to nil, +// +// because the local default config is always assumed good. +// +// # You should not make assumptions about the node's method of determining config stability +// +// and correctness, as this may change or become configurable in the future. +func (d *NodeConfigStatusDie) LastKnownGoodDie(fn func(d *NodeConfigSourceDie)) *NodeConfigStatusDie { + return d.DieStamp(func(r *corev1.NodeConfigStatus) { + d := NodeConfigSourceBlank.DieImmutable(false).DieFeedPtr(r.LastKnownGood) + fn(d) + r.LastKnownGood = d.DieReleasePtr() + }) +} + // Assigned reports the checkpointed config the node will try to use. // // # When Node.Spec.ConfigSource is updated, the node checkpoints the associated @@ -20961,6 +22053,17 @@ func (d *NodeRuntimeHandlerDie) DiePatch(patchType types.PatchType) ([]byte, err return patch.Create(d.seal, d.r, patchType) } +// FeaturesDie mutates Features as a die. +// +// Supported features. +func (d *NodeRuntimeHandlerDie) FeaturesDie(fn func(d *NodeRuntimeHandlerFeaturesDie)) *NodeRuntimeHandlerDie { + return d.DieStamp(func(r *corev1.NodeRuntimeHandler) { + d := NodeRuntimeHandlerFeaturesBlank.DieImmutable(false).DieFeedPtr(r.Features) + fn(d) + r.Features = d.DieReleasePtr() + }) +} + // Runtime handler name. // // Empty for the default runtime handler. @@ -21805,6 +22908,19 @@ func (d *PersistentVolumeSpecDie) DiePatch(patchType types.PatchType) ([]byte, e return patch.Create(d.seal, d.r, patchType) } +// NodeAffinityDie mutates NodeAffinity as a die. +// +// nodeAffinity defines constraints that limit what nodes this volume can be accessed from. +// +// This field influences the scheduling of pods that use this volume. +func (d *PersistentVolumeSpecDie) NodeAffinityDie(fn func(d *VolumeNodeAffinityDie)) *PersistentVolumeSpecDie { + return d.DieStamp(func(r *corev1.PersistentVolumeSpec) { + d := VolumeNodeAffinityBlank.DieImmutable(false).DieFeedPtr(r.NodeAffinity) + fn(d) + r.NodeAffinity = d.DieReleasePtr() + }) +} + // capacity is the description of the persistent volume's resources and capacity. // // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#capacity @@ -22699,6 +23815,23 @@ func (d *RBDPersistentVolumeSourceDie) DiePatch(patchType types.PatchType) ([]by return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef is name of the authentication secret for RBDUser. If provided +// +// overrides keyring. +// +// Default is nil. +// +// More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it +func (d *RBDPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *RBDPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.RBDPersistentVolumeSource) { + d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // monitors is a collection of Ceph monitors. // // More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it @@ -23017,6 +24150,17 @@ func (d *ISCSIPersistentVolumeSourceDie) DiePatch(patchType types.PatchType) ([] return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef is the CHAP Secret for iSCSI target and initiator authentication +func (d *ISCSIPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *ISCSIPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.ISCSIPersistentVolumeSource) { + d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // targetPortal is iSCSI Target Portal. The Portal is either an IP or ip_addr:port if the port // // is other than default (typically TCP ports 860 and 3260). @@ -23342,6 +24486,19 @@ func (d *CinderPersistentVolumeSourceDie) DiePatch(patchType types.PatchType) ([ return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef is Optional: points to a secret object containing parameters used to connect +// +// to OpenStack. +func (d *CinderPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *CinderPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.CinderPersistentVolumeSource) { + d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // volumeID used to identify the volume in cinder. // // More info: https://examples.k8s.io/mysql-cinder-pd/README.md @@ -23612,6 +24769,19 @@ func (d *CephFSPersistentVolumeSourceDie) DiePatch(patchType types.PatchType) ([ return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef is Optional: SecretRef is reference to the authentication secret for User, default is empty. +// +// More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it +func (d *CephFSPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *CephFSPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.CephFSPersistentVolumeSource) { + d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // monitors is Required: Monitors is a collection of Ceph monitors // // More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it @@ -23894,6 +25064,25 @@ func (d *FlexPersistentVolumeSourceDie) DiePatch(patchType types.PatchType) ([]b return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef is Optional: SecretRef is reference to the secret object containing +// +// sensitive information to pass to the plugin scripts. This may be +// +// empty if no secret object is specified. If the secret object +// +// contains more than one secret, all secrets are passed to the plugin +// +// scripts. +func (d *FlexPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *FlexPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.FlexPersistentVolumeSource) { + d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // driver is the name of the driver to use for this volume. func (d *FlexPersistentVolumeSourceDie) Driver(v string) *FlexPersistentVolumeSourceDie { return d.DieStamp(func(r *corev1.FlexPersistentVolumeSource) { @@ -24431,6 +25620,19 @@ func (d *ScaleIOPersistentVolumeSourceDie) DiePatch(patchType types.PatchType) ( return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef references to the secret for ScaleIO user and other +// +// sensitive information. If this is not provided, Login operation will fail. +func (d *ScaleIOPersistentVolumeSourceDie) SecretRefDie(fn func(d *SecretReferenceDie)) *ScaleIOPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.ScaleIOPersistentVolumeSource) { + d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // gateway is the host address of the ScaleIO API Gateway. func (d *ScaleIOPersistentVolumeSourceDie) Gateway(v string) *ScaleIOPersistentVolumeSourceDie { return d.DieStamp(func(r *corev1.ScaleIOPersistentVolumeSource) { @@ -24993,6 +26195,19 @@ func (d *StorageOSPersistentVolumeSourceDie) DiePatch(patchType types.PatchType) return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef specifies the secret to use for obtaining the StorageOS API +// +// credentials. If not specified, default values will be attempted. +func (d *StorageOSPersistentVolumeSourceDie) SecretRefDie(fn func(d *ObjectReferenceDie)) *StorageOSPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.StorageOSPersistentVolumeSource) { + d := ObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // volumeName is the human-readable name of the StorageOS volume. Volume // // names are only unique within a namespace. @@ -25276,6 +26491,101 @@ func (d *CSIPersistentVolumeSourceDie) DiePatch(patchType types.PatchType) ([]by return patch.Create(d.seal, d.r, patchType) } +// ControllerPublishSecretRefDie mutates ControllerPublishSecretRef as a die. +// +// controllerPublishSecretRef is a reference to the secret object containing +// +// sensitive information to pass to the CSI driver to complete the CSI +// +// ControllerPublishVolume and ControllerUnpublishVolume calls. +// +// This field is optional, and may be empty if no secret is required. If the +// +// secret object contains more than one secret, all secrets are passed. +func (d *CSIPersistentVolumeSourceDie) ControllerPublishSecretRefDie(fn func(d *SecretReferenceDie)) *CSIPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.CSIPersistentVolumeSource) { + d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.ControllerPublishSecretRef) + fn(d) + r.ControllerPublishSecretRef = d.DieReleasePtr() + }) +} + +// NodeStageSecretRefDie mutates NodeStageSecretRef as a die. +// +// nodeStageSecretRef is a reference to the secret object containing sensitive +// +// information to pass to the CSI driver to complete the CSI NodeStageVolume +// +// and NodeStageVolume and NodeUnstageVolume calls. +// +// This field is optional, and may be empty if no secret is required. If the +// +// secret object contains more than one secret, all secrets are passed. +func (d *CSIPersistentVolumeSourceDie) NodeStageSecretRefDie(fn func(d *SecretReferenceDie)) *CSIPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.CSIPersistentVolumeSource) { + d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.NodeStageSecretRef) + fn(d) + r.NodeStageSecretRef = d.DieReleasePtr() + }) +} + +// NodePublishSecretRefDie mutates NodePublishSecretRef as a die. +// +// nodePublishSecretRef is a reference to the secret object containing +// +// sensitive information to pass to the CSI driver to complete the CSI +// +// NodePublishVolume and NodeUnpublishVolume calls. +// +// This field is optional, and may be empty if no secret is required. If the +// +// secret object contains more than one secret, all secrets are passed. +func (d *CSIPersistentVolumeSourceDie) NodePublishSecretRefDie(fn func(d *SecretReferenceDie)) *CSIPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.CSIPersistentVolumeSource) { + d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.NodePublishSecretRef) + fn(d) + r.NodePublishSecretRef = d.DieReleasePtr() + }) +} + +// ControllerExpandSecretRefDie mutates ControllerExpandSecretRef as a die. +// +// controllerExpandSecretRef is a reference to the secret object containing +// +// sensitive information to pass to the CSI driver to complete the CSI +// +// ControllerExpandVolume call. +// +// This field is optional, and may be empty if no secret is required. If the +// +// secret object contains more than one secret, all secrets are passed. +func (d *CSIPersistentVolumeSourceDie) ControllerExpandSecretRefDie(fn func(d *SecretReferenceDie)) *CSIPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.CSIPersistentVolumeSource) { + d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.ControllerExpandSecretRef) + fn(d) + r.ControllerExpandSecretRef = d.DieReleasePtr() + }) +} + +// NodeExpandSecretRefDie mutates NodeExpandSecretRef as a die. +// +// nodeExpandSecretRef is a reference to the secret object containing +// +// sensitive information to pass to the CSI driver to complete the CSI +// +// NodeExpandVolume call. +// +// This field is optional, may be omitted if no secret is required. If the +// +// secret object contains more than one secret, all secrets are passed. +func (d *CSIPersistentVolumeSourceDie) NodeExpandSecretRefDie(fn func(d *SecretReferenceDie)) *CSIPersistentVolumeSourceDie { + return d.DieStamp(func(r *corev1.CSIPersistentVolumeSource) { + d := SecretReferenceBlank.DieImmutable(false).DieFeedPtr(r.NodeExpandSecretRef) + fn(d) + r.NodeExpandSecretRef = d.DieReleasePtr() + }) +} + // driver is the name of the driver to use for this volume. // // Required. @@ -25624,6 +26934,17 @@ func (d *VolumeNodeAffinityDie) DiePatch(patchType types.PatchType) ([]byte, err return patch.Create(d.seal, d.r, patchType) } +// RequiredDie mutates Required as a die. +// +// required specifies hard node constraints that must be met. +func (d *VolumeNodeAffinityDie) RequiredDie(fn func(d *NodeSelectorDie)) *VolumeNodeAffinityDie { + return d.DieStamp(func(r *corev1.VolumeNodeAffinity) { + d := NodeSelectorBlank.DieImmutable(false).DieFeedPtr(r.Required) + fn(d) + r.Required = d.DieReleasePtr() + }) +} + // required specifies hard node constraints that must be met. func (d *VolumeNodeAffinityDie) Required(v *corev1.NodeSelector) *VolumeNodeAffinityDie { return d.DieStamp(func(r *corev1.VolumeNodeAffinity) { @@ -25859,6 +27180,18 @@ func (d *NodeSelectorDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// NodeSelectorTermsDie replaces NodeSelectorTerms by collecting the released value from each die passed. +// +// Required. A list of node selector terms. The terms are ORed. +func (d *NodeSelectorDie) NodeSelectorTermsDie(v ...*NodeSelectorTermDie) *NodeSelectorDie { + return d.DieStamp(func(r *corev1.NodeSelector) { + r.NodeSelectorTerms = make([]corev1.NodeSelectorTerm, len(v)) + for i := range v { + r.NodeSelectorTerms[i] = v[i].DieRelease() + } + }) +} + // Required. A list of node selector terms. The terms are ORed. func (d *NodeSelectorDie) NodeSelectorTerms(v ...corev1.NodeSelectorTerm) *NodeSelectorDie { return d.DieStamp(func(r *corev1.NodeSelector) { @@ -26094,6 +27427,46 @@ func (d *NodeSelectorTermDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// MatchExpressionDie mutates a single item in MatchExpressions matched by the nested field Key, appending a new item if no match is found. +// +// A list of node selector requirements by node's labels. +func (d *NodeSelectorTermDie) MatchExpressionDie(v string, fn func(d *NodeSelectorRequirementDie)) *NodeSelectorTermDie { + return d.DieStamp(func(r *corev1.NodeSelectorTerm) { + for i := range r.MatchExpressions { + if v == r.MatchExpressions[i].Key { + d := NodeSelectorRequirementBlank.DieImmutable(false).DieFeed(r.MatchExpressions[i]) + fn(d) + r.MatchExpressions[i] = d.DieRelease() + return + } + } + + d := NodeSelectorRequirementBlank.DieImmutable(false).DieFeed(corev1.NodeSelectorRequirement{Key: v}) + fn(d) + r.MatchExpressions = append(r.MatchExpressions, d.DieRelease()) + }) +} + +// MatchFieldDie mutates a single item in MatchFields matched by the nested field Key, appending a new item if no match is found. +// +// A list of node selector requirements by node's fields. +func (d *NodeSelectorTermDie) MatchFieldDie(v string, fn func(d *NodeSelectorRequirementDie)) *NodeSelectorTermDie { + return d.DieStamp(func(r *corev1.NodeSelectorTerm) { + for i := range r.MatchFields { + if v == r.MatchFields[i].Key { + d := NodeSelectorRequirementBlank.DieImmutable(false).DieFeed(r.MatchFields[i]) + fn(d) + r.MatchFields[i] = d.DieRelease() + return + } + } + + d := NodeSelectorRequirementBlank.DieImmutable(false).DieFeed(corev1.NodeSelectorRequirement{Key: v}) + fn(d) + r.MatchFields = append(r.MatchFields, d.DieRelease()) + }) +} + // A list of node selector requirements by node's labels. func (d *NodeSelectorTermDie) MatchExpressions(v ...corev1.NodeSelectorRequirement) *NodeSelectorTermDie { return d.DieStamp(func(r *corev1.NodeSelectorTerm) { @@ -26956,6 +28329,116 @@ func (d *PersistentVolumeClaimSpecDie) DiePatch(patchType types.PatchType) ([]by return patch.Create(d.seal, d.r, patchType) } +// SelectorDie mutates Selector as a die. +// +// selector is a label query over volumes to consider for binding. +func (d *PersistentVolumeClaimSpecDie) SelectorDie(fn func(d *metav1.LabelSelectorDie)) *PersistentVolumeClaimSpecDie { + return d.DieStamp(func(r *corev1.PersistentVolumeClaimSpec) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.Selector) + fn(d) + r.Selector = d.DieReleasePtr() + }) +} + +// ResourcesDie mutates Resources as a die. +// +// resources represents the minimum resources the volume should have. +// +// # If RecoverVolumeExpansionFailure feature is enabled users are allowed to specify resource requirements +// +// that are lower than previous value but must still be higher than capacity recorded in the +// +// status field of the claim. +// +// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#resources +func (d *PersistentVolumeClaimSpecDie) ResourcesDie(fn func(d *VolumeResourceRequirementsDie)) *PersistentVolumeClaimSpecDie { + return d.DieStamp(func(r *corev1.PersistentVolumeClaimSpec) { + d := VolumeResourceRequirementsBlank.DieImmutable(false).DieFeed(r.Resources) + fn(d) + r.Resources = d.DieRelease() + }) +} + +// DataSourceDie mutates DataSource as a die. +// +// dataSource field can be used to specify either: +// +// * An existing VolumeSnapshot object (snapshot.storage.k8s.io/VolumeSnapshot) +// +// * An existing PVC (PersistentVolumeClaim) +// +// If the provisioner or an external controller can support the specified data source, +// +// it will create a new volume based on the contents of the specified data source. +// +// When the AnyVolumeDataSource feature gate is enabled, dataSource contents will be copied to dataSourceRef, +// +// and dataSourceRef contents will be copied to dataSource when dataSourceRef.namespace is not specified. +// +// If the namespace is specified, then dataSourceRef will not be copied to dataSource. +func (d *PersistentVolumeClaimSpecDie) DataSourceDie(fn func(d *TypedLocalObjectReferenceDie)) *PersistentVolumeClaimSpecDie { + return d.DieStamp(func(r *corev1.PersistentVolumeClaimSpec) { + d := TypedLocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.DataSource) + fn(d) + r.DataSource = d.DieReleasePtr() + }) +} + +// DataSourceRefDie mutates DataSourceRef as a die. +// +// dataSourceRef specifies the object from which to populate the volume with data, if a non-empty +// +// volume is desired. This may be any object from a non-empty API group (non +// +// core object) or a PersistentVolumeClaim object. +// +// # When this field is specified, volume binding will only succeed if the type of +// +// the specified object matches some installed volume populator or dynamic +// +// provisioner. +// +// # This field will replace the functionality of the dataSource field and as such +// +// if both fields are non-empty, they must have the same value. For backwards +// +// compatibility, when namespace isn't specified in dataSourceRef, +// +// both fields (dataSource and dataSourceRef) will be set to the same +// +// value automatically if one of them is empty and the other is non-empty. +// +// When namespace is specified in dataSourceRef, +// +// dataSource isn't set to the same value and must be empty. +// +// There are three important differences between dataSource and dataSourceRef: +// +// * While dataSource only allows two specific types of objects, dataSourceRef +// +// allows any non-core object, as well as PersistentVolumeClaim objects. +// +// * While dataSource ignores disallowed values (dropping them), dataSourceRef +// +// preserves all values, and generates an error if a disallowed value is +// +// specified. +// +// * While dataSource only allows local objects, dataSourceRef allows objects +// +// in any namespaces. +// +// (Beta) Using this field requires the AnyVolumeDataSource feature gate to be enabled. +// +// (Alpha) Using the namespace field of dataSourceRef requires the CrossNamespaceVolumeDataSource feature gate to be enabled. +func (d *PersistentVolumeClaimSpecDie) DataSourceRefDie(fn func(d *TypedObjectReferenceDie)) *PersistentVolumeClaimSpecDie { + return d.DieStamp(func(r *corev1.PersistentVolumeClaimSpec) { + d := TypedObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.DataSourceRef) + fn(d) + r.DataSourceRef = d.DieReleasePtr() + }) +} + // accessModes contains the desired access modes the volume should have. // // More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#access-modes-1 @@ -27647,6 +29130,21 @@ func (d *PersistentVolumeClaimStatusDie) DiePatch(patchType types.PatchType) ([] return patch.Create(d.seal, d.r, patchType) } +// ModifyVolumeStatusDie mutates ModifyVolumeStatus as a die. +// +// ModifyVolumeStatus represents the status object of ControllerModifyVolume operation. +// +// When this is unset, there is no ModifyVolume operation being attempted. +// +// This is an alpha field and requires enabling VolumeAttributesClass feature. +func (d *PersistentVolumeClaimStatusDie) ModifyVolumeStatusDie(fn func(d *ModifyVolumeStatusDie)) *PersistentVolumeClaimStatusDie { + return d.DieStamp(func(r *corev1.PersistentVolumeClaimStatus) { + d := ModifyVolumeStatusBlank.DieImmutable(false).DieFeedPtr(r.ModifyVolumeStatus) + fn(d) + r.ModifyVolumeStatus = d.DieReleasePtr() + }) +} + // phase represents the current phase of PersistentVolumeClaim. func (d *PersistentVolumeClaimStatusDie) Phase(v corev1.PersistentVolumeClaimPhase) *PersistentVolumeClaimStatusDie { return d.DieStamp(func(r *corev1.PersistentVolumeClaimStatus) { @@ -28344,6 +29842,38 @@ func (d *PersistentVolumeClaimTemplateDie) DiePatch(patchType types.PatchType) ( return patch.Create(d.seal, d.r, patchType) } +// ObjectMetaDie mutates ObjectMeta as a die. +// +// # May contain labels and annotations that will be copied into the PVC +// +// when creating it. No other fields are allowed and will be rejected during +// +// validation. +func (d *PersistentVolumeClaimTemplateDie) ObjectMetaDie(fn func(d *metav1.ObjectMetaDie)) *PersistentVolumeClaimTemplateDie { + return d.DieStamp(func(r *corev1.PersistentVolumeClaimTemplate) { + d := metav1.ObjectMetaBlank.DieImmutable(false).DieFeed(r.ObjectMeta) + fn(d) + r.ObjectMeta = d.DieRelease() + }) +} + +// SpecDie mutates Spec as a die. +// +// The specification for the PersistentVolumeClaim. The entire content is +// +// copied unchanged into the PVC that gets created from this +// +// template. The same fields as in a PersistentVolumeClaim +// +// are also valid here. +func (d *PersistentVolumeClaimTemplateDie) SpecDie(fn func(d *PersistentVolumeClaimSpecDie)) *PersistentVolumeClaimTemplateDie { + return d.DieStamp(func(r *corev1.PersistentVolumeClaimTemplate) { + d := PersistentVolumeClaimSpecBlank.DieImmutable(false).DieFeed(r.Spec) + fn(d) + r.Spec = d.DieRelease() + }) +} + // May contain labels and annotations that will be copied into the PVC // // when creating it. No other fields are allowed and will be rejected during @@ -28961,6 +30491,309 @@ func (d *PodSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// SecurityContextDie mutates SecurityContext as a die. +// +// SecurityContext holds pod-level security attributes and common container settings. +// +// Optional: Defaults to empty. See type description for default values of each field. +func (d *PodSpecDie) SecurityContextDie(fn func(d *PodSecurityContextDie)) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + d := PodSecurityContextBlank.DieImmutable(false).DieFeedPtr(r.SecurityContext) + fn(d) + r.SecurityContext = d.DieReleasePtr() + }) +} + +// DNSConfigDie mutates DNSConfig as a die. +// +// Specifies the DNS parameters of a pod. +// +// # Parameters specified here will be merged to the generated DNS +// +// configuration based on DNSPolicy. +func (d *PodSpecDie) DNSConfigDie(fn func(d *PodDNSConfigDie)) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + d := PodDNSConfigBlank.DieImmutable(false).DieFeedPtr(r.DNSConfig) + fn(d) + r.DNSConfig = d.DieReleasePtr() + }) +} + +// OSDie mutates OS as a die. +// +// Specifies the OS of the containers in the pod. +// +// Some pod and container fields are restricted if this is set. +// +// If the OS field is set to linux, the following fields must be unset: +// +// -securityContext.windowsOptions +// +// If the OS field is set to windows, following fields must be unset: +// +// - spec.hostPID +// +// - spec.hostIPC +// +// - spec.hostUsers +// +// - spec.securityContext.appArmorProfile +// +// - spec.securityContext.seLinuxOptions +// +// - spec.securityContext.seccompProfile +// +// - spec.securityContext.fsGroup +// +// - spec.securityContext.fsGroupChangePolicy +// +// - spec.securityContext.sysctls +// +// - spec.shareProcessNamespace +// +// - spec.securityContext.runAsUser +// +// - spec.securityContext.runAsGroup +// +// - spec.securityContext.supplementalGroups +// +// - spec.containers[*].securityContext.appArmorProfile +// +// - spec.containers[*].securityContext.seLinuxOptions +// +// - spec.containers[*].securityContext.seccompProfile +// +// - spec.containers[*].securityContext.capabilities +// +// - spec.containers[*].securityContext.readOnlyRootFilesystem +// +// - spec.containers[*].securityContext.privileged +// +// - spec.containers[*].securityContext.allowPrivilegeEscalation +// +// - spec.containers[*].securityContext.procMount +// +// - spec.containers[*].securityContext.runAsUser +// +// - spec.containers[*].securityContext.runAsGroup +func (d *PodSpecDie) OSDie(fn func(d *PodOSDie)) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + d := PodOSBlank.DieImmutable(false).DieFeedPtr(r.OS) + fn(d) + r.OS = d.DieReleasePtr() + }) +} + +// VolumeDie mutates a single item in Volumes matched by the nested field Name, appending a new item if no match is found. +// +// List of volumes that can be mounted by containers belonging to the pod. +// +// More info: https://kubernetes.io/docs/concepts/storage/volumes +func (d *PodSpecDie) VolumeDie(v string, fn func(d *VolumeDie)) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + for i := range r.Volumes { + if v == r.Volumes[i].Name { + d := VolumeBlank.DieImmutable(false).DieFeed(r.Volumes[i]) + fn(d) + r.Volumes[i] = d.DieRelease() + return + } + } + + d := VolumeBlank.DieImmutable(false).DieFeed(corev1.Volume{Name: v}) + fn(d) + r.Volumes = append(r.Volumes, d.DieRelease()) + }) +} + +// InitContainerDie mutates a single item in InitContainers matched by the nested field Name, appending a new item if no match is found. +// +// List of initialization containers belonging to the pod. +// +// Init containers are executed in order prior to containers being started. If any +// +// init container fails, the pod is considered to have failed and is handled according +// +// to its restartPolicy. The name for an init container or normal container must be +// +// unique among all containers. +// +// Init containers may not have Lifecycle actions, Readiness probes, Liveness probes, or Startup probes. +// +// # The resourceRequirements of an init container are taken into account during scheduling +// +// by finding the highest request/limit for each resource type, and then using the max of +// +// of that value or the sum of the normal containers. Limits are applied to init containers +// +// in a similar fashion. +// +// Init containers cannot currently be added or removed. +// +// Cannot be updated. +// +// More info: https://kubernetes.io/docs/concepts/workloads/pods/init-containers/ +func (d *PodSpecDie) InitContainerDie(v string, fn func(d *ContainerDie)) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + for i := range r.InitContainers { + if v == r.InitContainers[i].Name { + d := ContainerBlank.DieImmutable(false).DieFeed(r.InitContainers[i]) + fn(d) + r.InitContainers[i] = d.DieRelease() + return + } + } + + d := ContainerBlank.DieImmutable(false).DieFeed(corev1.Container{Name: v}) + fn(d) + r.InitContainers = append(r.InitContainers, d.DieRelease()) + }) +} + +// ContainerDie mutates a single item in Containers matched by the nested field Name, appending a new item if no match is found. +// +// List of containers belonging to the pod. +// +// Containers cannot currently be added or removed. +// +// There must be at least one container in a Pod. +// +// Cannot be updated. +func (d *PodSpecDie) ContainerDie(v string, fn func(d *ContainerDie)) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + for i := range r.Containers { + if v == r.Containers[i].Name { + d := ContainerBlank.DieImmutable(false).DieFeed(r.Containers[i]) + fn(d) + r.Containers[i] = d.DieRelease() + return + } + } + + d := ContainerBlank.DieImmutable(false).DieFeed(corev1.Container{Name: v}) + fn(d) + r.Containers = append(r.Containers, d.DieRelease()) + }) +} + +// TolerationDie mutates a single item in Tolerations matched by the nested field Key, appending a new item if no match is found. +// +// If specified, the pod's tolerations. +func (d *PodSpecDie) TolerationDie(v string, fn func(d *TolerationDie)) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + for i := range r.Tolerations { + if v == r.Tolerations[i].Key { + d := TolerationBlank.DieImmutable(false).DieFeed(r.Tolerations[i]) + fn(d) + r.Tolerations[i] = d.DieRelease() + return + } + } + + d := TolerationBlank.DieImmutable(false).DieFeed(corev1.Toleration{Key: v}) + fn(d) + r.Tolerations = append(r.Tolerations, d.DieRelease()) + }) +} + +// HostAliasesDie replaces HostAliases by collecting the released value from each die passed. +// +// # HostAliases is an optional list of hosts and IPs that will be injected into the pod's hosts +// +// file if specified. +func (d *PodSpecDie) HostAliasesDie(v ...*HostAliasDie) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + r.HostAliases = make([]corev1.HostAlias, len(v)) + for i := range v { + r.HostAliases[i] = v[i].DieRelease() + } + }) +} + +// ReadinessGatesDie replaces ReadinessGates by collecting the released value from each die passed. +// +// If specified, all readiness gates will be evaluated for pod readiness. +// +// # A pod is ready when all its containers are ready AND +// +// all conditions specified in the readiness gates have status equal to "True" +// +// More info: https://git.k8s.io/enhancements/keps/sig-network/580-pod-readiness-gates +func (d *PodSpecDie) ReadinessGatesDie(v ...*PodReadinessGateDie) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + r.ReadinessGates = make([]corev1.PodReadinessGate, len(v)) + for i := range v { + r.ReadinessGates[i] = v[i].DieRelease() + } + }) +} + +// TopologySpreadConstraintDie mutates a single item in TopologySpreadConstraints matched by the nested field TopologyKey, appending a new item if no match is found. +// +// # TopologySpreadConstraints describes how a group of pods ought to spread across topology +// +// domains. Scheduler will schedule pods in a way which abides by the constraints. +// +// All topologySpreadConstraints are ANDed. +func (d *PodSpecDie) TopologySpreadConstraintDie(v string, fn func(d *TopologySpreadConstraintDie)) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + for i := range r.TopologySpreadConstraints { + if v == r.TopologySpreadConstraints[i].TopologyKey { + d := TopologySpreadConstraintBlank.DieImmutable(false).DieFeed(r.TopologySpreadConstraints[i]) + fn(d) + r.TopologySpreadConstraints[i] = d.DieRelease() + return + } + } + + d := TopologySpreadConstraintBlank.DieImmutable(false).DieFeed(corev1.TopologySpreadConstraint{TopologyKey: v}) + fn(d) + r.TopologySpreadConstraints = append(r.TopologySpreadConstraints, d.DieRelease()) + }) +} + +// SchedulingGatesDie replaces SchedulingGates by collecting the released value from each die passed. +// +// SchedulingGates is an opaque list of values that if specified will block scheduling the pod. +// +// # If schedulingGates is not empty, the pod will stay in the SchedulingGated state and the +// +// scheduler will not attempt to schedule the pod. +// +// SchedulingGates can only be set at pod creation time, and be removed only afterwards. +func (d *PodSpecDie) SchedulingGatesDie(v ...*PodSchedulingGateDie) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + r.SchedulingGates = make([]corev1.PodSchedulingGate, len(v)) + for i := range v { + r.SchedulingGates[i] = v[i].DieRelease() + } + }) +} + +// ResourceClaimsDie replaces ResourceClaims by collecting the released value from each die passed. +// +// # ResourceClaims defines which ResourceClaims must be allocated +// +// and reserved before the Pod is allowed to start. The resources +// +// will be made available to those containers which consume them +// +// by name. +// +// # This is an alpha field and requires enabling the +// +// DynamicResourceAllocation feature gate. +// +// This field is immutable. +func (d *PodSpecDie) ResourceClaimsDie(v ...*PodResourceClaimDie) *PodSpecDie { + return d.DieStamp(func(r *corev1.PodSpec) { + r.ResourceClaims = make([]corev1.PodResourceClaim, len(v)) + for i := range v { + r.ResourceClaims[i] = v[i].DieRelease() + } + }) +} + // List of volumes that can be mounted by containers belonging to the pod. // // More info: https://kubernetes.io/docs/concepts/storage/volumes @@ -30013,6 +31846,17 @@ func (d *PodResourceClaimDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// SourceDie mutates Source as a die. +// +// Source describes where to find the ResourceClaim. +func (d *PodResourceClaimDie) SourceDie(fn func(d *ClaimSourceDie)) *PodResourceClaimDie { + return d.DieStamp(func(r *corev1.PodResourceClaim) { + d := ClaimSourceBlank.DieImmutable(false).DieFeed(r.Source) + fn(d) + r.Source = d.DieRelease() + }) +} + // Name uniquely identifies this resource claim inside the pod. // // This must be a DNS_LABEL. @@ -30519,6 +32363,86 @@ func (d *PodSecurityContextDie) DiePatch(patchType types.PatchType) ([]byte, err return patch.Create(d.seal, d.r, patchType) } +// SELinuxOptionsDie mutates SELinuxOptions as a die. +// +// The SELinux context to be applied to all containers. +// +// # If unspecified, the container runtime will allocate a random SELinux context for each +// +// container. May also be set in SecurityContext. If set in +// +// both SecurityContext and PodSecurityContext, the value specified in SecurityContext +// +// takes precedence for that container. +// +// Note that this field cannot be set when spec.os.name is windows. +func (d *PodSecurityContextDie) SELinuxOptionsDie(fn func(d *SELinuxOptionsDie)) *PodSecurityContextDie { + return d.DieStamp(func(r *corev1.PodSecurityContext) { + d := SELinuxOptionsBlank.DieImmutable(false).DieFeedPtr(r.SELinuxOptions) + fn(d) + r.SELinuxOptions = d.DieReleasePtr() + }) +} + +// WindowsOptionsDie mutates WindowsOptions as a die. +// +// The Windows specific settings applied to all containers. +// +// If unspecified, the options within a container's SecurityContext will be used. +// +// If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. +// +// Note that this field cannot be set when spec.os.name is linux. +func (d *PodSecurityContextDie) WindowsOptionsDie(fn func(d *WindowsSecurityContextOptionsDie)) *PodSecurityContextDie { + return d.DieStamp(func(r *corev1.PodSecurityContext) { + d := WindowsSecurityContextOptionsBlank.DieImmutable(false).DieFeedPtr(r.WindowsOptions) + fn(d) + r.WindowsOptions = d.DieReleasePtr() + }) +} + +// AppArmorProfileDie mutates AppArmorProfile as a die. +// +// appArmorProfile is the AppArmor options to use by the containers in this pod. +// +// Note that this field cannot be set when spec.os.name is windows. +func (d *PodSecurityContextDie) AppArmorProfileDie(fn func(d *AppArmorProfileDie)) *PodSecurityContextDie { + return d.DieStamp(func(r *corev1.PodSecurityContext) { + d := AppArmorProfileBlank.DieImmutable(false).DieFeedPtr(r.AppArmorProfile) + fn(d) + r.AppArmorProfile = d.DieReleasePtr() + }) +} + +// SysctlsDie replaces Sysctls by collecting the released value from each die passed. +// +// Sysctls hold a list of namespaced sysctls used for the pod. Pods with unsupported +// +// sysctls (by the container runtime) might fail to launch. +// +// Note that this field cannot be set when spec.os.name is windows. +func (d *PodSecurityContextDie) SysctlsDie(v ...*SysctlDie) *PodSecurityContextDie { + return d.DieStamp(func(r *corev1.PodSecurityContext) { + r.Sysctls = make([]corev1.Sysctl, len(v)) + for i := range v { + r.Sysctls[i] = v[i].DieRelease() + } + }) +} + +// SeccompProfileDie mutates SeccompProfile as a die. +// +// The seccomp options to use by the containers in this pod. +// +// Note that this field cannot be set when spec.os.name is windows. +func (d *PodSecurityContextDie) SeccompProfileDie(fn func(d *SeccompProfileDie)) *PodSecurityContextDie { + return d.DieStamp(func(r *corev1.PodSecurityContext) { + d := SeccompProfileBlank.DieImmutable(false).DieFeedPtr(r.SeccompProfile) + fn(d) + r.SeccompProfile = d.DieReleasePtr() + }) +} + // The SELinux context to be applied to all containers. // // # If unspecified, the container runtime will allocate a random SELinux context for each @@ -31681,6 +33605,24 @@ func (d *PodDNSConfigDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// OptionsDie replaces Options by collecting the released value from each die passed. +// +// A list of DNS resolver options. +// +// This will be merged with the base options generated from DNSPolicy. +// +// Duplicated entries will be removed. Resolution options given in Options +// +// will override those that appear in the base DNSPolicy. +func (d *PodDNSConfigDie) OptionsDie(v ...*PodDNSConfigOptionDie) *PodDNSConfigDie { + return d.DieStamp(func(r *corev1.PodDNSConfig) { + r.Options = make([]corev1.PodDNSConfigOption, len(v)) + for i := range v { + r.Options[i] = v[i].DieRelease() + } + }) +} + // A list of DNS name server IP addresses. // // This will be appended to the base nameservers generated from DNSPolicy. @@ -32420,6 +34362,21 @@ func (d *TopologySpreadConstraintDie) DiePatch(patchType types.PatchType) ([]byt return patch.Create(d.seal, d.r, patchType) } +// LabelSelectorDie mutates LabelSelector as a die. +// +// LabelSelector is used to find matching pods. +// +// # Pods that match this label selector are counted to determine the number of pods +// +// in their corresponding topology domain. +func (d *TopologySpreadConstraintDie) LabelSelectorDie(fn func(d *metav1.LabelSelectorDie)) *TopologySpreadConstraintDie { + return d.DieStamp(func(r *corev1.TopologySpreadConstraint) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.LabelSelector) + fn(d) + r.LabelSelector = d.DieReleasePtr() + }) +} + // MaxSkew describes the degree to which pods may be unevenly distributed. // // When `whenUnsatisfiable=DoNotSchedule`, it is the maximum permitted difference @@ -33105,6 +35062,74 @@ func (d *PodStatusDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// InitContainerStatusDie mutates a single item in InitContainerStatuses matched by the nested field Name, appending a new item if no match is found. +// +// The list has one entry per init container in the manifest. The most recent successful +// +// init container will have ready = true, the most recently started container will have +// +// startTime set. +// +// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-and-container-status +func (d *PodStatusDie) InitContainerStatusDie(v string, fn func(d *ContainerStatusDie)) *PodStatusDie { + return d.DieStamp(func(r *corev1.PodStatus) { + for i := range r.InitContainerStatuses { + if v == r.InitContainerStatuses[i].Name { + d := ContainerStatusBlank.DieImmutable(false).DieFeed(r.InitContainerStatuses[i]) + fn(d) + r.InitContainerStatuses[i] = d.DieRelease() + return + } + } + + d := ContainerStatusBlank.DieImmutable(false).DieFeed(corev1.ContainerStatus{Name: v}) + fn(d) + r.InitContainerStatuses = append(r.InitContainerStatuses, d.DieRelease()) + }) +} + +// ContainerStatusDie mutates a single item in ContainerStatuses matched by the nested field Name, appending a new item if no match is found. +// +// The list has one entry per container in the manifest. +// +// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-and-container-status +func (d *PodStatusDie) ContainerStatusDie(v string, fn func(d *ContainerStatusDie)) *PodStatusDie { + return d.DieStamp(func(r *corev1.PodStatus) { + for i := range r.ContainerStatuses { + if v == r.ContainerStatuses[i].Name { + d := ContainerStatusBlank.DieImmutable(false).DieFeed(r.ContainerStatuses[i]) + fn(d) + r.ContainerStatuses[i] = d.DieRelease() + return + } + } + + d := ContainerStatusBlank.DieImmutable(false).DieFeed(corev1.ContainerStatus{Name: v}) + fn(d) + r.ContainerStatuses = append(r.ContainerStatuses, d.DieRelease()) + }) +} + +// EphemeralContainerStatusDie mutates a single item in EphemeralContainerStatuses matched by the nested field Name, appending a new item if no match is found. +// +// Status for any ephemeral containers that have run in this pod. +func (d *PodStatusDie) EphemeralContainerStatusDie(v string, fn func(d *ContainerStatusDie)) *PodStatusDie { + return d.DieStamp(func(r *corev1.PodStatus) { + for i := range r.EphemeralContainerStatuses { + if v == r.EphemeralContainerStatuses[i].Name { + d := ContainerStatusBlank.DieImmutable(false).DieFeed(r.EphemeralContainerStatuses[i]) + fn(d) + r.EphemeralContainerStatuses[i] = d.DieRelease() + return + } + } + + d := ContainerStatusBlank.DieImmutable(false).DieFeed(corev1.ContainerStatus{Name: v}) + fn(d) + r.EphemeralContainerStatuses = append(r.EphemeralContainerStatuses, d.DieRelease()) + }) +} + // The phase of a Pod is a simple, high-level summary of where the Pod is in its lifecycle. // // # The conditions array, the reason and message fields, and the individual container status @@ -33612,6 +35637,19 @@ func (d *PodTemplateDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *PodTempl }) } +// TemplateDie mutates Template as a die. +// +// Template defines the pods that will be created from this pod template. +// +// https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status +func (d *PodTemplateDie) TemplateDie(fn func(d *PodTemplateSpecDie)) *PodTemplateDie { + return d.DieStamp(func(r *corev1.PodTemplate) { + d := PodTemplateSpecBlank.DieImmutable(false).DieFeed(r.Template) + fn(d) + r.Template = d.DieRelease() + }) +} + // Template defines the pods that will be created from this pod template. // // https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status @@ -33849,6 +35887,32 @@ func (d *PodTemplateSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// MetadataDie mutates ObjectMeta as a die. +// +// Standard object's metadata. +// +// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata +func (d *PodTemplateSpecDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *PodTemplateSpecDie { + return d.DieStamp(func(r *corev1.PodTemplateSpec) { + d := metav1.ObjectMetaBlank.DieImmutable(false).DieFeed(r.ObjectMeta) + fn(d) + r.ObjectMeta = d.DieRelease() + }) +} + +// SpecDie mutates Spec as a die. +// +// Specification of the desired behavior of the pod. +// +// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#spec-and-status +func (d *PodTemplateSpecDie) SpecDie(fn func(d *PodSpecDie)) *PodTemplateSpecDie { + return d.DieStamp(func(r *corev1.PodTemplateSpec) { + d := PodSpecBlank.DieImmutable(false).DieFeed(r.Spec) + fn(d) + r.Spec = d.DieRelease() + }) +} + // Standard object's metadata. // // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata @@ -34460,6 +36524,23 @@ func (d *ReplicationControllerSpecDie) DiePatch(patchType types.PatchType) ([]by return patch.Create(d.seal, d.r, patchType) } +// TemplateDie mutates Template as a die. +// +// # Template is the object that describes the pod that will be created if +// +// insufficient replicas are detected. This takes precedence over a TemplateRef. +// +// The only allowed template.spec.restartPolicy value is "Always". +// +// More info: https://kubernetes.io/docs/concepts/workloads/controllers/replicationcontroller#pod-template +func (d *ReplicationControllerSpecDie) TemplateDie(fn func(d *PodTemplateSpecDie)) *ReplicationControllerSpecDie { + return d.DieStamp(func(r *corev1.ReplicationControllerSpec) { + d := PodTemplateSpecBlank.DieImmutable(false).DieFeedPtr(r.Template) + fn(d) + r.Template = d.DieReleasePtr() + }) +} + // Replicas is the number of desired replicas. // // This is a pointer to distinguish between explicit zero and unspecified. @@ -35371,6 +37452,21 @@ func (d *ResourceQuotaSpecDie) DiePatch(patchType types.PatchType) ([]byte, erro return patch.Create(d.seal, d.r, patchType) } +// ScopeSelectorDie mutates ScopeSelector as a die. +// +// scopeSelector is also a collection of filters like scopes that must match each object tracked by a quota +// +// but expressed using ScopeSelectorOperator in combination with possible values. +// +// For a resource to match, both scopes AND scopeSelector (if specified in spec), must be matched. +func (d *ResourceQuotaSpecDie) ScopeSelectorDie(fn func(d *ScopeSelectorDie)) *ResourceQuotaSpecDie { + return d.DieStamp(func(r *corev1.ResourceQuotaSpec) { + d := ScopeSelectorBlank.DieImmutable(false).DieFeedPtr(r.ScopeSelector) + fn(d) + r.ScopeSelector = d.DieReleasePtr() + }) +} + // hard is the set of desired hard limits for each named resource. // // More info: https://kubernetes.io/docs/concepts/policy/resource-quotas/ @@ -35652,6 +37748,26 @@ func (d *ScopeSelectorDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// MatchExpressionDie mutates a single item in MatchExpressions matched by the nested field ScopeName, appending a new item if no match is found. +// +// A list of scope selector requirements by scope of the resources. +func (d *ScopeSelectorDie) MatchExpressionDie(v corev1.ResourceQuotaScope, fn func(d *ScopedResourceSelectorRequirementDie)) *ScopeSelectorDie { + return d.DieStamp(func(r *corev1.ScopeSelector) { + for i := range r.MatchExpressions { + if v == r.MatchExpressions[i].ScopeName { + d := ScopedResourceSelectorRequirementBlank.DieImmutable(false).DieFeed(r.MatchExpressions[i]) + fn(d) + r.MatchExpressions[i] = d.DieRelease() + return + } + } + + d := ScopedResourceSelectorRequirementBlank.DieImmutable(false).DieFeed(corev1.ScopedResourceSelectorRequirement{ScopeName: v}) + fn(d) + r.MatchExpressions = append(r.MatchExpressions, d.DieRelease()) + }) +} + // A list of scope selector requirements by scope of the resources. func (d *ScopeSelectorDie) MatchExpressions(v ...corev1.ScopedResourceSelectorRequirement) *ScopeSelectorDie { return d.DieStamp(func(r *corev1.ScopeSelector) { @@ -37140,6 +39256,17 @@ func (d *ServiceSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// SessionAffinityConfigDie mutates SessionAffinityConfig as a die. +// +// sessionAffinityConfig contains the configurations of session affinity. +func (d *ServiceSpecDie) SessionAffinityConfigDie(fn func(d *SessionAffinityConfigDie)) *ServiceSpecDie { + return d.DieStamp(func(r *corev1.ServiceSpec) { + d := SessionAffinityConfigBlank.DieImmutable(false).DieFeedPtr(r.SessionAffinityConfig) + fn(d) + r.SessionAffinityConfig = d.DieReleasePtr() + }) +} + // The list of ports that are exposed by this service. // // More info: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies @@ -38188,6 +40315,17 @@ func (d *SessionAffinityConfigDie) DiePatch(patchType types.PatchType) ([]byte, return patch.Create(d.seal, d.r, patchType) } +// ClientIPDie mutates ClientIP as a die. +// +// clientIP contains the configurations of Client IP based session affinity. +func (d *SessionAffinityConfigDie) ClientIPDie(fn func(d *ClientIPConfigDie)) *SessionAffinityConfigDie { + return d.DieStamp(func(r *corev1.SessionAffinityConfig) { + d := ClientIPConfigBlank.DieImmutable(false).DieFeedPtr(r.ClientIP) + fn(d) + r.ClientIP = d.DieReleasePtr() + }) +} + // clientIP contains the configurations of Client IP based session affinity. func (d *SessionAffinityConfigDie) ClientIP(v *corev1.ClientIPConfig) *SessionAffinityConfigDie { return d.DieStamp(func(r *corev1.SessionAffinityConfig) { @@ -38662,6 +40800,19 @@ func (d *ServiceStatusDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// LoadBalancerDie mutates LoadBalancer as a die. +// +// LoadBalancer contains the current status of the load-balancer, +// +// if one is present. +func (d *ServiceStatusDie) LoadBalancerDie(fn func(d *LoadBalancerStatusDie)) *ServiceStatusDie { + return d.DieStamp(func(r *corev1.ServiceStatus) { + d := LoadBalancerStatusBlank.DieImmutable(false).DieFeed(r.LoadBalancer) + fn(d) + r.LoadBalancer = d.DieRelease() + }) +} + // LoadBalancer contains the current status of the load-balancer, // // if one is present. @@ -38906,6 +41057,20 @@ func (d *LoadBalancerStatusDie) DiePatch(patchType types.PatchType) ([]byte, err return patch.Create(d.seal, d.r, patchType) } +// IngressDie replaces Ingress by collecting the released value from each die passed. +// +// Ingress is a list containing ingress points for the load-balancer. +// +// Traffic intended for the service should be sent to these ingress points. +func (d *LoadBalancerStatusDie) IngressDie(v ...*LoadBalancerIngressDie) *LoadBalancerStatusDie { + return d.DieStamp(func(r *corev1.LoadBalancerStatus) { + r.Ingress = make([]corev1.LoadBalancerIngress, len(v)) + for i := range v { + r.Ingress[i] = v[i].DieRelease() + } + }) +} + // Ingress is a list containing ingress points for the load-balancer. // // Traffic intended for the service should be sent to these ingress points. @@ -39143,6 +41308,20 @@ func (d *LoadBalancerIngressDie) DiePatch(patchType types.PatchType) ([]byte, er return patch.Create(d.seal, d.r, patchType) } +// PortsDie replaces Ports by collecting the released value from each die passed. +// +// # Ports is a list of records of service ports +// +// If used, every port defined in the service should have an entry in it +func (d *LoadBalancerIngressDie) PortsDie(v ...*PortStatusDie) *LoadBalancerIngressDie { + return d.DieStamp(func(r *corev1.LoadBalancerIngress) { + r.Ports = make([]corev1.PortStatus, len(v)) + for i := range v { + r.Ports[i] = v[i].DieRelease() + } + }) +} + // IP is set for load-balancer ingress points that are IP based // // (typically GCE or OpenStack load-balancers) @@ -39775,6 +41954,44 @@ func (d *ServiceAccountDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *Servi }) } +// SecretsDie replaces Secrets by collecting the released value from each die passed. +// +// Secrets is a list of the secrets in the same namespace that pods running using this ServiceAccount are allowed to use. +// +// Pods are only limited to this list if this service account has a "kubernetes.io/enforce-mountable-secrets" annotation set to "true". +// +// This field should not be used to find auto-generated service account token secrets for use outside of pods. +// +// Instead, tokens can be requested directly using the TokenRequest API, or service account token secrets can be manually created. +// +// More info: https://kubernetes.io/docs/concepts/configuration/secret +func (d *ServiceAccountDie) SecretsDie(v ...*ObjectReferenceDie) *ServiceAccountDie { + return d.DieStamp(func(r *corev1.ServiceAccount) { + r.Secrets = make([]corev1.ObjectReference, len(v)) + for i := range v { + r.Secrets[i] = v[i].DieRelease() + } + }) +} + +// ImagePullSecretsDie replaces ImagePullSecrets by collecting the released value from each die passed. +// +// # ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling any images +// +// in pods that reference this ServiceAccount. ImagePullSecrets are distinct from Secrets because Secrets +// +// can be mounted in the pod, but ImagePullSecrets are only accessed by the kubelet. +// +// More info: https://kubernetes.io/docs/concepts/containers/images/#specifying-imagepullsecrets-on-a-pod +func (d *ServiceAccountDie) ImagePullSecretsDie(v ...*LocalObjectReferenceDie) *ServiceAccountDie { + return d.DieStamp(func(r *corev1.ServiceAccount) { + r.ImagePullSecrets = make([]corev1.LocalObjectReference, len(v)) + for i := range v { + r.ImagePullSecrets[i] = v[i].DieRelease() + } + }) +} + // Secrets is a list of the secrets in the same namespace that pods running using this ServiceAccount are allowed to use. // // Pods are only limited to this list if this service account has a "kubernetes.io/enforce-mountable-secrets" annotation set to "true". @@ -41623,6 +43840,38 @@ func (d *SecretVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, err return patch.Create(d.seal, d.r, patchType) } +// ItemDie mutates a single item in Items matched by the nested field Key, appending a new item if no match is found. +// +// items If unspecified, each key-value pair in the Data field of the referenced +// +// # Secret will be projected into the volume as a file whose name is the +// +// key and content is the value. If specified, the listed keys will be +// +// projected into the specified paths, and unlisted keys will not be +// +// present. If a key is specified which is not present in the Secret, +// +// the volume setup will error unless it is marked optional. Paths must be +// +// relative and may not contain the '..' path or start with '..'. +func (d *SecretVolumeSourceDie) ItemDie(v string, fn func(d *KeyToPathDie)) *SecretVolumeSourceDie { + return d.DieStamp(func(r *corev1.SecretVolumeSource) { + for i := range r.Items { + if v == r.Items[i].Key { + d := KeyToPathBlank.DieImmutable(false).DieFeed(r.Items[i]) + fn(d) + r.Items[i] = d.DieRelease() + return + } + } + + d := KeyToPathBlank.DieImmutable(false).DieFeed(corev1.KeyToPath{Key: v}) + fn(d) + r.Items = append(r.Items, d.DieRelease()) + }) +} + // secretName is the name of the secret in the pod's namespace to use. // // More info: https://kubernetes.io/docs/concepts/storage/volumes#secret @@ -42162,6 +44411,17 @@ func (d *ISCSIVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, erro return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef is the CHAP Secret for iSCSI target and initiator authentication +func (d *ISCSIVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *ISCSIVolumeSourceDie { + return d.DieStamp(func(r *corev1.ISCSIVolumeSource) { + d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // targetPortal is iSCSI Target Portal. The Portal is either an IP or ip_addr:port if the port // // is other than default (typically TCP ports 860 and 3260). @@ -42990,6 +45250,23 @@ func (d *RBDVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef is name of the authentication secret for RBDUser. If provided +// +// overrides keyring. +// +// Default is nil. +// +// More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it +func (d *RBDVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *RBDVolumeSourceDie { + return d.DieStamp(func(r *corev1.RBDVolumeSource) { + d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // monitors is a collection of Ceph monitors. // // More info: https://examples.k8s.io/volumes/rbd/README.md#how-to-use-it @@ -43308,6 +45585,25 @@ func (d *FlexVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef is Optional: secretRef is reference to the secret object containing +// +// sensitive information to pass to the plugin scripts. This may be +// +// empty if no secret object is specified. If the secret object +// +// contains more than one secret, all secrets are passed to the plugin +// +// scripts. +func (d *FlexVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *FlexVolumeSourceDie { + return d.DieStamp(func(r *corev1.FlexVolumeSource) { + d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // driver is the name of the driver to use for this volume. func (d *FlexVolumeSourceDie) Driver(v string) *FlexVolumeSourceDie { return d.DieStamp(func(r *corev1.FlexVolumeSource) { @@ -43585,6 +45881,19 @@ func (d *CinderVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, err return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef is optional: points to a secret object containing parameters used to connect +// +// to OpenStack. +func (d *CinderVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *CinderVolumeSourceDie { + return d.DieStamp(func(r *corev1.CinderVolumeSource) { + d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // volumeID used to identify the volume in cinder. // // More info: https://examples.k8s.io/mysql-cinder-pd/README.md @@ -43855,6 +46164,19 @@ func (d *CephFSVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, err return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef is Optional: SecretRef is reference to the authentication secret for User, default is empty. +// +// More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it +func (d *CephFSVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *CephFSVolumeSourceDie { + return d.DieStamp(func(r *corev1.CephFSVolumeSource) { + d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // monitors is Required: Monitors is a collection of Ceph monitors // // More info: https://examples.k8s.io/volumes/cephfs/README.md#how-to-use-it @@ -44381,6 +46703,26 @@ func (d *DownwardAPIVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte return patch.Create(d.seal, d.r, patchType) } +// ItemDie mutates a single item in Items matched by the nested field Path, appending a new item if no match is found. +// +// Items is a list of downward API volume file +func (d *DownwardAPIVolumeSourceDie) ItemDie(v string, fn func(d *DownwardAPIVolumeFileDie)) *DownwardAPIVolumeSourceDie { + return d.DieStamp(func(r *corev1.DownwardAPIVolumeSource) { + for i := range r.Items { + if v == r.Items[i].Path { + d := DownwardAPIVolumeFileBlank.DieImmutable(false).DieFeed(r.Items[i]) + fn(d) + r.Items[i] = d.DieRelease() + return + } + } + + d := DownwardAPIVolumeFileBlank.DieImmutable(false).DieFeed(corev1.DownwardAPIVolumeFile{Path: v}) + fn(d) + r.Items = append(r.Items, d.DieRelease()) + }) +} + // Items is a list of downward API volume file func (d *DownwardAPIVolumeSourceDie) Items(v ...corev1.DownwardAPIVolumeFile) *DownwardAPIVolumeSourceDie { return d.DieStamp(func(r *corev1.DownwardAPIVolumeSource) { @@ -44637,6 +46979,30 @@ func (d *DownwardAPIVolumeFileDie) DiePatch(patchType types.PatchType) ([]byte, return patch.Create(d.seal, d.r, patchType) } +// FieldRefDie mutates FieldRef as a die. +// +// Required: Selects a field of the pod: only annotations, labels, name, namespace and uid are supported. +func (d *DownwardAPIVolumeFileDie) FieldRefDie(fn func(d *ObjectFieldSelectorDie)) *DownwardAPIVolumeFileDie { + return d.DieStamp(func(r *corev1.DownwardAPIVolumeFile) { + d := ObjectFieldSelectorBlank.DieImmutable(false).DieFeedPtr(r.FieldRef) + fn(d) + r.FieldRef = d.DieReleasePtr() + }) +} + +// ResourceFieldRefDie mutates ResourceFieldRef as a die. +// +// Selects a resource of the container: only resources limits and requests +// +// (limits.cpu, limits.memory, requests.cpu and requests.memory) are currently supported. +func (d *DownwardAPIVolumeFileDie) ResourceFieldRefDie(fn func(d *ResourceFieldSelectorDie)) *DownwardAPIVolumeFileDie { + return d.DieStamp(func(r *corev1.DownwardAPIVolumeFile) { + d := ResourceFieldSelectorBlank.DieImmutable(false).DieFeedPtr(r.ResourceFieldRef) + fn(d) + r.ResourceFieldRef = d.DieReleasePtr() + }) +} + // Required: Path is the relative path name of the file to be created. Must not be absolute or contain the '..' path. Must be utf-8 encoded. The first item of the relative path must not start with '..' func (d *DownwardAPIVolumeFileDie) Path(v string) *DownwardAPIVolumeFileDie { return d.DieStamp(func(r *corev1.DownwardAPIVolumeFile) { @@ -45429,6 +47795,38 @@ func (d *ConfigMapVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, return patch.Create(d.seal, d.r, patchType) } +// ItemDie mutates a single item in Items matched by the nested field Key, appending a new item if no match is found. +// +// items if unspecified, each key-value pair in the Data field of the referenced +// +// # ConfigMap will be projected into the volume as a file whose name is the +// +// key and content is the value. If specified, the listed keys will be +// +// projected into the specified paths, and unlisted keys will not be +// +// present. If a key is specified which is not present in the ConfigMap, +// +// the volume setup will error unless it is marked optional. Paths must be +// +// relative and may not contain the '..' path or start with '..'. +func (d *ConfigMapVolumeSourceDie) ItemDie(v string, fn func(d *KeyToPathDie)) *ConfigMapVolumeSourceDie { + return d.DieStamp(func(r *corev1.ConfigMapVolumeSource) { + for i := range r.Items { + if v == r.Items[i].Key { + d := KeyToPathBlank.DieImmutable(false).DieFeed(r.Items[i]) + fn(d) + r.Items[i] = d.DieRelease() + return + } + } + + d := KeyToPathBlank.DieImmutable(false).DieFeed(corev1.KeyToPath{Key: v}) + fn(d) + r.Items = append(r.Items, d.DieRelease()) + }) +} + func (d *ConfigMapVolumeSourceDie) LocalObjectReference(v corev1.LocalObjectReference) *ConfigMapVolumeSourceDie { return d.DieStamp(func(r *corev1.ConfigMapVolumeSource) { r.LocalObjectReference = v @@ -46772,6 +49170,18 @@ func (d *ProjectedVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, return patch.Create(d.seal, d.r, patchType) } +// SourcesDie replaces Sources by collecting the released value from each die passed. +// +// sources is the list of volume projections +func (d *ProjectedVolumeSourceDie) SourcesDie(v ...*VolumeProjectionDie) *ProjectedVolumeSourceDie { + return d.DieStamp(func(r *corev1.ProjectedVolumeSource) { + r.Sources = make([]corev1.VolumeProjection, len(v)) + for i := range v { + r.Sources[i] = v[i].DieRelease() + } + }) +} + // sources is the list of volume projections func (d *ProjectedVolumeSourceDie) Sources(v ...corev1.VolumeProjection) *ProjectedVolumeSourceDie { return d.DieStamp(func(r *corev1.ProjectedVolumeSource) { @@ -47024,6 +49434,79 @@ func (d *VolumeProjectionDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// SecretDie mutates Secret as a die. +// +// secret information about the secret data to project +func (d *VolumeProjectionDie) SecretDie(fn func(d *SecretProjectionDie)) *VolumeProjectionDie { + return d.DieStamp(func(r *corev1.VolumeProjection) { + d := SecretProjectionBlank.DieImmutable(false).DieFeedPtr(r.Secret) + fn(d) + r.Secret = d.DieReleasePtr() + }) +} + +// DownwardAPIDie mutates DownwardAPI as a die. +// +// downwardAPI information about the downwardAPI data to project +func (d *VolumeProjectionDie) DownwardAPIDie(fn func(d *DownwardAPIProjectionDie)) *VolumeProjectionDie { + return d.DieStamp(func(r *corev1.VolumeProjection) { + d := DownwardAPIProjectionBlank.DieImmutable(false).DieFeedPtr(r.DownwardAPI) + fn(d) + r.DownwardAPI = d.DieReleasePtr() + }) +} + +// ConfigMapDie mutates ConfigMap as a die. +// +// configMap information about the configMap data to project +func (d *VolumeProjectionDie) ConfigMapDie(fn func(d *ConfigMapProjectionDie)) *VolumeProjectionDie { + return d.DieStamp(func(r *corev1.VolumeProjection) { + d := ConfigMapProjectionBlank.DieImmutable(false).DieFeedPtr(r.ConfigMap) + fn(d) + r.ConfigMap = d.DieReleasePtr() + }) +} + +// ServiceAccountTokenDie mutates ServiceAccountToken as a die. +// +// serviceAccountToken is information about the serviceAccountToken data to project +func (d *VolumeProjectionDie) ServiceAccountTokenDie(fn func(d *ServiceAccountTokenProjectionDie)) *VolumeProjectionDie { + return d.DieStamp(func(r *corev1.VolumeProjection) { + d := ServiceAccountTokenProjectionBlank.DieImmutable(false).DieFeedPtr(r.ServiceAccountToken) + fn(d) + r.ServiceAccountToken = d.DieReleasePtr() + }) +} + +// ClusterTrustBundleDie mutates ClusterTrustBundle as a die. +// +// # ClusterTrustBundle allows a pod to access the `.spec.trustBundle` field +// +// of ClusterTrustBundle objects in an auto-updating file. +// +// Alpha, gated by the ClusterTrustBundleProjection feature gate. +// +// # ClusterTrustBundle objects can either be selected by name, or by the +// +// combination of signer name and a label selector. +// +// # Kubelet performs aggressive normalization of the PEM contents written +// +// into the pod filesystem. Esoteric PEM features such as inter-block +// +// comments and block headers are stripped. Certificates are deduplicated. +// +// # The ordering of certificates within the file is arbitrary, and Kubelet +// +// may change the order over time. +func (d *VolumeProjectionDie) ClusterTrustBundleDie(fn func(d *ClusterTrustBundleProjectionDie)) *VolumeProjectionDie { + return d.DieStamp(func(r *corev1.VolumeProjection) { + d := ClusterTrustBundleProjectionBlank.DieImmutable(false).DieFeedPtr(r.ClusterTrustBundle) + fn(d) + r.ClusterTrustBundle = d.DieReleasePtr() + }) +} + // secret information about the secret data to project func (d *VolumeProjectionDie) Secret(v *corev1.SecretProjection) *VolumeProjectionDie { return d.DieStamp(func(r *corev1.VolumeProjection) { @@ -47305,6 +49788,38 @@ func (d *SecretProjectionDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// ItemDie mutates a single item in Items matched by the nested field Key, appending a new item if no match is found. +// +// items if unspecified, each key-value pair in the Data field of the referenced +// +// # Secret will be projected into the volume as a file whose name is the +// +// key and content is the value. If specified, the listed keys will be +// +// projected into the specified paths, and unlisted keys will not be +// +// present. If a key is specified which is not present in the Secret, +// +// the volume setup will error unless it is marked optional. Paths must be +// +// relative and may not contain the '..' path or start with '..'. +func (d *SecretProjectionDie) ItemDie(v string, fn func(d *KeyToPathDie)) *SecretProjectionDie { + return d.DieStamp(func(r *corev1.SecretProjection) { + for i := range r.Items { + if v == r.Items[i].Key { + d := KeyToPathBlank.DieImmutable(false).DieFeed(r.Items[i]) + fn(d) + r.Items[i] = d.DieRelease() + return + } + } + + d := KeyToPathBlank.DieImmutable(false).DieFeed(corev1.KeyToPath{Key: v}) + fn(d) + r.Items = append(r.Items, d.DieRelease()) + }) +} + func (d *SecretProjectionDie) LocalObjectReference(v corev1.LocalObjectReference) *SecretProjectionDie { return d.DieStamp(func(r *corev1.SecretProjection) { r.LocalObjectReference = v @@ -47565,6 +50080,26 @@ func (d *DownwardAPIProjectionDie) DiePatch(patchType types.PatchType) ([]byte, return patch.Create(d.seal, d.r, patchType) } +// ItemDie mutates a single item in Items matched by the nested field Path, appending a new item if no match is found. +// +// Items is a list of DownwardAPIVolume file +func (d *DownwardAPIProjectionDie) ItemDie(v string, fn func(d *DownwardAPIVolumeFileDie)) *DownwardAPIProjectionDie { + return d.DieStamp(func(r *corev1.DownwardAPIProjection) { + for i := range r.Items { + if v == r.Items[i].Path { + d := DownwardAPIVolumeFileBlank.DieImmutable(false).DieFeed(r.Items[i]) + fn(d) + r.Items[i] = d.DieRelease() + return + } + } + + d := DownwardAPIVolumeFileBlank.DieImmutable(false).DieFeed(corev1.DownwardAPIVolumeFile{Path: v}) + fn(d) + r.Items = append(r.Items, d.DieRelease()) + }) +} + // Items is a list of DownwardAPIVolume file func (d *DownwardAPIProjectionDie) Items(v ...corev1.DownwardAPIVolumeFile) *DownwardAPIProjectionDie { return d.DieStamp(func(r *corev1.DownwardAPIProjection) { @@ -47800,6 +50335,38 @@ func (d *ConfigMapProjectionDie) DiePatch(patchType types.PatchType) ([]byte, er return patch.Create(d.seal, d.r, patchType) } +// ItemDie mutates a single item in Items matched by the nested field Key, appending a new item if no match is found. +// +// items if unspecified, each key-value pair in the Data field of the referenced +// +// # ConfigMap will be projected into the volume as a file whose name is the +// +// key and content is the value. If specified, the listed keys will be +// +// projected into the specified paths, and unlisted keys will not be +// +// present. If a key is specified which is not present in the ConfigMap, +// +// the volume setup will error unless it is marked optional. Paths must be +// +// relative and may not contain the '..' path or start with '..'. +func (d *ConfigMapProjectionDie) ItemDie(v string, fn func(d *KeyToPathDie)) *ConfigMapProjectionDie { + return d.DieStamp(func(r *corev1.ConfigMapProjection) { + for i := range r.Items { + if v == r.Items[i].Key { + d := KeyToPathBlank.DieImmutable(false).DieFeed(r.Items[i]) + fn(d) + r.Items[i] = d.DieRelease() + return + } + } + + d := KeyToPathBlank.DieImmutable(false).DieFeed(corev1.KeyToPath{Key: v}) + fn(d) + r.Items = append(r.Items, d.DieRelease()) + }) +} + func (d *ConfigMapProjectionDie) LocalObjectReference(v corev1.LocalObjectReference) *ConfigMapProjectionDie { return d.DieStamp(func(r *corev1.ConfigMapProjection) { r.LocalObjectReference = v @@ -48327,6 +50894,23 @@ func (d *ClusterTrustBundleProjectionDie) DiePatch(patchType types.PatchType) ([ return patch.Create(d.seal, d.r, patchType) } +// LabelSelectorDie mutates LabelSelector as a die. +// +// Select all ClusterTrustBundles that match this label selector. Only has +// +// effect if signerName is set. Mutually-exclusive with name. If unset, +// +// interpreted as "match nothing". If set but empty, interpreted as "match +// +// everything". +func (d *ClusterTrustBundleProjectionDie) LabelSelectorDie(fn func(d *metav1.LabelSelectorDie)) *ClusterTrustBundleProjectionDie { + return d.DieStamp(func(r *corev1.ClusterTrustBundleProjection) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.LabelSelector) + fn(d) + r.LabelSelector = d.DieReleasePtr() + }) +} + // Select a single ClusterTrustBundle by object name. Mutually-exclusive // // with signerName and labelSelector. @@ -48865,6 +51449,19 @@ func (d *ScaleIOVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, er return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef references to the secret for ScaleIO user and other +// +// sensitive information. If this is not provided, Login operation will fail. +func (d *ScaleIOVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *ScaleIOVolumeSourceDie { + return d.DieStamp(func(r *corev1.ScaleIOVolumeSource) { + d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // gateway is the host address of the ScaleIO API Gateway. func (d *ScaleIOVolumeSourceDie) Gateway(v string) *ScaleIOVolumeSourceDie { return d.DieStamp(func(r *corev1.ScaleIOVolumeSource) { @@ -49177,6 +51774,19 @@ func (d *StorageOSVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, return patch.Create(d.seal, d.r, patchType) } +// SecretRefDie mutates SecretRef as a die. +// +// secretRef specifies the secret to use for obtaining the StorageOS API +// +// credentials. If not specified, default values will be attempted. +func (d *StorageOSVolumeSourceDie) SecretRefDie(fn func(d *LocalObjectReferenceDie)) *StorageOSVolumeSourceDie { + return d.DieStamp(func(r *corev1.StorageOSVolumeSource) { + d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.SecretRef) + fn(d) + r.SecretRef = d.DieReleasePtr() + }) +} + // volumeName is the human-readable name of the StorageOS volume. Volume // // names are only unique within a namespace. @@ -49460,6 +52070,25 @@ func (d *CSIVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// NodePublishSecretRefDie mutates NodePublishSecretRef as a die. +// +// nodePublishSecretRef is a reference to the secret object containing +// +// sensitive information to pass to the CSI driver to complete the CSI +// +// NodePublishVolume and NodeUnpublishVolume calls. +// +// This field is optional, and may be empty if no secret is required. If the +// +// secret object contains more than one secret, all secret references are passed. +func (d *CSIVolumeSourceDie) NodePublishSecretRefDie(fn func(d *LocalObjectReferenceDie)) *CSIVolumeSourceDie { + return d.DieStamp(func(r *corev1.CSIVolumeSource) { + d := LocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.NodePublishSecretRef) + fn(d) + r.NodePublishSecretRef = d.DieReleasePtr() + }) +} + // driver is the name of the CSI driver that handles this volume. // // Consult with your admin for the correct name as registered in the cluster. @@ -49741,6 +52370,51 @@ func (d *EphemeralVolumeSourceDie) DiePatch(patchType types.PatchType) ([]byte, return patch.Create(d.seal, d.r, patchType) } +// VolumeClaimTemplateDie mutates VolumeClaimTemplate as a die. +// +// Will be used to create a stand-alone PVC to provision the volume. +// +// # The pod in which this EphemeralVolumeSource is embedded will be the +// +// owner of the PVC, i.e. the PVC will be deleted together with the +// +// pod. The name of the PVC will be `-` where +// +// `` is the name from the `PodSpec.Volumes` array +// +// entry. Pod validation will reject the pod if the concatenated name +// +// is not valid for a PVC (for example, too long). +// +// # An existing PVC with that name that is not owned by the pod +// +// will *not* be used for the pod to avoid using an unrelated +// +// volume by mistake. Starting the pod is then blocked until +// +// the unrelated PVC is removed. If such a pre-created PVC is +// +// meant to be used by the pod, the PVC has to updated with an +// +// owner reference to the pod once the pod exists. Normally +// +// this should not be necessary, but it may be useful when +// +// manually reconstructing a broken cluster. +// +// # This field is read-only and no changes will be made by Kubernetes +// +// to the PVC after it has been created. +// +// Required, must not be nil. +func (d *EphemeralVolumeSourceDie) VolumeClaimTemplateDie(fn func(d *PersistentVolumeClaimTemplateDie)) *EphemeralVolumeSourceDie { + return d.DieStamp(func(r *corev1.EphemeralVolumeSource) { + d := PersistentVolumeClaimTemplateBlank.DieImmutable(false).DieFeedPtr(r.VolumeClaimTemplate) + fn(d) + r.VolumeClaimTemplate = d.DieReleasePtr() + }) +} + // Will be used to create a stand-alone PVC to provision the volume. // // # The pod in which this EphemeralVolumeSource is embedded will be the diff --git a/apis/discovery/v1/endpointslice.go b/apis/discovery/v1/endpointslice.go index e8b78e0..5ee8ace 100644 --- a/apis/discovery/v1/endpointslice.go +++ b/apis/discovery/v1/endpointslice.go @@ -18,49 +18,19 @@ package v1 import ( discoveryv1 "k8s.io/api/discovery/v1" - diecorev1 "reconciler.io/dies/apis/core/v1" ) // +die:object=true,apiVersion=discovery.k8s.io/v1,kind=EndpointSlice +// +die:field:name=Endpoints,die=EndpointDie,listType=atomic +// +die:field:name=Ports,die=EndpointPortDie,listType=atomic 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 +// +die:field:name=Conditions,die=EndpointConditionsDie +// +die:field:name=TargetRef,package=_/core/v1,die=ObjectReferenceDie,pointer=true +// +die:field:name=Hints,die=EndpointHintsDie,pointer=true 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 { @@ -70,29 +40,13 @@ func (d *EndpointDie) AddDeprecatedTopology(key, value string) *EndpointDie { }) } -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 +// +die:field:name=ForZones,die=ForZoneDie,listType=atomic 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 diff --git a/apis/discovery/v1/zz_generated.die.go b/apis/discovery/v1/zz_generated.die.go index eceac07..3eee459 100644 --- a/apis/discovery/v1/zz_generated.die.go +++ b/apis/discovery/v1/zz_generated.die.go @@ -24,7 +24,7 @@ package v1 import ( fmtx "fmt" cmp "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" + apicorev1 "k8s.io/api/core/v1" discoveryv1 "k8s.io/api/discovery/v1" apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" unstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -34,6 +34,7 @@ import ( json "k8s.io/apimachinery/pkg/util/json" jsonpath "k8s.io/client-go/util/jsonpath" osx "os" + corev1 "reconciler.io/dies/apis/core/v1" metav1 "reconciler.io/dies/apis/meta/v1" patch "reconciler.io/dies/patch" reflectx "reflect" @@ -363,6 +364,40 @@ func (d *EndpointSliceDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *Endpoi }) } +// EndpointsDie replaces Endpoints by collecting the released value from each die passed. +// +// endpoints is a list of unique endpoints in this slice. Each slice may +// +// include a maximum of 1000 endpoints. +func (d *EndpointSliceDie) EndpointsDie(v ...*EndpointDie) *EndpointSliceDie { + return d.DieStamp(func(r *discoveryv1.EndpointSlice) { + r.Endpoints = make([]discoveryv1.Endpoint, len(v)) + for i := range v { + r.Endpoints[i] = v[i].DieRelease() + } + }) +} + +// PortsDie replaces Ports by collecting the released value from each die passed. +// +// 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) PortsDie(v ...*EndpointPortDie) *EndpointSliceDie { + return d.DieStamp(func(r *discoveryv1.EndpointSlice) { + r.Ports = make([]discoveryv1.EndpointPort, len(v)) + for i := range v { + r.Ports[i] = v[i].DieRelease() + } + }) +} + // addressType specifies the type of address carried by this EndpointSlice. // // All addresses in this slice must be the same type. This field is @@ -634,6 +669,43 @@ func (d *EndpointDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ConditionsDie mutates Conditions as a die. +// +// conditions contains information about the current status of the 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() + }) +} + +// TargetRefDie mutates TargetRef as a die. +// +// targetRef is a reference to a Kubernetes object that represents this +// +// endpoint. +func (d *EndpointDie) TargetRefDie(fn func(d *corev1.ObjectReferenceDie)) *EndpointDie { + return d.DieStamp(func(r *discoveryv1.Endpoint) { + d := corev1.ObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.TargetRef) + fn(d) + r.TargetRef = d.DieReleasePtr() + }) +} + +// HintsDie mutates Hints as a die. +// +// hints contains information associated with how an endpoint should be +// +// consumed. +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() + }) +} + // addresses of this endpoint. The contents of this field are interpreted // // according to the corresponding EndpointSlice addressType field. Consumers @@ -676,7 +748,7 @@ func (d *EndpointDie) Hostname(v *string) *EndpointDie { // targetRef is a reference to a Kubernetes object that represents this // // endpoint. -func (d *EndpointDie) TargetRef(v *corev1.ObjectReference) *EndpointDie { +func (d *EndpointDie) TargetRef(v *apicorev1.ObjectReference) *EndpointDie { return d.DieStamp(func(r *discoveryv1.Endpoint) { r.TargetRef = v }) @@ -1223,6 +1295,20 @@ func (d *EndpointHintsDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ForZonesDie replaces ForZones by collecting the released value from each die passed. +// +// forZones indicates the zone(s) this endpoint should be consumed by to +// +// enable topology aware routing. +func (d *EndpointHintsDie) ForZonesDie(v ...*ForZoneDie) *EndpointHintsDie { + return d.DieStamp(func(r *discoveryv1.EndpointHints) { + r.ForZones = make([]discoveryv1.ForZone, len(v)) + for i := range v { + r.ForZones[i] = v[i].DieRelease() + } + }) +} + // forZones indicates the zone(s) this endpoint should be consumed by to // // enable topology aware routing. @@ -1719,7 +1805,7 @@ func (d *EndpointPortDie) Name(v *string) *EndpointPortDie { // Must be UDP, TCP, or SCTP. // // Default is TCP. -func (d *EndpointPortDie) Protocol(v *corev1.Protocol) *EndpointPortDie { +func (d *EndpointPortDie) Protocol(v *apicorev1.Protocol) *EndpointPortDie { return d.DieStamp(func(r *discoveryv1.EndpointPort) { r.Protocol = v }) diff --git a/apis/events/v1/event.go b/apis/events/v1/event.go index 5cf779e..b313175 100644 --- a/apis/events/v1/event.go +++ b/apis/events/v1/event.go @@ -18,43 +18,14 @@ package v1 import ( eventsv1 "k8s.io/api/events/v1" - diecorev1 "reconciler.io/dies/apis/core/v1" ) // +die:object=true,apiVersion=events.k8s.io/v1,kind=Event +// +die:field:name=Series,die=EventSeriesDie,pointer=true +// +die:field:name=Regarding,package=_/core/v1,die=ObjectReferenceDie +// +die:field:name=Related,package=_/core/v1,die=ObjectReferenceDie,pointer=true +// +die:field:name=DeprecatedSource,package=_/core/v1,die=EventSourceDie type _ = eventsv1.Event -func (d *EventDie) SeriesDie(fn func(d *EventSeriesDie)) *EventDie { - return d.DieStamp(func(r *eventsv1.Event) { - d := EventSeriesBlank.DieImmutable(false).DieFeedPtr(r.Series) - fn(d) - r.Series = d.DieReleasePtr() - }) -} - -func (d *EventDie) RegardingDie(fn func(d *diecorev1.ObjectReferenceDie)) *EventDie { - return d.DieStamp(func(r *eventsv1.Event) { - d := diecorev1.ObjectReferenceBlank.DieImmutable(false).DieFeed(r.Regarding) - fn(d) - r.Regarding = d.DieRelease() - }) -} - -func (d *EventDie) RelatedDie(fn func(d *diecorev1.ObjectReferenceDie)) *EventDie { - return d.DieStamp(func(r *eventsv1.Event) { - d := diecorev1.ObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.Related) - fn(d) - r.Related = d.DieReleasePtr() - }) -} - -func (d *EventDie) DeprecatedSourceDie(fn func(d *diecorev1.EventSourceDie)) *EventDie { - return d.DieStamp(func(r *eventsv1.Event) { - d := diecorev1.EventSourceBlank.DieImmutable(false).DieFeed(r.DeprecatedSource) - fn(d) - r.DeprecatedSource = d.DieRelease() - }) -} - // +die type _ = eventsv1.EventSeries diff --git a/apis/events/v1/zz_generated.die.go b/apis/events/v1/zz_generated.die.go index 4f2608a..f42e02f 100644 --- a/apis/events/v1/zz_generated.die.go +++ b/apis/events/v1/zz_generated.die.go @@ -24,7 +24,7 @@ package v1 import ( fmtx "fmt" cmp "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" + apicorev1 "k8s.io/api/core/v1" eventsv1 "k8s.io/api/events/v1" apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" unstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -34,6 +34,7 @@ import ( json "k8s.io/apimachinery/pkg/util/json" jsonpath "k8s.io/client-go/util/jsonpath" osx "os" + corev1 "reconciler.io/dies/apis/core/v1" metav1 "reconciler.io/dies/apis/meta/v1" patch "reconciler.io/dies/patch" reflectx "reflect" @@ -363,6 +364,56 @@ func (d *EventDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *EventDie { }) } +// SeriesDie mutates Series as a die. +// +// series is data about the Event series this event represents or nil if it's a singleton Event. +func (d *EventDie) SeriesDie(fn func(d *EventSeriesDie)) *EventDie { + return d.DieStamp(func(r *eventsv1.Event) { + d := EventSeriesBlank.DieImmutable(false).DieFeedPtr(r.Series) + fn(d) + r.Series = d.DieReleasePtr() + }) +} + +// RegardingDie mutates Regarding as a die. +// +// regarding contains the object this Event is about. In most cases it's an Object reporting controller +// +// implements, e.g. ReplicaSetController implements ReplicaSets and this event is emitted because +// +// it acts on some changes in a ReplicaSet object. +func (d *EventDie) RegardingDie(fn func(d *corev1.ObjectReferenceDie)) *EventDie { + return d.DieStamp(func(r *eventsv1.Event) { + d := corev1.ObjectReferenceBlank.DieImmutable(false).DieFeed(r.Regarding) + fn(d) + r.Regarding = d.DieRelease() + }) +} + +// RelatedDie mutates Related as a die. +// +// related is the optional secondary object for more complex actions. E.g. when regarding object triggers +// +// a creation or deletion of related object. +func (d *EventDie) RelatedDie(fn func(d *corev1.ObjectReferenceDie)) *EventDie { + return d.DieStamp(func(r *eventsv1.Event) { + d := corev1.ObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.Related) + fn(d) + r.Related = d.DieReleasePtr() + }) +} + +// DeprecatedSourceDie mutates DeprecatedSource as a die. +// +// deprecatedSource is the deprecated field assuring backward compatibility with core.v1 Event type. +func (d *EventDie) DeprecatedSourceDie(fn func(d *corev1.EventSourceDie)) *EventDie { + return d.DieStamp(func(r *eventsv1.Event) { + d := corev1.EventSourceBlank.DieImmutable(false).DieFeed(r.DeprecatedSource) + fn(d) + r.DeprecatedSource = d.DieRelease() + }) +} + // eventTime is the time when this Event was first observed. It is required. func (d *EventDie) EventTime(v apismetav1.MicroTime) *EventDie { return d.DieStamp(func(r *eventsv1.Event) { @@ -418,7 +469,7 @@ func (d *EventDie) Reason(v string) *EventDie { // implements, e.g. ReplicaSetController implements ReplicaSets and this event is emitted because // // it acts on some changes in a ReplicaSet object. -func (d *EventDie) Regarding(v corev1.ObjectReference) *EventDie { +func (d *EventDie) Regarding(v apicorev1.ObjectReference) *EventDie { return d.DieStamp(func(r *eventsv1.Event) { r.Regarding = v }) @@ -427,7 +478,7 @@ func (d *EventDie) Regarding(v corev1.ObjectReference) *EventDie { // related is the optional secondary object for more complex actions. E.g. when regarding object triggers // // a creation or deletion of related object. -func (d *EventDie) Related(v *corev1.ObjectReference) *EventDie { +func (d *EventDie) Related(v *apicorev1.ObjectReference) *EventDie { return d.DieStamp(func(r *eventsv1.Event) { r.Related = v }) @@ -456,7 +507,7 @@ func (d *EventDie) Type(v string) *EventDie { } // deprecatedSource is the deprecated field assuring backward compatibility with core.v1 Event type. -func (d *EventDie) DeprecatedSource(v corev1.EventSource) *EventDie { +func (d *EventDie) DeprecatedSource(v apicorev1.EventSource) *EventDie { return d.DieStamp(func(r *eventsv1.Event) { r.DeprecatedSource = v }) diff --git a/apis/meta/v1/objectmeta.go b/apis/meta/v1/objectmeta.go index 1a039f9..dc69c2e 100644 --- a/apis/meta/v1/objectmeta.go +++ b/apis/meta/v1/objectmeta.go @@ -26,6 +26,7 @@ import ( ) // +die +// +die:field:name=ManagedFields,die=ManagedFieldsEntryDie,listType=atomic type _ = metav1.ObjectMeta func (d *ObjectMetaDie) AddLabel(key, value string) *ObjectMetaDie { @@ -63,15 +64,6 @@ func (d *ObjectMetaDie) ControlledBy(obj runtime.Object, scheme *runtime.Scheme) }) } -func (d *ObjectMetaDie) ManagedFieldsDie(fields ...*ManagedFieldsEntryDie) *ObjectMetaDie { - return d.DieStamp(func(r *metav1.ObjectMeta) { - r.ManagedFields = make([]metav1.ManagedFieldsEntry, len(fields)) - for i := range fields { - r.ManagedFields[i] = fields[i].DieRelease() - } - }) -} - // +die type _ = metav1.ManagedFieldsEntry diff --git a/apis/meta/v1/status.go b/apis/meta/v1/status.go index 2f8be22..4f78d32 100644 --- a/apis/meta/v1/status.go +++ b/apis/meta/v1/status.go @@ -21,6 +21,8 @@ import ( ) // +die +// +die:field:name=ListMeta,die=ListMetaDie +// +die:field:name=Details,die=StatusDetailsDie,pointer=true type _ = metav1.Status // 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 @@ -37,34 +39,9 @@ func (d *StatusDie) APIVersion(v string) *StatusDie { }) } -func (d *StatusDie) ListMetaDie(fn func(d *ListMetaDie)) *StatusDie { - return d.DieStamp(func(r *metav1.Status) { - d := ListMetaBlank.DieImmutable(false).DieFeed(r.ListMeta) - fn(d) - r.ListMeta = d.DieRelease() - }) -} - -func (d *StatusDie) DetailDie(fn func(d *StatusDetailsDie)) *StatusDie { - return d.DieStamp(func(r *metav1.Status) { - d := StatusDetailsBlank.DieImmutable(false).DieFeedPtr(r.Details) - fn(d) - r.Details = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Causes,die=StatusCauseDie,listType=atomic type _ = metav1.StatusDetails -func (d *StatusDetailsDie) CausesDie(causes ...*StatusCauseDie) *StatusDetailsDie { - return d.DieStamp(func(r *metav1.StatusDetails) { - r.Causes = make([]metav1.StatusCause, len(causes)) - for i := range causes { - c := causes[i].DieRelease() - r.Causes[i] = c - } - }) -} - // +die type _ = metav1.StatusCause diff --git a/apis/meta/v1/typemeta.go b/apis/meta/v1/typemeta.go index 6258af7..f5e972c 100644 --- a/apis/meta/v1/typemeta.go +++ b/apis/meta/v1/typemeta.go @@ -17,11 +17,19 @@ limitations under the License. package v1 import ( - json "encoding/json" + "encoding/json" + "fmt" + "os" + "reflect" + "github.com/google/go-cmp/cmp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/types" + "k8s.io/client-go/util/jsonpath" + "reconciler.io/dies/patch" + "sigs.k8s.io/yaml" ) var TypeMetaBlank = (&TypeMetaDie{}).DieFeed(metav1.TypeMeta{}) @@ -29,6 +37,7 @@ var TypeMetaBlank = (&TypeMetaDie{}).DieFeed(metav1.TypeMeta{}) type TypeMetaDie struct { mutable bool r metav1.TypeMeta + seal metav1.TypeMeta } // DieImmutable returns a new die for the current die's state that is either mutable (`false`) or immutable (`true`). @@ -50,6 +59,7 @@ func (d *TypeMetaDie) DieFeed(r metav1.TypeMeta) *TypeMetaDie { return &TypeMetaDie{ mutable: d.mutable, r: r, + seal: d.seal, } } @@ -61,14 +71,42 @@ func (d *TypeMetaDie) DieFeedPtr(r *metav1.TypeMeta) *TypeMetaDie { return d.DieFeed(*r) } -// DieFeedRawExtension returns the resource managed by the die as an raw extension. -func (d *TypeMetaDie) DieFeedRawExtension(raw runtime.RawExtension) *TypeMetaDie { - b, _ := json.Marshal(raw) +// DieFeedJSON returns a new die with the provided JSON. Panics on error. +func (d *TypeMetaDie) DieFeedJSON(j []byte) *TypeMetaDie { r := metav1.TypeMeta{} - _ = json.Unmarshal(b, &r) + 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 *TypeMetaDie) DieFeedYAML(y []byte) *TypeMetaDie { + r := metav1.TypeMeta{} + 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 *TypeMetaDie) DieFeedYAMLFile(name string) *TypeMetaDie { + y, err := os.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 *TypeMetaDie) DieFeedRawExtension(raw runtime.RawExtension) *TypeMetaDie { + j, err := json.Marshal(raw) + if err != nil { + panic(err) + } + return d.DieFeedJSON(j) +} + // DieRelease returns the resource managed by the die. func (d *TypeMetaDie) DieRelease() metav1.TypeMeta { if d.mutable { @@ -86,12 +124,33 @@ func (d *TypeMetaDie) DieReleasePtr() *metav1.TypeMeta { return &r } -// DieReleaseRawExtension returns the resource managed by the die as an raw extension. -func (d *TypeMetaDie) DieReleaseRawExtension() runtime.RawExtension { +// DieReleaseJSON returns the resource managed by the die as JSON. Panics on error. +func (d *TypeMetaDie) DieReleaseJSON() []byte { r := d.DieReleasePtr() - b, _ := json.Marshal(r) + 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 *TypeMetaDie) 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 *TypeMetaDie) DieReleaseRawExtension() runtime.RawExtension { + j := d.DieReleaseJSON() raw := runtime.RawExtension{} - _ = json.Unmarshal(b, &raw) + if err := json.Unmarshal(j, &raw); err != nil { + panic(err) + } return raw } @@ -102,25 +161,139 @@ func (d *TypeMetaDie) DieStamp(fn func(r *metav1.TypeMeta)) *TypeMetaDie { 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 *TypeMetaDie) DieStampAt(jp string, fn interface{}) *TypeMetaDie { + return d.DieStamp(func(r *metav1.TypeMeta) { + if ni := reflect.ValueOf(fn).Type().NumIn(); ni != 1 { + panic(fmt.Errorf("callback function must have 1 input parameters, found %d", ni)) + } + if no := reflect.ValueOf(fn).Type().NumOut(); no != 0 { + panic(fmt.Errorf("callback function must have 0 output parameters, found %d", no)) + } + + cp := jsonpath.New("") + if err := cp.Parse(fmt.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 := reflect.ValueOf(fn).Type().In(0) + + var args []reflect.Value + if cv.Type().AssignableTo(arg0t) { + args = []reflect.Value{cv} + } else if cv.CanAddr() && cv.Addr().Type().AssignableTo(arg0t) { + args = []reflect.Value{cv.Addr()} + } else { + panic(fmt.Errorf("callback function must accept value of type %q, found type %q", cv.Type(), arg0t)) + } + + reflect.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 *TypeMetaDie) DieWith(fns ...func(d *TypeMetaDie)) *TypeMetaDie { + nd := TypeMetaBlank.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 *TypeMetaDie) DeepCopy() *TypeMetaDie { + r := metav1.TypeMeta{ + APIVersion: d.r.APIVersion, + Kind: d.r.Kind, + } return &TypeMetaDie{ mutable: d.mutable, - r: metav1.TypeMeta{ - APIVersion: d.r.APIVersion, - Kind: d.r.Kind, - }, + r: r, + seal: d.seal, + } +} + +// DieSeal returns a new die for the current die's state that is sealed for comparison in future diff and patch operations. +func (d *TypeMetaDie) DieSeal() *TypeMetaDie { + return d.DieSealFeed(d.r) +} + +// DieSealFeed returns a new die for the current die's state that uses a specific resource for comparison in future diff and patch operations. +func (d *TypeMetaDie) DieSealFeed(r metav1.TypeMeta) *TypeMetaDie { + if !d.mutable { + d = d.DeepCopy() + } + d.seal = metav1.TypeMeta{ + APIVersion: r.APIVersion, + Kind: r.Kind, } + return d +} + +// DieSealFeedPtr returns a new die for the current die's state that uses a specific resource pointer for comparison in future diff and patch operations. If the resource is nil, the empty value is used instead. +func (d *TypeMetaDie) DieSealFeedPtr(r *metav1.TypeMeta) *TypeMetaDie { + if r == nil { + r = &metav1.TypeMeta{} + } + return d.DieSealFeed(*r) +} + +// DieSealRelease returns the sealed resource managed by the die. +func (d *TypeMetaDie) DieSealRelease() metav1.TypeMeta { + return metav1.TypeMeta{ + APIVersion: d.seal.APIVersion, + Kind: d.seal.Kind, + } +} + +// DieSealReleasePtr returns the sealed resource pointer managed by the die. +func (d *TypeMetaDie) DieSealReleasePtr() *metav1.TypeMeta { + r := d.DieSealRelease() + return &r +} + +// DieDiff uses cmp.Diff to compare the current value of the die with the sealed value. +func (d *TypeMetaDie) DieDiff(opts ...cmp.Option) string { + return cmp.Diff(d.seal, d.r, opts...) +} + +// DiePatch generates a patch between the current value of the die and the sealed value. +func (d *TypeMetaDie) DiePatch(patchType types.PatchType) ([]byte, error) { + return patch.Create(d.seal, d.r, patchType) } -// 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 +// 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 *TypeMetaDie) Kind(v string) *TypeMetaDie { return d.DieStamp(func(r *metav1.TypeMeta) { r.Kind = v }) } -// 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 +// 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 *TypeMetaDie) APIVersion(v string) *TypeMetaDie { return d.DieStamp(func(r *metav1.TypeMeta) { r.APIVersion = v diff --git a/apis/meta/v1/zz_generated.die.go b/apis/meta/v1/zz_generated.die.go index 7c9d25b..62f4354 100644 --- a/apis/meta/v1/zz_generated.die.go +++ b/apis/meta/v1/zz_generated.die.go @@ -23,16 +23,16 @@ package v1 import ( fmtx "fmt" - cmp "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" json "k8s.io/apimachinery/pkg/util/json" - jsonpath "k8s.io/client-go/util/jsonpath" + "k8s.io/client-go/util/jsonpath" osx "os" - patch "reconciler.io/dies/patch" + "reconciler.io/dies/patch" reflectx "reflect" - yaml "sigs.k8s.io/yaml" + "sigs.k8s.io/yaml" ) var ConditionBlank = (&ConditionDie{}).DieFeed(metav1.Condition{}) @@ -2067,6 +2067,30 @@ func (d *ObjectMetaDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ManagedFieldsDie replaces ManagedFields by collecting the released value from each die passed. +// +// # ManagedFields maps workflow-id and version to the set of fields +// +// that are managed by that workflow. This is mostly for internal +// +// housekeeping, and users typically shouldn't need to set or +// +// understand this field. A workflow can be the user's name, a +// +// controller's name, or the name of a specific apply path like +// +// "ci-cd". The set of fields is always in the version that the +// +// workflow used when modifying the object. +func (d *ObjectMetaDie) ManagedFieldsDie(v ...*ManagedFieldsEntryDie) *ObjectMetaDie { + return d.DieStamp(func(r *metav1.ObjectMeta) { + r.ManagedFields = make([]metav1.ManagedFieldsEntry, len(v)) + for i := range v { + r.ManagedFields[i] = v[i].DieRelease() + } + }) +} + // Name must be unique within a namespace. Is required when creating resources, although // // some resources may allow a client to request the generation of an appropriate name @@ -3125,6 +3149,36 @@ func (d *StatusDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// ListMetaDie mutates ListMeta as a die. +// +// Standard list metadata. +// +// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds +func (d *StatusDie) ListMetaDie(fn func(d *ListMetaDie)) *StatusDie { + return d.DieStamp(func(r *metav1.Status) { + d := ListMetaBlank.DieImmutable(false).DieFeed(r.ListMeta) + fn(d) + r.ListMeta = d.DieRelease() + }) +} + +// DetailsDie mutates Details as a die. +// +// Extended data associated with the reason. Each reason may define its +// +// own extended details. This field is optional and the data returned +// +// is not guaranteed to conform to any schema except that defined by +// +// the reason type. +func (d *StatusDie) DetailsDie(fn func(d *StatusDetailsDie)) *StatusDie { + return d.DieStamp(func(r *metav1.Status) { + d := StatusDetailsBlank.DieImmutable(false).DieFeedPtr(r.Details) + fn(d) + r.Details = d.DieReleasePtr() + }) +} + func (d *StatusDie) TypeMeta(v metav1.TypeMeta) *StatusDie { return d.DieStamp(func(r *metav1.Status) { r.TypeMeta = v @@ -3419,6 +3473,20 @@ func (d *StatusDetailsDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// CausesDie replaces Causes by collecting the released value from each die passed. +// +// # The Causes array includes more details associated with the StatusReason +// +// failure. Not all StatusReasons may provide detailed causes. +func (d *StatusDetailsDie) CausesDie(v ...*StatusCauseDie) *StatusDetailsDie { + return d.DieStamp(func(r *metav1.StatusDetails) { + r.Causes = make([]metav1.StatusCause, len(v)) + for i := range v { + r.Causes[i] = v[i].DieRelease() + } + }) +} + // The name attribute of the resource associated with the status StatusReason // // (when there is a single name which can be described). diff --git a/apis/networking/v1/ingress.go b/apis/networking/v1/ingress.go index cf4ec1b..652bcc2 100644 --- a/apis/networking/v1/ingress.go +++ b/apis/networking/v1/ingress.go @@ -18,71 +18,26 @@ package v1 import ( networkingv1 "k8s.io/api/networking/v1" - diecorev1 "reconciler.io/dies/apis/core/v1" ) // +die:object=true,apiVersion=networking.k8s.io/v1,kind=Ingress type _ = networkingv1.Ingress // +die +// +die:field:name=DefaultBackend,die=IngressBackendDie,pointer=true +// +die:field:name=TLS,die=IngressTLSDie,listType=atomic +// +die:field:name=Rules,die=IngressRuleDie,listType=atomic type _ = networkingv1.IngressSpec -func (d *IngressSpecDie) DefaultBackendDie(fn func(d *IngressBackendDie)) *IngressSpecDie { - return d.DieStamp(func(r *networkingv1.IngressSpec) { - d := IngressBackendBlank.DieImmutable(false).DieFeedPtr(r.DefaultBackend) - fn(d) - r.DefaultBackend = d.DieReleasePtr() - }) -} - -func (d *IngressSpecDie) TLSDie(tls ...*IngressTLSDie) *IngressSpecDie { - return d.DieStamp(func(r *networkingv1.IngressSpec) { - r.TLS = make([]networkingv1.IngressTLS, len(tls)) - for i := range tls { - r.TLS[i] = tls[i].DieRelease() - } - }) -} - -func (d *IngressSpecDie) RulesDie(rules ...*IngressRuleDie) *IngressSpecDie { - return d.DieStamp(func(r *networkingv1.IngressSpec) { - r.Rules = make([]networkingv1.IngressRule, len(rules)) - for i := range rules { - r.Rules[i] = rules[i].DieRelease() - } - }) -} - // +die +// +die:field:name=Service,die=IngressServiceBackendDie,pointer=true +// +die:field:name=Resource,package=_/core/v1,die=TypedLocalObjectReferenceDie,pointer=true type _ = networkingv1.IngressBackend -func (d *IngressBackendDie) ServiceDie(fn func(d *IngressServiceBackendDie)) *IngressBackendDie { - return d.DieStamp(func(r *networkingv1.IngressBackend) { - d := IngressServiceBackendBlank.DieImmutable(false).DieFeedPtr(r.Service) - fn(d) - r.Service = d.DieReleasePtr() - }) -} - -func (d *IngressBackendDie) ResourceDie(fn func(d *diecorev1.TypedLocalObjectReferenceDie)) *IngressBackendDie { - return d.DieStamp(func(r *networkingv1.IngressBackend) { - d := diecorev1.TypedLocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.Resource) - fn(d) - r.Resource = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Port,die=ServiceBackendPortDie type _ = networkingv1.IngressServiceBackend -func (d *IngressServiceBackendDie) PortDie(fn func(d *ServiceBackendPortDie)) *IngressServiceBackendDie { - return d.DieStamp(func(r *networkingv1.IngressServiceBackend) { - d := ServiceBackendPortBlank.DieImmutable(false).DieFeed(r.Port) - fn(d) - r.Port = d.DieRelease() - }) -} - // +die type _ = networkingv1.ServiceBackendPort @@ -90,73 +45,28 @@ type _ = networkingv1.ServiceBackendPort type _ = networkingv1.IngressTLS // +die +// +die:field:name=HTTP,die=HTTPIngressRuleValueDie,pointer=true type _ = networkingv1.IngressRule -func (d *IngressRuleDie) HTTPDie(fn func(d *HTTPIngressRuleValueDie)) *IngressRuleDie { - return d.DieStamp(func(r *networkingv1.IngressRule) { - d := HTTPIngressRuleValueBlank.DieImmutable(false).DieFeedPtr(r.HTTP) - fn(d) - r.HTTP = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=Paths,die=HTTPIngressPathDie,listType=atomic type _ = networkingv1.HTTPIngressRuleValue -func (d *HTTPIngressRuleValueDie) PathsDie(paths ...*HTTPIngressPathDie) *HTTPIngressRuleValueDie { - return d.DieStamp(func(r *networkingv1.HTTPIngressRuleValue) { - r.Paths = make([]networkingv1.HTTPIngressPath, len(paths)) - for i := range paths { - r.Paths[i] = paths[i].DieRelease() - } - }) -} - // +die +// +die:field:name=Backend,die=IngressBackendDie type _ = networkingv1.HTTPIngressPath -func (d *HTTPIngressPathDie) BackendDie(fn func(d *IngressBackendDie)) *HTTPIngressPathDie { - return d.DieStamp(func(r *networkingv1.HTTPIngressPath) { - d := IngressBackendBlank.DieImmutable(false).DieFeed(r.Backend) - fn(d) - r.Backend = d.DieRelease() - }) -} - // +die +// +die:field:name=LoadBalancer,die=IngressLoadBalancerStatusDie type IngressStatus = networkingv1.IngressStatus -func (d *IngressStatusDie) LoadBalancerDie(fn func(d *IngressLoadBalancerStatusDie)) *IngressStatusDie { - return d.DieStamp(func(r *networkingv1.IngressStatus) { - d := IngressLoadBalancerStatusBlank.DieImmutable(false).DieFeed(r.LoadBalancer) - fn(d) - r.LoadBalancer = d.DieRelease() - }) -} - // +die +// +die:field:name=Ingress,die=IngressLoadBalancerIngressDie,listType=atomic type IngressLoadBalancerStatus = networkingv1.IngressLoadBalancerStatus -func (d *IngressLoadBalancerStatusDie) IngressDie(ingress ...*IngressLoadBalancerIngressDie) *IngressLoadBalancerStatusDie { - return d.DieStamp(func(r *networkingv1.IngressLoadBalancerStatus) { - r.Ingress = make([]networkingv1.IngressLoadBalancerIngress, len(ingress)) - for i := range ingress { - r.Ingress[i] = ingress[i].DieRelease() - } - }) -} - // +die +// +die:field:name=Ports,die=IngressPortStatusDie,listType=atomic type IngressLoadBalancerIngress = networkingv1.IngressLoadBalancerIngress -func (d *IngressLoadBalancerIngressDie) PortsDie(ports ...*IngressPortStatusDie) *IngressLoadBalancerIngressDie { - return d.DieStamp(func(r *networkingv1.IngressLoadBalancerIngress) { - r.Ports = make([]networkingv1.IngressPortStatus, len(ports)) - for i := range ports { - r.Ports[i] = ports[i].DieRelease() - } - }) -} - // +die type IngressPortStatus = networkingv1.IngressPortStatus diff --git a/apis/networking/v1/ingressclass.go b/apis/networking/v1/ingressclass.go index cab27d2..c2650c1 100644 --- a/apis/networking/v1/ingressclass.go +++ b/apis/networking/v1/ingressclass.go @@ -24,15 +24,8 @@ import ( type _ = networkingv1.IngressClass // +die +// +die:field:name=Parameters,die=IngressClassParametersReferenceDie,pointer=true type _ = networkingv1.IngressClassSpec -func (d *IngressClassSpecDie) ParametersDie(fn func(d *IngressClassParametersReferenceDie)) *IngressClassSpecDie { - return d.DieStamp(func(r *networkingv1.IngressClassSpec) { - d := IngressClassParametersReferenceBlank.DieImmutable(false).DieFeedPtr(r.Parameters) - fn(d) - r.Parameters = d.DieReleasePtr() - }) -} - // +die type _ = networkingv1.IngressClassParametersReference diff --git a/apis/networking/v1/networkpolicy.go b/apis/networking/v1/networkpolicy.go index 5a97d9b..5a38a53 100644 --- a/apis/networking/v1/networkpolicy.go +++ b/apis/networking/v1/networkpolicy.go @@ -18,112 +18,35 @@ package v1 import ( networkingv1 "k8s.io/api/networking/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die:object=true,apiVersion=networking.k8s.io/v1,kind=NetworkPolicy type _ = networkingv1.NetworkPolicy // +die +// +die:field:name=PodSelector,package=_/meta/v1,die=LabelSelectorDie +// +die:field:name=Ingress,die=NetworkPolicyIngressRuleDie,listType=atomic +// +die:field:name=Egress,die=NetworkPolicyEgressRuleDie,listType=atomic type _ = networkingv1.NetworkPolicySpec -func (d *NetworkPolicySpecDie) PodSelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *NetworkPolicySpecDie { - return d.DieStamp(func(r *networkingv1.NetworkPolicySpec) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeed(r.PodSelector) - fn(d) - r.PodSelector = d.DieRelease() - }) -} - -func (d *NetworkPolicySpecDie) IngressDie(ingress ...*NetworkPolicyIngressRuleDie) *NetworkPolicySpecDie { - return d.DieStamp(func(r *networkingv1.NetworkPolicySpec) { - r.Ingress = make([]networkingv1.NetworkPolicyIngressRule, len(ingress)) - for i := range ingress { - r.Ingress[i] = ingress[i].DieRelease() - } - }) -} - -func (d *NetworkPolicySpecDie) EgressDie(egress ...*NetworkPolicyEgressRuleDie) *NetworkPolicySpecDie { - return d.DieStamp(func(r *networkingv1.NetworkPolicySpec) { - r.Egress = make([]networkingv1.NetworkPolicyEgressRule, len(egress)) - for i := range egress { - r.Egress[i] = egress[i].DieRelease() - } - }) -} - // +die +// +die:field:name=Ports,die=NetworkPolicyPortDie,listType=atomic +// +die:field:name=From,die=NetworkPolicyPeerDie,listType=atomic type _ = networkingv1.NetworkPolicyIngressRule -func (d *NetworkPolicyIngressRuleDie) PortsDie(ports ...*NetworkPolicyPortDie) *NetworkPolicyIngressRuleDie { - return d.DieStamp(func(r *networkingv1.NetworkPolicyIngressRule) { - r.Ports = make([]networkingv1.NetworkPolicyPort, len(ports)) - for i := range ports { - r.Ports[i] = ports[i].DieRelease() - } - }) -} - -func (d *NetworkPolicyIngressRuleDie) FromDie(from ...*NetworkPolicyPeerDie) *NetworkPolicyIngressRuleDie { - return d.DieStamp(func(r *networkingv1.NetworkPolicyIngressRule) { - r.From = make([]networkingv1.NetworkPolicyPeer, len(from)) - for i := range from { - r.From[i] = from[i].DieRelease() - } - }) -} - // +die +// +die:field:name=Ports,die=NetworkPolicyPortDie,listType=atomic +// +die:field:name=To,die=NetworkPolicyPeerDie,listType=atomic type _ = networkingv1.NetworkPolicyEgressRule -func (d *NetworkPolicyEgressRuleDie) PortsDie(ports ...*NetworkPolicyPortDie) *NetworkPolicyEgressRuleDie { - return d.DieStamp(func(r *networkingv1.NetworkPolicyEgressRule) { - r.Ports = make([]networkingv1.NetworkPolicyPort, len(ports)) - for i := range ports { - r.Ports[i] = ports[i].DieRelease() - } - }) -} - -func (d *NetworkPolicyEgressRuleDie) ToDie(to ...*NetworkPolicyPeerDie) *NetworkPolicyEgressRuleDie { - return d.DieStamp(func(r *networkingv1.NetworkPolicyEgressRule) { - r.To = make([]networkingv1.NetworkPolicyPeer, len(to)) - for i := range to { - r.To[i] = to[i].DieRelease() - } - }) -} - // +die type _ = networkingv1.NetworkPolicyPort // +die +// +die:field:name=PodSelector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=NamespaceSelector,package=_/meta/v1,die=LabelSelectorDie,pointer=true +// +die:field:name=IPBlock,die=IPBlockDie,pointer=true type _ = networkingv1.NetworkPolicyPeer -func (d *NetworkPolicyPeerDie) PodSelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *NetworkPolicyPeerDie { - return d.DieStamp(func(r *networkingv1.NetworkPolicyPeer) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.PodSelector) - fn(d) - r.PodSelector = d.DieReleasePtr() - }) -} - -func (d *NetworkPolicyPeerDie) NamespaceSelectorDie(fn func(d *diemetav1.LabelSelectorDie)) *NetworkPolicyPeerDie { - return d.DieStamp(func(r *networkingv1.NetworkPolicyPeer) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NamespaceSelector) - fn(d) - r.NamespaceSelector = d.DieReleasePtr() - }) -} - -func (d *NetworkPolicyPeerDie) IPBlockDie(fn func(d *IPBlockDie)) *NetworkPolicyPeerDie { - return d.DieStamp(func(r *networkingv1.NetworkPolicyPeer) { - d := IPBlockBlank.DieImmutable(false).DieFeedPtr(r.IPBlock) - fn(d) - r.IPBlock = d.DieReleasePtr() - }) -} - // +die type _ = networkingv1.IPBlock diff --git a/apis/networking/v1/zz_generated.die.go b/apis/networking/v1/zz_generated.die.go index c750400..18d3312 100644 --- a/apis/networking/v1/zz_generated.die.go +++ b/apis/networking/v1/zz_generated.die.go @@ -24,7 +24,7 @@ package v1 import ( fmtx "fmt" cmp "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" + apicorev1 "k8s.io/api/core/v1" networkingv1 "k8s.io/api/networking/v1" apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" unstructured "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -35,6 +35,7 @@ import ( json "k8s.io/apimachinery/pkg/util/json" jsonpath "k8s.io/client-go/util/jsonpath" osx "os" + corev1 "reconciler.io/dies/apis/core/v1" metav1 "reconciler.io/dies/apis/meta/v1" patch "reconciler.io/dies/patch" reflectx "reflect" @@ -628,6 +629,57 @@ func (d *IngressSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// DefaultBackendDie mutates DefaultBackend as a die. +// +// defaultBackend is the backend that should handle requests that don't +// +// match any rule. If Rules are not specified, DefaultBackend must be specified. +// +// # If DefaultBackend is not set, the handling of requests that do not match any +// +// of the rules will be up to the Ingress controller. +func (d *IngressSpecDie) DefaultBackendDie(fn func(d *IngressBackendDie)) *IngressSpecDie { + return d.DieStamp(func(r *networkingv1.IngressSpec) { + d := IngressBackendBlank.DieImmutable(false).DieFeedPtr(r.DefaultBackend) + fn(d) + r.DefaultBackend = d.DieReleasePtr() + }) +} + +// TLSDie replaces TLS by collecting the released value from each die passed. +// +// tls represents the TLS configuration. Currently the Ingress only supports a +// +// single TLS port, 443. If multiple members of this list specify different hosts, +// +// they will be multiplexed on the same port according to the hostname specified +// +// through the SNI TLS extension, if the ingress controller fulfilling the +// +// ingress supports SNI. +func (d *IngressSpecDie) TLSDie(v ...*IngressTLSDie) *IngressSpecDie { + return d.DieStamp(func(r *networkingv1.IngressSpec) { + r.TLS = make([]networkingv1.IngressTLS, len(v)) + for i := range v { + r.TLS[i] = v[i].DieRelease() + } + }) +} + +// RulesDie replaces Rules by collecting the released value from each die passed. +// +// rules is a list of host rules used to configure the Ingress. If unspecified, +// +// or no rule matches, all traffic is sent to the default backend. +func (d *IngressSpecDie) RulesDie(v ...*IngressRuleDie) *IngressSpecDie { + return d.DieStamp(func(r *networkingv1.IngressSpec) { + r.Rules = make([]networkingv1.IngressRule, len(v)) + for i := range v { + r.Rules[i] = v[i].DieRelease() + } + }) +} + // ingressClassName is the name of an IngressClass cluster resource. Ingress // // controller implementations use this field to know whether they should be @@ -918,6 +970,36 @@ func (d *IngressBackendDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// ServiceDie mutates Service as a die. +// +// service references a service as a backend. +// +// This is a mutually exclusive setting with "Resource". +func (d *IngressBackendDie) ServiceDie(fn func(d *IngressServiceBackendDie)) *IngressBackendDie { + return d.DieStamp(func(r *networkingv1.IngressBackend) { + d := IngressServiceBackendBlank.DieImmutable(false).DieFeedPtr(r.Service) + fn(d) + r.Service = d.DieReleasePtr() + }) +} + +// ResourceDie mutates Resource as a die. +// +// resource is an ObjectRef to another Kubernetes resource in the namespace +// +// of the Ingress object. If resource is specified, a service.Name and +// +// service.Port must not be specified. +// +// This is a mutually exclusive setting with "Service". +func (d *IngressBackendDie) ResourceDie(fn func(d *corev1.TypedLocalObjectReferenceDie)) *IngressBackendDie { + return d.DieStamp(func(r *networkingv1.IngressBackend) { + d := corev1.TypedLocalObjectReferenceBlank.DieImmutable(false).DieFeedPtr(r.Resource) + fn(d) + r.Resource = d.DieReleasePtr() + }) +} + // service references a service as a backend. // // This is a mutually exclusive setting with "Resource". @@ -934,7 +1016,7 @@ func (d *IngressBackendDie) Service(v *networkingv1.IngressServiceBackend) *Ingr // service.Port must not be specified. // // This is a mutually exclusive setting with "Service". -func (d *IngressBackendDie) Resource(v *corev1.TypedLocalObjectReference) *IngressBackendDie { +func (d *IngressBackendDie) Resource(v *apicorev1.TypedLocalObjectReference) *IngressBackendDie { return d.DieStamp(func(r *networkingv1.IngressBackend) { r.Resource = v }) @@ -1168,6 +1250,19 @@ func (d *IngressServiceBackendDie) DiePatch(patchType types.PatchType) ([]byte, return patch.Create(d.seal, d.r, patchType) } +// PortDie mutates Port as a die. +// +// port of the referenced service. A port name or port number +// +// is required for a IngressServiceBackend. +func (d *IngressServiceBackendDie) PortDie(fn func(d *ServiceBackendPortDie)) *IngressServiceBackendDie { + return d.DieStamp(func(r *networkingv1.IngressServiceBackend) { + d := ServiceBackendPortBlank.DieImmutable(false).DieFeed(r.Port) + fn(d) + r.Port = d.DieRelease() + }) +} + // name is the referenced service. The service must exist in // // the same namespace as the Ingress object. @@ -1916,6 +2011,15 @@ func (d *IngressRuleDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// HTTPDie mutates HTTP as a die. +func (d *IngressRuleDie) HTTPDie(fn func(d *HTTPIngressRuleValueDie)) *IngressRuleDie { + return d.DieStamp(func(r *networkingv1.IngressRule) { + d := HTTPIngressRuleValueBlank.DieImmutable(false).DieFeedPtr(r.HTTP) + fn(d) + r.HTTP = d.DieReleasePtr() + }) +} + // host is the fully qualified domain name of a network host, as defined by RFC 3986. // // Note the following deviations from the "host" part of the @@ -2206,6 +2310,18 @@ func (d *HTTPIngressRuleValueDie) DiePatch(patchType types.PatchType) ([]byte, e return patch.Create(d.seal, d.r, patchType) } +// PathsDie replaces Paths by collecting the released value from each die passed. +// +// paths is a collection of paths that map requests to backends. +func (d *HTTPIngressRuleValueDie) PathsDie(v ...*HTTPIngressPathDie) *HTTPIngressRuleValueDie { + return d.DieStamp(func(r *networkingv1.HTTPIngressRuleValue) { + r.Paths = make([]networkingv1.HTTPIngressPath, len(v)) + for i := range v { + r.Paths[i] = v[i].DieRelease() + } + }) +} + // paths is a collection of paths that map requests to backends. func (d *HTTPIngressRuleValueDie) Paths(v ...networkingv1.HTTPIngressPath) *HTTPIngressRuleValueDie { return d.DieStamp(func(r *networkingv1.HTTPIngressRuleValue) { @@ -2441,6 +2557,19 @@ func (d *HTTPIngressPathDie) DiePatch(patchType types.PatchType) ([]byte, error) return patch.Create(d.seal, d.r, patchType) } +// BackendDie mutates Backend as a die. +// +// backend defines the referenced service endpoint to which the traffic +// +// will be forwarded to. +func (d *HTTPIngressPathDie) BackendDie(fn func(d *IngressBackendDie)) *HTTPIngressPathDie { + return d.DieStamp(func(r *networkingv1.HTTPIngressPath) { + d := IngressBackendBlank.DieImmutable(false).DieFeed(r.Backend) + fn(d) + r.Backend = d.DieRelease() + }) +} + // path is matched against the path of an incoming request. Currently it can // // contain characters disallowed from the conventional "path" part of a URL @@ -2724,6 +2853,17 @@ func (d *IngressStatusDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// LoadBalancerDie mutates LoadBalancer as a die. +// +// loadBalancer contains the current status of the load-balancer. +func (d *IngressStatusDie) LoadBalancerDie(fn func(d *IngressLoadBalancerStatusDie)) *IngressStatusDie { + return d.DieStamp(func(r *networkingv1.IngressStatus) { + d := IngressLoadBalancerStatusBlank.DieImmutable(false).DieFeed(r.LoadBalancer) + fn(d) + r.LoadBalancer = d.DieRelease() + }) +} + // loadBalancer contains the current status of the load-balancer. func (d *IngressStatusDie) LoadBalancer(v networkingv1.IngressLoadBalancerStatus) *IngressStatusDie { return d.DieStamp(func(r *networkingv1.IngressStatus) { @@ -2959,6 +3099,18 @@ func (d *IngressLoadBalancerStatusDie) DiePatch(patchType types.PatchType) ([]by return patch.Create(d.seal, d.r, patchType) } +// IngressDie replaces Ingress by collecting the released value from each die passed. +// +// ingress is a list containing ingress points for the load-balancer. +func (d *IngressLoadBalancerStatusDie) IngressDie(v ...*IngressLoadBalancerIngressDie) *IngressLoadBalancerStatusDie { + return d.DieStamp(func(r *networkingv1.IngressLoadBalancerStatus) { + r.Ingress = make([]networkingv1.IngressLoadBalancerIngress, len(v)) + for i := range v { + r.Ingress[i] = v[i].DieRelease() + } + }) +} + // ingress is a list containing ingress points for the load-balancer. func (d *IngressLoadBalancerStatusDie) Ingress(v ...networkingv1.IngressLoadBalancerIngress) *IngressLoadBalancerStatusDie { return d.DieStamp(func(r *networkingv1.IngressLoadBalancerStatus) { @@ -3194,6 +3346,18 @@ func (d *IngressLoadBalancerIngressDie) DiePatch(patchType types.PatchType) ([]b return patch.Create(d.seal, d.r, patchType) } +// PortsDie replaces Ports by collecting the released value from each die passed. +// +// ports provides information about the ports exposed by this LoadBalancer. +func (d *IngressLoadBalancerIngressDie) PortsDie(v ...*IngressPortStatusDie) *IngressLoadBalancerIngressDie { + return d.DieStamp(func(r *networkingv1.IngressLoadBalancerIngress) { + r.Ports = make([]networkingv1.IngressPortStatus, len(v)) + for i := range v { + r.Ports[i] = v[i].DieRelease() + } + }) +} + // ip is set for load-balancer ingress points that are IP based. func (d *IngressLoadBalancerIngressDie) IP(v string) *IngressLoadBalancerIngressDie { return d.DieStamp(func(r *networkingv1.IngressLoadBalancerIngress) { @@ -3453,7 +3617,7 @@ func (d *IngressPortStatusDie) Port(v int32) *IngressPortStatusDie { // protocol is the protocol of the ingress port. // // The supported values are: "TCP", "UDP", "SCTP" -func (d *IngressPortStatusDie) Protocol(v corev1.Protocol) *IngressPortStatusDie { +func (d *IngressPortStatusDie) Protocol(v apicorev1.Protocol) *IngressPortStatusDie { return d.DieStamp(func(r *networkingv1.IngressPortStatus) { r.Protocol = v }) @@ -4049,6 +4213,21 @@ func (d *IngressClassSpecDie) DiePatch(patchType types.PatchType) ([]byte, error return patch.Create(d.seal, d.r, patchType) } +// ParametersDie mutates Parameters as a die. +// +// parameters is a link to a custom resource containing additional +// +// configuration for the controller. This is optional if the controller does +// +// not require extra parameters. +func (d *IngressClassSpecDie) ParametersDie(fn func(d *IngressClassParametersReferenceDie)) *IngressClassSpecDie { + return d.DieStamp(func(r *networkingv1.IngressClassSpec) { + d := IngressClassParametersReferenceBlank.DieImmutable(false).DieFeedPtr(r.Parameters) + fn(d) + r.Parameters = d.DieReleasePtr() + }) +} + // controller refers to the name of the controller that should handle this // // class. This allows for different "flavors" that are controlled by the @@ -4917,6 +5096,75 @@ func (d *NetworkPolicySpecDie) DiePatch(patchType types.PatchType) ([]byte, erro return patch.Create(d.seal, d.r, patchType) } +// PodSelectorDie mutates PodSelector as a die. +// +// podSelector selects the pods to which this NetworkPolicy object applies. +// +// The array of ingress rules is applied to any pods selected by this field. +// +// Multiple network policies can select the same set of pods. In this case, +// +// the ingress rules for each are combined additively. +// +// This field is NOT optional and follows standard label selector semantics. +// +// An empty podSelector matches all pods in this namespace. +func (d *NetworkPolicySpecDie) PodSelectorDie(fn func(d *metav1.LabelSelectorDie)) *NetworkPolicySpecDie { + return d.DieStamp(func(r *networkingv1.NetworkPolicySpec) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeed(r.PodSelector) + fn(d) + r.PodSelector = d.DieRelease() + }) +} + +// IngressDie replaces Ingress by collecting the released value from each die passed. +// +// ingress is a list of ingress rules to be applied to the selected pods. +// +// # Traffic is allowed to a pod if there are no NetworkPolicies selecting the pod +// +// (and cluster policy otherwise allows the traffic), OR if the traffic source is +// +// the pod's local node, OR if the traffic matches at least one ingress rule +// +// across all of the NetworkPolicy objects whose podSelector matches the pod. If +// +// this field is empty then this NetworkPolicy does not allow any traffic (and serves +// +// solely to ensure that the pods it selects are isolated by default) +func (d *NetworkPolicySpecDie) IngressDie(v ...*NetworkPolicyIngressRuleDie) *NetworkPolicySpecDie { + return d.DieStamp(func(r *networkingv1.NetworkPolicySpec) { + r.Ingress = make([]networkingv1.NetworkPolicyIngressRule, len(v)) + for i := range v { + r.Ingress[i] = v[i].DieRelease() + } + }) +} + +// EgressDie replaces Egress by collecting the released value from each die passed. +// +// egress is a list of egress rules to be applied to the selected pods. Outgoing traffic +// +// is allowed if there are no NetworkPolicies selecting the pod (and cluster policy +// +// otherwise allows the traffic), OR if the traffic matches at least one egress rule +// +// across all of the NetworkPolicy objects whose podSelector matches the pod. If +// +// this field is empty then this NetworkPolicy limits all outgoing traffic (and serves +// +// solely to ensure that the pods it selects are isolated by default). +// +// This field is beta-level in 1.8 +func (d *NetworkPolicySpecDie) EgressDie(v ...*NetworkPolicyEgressRuleDie) *NetworkPolicySpecDie { + return d.DieStamp(func(r *networkingv1.NetworkPolicySpec) { + r.Egress = make([]networkingv1.NetworkPolicyEgressRule, len(v)) + for i := range v { + r.Egress[i] = v[i].DieRelease() + } + }) +} + // podSelector selects the pods to which this NetworkPolicy object applies. // // The array of ingress rules is applied to any pods selected by this field. @@ -5225,6 +5473,46 @@ func (d *NetworkPolicyIngressRuleDie) DiePatch(patchType types.PatchType) ([]byt return patch.Create(d.seal, d.r, patchType) } +// PortsDie replaces Ports by collecting the released value from each die passed. +// +// ports is a list of ports which should be made accessible on the pods selected for +// +// this rule. Each item in this list is combined using a logical OR. If this field is +// +// empty or missing, this rule matches all ports (traffic not restricted by port). +// +// # If this field is present and contains at least one item, then this rule allows +// +// traffic only if the traffic matches at least one port in the list. +func (d *NetworkPolicyIngressRuleDie) PortsDie(v ...*NetworkPolicyPortDie) *NetworkPolicyIngressRuleDie { + return d.DieStamp(func(r *networkingv1.NetworkPolicyIngressRule) { + r.Ports = make([]networkingv1.NetworkPolicyPort, len(v)) + for i := range v { + r.Ports[i] = v[i].DieRelease() + } + }) +} + +// FromDie replaces From by collecting the released value from each die passed. +// +// from is a list of sources which should be able to access the pods selected for this rule. +// +// Items in this list are combined using a logical OR operation. If this field is +// +// empty or missing, this rule matches all sources (traffic not restricted by +// +// source). If this field is present and contains at least one item, this rule +// +// allows traffic only if the traffic matches at least one item in the from list. +func (d *NetworkPolicyIngressRuleDie) FromDie(v ...*NetworkPolicyPeerDie) *NetworkPolicyIngressRuleDie { + return d.DieStamp(func(r *networkingv1.NetworkPolicyIngressRule) { + r.From = make([]networkingv1.NetworkPolicyPeer, len(v)) + for i := range v { + r.From[i] = v[i].DieRelease() + } + }) +} + // ports is a list of ports which should be made accessible on the pods selected for // // this rule. Each item in this list is combined using a logical OR. If this field is @@ -5483,6 +5771,46 @@ func (d *NetworkPolicyEgressRuleDie) DiePatch(patchType types.PatchType) ([]byte return patch.Create(d.seal, d.r, patchType) } +// PortsDie replaces Ports by collecting the released value from each die passed. +// +// ports is a list of destination ports for outgoing traffic. +// +// Each item in this list is combined using a logical OR. If this field is +// +// empty or missing, this rule matches all ports (traffic not restricted by port). +// +// # If this field is present and contains at least one item, then this rule allows +// +// traffic only if the traffic matches at least one port in the list. +func (d *NetworkPolicyEgressRuleDie) PortsDie(v ...*NetworkPolicyPortDie) *NetworkPolicyEgressRuleDie { + return d.DieStamp(func(r *networkingv1.NetworkPolicyEgressRule) { + r.Ports = make([]networkingv1.NetworkPolicyPort, len(v)) + for i := range v { + r.Ports[i] = v[i].DieRelease() + } + }) +} + +// ToDie replaces To by collecting the released value from each die passed. +// +// to is a list of destinations for outgoing traffic of pods selected for this rule. +// +// Items in this list are combined using a logical OR operation. If this field is +// +// empty or missing, this rule matches all destinations (traffic not restricted by +// +// destination). If this field is present and contains at least one item, this rule +// +// allows traffic only if the traffic matches at least one item in the to list. +func (d *NetworkPolicyEgressRuleDie) ToDie(v ...*NetworkPolicyPeerDie) *NetworkPolicyEgressRuleDie { + return d.DieStamp(func(r *networkingv1.NetworkPolicyEgressRule) { + r.To = make([]networkingv1.NetworkPolicyPeer, len(v)) + for i := range v { + r.To[i] = v[i].DieRelease() + } + }) +} + // ports is a list of destination ports for outgoing traffic. // // Each item in this list is combined using a logical OR. If this field is @@ -5744,7 +6072,7 @@ func (d *NetworkPolicyPortDie) DiePatch(patchType types.PatchType) ([]byte, erro // protocol represents the protocol (TCP, UDP, or SCTP) which traffic must match. // // If not specified, this field defaults to TCP. -func (d *NetworkPolicyPortDie) Protocol(v *corev1.Protocol) *NetworkPolicyPortDie { +func (d *NetworkPolicyPortDie) Protocol(v *apicorev1.Protocol) *NetworkPolicyPortDie { return d.DieStamp(func(r *networkingv1.NetworkPolicyPort) { r.Protocol = v }) @@ -6036,6 +6364,57 @@ func (d *NetworkPolicyPeerDie) DiePatch(patchType types.PatchType) ([]byte, erro return patch.Create(d.seal, d.r, patchType) } +// PodSelectorDie mutates PodSelector as a die. +// +// podSelector is a label selector which selects pods. This field follows standard label +// +// selector semantics; if present but empty, it selects all pods. +// +// # If namespaceSelector is also set, then the NetworkPolicyPeer as a whole selects +// +// the pods matching podSelector in the Namespaces selected by NamespaceSelector. +// +// Otherwise it selects the pods matching podSelector in the policy's own namespace. +func (d *NetworkPolicyPeerDie) PodSelectorDie(fn func(d *metav1.LabelSelectorDie)) *NetworkPolicyPeerDie { + return d.DieStamp(func(r *networkingv1.NetworkPolicyPeer) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.PodSelector) + fn(d) + r.PodSelector = d.DieReleasePtr() + }) +} + +// NamespaceSelectorDie mutates NamespaceSelector as a die. +// +// namespaceSelector selects namespaces using cluster-scoped labels. This field follows +// +// standard label selector semantics; if present but empty, it selects all namespaces. +// +// # If podSelector is also set, then the NetworkPolicyPeer as a whole selects +// +// the pods matching podSelector in the namespaces selected by namespaceSelector. +// +// Otherwise it selects all pods in the namespaces selected by namespaceSelector. +func (d *NetworkPolicyPeerDie) NamespaceSelectorDie(fn func(d *metav1.LabelSelectorDie)) *NetworkPolicyPeerDie { + return d.DieStamp(func(r *networkingv1.NetworkPolicyPeer) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NamespaceSelector) + fn(d) + r.NamespaceSelector = d.DieReleasePtr() + }) +} + +// IPBlockDie mutates IPBlock as a die. +// +// ipBlock defines policy on a particular IPBlock. If this field is set then +// +// neither of the other fields can be. +func (d *NetworkPolicyPeerDie) IPBlockDie(fn func(d *IPBlockDie)) *NetworkPolicyPeerDie { + return d.DieStamp(func(r *networkingv1.NetworkPolicyPeer) { + d := IPBlockBlank.DieImmutable(false).DieFeedPtr(r.IPBlock) + fn(d) + r.IPBlock = d.DieReleasePtr() + }) +} + // podSelector is a label selector which selects pods. This field follows standard label // // selector semantics; if present but empty, it selects all pods. diff --git a/apis/node/v1/runtimeclass.go b/apis/node/v1/runtimeclass.go index 192e961..b9d587f 100644 --- a/apis/node/v1/runtimeclass.go +++ b/apis/node/v1/runtimeclass.go @@ -17,7 +17,6 @@ limitations under the License. package v1 import ( - corev1 "k8s.io/api/core/v1" nodev1 "k8s.io/api/node/v1" diecorev1 "reconciler.io/dies/apis/core/v1" ) @@ -29,21 +28,10 @@ type _ = nodev1.RuntimeClass type _ = nodev1.Overhead // +die +// +die:field:name=Tolerations,package=_/core/v1,die=TolerationDie,listMapKey=Key type _ = nodev1.Scheduling +// deprecated?: use TolerationDie func (d *SchedulingDie) TolerationsDie(key string, fn func(d *diecorev1.TolerationDie)) *SchedulingDie { - return d.DieStamp(func(r *nodev1.Scheduling) { - for i := range r.Tolerations { - if key == r.Tolerations[i].Key { - d := diecorev1.TolerationBlank.DieImmutable(false).DieFeed(r.Tolerations[i]) - fn(d) - r.Tolerations[i] = d.DieRelease() - return - } - } - - d := diecorev1.TolerationBlank.DieImmutable(false).DieFeed(corev1.Toleration{Key: key}) - fn(d) - r.Tolerations = append(r.Tolerations, d.DieRelease()) - }) + return d.TolerationDie(key, fn) } diff --git a/apis/node/v1/zz_generated.die.go b/apis/node/v1/zz_generated.die.go index d48d303..5491fce 100644 --- a/apis/node/v1/zz_generated.die.go +++ b/apis/node/v1/zz_generated.die.go @@ -35,6 +35,7 @@ import ( json "k8s.io/apimachinery/pkg/util/json" jsonpath "k8s.io/client-go/util/jsonpath" osx "os" + apiscorev1 "reconciler.io/dies/apis/core/v1" metav1 "reconciler.io/dies/apis/meta/v1" patch "reconciler.io/dies/patch" reflectx "reflect" @@ -896,6 +897,30 @@ func (d *SchedulingDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// TolerationDie mutates a single item in Tolerations matched by the nested field Key, appending a new item if no match is found. +// +// tolerations are appended (excluding duplicates) to pods running with this +// +// # RuntimeClass during admission, effectively unioning the set of nodes +// +// tolerated by the pod and the RuntimeClass. +func (d *SchedulingDie) TolerationDie(v string, fn func(d *apiscorev1.TolerationDie)) *SchedulingDie { + return d.DieStamp(func(r *nodev1.Scheduling) { + for i := range r.Tolerations { + if v == r.Tolerations[i].Key { + d := apiscorev1.TolerationBlank.DieImmutable(false).DieFeed(r.Tolerations[i]) + fn(d) + r.Tolerations[i] = d.DieRelease() + return + } + } + + d := apiscorev1.TolerationBlank.DieImmutable(false).DieFeed(corev1.Toleration{Key: v}) + fn(d) + r.Tolerations = append(r.Tolerations, d.DieRelease()) + }) +} + // nodeSelector lists labels that must be present on nodes that support this // // RuntimeClass. Pods using this RuntimeClass can only be scheduled to a diff --git a/apis/policy/v1/poddisruptionbudget.go b/apis/policy/v1/poddisruptionbudget.go index 6126c88..f17da9f 100644 --- a/apis/policy/v1/poddisruptionbudget.go +++ b/apis/policy/v1/poddisruptionbudget.go @@ -19,7 +19,6 @@ package v1 import ( policyv1 "k8s.io/api/policy/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die:object=true,apiVersion=policy/v1,kind=PodDisruptionBudget @@ -31,6 +30,7 @@ type _ = policyv1.PodDisruptionBudgetSpec // TODO(scothis) fix import for maps with struct values, ignore the 'DisruptedPods' field until then // +die:ignore={DisruptedPods} +// +die:field:name=Conditions,package=_/meta/v1,die=ConditionDie,listType=atomic type _ = policyv1.PodDisruptionBudgetStatus // DisruptedPods contains information about pods whose eviction was processed by the API server eviction subresource handler but has not yet been observed by the PodDisruptionBudget controller. A pod will be in this map from the time when the API server processed the eviction request to the time when the pod is seen by PDB controller as having been marked for deletion (or after a timeout). The key in the map is the name of the pod and the value is the time when the API server processed the eviction request. If the deletion didn't occur and a pod is still there it will be removed from the list automatically by PodDisruptionBudget controller after some time. If everything goes smooth this map should be empty for the most of the time. Large number of entries in the map may indicate problems with pod deletions. @@ -48,12 +48,3 @@ func (d *PodDisruptionBudgetStatusDie) DisruptedPodDie(key string, value metav1. r.DisruptedPods[key] = value }) } - -func (d *PodDisruptionBudgetStatusDie) ConditionsDie(conditions ...*diemetav1.ConditionDie) *PodDisruptionBudgetStatusDie { - return d.DieStamp(func(r *policyv1.PodDisruptionBudgetStatus) { - r.Conditions = make([]metav1.Condition, len(conditions)) - for i := range conditions { - r.Conditions[i] = conditions[i].DieRelease() - } - }) -} diff --git a/apis/policy/v1/zz_generated.die.go b/apis/policy/v1/zz_generated.die.go index 56b4c5e..9de1371 100644 --- a/apis/policy/v1/zz_generated.die.go +++ b/apis/policy/v1/zz_generated.die.go @@ -999,6 +999,40 @@ func (d *PodDisruptionBudgetStatusDie) DiePatch(patchType types.PatchType) ([]by return patch.Create(d.seal, d.r, patchType) } +// ConditionsDie replaces Conditions by collecting the released value from each die passed. +// +// Conditions contain conditions for PDB. The disruption controller sets the +// +// DisruptionAllowed condition. The following are known values for the reason field +// +// (additional reasons could be added in the future): +// +// - SyncFailed: The controller encountered an error and wasn't able to compute +// +// the number of allowed disruptions. Therefore no disruptions are +// +// allowed and the status of the condition will be False. +// +// - InsufficientPods: The number of pods are either at or below the number +// +// required by the PodDisruptionBudget. No disruptions are +// +// allowed and the status of the condition will be False. +// +// - SufficientPods: There are more pods than required by the PodDisruptionBudget. +// +// # The condition will be True, and the number of allowed +// +// disruptions are provided by the disruptionsAllowed property. +func (d *PodDisruptionBudgetStatusDie) ConditionsDie(v ...*metav1.ConditionDie) *PodDisruptionBudgetStatusDie { + return d.DieStamp(func(r *policyv1.PodDisruptionBudgetStatus) { + r.Conditions = make([]apismetav1.Condition, len(v)) + for i := range v { + r.Conditions[i] = v[i].DieRelease() + } + }) +} + // Most recent generation observed when updating this PDB status. DisruptionsAllowed and other // // status information is valid only if observedGeneration equals to PDB's object generation. diff --git a/apis/storage/v1/csidriver.go b/apis/storage/v1/csidriver.go index 7fa6661..6fdb2d6 100644 --- a/apis/storage/v1/csidriver.go +++ b/apis/storage/v1/csidriver.go @@ -24,16 +24,8 @@ import ( type _ = storagev1.CSIDriver // +die +// +die:field:name=TokenRequests,die=TokenRequestDie,listType=atomic type _ = storagev1.CSIDriverSpec -func (d *CSIDriverSpecDie) TokenRequestsDie(requests ...*TokenRequestDie) *CSIDriverSpecDie { - return d.DieStamp(func(r *storagev1.CSIDriverSpec) { - r.TokenRequests = make([]storagev1.TokenRequest, len(requests)) - for i := range requests { - r.TokenRequests[i] = requests[i].DieRelease() - } - }) -} - // +die type _ = storagev1.TokenRequest diff --git a/apis/storage/v1/csinode.go b/apis/storage/v1/csinode.go index b154621..1caeb35 100644 --- a/apis/storage/v1/csinode.go +++ b/apis/storage/v1/csinode.go @@ -24,27 +24,12 @@ import ( type _ = storagev1.CSINode // +die +// +die:field:name=Drivers,die=CSINodeDriverDie,listType=atomic type _ = storagev1.CSINodeSpec -func (d *CSINodeSpecDie) DriversDie(drivers ...*CSINodeDriverDie) *CSINodeSpecDie { - return d.DieStamp(func(r *storagev1.CSINodeSpec) { - r.Drivers = make([]storagev1.CSINodeDriver, len(drivers)) - for i := range drivers { - r.Drivers[i] = drivers[i].DieRelease() - } - }) -} - // +die +// +die:field:name=Allocatable,die=VolumeNodeResourcesDie,pointer=true type _ = storagev1.CSINodeDriver -func (d *CSINodeDriverDie) AllocatableDie(fn func(d *VolumeNodeResourcesDie)) *CSINodeDriverDie { - return d.DieStamp(func(r *storagev1.CSINodeDriver) { - d := VolumeNodeResourcesBlank.DieImmutable(false).DieFeedPtr(r.Allocatable) - fn(d) - r.Allocatable = d.DieReleasePtr() - }) -} - // +die type _ = storagev1.VolumeNodeResources diff --git a/apis/storage/v1/csistoragecapacities.go b/apis/storage/v1/csistoragecapacities.go index 268aea2..1d28453 100644 --- a/apis/storage/v1/csistoragecapacities.go +++ b/apis/storage/v1/csistoragecapacities.go @@ -18,16 +18,8 @@ package v1 import ( storagev1 "k8s.io/api/storage/v1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die:object=true,apiVersion=storage.k8s.io/v1,kind=CSIStorageCapacity +// +die:field:name=NodeTopology,package=_/meta/v1,die=LabelSelectorDie,pointer=true type _ = storagev1.CSIStorageCapacity - -func (d *CSIStorageCapacityDie) NodeTopologyDie(fn func(d *diemetav1.LabelSelectorDie)) *CSIStorageCapacityDie { - return d.DieStamp(func(r *storagev1.CSIStorageCapacity) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NodeTopology) - fn(d) - r.NodeTopology = d.DieReleasePtr() - }) -} diff --git a/apis/storage/v1/storageclass.go b/apis/storage/v1/storageclass.go index ceeef01..0516e91 100644 --- a/apis/storage/v1/storageclass.go +++ b/apis/storage/v1/storageclass.go @@ -17,12 +17,11 @@ limitations under the License. package v1 import ( - corev1 "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" - diecorev1 "reconciler.io/dies/apis/core/v1" ) // +die:object=true,apiVersion=storage.k8s.io/v1,kind=StorageClass +// +die:field:name=AllowedTopologies,package=_/core/v1,die=TopologySelectorTermDie,listType=atomic type _ = storagev1.StorageClass func (d *StorageClassDie) AddParameter(key, value string) *StorageClassDie { @@ -33,12 +32,3 @@ func (d *StorageClassDie) AddParameter(key, value string) *StorageClassDie { r.Parameters[key] = value }) } - -func (d *StorageClassDie) AllowedTopologiesDie(topologies ...*diecorev1.TopologySelectorTermDie) *StorageClassDie { - return d.DieStamp(func(r *storagev1.StorageClass) { - r.AllowedTopologies = make([]corev1.TopologySelectorTerm, len(topologies)) - for i := range topologies { - r.AllowedTopologies[i] = topologies[i].DieRelease() - } - }) -} diff --git a/apis/storage/v1/volumeattachment.go b/apis/storage/v1/volumeattachment.go index bc4401c..17b7382 100644 --- a/apis/storage/v1/volumeattachment.go +++ b/apis/storage/v1/volumeattachment.go @@ -18,52 +18,23 @@ package v1 import ( storagev1 "k8s.io/api/storage/v1" - diecorev1 "reconciler.io/dies/apis/core/v1" ) // +die:object=true,apiVersion=storage.k8s.io/v1,kind=VolumeAttachment type _ = storagev1.VolumeAttachment // +die +// +die:field:name=Source,die=VolumeAttachmentSourceDie type _ = storagev1.VolumeAttachmentSpec -func (d *VolumeAttachmentSpecDie) SourceDie(fn func(d *VolumeAttachmentSourceDie)) *VolumeAttachmentSpecDie { - return d.DieStamp(func(r *storagev1.VolumeAttachmentSpec) { - d := VolumeAttachmentSourceBlank.DieImmutable(false).DieFeed(r.Source) - fn(d) - r.Source = d.DieRelease() - }) -} - // +die +// +die:field:name=InlineVolumeSpec,package=_/core/v1,die=PersistentVolumeSpecDie,pointer=true type _ = storagev1.VolumeAttachmentSource -func (d *VolumeAttachmentSourceDie) SourceDie(fn func(d *diecorev1.PersistentVolumeSpecDie)) *VolumeAttachmentSourceDie { - return d.DieStamp(func(r *storagev1.VolumeAttachmentSource) { - d := diecorev1.PersistentVolumeSpecBlank.DieImmutable(false).DieFeedPtr(r.InlineVolumeSpec) - fn(d) - r.InlineVolumeSpec = d.DieReleasePtr() - }) -} - // +die +// +die:field:name=AttachError,die=VolumeErrorDie,pointer=true +// +die:field:name=DetachError,die=VolumeErrorDie,pointer=true type _ = storagev1.VolumeAttachmentStatus -func (d *VolumeAttachmentStatusDie) AttachErrorDie(fn func(d *VolumeErrorDie)) *VolumeAttachmentStatusDie { - return d.DieStamp(func(r *storagev1.VolumeAttachmentStatus) { - d := VolumeErrorBlank.DieImmutable(false).DieFeedPtr(r.AttachError) - fn(d) - r.AttachError = d.DieReleasePtr() - }) -} - -func (d *VolumeAttachmentStatusDie) DetachErrorDie(fn func(d *VolumeErrorDie)) *VolumeAttachmentStatusDie { - return d.DieStamp(func(r *storagev1.VolumeAttachmentStatus) { - d := VolumeErrorBlank.DieImmutable(false).DieFeedPtr(r.DetachError) - fn(d) - r.DetachError = d.DieReleasePtr() - }) -} - // +die type _ = storagev1.VolumeError diff --git a/apis/storage/v1/zz_generated.die.go b/apis/storage/v1/zz_generated.die.go index ae20de7..45cd15a 100644 --- a/apis/storage/v1/zz_generated.die.go +++ b/apis/storage/v1/zz_generated.die.go @@ -24,7 +24,7 @@ package v1 import ( fmtx "fmt" cmp "github.com/google/go-cmp/cmp" - corev1 "k8s.io/api/core/v1" + apicorev1 "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" resource "k8s.io/apimachinery/pkg/api/resource" apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -35,6 +35,7 @@ import ( json "k8s.io/apimachinery/pkg/util/json" jsonpath "k8s.io/client-go/util/jsonpath" osx "os" + corev1 "reconciler.io/dies/apis/core/v1" metav1 "reconciler.io/dies/apis/meta/v1" patch "reconciler.io/dies/patch" reflectx "reflect" @@ -608,6 +609,44 @@ func (d *CSIDriverSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// TokenRequestsDie replaces TokenRequests by collecting the released value from each die passed. +// +// tokenRequests indicates the CSI driver needs pods' service account +// +// tokens it is mounting volume for to do necessary authentication. Kubelet +// +// will pass the tokens in VolumeContext in the CSI NodePublishVolume calls. +// +// The CSI driver should parse and validate the following VolumeContext: +// +// "csi.storage.k8s.io/serviceAccount.tokens": { +// +// "": { +// +// "token": , +// +// "expirationTimestamp": , +// +// }, +// +// ... +// +// } +// +// Note: Audience in each TokenRequest should be different and at +// +// most one token is empty string. To receive a new token after expiry, +// +// RequiresRepublish can be used to trigger NodePublishVolume periodically. +func (d *CSIDriverSpecDie) TokenRequestsDie(v ...*TokenRequestDie) *CSIDriverSpecDie { + return d.DieStamp(func(r *storagev1.CSIDriverSpec) { + r.TokenRequests = make([]storagev1.TokenRequest, len(v)) + for i := range v { + r.TokenRequests[i] = v[i].DieRelease() + } + }) +} + // attachRequired indicates this CSI volume driver requires an attach // // operation (because it implements the CSI ControllerPublishVolume() @@ -1653,6 +1692,20 @@ func (d *CSINodeSpecDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// DriversDie replaces Drivers by collecting the released value from each die passed. +// +// drivers is a list of information of all CSI Drivers existing on a node. +// +// If all drivers in the list are uninstalled, this can become empty. +func (d *CSINodeSpecDie) DriversDie(v ...*CSINodeDriverDie) *CSINodeSpecDie { + return d.DieStamp(func(r *storagev1.CSINodeSpec) { + r.Drivers = make([]storagev1.CSINodeDriver, len(v)) + for i := range v { + r.Drivers[i] = v[i].DieRelease() + } + }) +} + // drivers is a list of information of all CSI Drivers existing on a node. // // If all drivers in the list are uninstalled, this can become empty. @@ -1890,6 +1943,19 @@ func (d *CSINodeDriverDie) DiePatch(patchType types.PatchType) ([]byte, error) { return patch.Create(d.seal, d.r, patchType) } +// AllocatableDie mutates Allocatable as a die. +// +// allocatable represents the volume resources of a node that are available for scheduling. +// +// This field is beta. +func (d *CSINodeDriverDie) AllocatableDie(fn func(d *VolumeNodeResourcesDie)) *CSINodeDriverDie { + return d.DieStamp(func(r *storagev1.CSINodeDriver) { + d := VolumeNodeResourcesBlank.DieImmutable(false).DieFeedPtr(r.Allocatable) + fn(d) + r.Allocatable = d.DieReleasePtr() + }) +} + // name represents the name of the CSI driver that this object refers to. // // # This MUST be the same name returned by the CSI GetPluginName() call for @@ -2522,6 +2588,25 @@ func (d *CSIStorageCapacityDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *C }) } +// NodeTopologyDie mutates NodeTopology as a die. +// +// nodeTopology defines which nodes have access to the storage +// +// for which capacity was reported. If not set, the storage is +// +// not accessible from any node in the cluster. If empty, the +// +// storage is accessible from all nodes. This field is +// +// immutable. +func (d *CSIStorageCapacityDie) NodeTopologyDie(fn func(d *metav1.LabelSelectorDie)) *CSIStorageCapacityDie { + return d.DieStamp(func(r *storagev1.CSIStorageCapacity) { + d := metav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NodeTopology) + fn(d) + r.NodeTopology = d.DieReleasePtr() + }) +} + // nodeTopology defines which nodes have access to the storage // // for which capacity was reported. If not set, the storage is @@ -2963,6 +3048,24 @@ func (d *StorageClassDie) MetadataDie(fn func(d *metav1.ObjectMetaDie)) *Storage }) } +// AllowedTopologiesDie replaces AllowedTopologies by collecting the released value from each die passed. +// +// allowedTopologies restrict the node topologies where volumes can be dynamically provisioned. +// +// Each volume plugin defines its own supported topology specifications. +// +// An empty TopologySelectorTerm list means there is no topology restriction. +// +// This field is only honored by servers that enable the VolumeScheduling feature. +func (d *StorageClassDie) AllowedTopologiesDie(v ...*corev1.TopologySelectorTermDie) *StorageClassDie { + return d.DieStamp(func(r *storagev1.StorageClass) { + r.AllowedTopologies = make([]apicorev1.TopologySelectorTerm, len(v)) + for i := range v { + r.AllowedTopologies[i] = v[i].DieRelease() + } + }) +} + // provisioner indicates the type of the provisioner. func (d *StorageClassDie) Provisioner(v string) *StorageClassDie { return d.DieStamp(func(r *storagev1.StorageClass) { @@ -2982,7 +3085,7 @@ func (d *StorageClassDie) Parameters(v map[string]string) *StorageClassDie { // reclaimPolicy controls the reclaimPolicy for dynamically provisioned PersistentVolumes of this storage class. // // Defaults to Delete. -func (d *StorageClassDie) ReclaimPolicy(v *corev1.PersistentVolumeReclaimPolicy) *StorageClassDie { +func (d *StorageClassDie) ReclaimPolicy(v *apicorev1.PersistentVolumeReclaimPolicy) *StorageClassDie { return d.DieStamp(func(r *storagev1.StorageClass) { r.ReclaimPolicy = v }) @@ -3024,7 +3127,7 @@ func (d *StorageClassDie) VolumeBindingMode(v *storagev1.VolumeBindingMode) *Sto // An empty TopologySelectorTerm list means there is no topology restriction. // // This field is only honored by servers that enable the VolumeScheduling feature. -func (d *StorageClassDie) AllowedTopologies(v ...corev1.TopologySelectorTerm) *StorageClassDie { +func (d *StorageClassDie) AllowedTopologies(v ...apicorev1.TopologySelectorTerm) *StorageClassDie { return d.DieStamp(func(r *storagev1.StorageClass) { r.AllowedTopologies = v }) @@ -3619,6 +3722,17 @@ func (d *VolumeAttachmentSpecDie) DiePatch(patchType types.PatchType) ([]byte, e return patch.Create(d.seal, d.r, patchType) } +// SourceDie mutates Source as a die. +// +// source represents the volume that should be attached. +func (d *VolumeAttachmentSpecDie) SourceDie(fn func(d *VolumeAttachmentSourceDie)) *VolumeAttachmentSpecDie { + return d.DieStamp(func(r *storagev1.VolumeAttachmentSpec) { + d := VolumeAttachmentSourceBlank.DieImmutable(false).DieFeed(r.Source) + fn(d) + r.Source = d.DieRelease() + }) +} + // attacher indicates the name of the volume driver that MUST handle this // // request. This is the name returned by GetPluginName(). @@ -3870,6 +3984,27 @@ func (d *VolumeAttachmentSourceDie) DiePatch(patchType types.PatchType) ([]byte, return patch.Create(d.seal, d.r, patchType) } +// InlineVolumeSpecDie mutates InlineVolumeSpec as a die. +// +// inlineVolumeSpec contains all the information necessary to attach +// +// a persistent volume defined by a pod's inline VolumeSource. This field +// +// is populated only for the CSIMigration feature. It contains +// +// translated fields from a pod's inline VolumeSource to a +// +// PersistentVolumeSpec. This field is beta-level and is only +// +// honored by servers that enabled the CSIMigration feature. +func (d *VolumeAttachmentSourceDie) InlineVolumeSpecDie(fn func(d *corev1.PersistentVolumeSpecDie)) *VolumeAttachmentSourceDie { + return d.DieStamp(func(r *storagev1.VolumeAttachmentSource) { + d := corev1.PersistentVolumeSpecBlank.DieImmutable(false).DieFeedPtr(r.InlineVolumeSpec) + fn(d) + r.InlineVolumeSpec = d.DieReleasePtr() + }) +} + // persistentVolumeName represents the name of the persistent volume to attach. func (d *VolumeAttachmentSourceDie) PersistentVolumeName(v *string) *VolumeAttachmentSourceDie { return d.DieStamp(func(r *storagev1.VolumeAttachmentSource) { @@ -3888,7 +4023,7 @@ func (d *VolumeAttachmentSourceDie) PersistentVolumeName(v *string) *VolumeAttac // PersistentVolumeSpec. This field is beta-level and is only // // honored by servers that enabled the CSIMigration feature. -func (d *VolumeAttachmentSourceDie) InlineVolumeSpec(v *corev1.PersistentVolumeSpec) *VolumeAttachmentSourceDie { +func (d *VolumeAttachmentSourceDie) InlineVolumeSpec(v *apicorev1.PersistentVolumeSpec) *VolumeAttachmentSourceDie { return d.DieStamp(func(r *storagev1.VolumeAttachmentSource) { r.InlineVolumeSpec = v }) @@ -4122,6 +4257,36 @@ func (d *VolumeAttachmentStatusDie) DiePatch(patchType types.PatchType) ([]byte, return patch.Create(d.seal, d.r, patchType) } +// AttachErrorDie mutates AttachError as a die. +// +// attachError represents the last error encountered during attach operation, if any. +// +// # This field must only be set by the entity completing the attach +// +// operation, i.e. the external-attacher. +func (d *VolumeAttachmentStatusDie) AttachErrorDie(fn func(d *VolumeErrorDie)) *VolumeAttachmentStatusDie { + return d.DieStamp(func(r *storagev1.VolumeAttachmentStatus) { + d := VolumeErrorBlank.DieImmutable(false).DieFeedPtr(r.AttachError) + fn(d) + r.AttachError = d.DieReleasePtr() + }) +} + +// DetachErrorDie mutates DetachError as a die. +// +// detachError represents the last error encountered during detach operation, if any. +// +// # This field must only be set by the entity completing the detach +// +// operation, i.e. the external-attacher. +func (d *VolumeAttachmentStatusDie) DetachErrorDie(fn func(d *VolumeErrorDie)) *VolumeAttachmentStatusDie { + return d.DieStamp(func(r *storagev1.VolumeAttachmentStatus) { + d := VolumeErrorBlank.DieImmutable(false).DieFeedPtr(r.DetachError) + fn(d) + r.DetachError = d.DieReleasePtr() + }) +} + // attached indicates the volume is successfully attached. // // # This field must only be set by the entity completing the attach diff --git a/apis/storage/v1beta1/csistoragecapacity.go b/apis/storage/v1beta1/csistoragecapacity.go index 50bf2a4..e74cfc5 100644 --- a/apis/storage/v1beta1/csistoragecapacity.go +++ b/apis/storage/v1beta1/csistoragecapacity.go @@ -18,16 +18,8 @@ package v1beta1 import ( storagev1beta1 "k8s.io/api/storage/v1beta1" - diemetav1 "reconciler.io/dies/apis/meta/v1" ) // +die:object=true,apiVersion=storage.k8s.io/v1beta1,kind=CSIStorageCapacity +// +die:field:name=NodeTopology,package=_/meta/v1,die=LabelSelectorDie,pointer=true type _ = storagev1beta1.CSIStorageCapacity - -func (d *CSIStorageCapacityDie) NodeTopologyDie(fn func(d *diemetav1.LabelSelectorDie)) *CSIStorageCapacityDie { - return d.DieStamp(func(r *storagev1beta1.CSIStorageCapacity) { - d := diemetav1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NodeTopology) - fn(d) - r.NodeTopology = d.DieReleasePtr() - }) -} diff --git a/apis/storage/v1beta1/zz_generated.die.go b/apis/storage/v1beta1/zz_generated.die.go index 7628be6..27f3510 100644 --- a/apis/storage/v1beta1/zz_generated.die.go +++ b/apis/storage/v1beta1/zz_generated.die.go @@ -34,7 +34,7 @@ import ( json "k8s.io/apimachinery/pkg/util/json" jsonpath "k8s.io/client-go/util/jsonpath" osx "os" - "reconciler.io/dies/apis/meta/v1" + v1 "reconciler.io/dies/apis/meta/v1" patch "reconciler.io/dies/patch" reflectx "reflect" yaml "sigs.k8s.io/yaml" @@ -363,6 +363,25 @@ func (d *CSIStorageCapacityDie) MetadataDie(fn func(d *v1.ObjectMetaDie)) *CSISt }) } +// NodeTopologyDie mutates NodeTopology as a die. +// +// nodeTopology defines which nodes have access to the storage +// +// for which capacity was reported. If not set, the storage is +// +// not accessible from any node in the cluster. If empty, the +// +// storage is accessible from all nodes. This field is +// +// immutable. +func (d *CSIStorageCapacityDie) NodeTopologyDie(fn func(d *v1.LabelSelectorDie)) *CSIStorageCapacityDie { + return d.DieStamp(func(r *storagev1beta1.CSIStorageCapacity) { + d := v1.LabelSelectorBlank.DieImmutable(false).DieFeedPtr(r.NodeTopology) + fn(d) + r.NodeTopology = d.DieReleasePtr() + }) +} + // nodeTopology defines which nodes have access to the storage // // for which capacity was reported. If not set, the storage is diff --git a/diegen/die/gen.go b/diegen/die/gen.go index a1f240d..ed63a95 100644 --- a/diegen/die/gen.go +++ b/diegen/die/gen.go @@ -26,13 +26,15 @@ import ( "unicode" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/utils/ptr" "sigs.k8s.io/controller-tools/pkg/genall" "sigs.k8s.io/controller-tools/pkg/loader" "sigs.k8s.io/controller-tools/pkg/markers" ) var ( - dieMarker = markers.Must(markers.MakeDefinition("die", markers.DescribesType, Die{})) + dieMarker = markers.Must(markers.MakeDefinition("die", markers.DescribesType, Die{})) + dieFieldMarker = markers.Must(markers.MakeDefinition("die:field", markers.DescribesType, DieField{})) ) type Die struct { @@ -125,6 +127,57 @@ func (d *Field) Default() { } } +type DieField struct { + Name string `marker:"name"` + Method string `marker:"method,optional"` + Field string `marker:"field,optional"` + Package string `marker:"package,optional"` + Die string `marker:"die"` + Blank string `marker:"blank,optional"` + Pointer *bool `marker:"pointer,optional"` + + ListType string `marker:"listType,optional"` + ListMapKey string `marker:"listMapKey,optional"` + ListMapKeyPackage string `marker:"listMapKeyPackage,optional"` + ListMapKeyType string `marker:"listMapKeyType,optional"` +} + +func (d *DieField) Default() { + if d.ListType == "" && d.ListMapKey != "" { + // TODO(scothis) default from +listType +listMapKey on target field + d.ListType = "map" + } + if d.ListType == "map" { + if d.ListMapKey == "" { + d.ListMapKey = "Name" + } + if d.ListMapKeyType == "" { + d.ListMapKeyType = "string" + } + } + if d.Method == "" { + name := d.Name + if d.ListType == "map" { + // try to singularize the name + name = strings.TrimSuffix(name, "s") + } + d.Method = fmt.Sprintf("%sDie", name) + + } + if d.Field == "" { + d.Field = d.Name + } + if strings.HasPrefix(d.Package, "_/") { + d.Package = strings.Replace(d.Package, "_/", "reconciler.io/dies/apis/", 1) + } + if d.Blank == "" { + d.Blank = fmt.Sprintf("%sBlank", strings.TrimSuffix(d.Die, "Die")) + } + if d.Pointer == nil { + d.Pointer = ptr.To(false) + } +} + type Generator struct { // HeaderFile specifies the header text (e.g. license) to prepend to generated files. HeaderFile string `marker:",optional"` @@ -146,6 +199,11 @@ func (Generator) RegisterMarkers(into *markers.Registry) error { } into.AddHelp(dieMarker, markers.SimpleHelp("die", "generates a die for the type")) + if err := into.Register(dieFieldMarker); err != nil { + return err + } + into.AddHelp(dieFieldMarker, markers.SimpleHelp("die:field", "generates a helper method for a field on the type using another die")) + return nil } @@ -241,6 +299,7 @@ func (ctx *ObjectGenCtx) generateForPackage(root *loader.Package) ([]byte, []byt dies := []Die{} dieSet := sets.New[string]() fieldMap := map[string][]Field{} + dieFieldMap := map[string][]DieField{} if err := markers.EachType(ctx.Collector, root, func(info *markers.TypeInfo) { if dieMarkers, ok := info.Markers[dieMarker.Name]; ok { @@ -252,6 +311,15 @@ func (ctx *ObjectGenCtx) generateForPackage(root *loader.Package) ([]byte, []byt } die.Default() + if dieFieldMarkers, ok := info.Markers[dieFieldMarker.Name]; ok { + dieFieldMap[die.Type] = []DieField{} + for i := range dieFieldMarkers { + dieField := dieFieldMarkers[i].(DieField) + dieField.Default() + dieFieldMap[die.Type] = append(dieFieldMap[die.Type], dieField) + } + } + dies = append(dies, die) dieSet.Insert(die.Name) @@ -292,7 +360,6 @@ func (ctx *ObjectGenCtx) generateForPackage(root *loader.Package) ([]byte, []byt root.AddError(err) return } - } }); err != nil { root.AddError(err) @@ -315,8 +382,9 @@ func (ctx *ObjectGenCtx) generateForPackage(root *loader.Package) ([]byte, []byt for _, die := range dies { fmt.Printf("Generating die for %q\n", die.Name) fields := fieldMap[die.Type] + dieFields := dieFieldMap[die.Type] - copyCtx.GenerateMethodsFor(die, fields) + copyCtx.GenerateMethodsFor(die, fields, dieFields) // print fields for this die for _, field := range fields { diff --git a/diegen/die/traverse.go b/diegen/die/traverse.go index d0915c1..04ea0ef 100644 --- a/diegen/die/traverse.go +++ b/diegen/die/traverse.go @@ -144,9 +144,10 @@ type copyMethodMaker struct { dies sets.Set[string] } -func (c *copyMethodMaker) GenerateMethodsFor(die Die, fields []Field) { +func (c *copyMethodMaker) GenerateMethodsFor(die Die, fields []Field, dieFields []DieField) { c.generateDieFor(die) c.generateObjectMethodsFor(die) + c.generateDieFieldMethodsFor(die, fields, dieFields) } func (c *copyMethodMaker) GenerateFieldFor(field Field, die Die) { @@ -546,6 +547,80 @@ func (c *copyMethodMaker) generateSealMethodFor(die Die) { c.Linef("}") } +func (c *copyMethodMaker) generateDieFieldMethodsFor(die Die, resourceFields []Field, dieFields []DieField) { + resourceFieldByName := map[string]Field{} + for _, field := range resourceFields { + resourceFieldByName[field.Name] = field + } + + for _, field := range dieFields { + resourceField := resourceFieldByName[field.Field] + + ptr := "" + if *field.Pointer { + ptr = "Ptr" + } + + switch field.ListType { + case "atomic": + c.Linef("") + c.Linef("// %s replaces %s by collecting the released value from each die passed.", field.Method, field.Field) + if resourceField.Doc != "" { + c.Linef("//") + c.Linef("%s", c.Doc(resourceField.Doc)) + } + c.Linef("func (d *%s) %s(v ...*%s) *%s {", die.Type, field.Method, c.AliasedRef(field.Package, field.Die), die.Type) + c.Linef(" return d.DieStamp(func(r *%s) {", c.AliasedRef(die.TargetPackage, die.TargetType)) + c.Linef(" r.%s = make([]%s, len(v))", field.Field, c.AliasedRef(resourceField.TypePackage, resourceField.Type)) + c.Linef(" for i := range v {") + c.Linef(" r.%s[i] = v[i].DieRelease%s()", field.Field, ptr) + c.Linef(" }") + c.Linef(" })") + c.Linef("}") + + case "map": + c.Linef("") + c.Linef("// %s mutates a single item in %s matched by the nested field %s, appending a new item if no match is found.", field.Method, field.Field, field.ListMapKey) + if resourceField.Doc != "" { + c.Linef("//") + c.Linef("%s", c.Doc(resourceField.Doc)) + } + c.Linef("func (d *%s) %s(v %s, fn func(d *%s)) *%s {", die.Type, field.Method, c.AliasedRef(field.ListMapKeyPackage, field.ListMapKeyType), c.AliasedRef(field.Package, field.Die), die.Type) + c.Linef(" return d.DieStamp(func(r *%s) {", c.AliasedRef(die.TargetPackage, die.TargetType)) + c.Linef(" for i := range r.%s {", field.Name) + c.Linef(" if v == r.%s[i].%s {", field.Name, field.ListMapKey) + c.Linef(" d := %s.DieImmutable(false).DieFeed%s(r.%s[i])", c.AliasedRef(field.Package, field.Blank), ptr, field.Field) + c.Linef(" fn(d)") + c.Linef(" r.%s[i] = d.DieRelease%s()", field.Field, ptr) + c.Linef(" return") + c.Linef(" }") + c.Linef(" }") + c.Linef("") + c.Linef(" d := %s.DieImmutable(false).DieFeed%s(%s{%s: v})", c.AliasedRef(field.Package, field.Blank), ptr, c.AliasedRef(resourceField.TypePackage, resourceField.Type), field.ListMapKey) + c.Linef(" fn(d)") + c.Linef(" r.%s = append(r.%s, d.DieRelease%s())", field.Field, field.Field, ptr) + c.Linef(" })") + c.Linef("}") + + default: + c.Linef("") + c.Linef("// %s mutates %s as a die.", field.Method, field.Field) + if resourceField.Doc != "" { + c.Linef("//") + c.Linef("%s", c.Doc(resourceField.Doc)) + } + c.Linef("func (d *%s) %s(fn func(d *%s)) *%s {", die.Type, field.Method, c.AliasedRef(field.Package, field.Die), die.Type) + c.Linef(" return d.DieStamp(func(r *%s) {", c.AliasedRef(die.TargetPackage, die.TargetType)) + c.Linef(" d := %s.DieImmutable(false).DieFeed%s(r.%s)", c.AliasedRef(field.Package, field.Blank), ptr, field.Field) + c.Linef(" fn(d)") + c.Linef(" r.%s = d.DieRelease%s()", field.Field, ptr) + c.Linef(" })") + c.Linef("}") + } + + } +} + func (c *copyMethodMaker) generateObjectMethodsFor(die Die) { if die.Object { c.generateRuntimeObjectMethodsFor(die)