From 060510266260dedd4bdf54145679231d7b88ea94 Mon Sep 17 00:00:00 2001 From: Jefftree Date: Tue, 19 Jan 2021 10:57:21 -0800 Subject: [PATCH] WIP --- pkg/applyconfigurations/gen.go | 39 +- .../testdata/cronjob_types.go | 309 ++++ .../zz_generated.applyconfigurations.go | 230 +++ ...z_generated.applyconfigurations_builder.go | 1601 +++++++++++++++++ .../testdata/zz_generated.deepcopy.go | 84 + pkg/applyconfigurations/traverse.go | 278 ++- pkg/crd/testdata/go.sum | 9 + pkg/deepcopy/testdata/go.sum | 9 + 8 files changed, 2542 insertions(+), 17 deletions(-) create mode 100644 pkg/applyconfigurations/testdata/cronjob_types.go create mode 100644 pkg/applyconfigurations/testdata/zz_generated.applyconfigurations.go create mode 100644 pkg/applyconfigurations/testdata/zz_generated.applyconfigurations_builder.go create mode 100644 pkg/applyconfigurations/testdata/zz_generated.deepcopy.go diff --git a/pkg/applyconfigurations/gen.go b/pkg/applyconfigurations/gen.go index 70e3c2119..05960a3a9 100644 --- a/pkg/applyconfigurations/gen.go +++ b/pkg/applyconfigurations/gen.go @@ -163,11 +163,11 @@ import ( // types in the given package, writing the formatted result to given writer. // May return nil if source could not be generated. func (ctx *ObjectGenCtx) generateForPackage(root *loader.Package) []byte { - allTypes, err := enabledOnPackage(ctx.Collector, root) - if err != nil { - root.AddError(err) - return nil - } + // allTypes, err := enabledOnPackage(ctx.Collector, root) + // if err != nil { + // root.AddError(err) + // return nil + // } ctx.Checker.Check(root) @@ -184,12 +184,6 @@ func (ctx *ObjectGenCtx) generateForPackage(root *loader.Package) []byte { if err := markers.EachType(ctx.Collector, root, func(info *markers.TypeInfo) { outContent := new(bytes.Buffer) - - if !enabledOnType(allTypes, info) { - //root.AddError(fmt.Errorf("skipping type: %v", info.Name)) // TODO(jpbetz): Remove - return - } - // not all types required a generate apply configuration. For example, no apply configuration // type is needed for Quantity, IntOrString, RawExtension or Unknown. if !shouldBeApplyConfiguration(root, info) { @@ -203,7 +197,28 @@ func (ctx *ObjectGenCtx) generateForPackage(root *loader.Package) []byte { codeWriter: &codeWriter{out: outContent}, } - copyCtx.GenerateTypesFor(root, info) + // TODO|jefftree: Make this a CLI toggle between builder and go structs + if false { + copyCtx.GenerateStruct(root, info) + copyCtx.GenerateFieldsStruct(root, info) + for _, field := range info.Fields { + if field.Name != "" { + copyCtx.GenerateMemberSet(field, root, info) + copyCtx.GenerateMemberRemove(field, root, info) + copyCtx.GenerateMemberGet(field, root, info) + } + } + copyCtx.GenerateToUnstructured(root, info) + copyCtx.GenerateFromUnstructured(root, info) + copyCtx.GenerateMarshal(root, info) + copyCtx.GenerateUnmarshal(root, info) + copyCtx.GeneratePrePostFunctions(root, info) + + } else { + copyCtx.GenerateTypesFor(root, info) + copyCtx.GenerateStructConstructor(root, info) + } + copyCtx.GenerateListMapAlias(root, info) outBytes := outContent.Bytes() if len(outBytes) > 0 { diff --git a/pkg/applyconfigurations/testdata/cronjob_types.go b/pkg/applyconfigurations/testdata/cronjob_types.go new file mode 100644 index 000000000..7ebb1171e --- /dev/null +++ b/pkg/applyconfigurations/testdata/cronjob_types.go @@ -0,0 +1,309 @@ +/* + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// TODO(directxman12): test this across both versions (right now we're just +// trusting k/k conversion, which is probably fine though) + +//go:generate ../../../.run-controller-gen.sh paths=. output:dir=. + +// +groupName=testdata.kubebuilder.io +// +versionName=v1 +package cronjob + +import ( + "encoding/json" + "fmt" + + batchv1beta1 "k8s.io/api/batch/v1beta1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! +// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. + +// CronJobSpec defines the desired state of CronJob +type CronJobSpec struct { + // The schedule in Cron format, see https://en.wikipedia.org/wiki/Cron. + Schedule string `json:"schedule"` + + // Optional deadline in seconds for starting the job if it misses scheduled + // time for any reason. Missed jobs executions will be counted as failed ones. + // +optional + StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds,omitempty"` + + // Specifies how to treat concurrent executions of a Job. + // Valid values are: + // - "Allow" (default): allows CronJobs to run concurrently; + // - "Forbid": forbids concurrent runs, skipping next run if previous run hasn't finished yet; + // - "Replace": cancels currently running job and replaces it with a new one + // +optional + ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy,omitempty"` + + // This flag tells the controller to suspend subsequent executions, it does + // not apply to already started executions. Defaults to false. + // +optional + Suspend *bool `json:"suspend,omitempty"` + + // This tests that non-serialized fields aren't included in the schema. + InternalData string `json:"-"` + + // This flag is like suspend, but for when you really mean it. + // It helps test the +kubebuilder:validation:Type marker. + // +optional + NoReallySuspend *TotallyABool `json:"noReallySuspend,omitempty"` + + // This tests byte slice schema generation. + BinaryName []byte `json:"binaryName"` + + // This tests that nullable works correctly + // +nullable + CanBeNull string `json:"canBeNull"` + + // Specifies the job that will be created when executing a CronJob. + JobTemplate batchv1beta1.JobTemplateSpec `json:"jobTemplate"` + + // The number of successful finished jobs to retain. + // This is a pointer to distinguish between explicit zero and not specified. + // +optional + SuccessfulJobsHistoryLimit *int32 `json:"successfulJobsHistoryLimit,omitempty"` + + // The number of failed finished jobs to retain. + // This is a pointer to distinguish between explicit zero and not specified. + // +optional + FailedJobsHistoryLimit *int32 `json:"failedJobsHistoryLimit,omitempty"` + + // This tests byte slices are allowed as map values. + ByteSliceData map[string][]byte `json:"byteSliceData,omitempty"` + + // This tests string slices are allowed as map values. + StringSliceData map[string][]string `json:"stringSliceData,omitempty"` + + // This tests pointers are allowed as map values. + PtrData map[string]*string `json:"ptrData,omitempty"` + + // This tests that markers that are allowed on both fields and types are applied to fields + // +kubebuilder:validation:MinLength=4 + TwoOfAKindPart0 string `json:"twoOfAKindPart0"` + + // This tests that markers that are allowed on both fields and types are applied to types + TwoOfAKindPart1 LongerString `json:"twoOfAKindPart1"` + + // This tests that primitive defaulting can be performed. + // +kubebuilder:default=forty-two + DefaultedString string `json:"defaultedString"` + + // This tests that slice defaulting can be performed. + // +kubebuilder:default={a,b} + DefaultedSlice []string `json:"defaultedSlice"` + + // This tests that object defaulting can be performed. + // +kubebuilder:default={{nested: {foo: "baz", bar: true}},{nested: {bar: false}}} + DefaultedObject []RootObject `json:"defaultedObject"` + + // This tests that pattern validator is properly applied. + // +kubebuilder:validation:Pattern=`^$|^((https):\/\/?)[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/?))$` + PatternObject string `json:"patternObject"` + + // +kubebuilder:validation:EmbeddedResource + // +kubebuilder:validation:nullable + EmbeddedResource runtime.RawExtension `json:"embeddedResource"` + + // +kubebuilder:validation:nullable + // +kubebuilder:pruning:PreserveUnknownFields + UnprunedJSON NestedObject `json:"unprunedJSON"` + + // +kubebuilder:pruning:PreserveUnknownFields + // +kubebuilder:validation:EmbeddedResource + // +kubebuilder:validation:nullable + UnprunedEmbeddedResource runtime.RawExtension `json:"unprunedEmbeddedResource"` + + // This tests that a type-level pruning maker works. + UnprunedFromType Preserved `json:"unprunedFomType"` + + // This tests that associative lists work. + // +listType=map + // +listMapKey=name + // +listMapKey=secondary + AssociativeList []AssociativeType `json:"associativeList"` + + // A map that allows different actors to manage different fields + // +mapType=granular + MapOfInfo map[string][]byte `json:"mapOfInfo"` + + // A struct that can only be entirely replaced + // +structType=atomic + StructWithSeveralFields NestedObject `json:"structWithSeveralFields"` + + // This tests that type references are properly flattened + // +kubebuilder:validation:optional + JustNestedObject *JustNestedObject `json:"justNestedObject,omitempty"` + + // This tests that min/max properties work + MinMaxProperties MinMaxObject `json:"minMaxProperties,omitempty"` +} + +// +kubebuilder:validation:Type=object +// +kubebuilder:pruning:PreserveUnknownFields +type Preserved struct { + ConcreteField string `json:"concreteField"` + Rest map[string]interface{} `json:"-"` +} +func (p *Preserved) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, &p.Rest); err != nil { + return err + } + conc, found := p.Rest["concreteField"] + if !found { + return nil + } + concStr, isStr := conc.(string) + if !isStr { + return fmt.Errorf("concreteField was not string") + } + delete(p.Rest, "concreteField") + p.ConcreteField = concStr + return nil +} +func (p *Preserved) MarshalJSON() ([]byte, error) { + full := make(map[string]interface{}, len(p.Rest)+1) + for k, v := range p.Rest { + full[k] = v + } + full["concreteField"] = p.ConcreteField + return json.Marshal(full) +} + +type NestedObject struct { + Foo string `json:"foo"` + Bar bool `json:"bar"` +} + +type JustNestedObject NestedObject + +// +kubebuilder:validation:MinProperties=1 +// +kubebuilder:validation:MaxProperties=2 +type MinMaxObject struct { + Foo string `json:"foo,omitempty"` + Bar string `json:"bar,omitempty"` + Baz string `json:"baz,omitempty"` +} + +type RootObject struct { + Nested NestedObject `json:"nested"` +} + +type AssociativeType struct { + Name string `json:"name"` + Secondary int `json:"secondary"` + Foo string `json:"foo"` +} + +// +kubebuilder:validation:MinLength=4 +// This tests that markers that are allowed on both fields and types are applied to types +type LongerString string + +// use an explicit type marker to verify that apply-first markers generate properly + +// +kubebuilder:validation:Type=string +// TotallyABool is a bool that serializes as a string. +type TotallyABool bool + +func (t TotallyABool) MarshalJSON() ([]byte, error) { + if t { + return []byte(`"true"`), nil + } else { + return []byte(`"false"`), nil + } +} +func (t *TotallyABool) UnmarshalJSON(in []byte) error { + switch string(in) { + case `"true"`: + *t = true + return nil + case `"false"`: + *t = false + default: + return fmt.Errorf("bad TotallyABool value %q", string(in)) + } + return nil +} + +// ConcurrencyPolicy describes how the job will be handled. +// Only one of the following concurrent policies may be specified. +// If none of the following policies is specified, the default one +// is AllowConcurrent. +// +kubebuilder:validation:Enum=Allow;Forbid;Replace +type ConcurrencyPolicy string + +const ( + // AllowConcurrent allows CronJobs to run concurrently. + AllowConcurrent ConcurrencyPolicy = "Allow" + + // ForbidConcurrent forbids concurrent runs, skipping next run if previous + // hasn't finished yet. + ForbidConcurrent ConcurrencyPolicy = "Forbid" + + // ReplaceConcurrent cancels currently running job and replaces it with a new one. + ReplaceConcurrent ConcurrencyPolicy = "Replace" +) + +// CronJobStatus defines the observed state of CronJob +type CronJobStatus struct { + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster + // Important: Run "make" to regenerate code after modifying this file + + // A list of pointers to currently running jobs. + // +optional + Active []corev1.ObjectReference `json:"active,omitempty"` + + // Information when was the last time the job was successfully scheduled. + // +optional + LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"` + + // Information about the last time the job was successfully scheduled, + // with microsecond precision. + // +optional + LastScheduleMicroTime *metav1.MicroTime `json:"lastScheduleMicroTime,omitempty"` +} + +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:resource:singular=mycronjob + +// CronJob is the Schema for the cronjobs API +type CronJob struct { + /* + */ + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec CronJobSpec `json:"spec,omitempty"` + Status CronJobStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true + +// CronJobList contains a list of CronJob +type CronJobList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []CronJob `json:"items"` +} + +func init() { + SchemeBuilder.Register(&CronJob{}, &CronJobList{}) +} diff --git a/pkg/applyconfigurations/testdata/zz_generated.applyconfigurations.go b/pkg/applyconfigurations/testdata/zz_generated.applyconfigurations.go new file mode 100644 index 000000000..4022553c3 --- /dev/null +++ b/pkg/applyconfigurations/testdata/zz_generated.applyconfigurations.go @@ -0,0 +1,230 @@ +// +build !ignore_autogenerated + +// Code generated by controller-gen. DO NOT EDIT. + +package cronjob + +import ( + "k8s.io/api/batch/v1beta1" + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// AssociativeTypeApplyConfiguration represents a declarative configuration of the AssociativeType type for use +// with apply. +type AssociativeTypeApplyConfiguration struct { + Name *string `json:"name,omitempty"` + Secondary *int `json:"secondary,omitempty"` + Foo *string `json:"foo,omitempty"` +} + +// AssociativeTypeApplyConfiguration represents a declarative configuration of the AssociativeType type for use +// with apply. +func AssociativeType() *AssociativeTypeApplyConfiguration { + return &AssociativeTypeApplyConfiguration{} +} + +// AssociativeTypeList represents a listAlias of AssociativeTypeApplyConfiguration. +type AssociativeTypeList []*AssociativeTypeApplyConfiguration + +// AssociativeTypeMap represents a map of AssociativeTypeApplyConfiguration. +type AssociativeTypeMap map[string]AssociativeTypeApplyConfiguration + +// CronJobApplyConfiguration represents a declarative configuration of the CronJob type for use +// with apply. +type CronJobApplyConfiguration struct { + metav1.TypeMeta `json:",inline"` + *metav1.ObjectMeta `json:"metadata,omitempty"` + Spec *CronJobSpecApplyConfiguration `json:"spec,omitempty"` + Status *CronJobStatusApplyConfiguration `json:"status,omitempty"` +} + +// CronJobApplyConfiguration represents a declarative configuration of the CronJob type for use +// with apply. +func CronJob() *CronJobApplyConfiguration { + return &CronJobApplyConfiguration{} +} + +// CronJobList represents a listAlias of CronJobApplyConfiguration. +type CronJobList []*CronJobApplyConfiguration + +// CronJobMap represents a map of CronJobApplyConfiguration. +type CronJobMap map[string]CronJobApplyConfiguration + +// CronJobListApplyConfiguration represents a declarative configuration of the CronJobList type for use +// with apply. +type CronJobListApplyConfiguration struct { + metav1.TypeMeta `json:",inline"` + *metav1.ListMeta `json:"metadata,omitempty"` + Items *[]CronJobApplyConfiguration `json:"items,omitempty"` +} + +// CronJobListApplyConfiguration represents a declarative configuration of the CronJobList type for use +// with apply. +func CronJobList() *CronJobListApplyConfiguration { + return &CronJobListApplyConfiguration{} +} + +// CronJobListList represents a listAlias of CronJobListApplyConfiguration. +type CronJobListList []*CronJobListApplyConfiguration + +// CronJobListMap represents a map of CronJobListApplyConfiguration. +type CronJobListMap map[string]CronJobListApplyConfiguration + +// CronJobSpecApplyConfiguration represents a declarative configuration of the CronJobSpec type for use +// with apply. +type CronJobSpecApplyConfiguration struct { + Schedule *string `json:"schedule,omitempty"` + StartingDeadlineSeconds **int64 `json:"startingDeadlineSeconds,omitempty"` + ConcurrencyPolicy *ConcurrencyPolicy `json:"concurrencyPolicy,omitempty"` + Suspend **bool `json:"suspend,omitempty"` + NoReallySuspend **TotallyABool `json:"noReallySuspend,omitempty"` + BinaryName *[]byte `json:"binaryName,omitempty"` + CanBeNull *string `json:"canBeNull,omitempty"` + JobTemplate *v1beta1.JobTemplateSpec `json:"jobTemplate,omitempty"` + SuccessfulJobsHistoryLimit **int32 `json:"successfulJobsHistoryLimit,omitempty"` + FailedJobsHistoryLimit **int32 `json:"failedJobsHistoryLimit,omitempty"` + ByteSliceData *map[string][]byte `json:"byteSliceData,omitempty"` + StringSliceData *map[string][]string `json:"stringSliceData,omitempty"` + PtrData *map[string]*string `json:"ptrData,omitempty"` + TwoOfAKindPart0 *string `json:"twoOfAKindPart0,omitempty"` + TwoOfAKindPart1 *LongerString `json:"twoOfAKindPart1,omitempty"` + DefaultedString *string `json:"defaultedString,omitempty"` + DefaultedSlice *[]string `json:"defaultedSlice,omitempty"` + DefaultedObject *[]RootObjectApplyConfiguration `json:"defaultedObject,omitempty"` + PatternObject *string `json:"patternObject,omitempty"` + EmbeddedResource *runtime.RawExtension `json:"embeddedResource,omitempty"` + UnprunedJSON *NestedObjectApplyConfiguration `json:"unprunedJSON,omitempty"` + UnprunedEmbeddedResource *runtime.RawExtension `json:"unprunedEmbeddedResource,omitempty"` + UnprunedFromType *PreservedApplyConfiguration `json:"unprunedFomType,omitempty"` + AssociativeList *[]AssociativeTypeApplyConfiguration `json:"associativeList,omitempty"` + MapOfInfo *map[string][]byte `json:"mapOfInfo,omitempty"` + StructWithSeveralFields *NestedObjectApplyConfiguration `json:"structWithSeveralFields,omitempty"` + JustNestedObject **JustNestedObjectApplyConfiguration `json:"justNestedObject,omitempty"` + MinMaxProperties *MinMaxObjectApplyConfiguration `json:"minMaxProperties,omitempty"` +} + +// CronJobSpecApplyConfiguration represents a declarative configuration of the CronJobSpec type for use +// with apply. +func CronJobSpec() *CronJobSpecApplyConfiguration { + return &CronJobSpecApplyConfiguration{} +} + +// CronJobSpecList represents a listAlias of CronJobSpecApplyConfiguration. +type CronJobSpecList []*CronJobSpecApplyConfiguration + +// CronJobSpecMap represents a map of CronJobSpecApplyConfiguration. +type CronJobSpecMap map[string]CronJobSpecApplyConfiguration + +// CronJobStatusApplyConfiguration represents a declarative configuration of the CronJobStatus type for use +// with apply. +type CronJobStatusApplyConfiguration struct { + Active *[]v1.ObjectReference `json:"active,omitempty"` + LastScheduleTime **metav1.Time `json:"lastScheduleTime,omitempty"` + LastScheduleMicroTime **metav1.MicroTime `json:"lastScheduleMicroTime,omitempty"` +} + +// CronJobStatusApplyConfiguration represents a declarative configuration of the CronJobStatus type for use +// with apply. +func CronJobStatus() *CronJobStatusApplyConfiguration { + return &CronJobStatusApplyConfiguration{} +} + +// CronJobStatusList represents a listAlias of CronJobStatusApplyConfiguration. +type CronJobStatusList []*CronJobStatusApplyConfiguration + +// CronJobStatusMap represents a map of CronJobStatusApplyConfiguration. +type CronJobStatusMap map[string]CronJobStatusApplyConfiguration + +// JustNestedObjectApplyConfiguration represents a declarative configuration of the JustNestedObject type for use +// with apply. +type JustNestedObjectApplyConfiguration struct { +} + +// JustNestedObjectApplyConfiguration represents a declarative configuration of the JustNestedObject type for use +// with apply. +func JustNestedObject() *JustNestedObjectApplyConfiguration { + return &JustNestedObjectApplyConfiguration{} +} + +// JustNestedObjectList represents a listAlias of JustNestedObjectApplyConfiguration. +type JustNestedObjectList []*JustNestedObjectApplyConfiguration + +// JustNestedObjectMap represents a map of JustNestedObjectApplyConfiguration. +type JustNestedObjectMap map[string]JustNestedObjectApplyConfiguration + +// MinMaxObjectApplyConfiguration represents a declarative configuration of the MinMaxObject type for use +// with apply. +type MinMaxObjectApplyConfiguration struct { + Foo *string `json:"foo,omitempty"` + Bar *string `json:"bar,omitempty"` + Baz *string `json:"baz,omitempty"` +} + +// MinMaxObjectApplyConfiguration represents a declarative configuration of the MinMaxObject type for use +// with apply. +func MinMaxObject() *MinMaxObjectApplyConfiguration { + return &MinMaxObjectApplyConfiguration{} +} + +// MinMaxObjectList represents a listAlias of MinMaxObjectApplyConfiguration. +type MinMaxObjectList []*MinMaxObjectApplyConfiguration + +// MinMaxObjectMap represents a map of MinMaxObjectApplyConfiguration. +type MinMaxObjectMap map[string]MinMaxObjectApplyConfiguration + +// NestedObjectApplyConfiguration represents a declarative configuration of the NestedObject type for use +// with apply. +type NestedObjectApplyConfiguration struct { + Foo *string `json:"foo,omitempty"` + Bar *bool `json:"bar,omitempty"` +} + +// NestedObjectApplyConfiguration represents a declarative configuration of the NestedObject type for use +// with apply. +func NestedObject() *NestedObjectApplyConfiguration { + return &NestedObjectApplyConfiguration{} +} + +// NestedObjectList represents a listAlias of NestedObjectApplyConfiguration. +type NestedObjectList []*NestedObjectApplyConfiguration + +// NestedObjectMap represents a map of NestedObjectApplyConfiguration. +type NestedObjectMap map[string]NestedObjectApplyConfiguration + +// PreservedApplyConfiguration represents a declarative configuration of the Preserved type for use +// with apply. +type PreservedApplyConfiguration struct { + ConcreteField *string `json:"concreteField,omitempty"` +} + +// PreservedApplyConfiguration represents a declarative configuration of the Preserved type for use +// with apply. +func Preserved() *PreservedApplyConfiguration { + return &PreservedApplyConfiguration{} +} + +// PreservedList represents a listAlias of PreservedApplyConfiguration. +type PreservedList []*PreservedApplyConfiguration + +// PreservedMap represents a map of PreservedApplyConfiguration. +type PreservedMap map[string]PreservedApplyConfiguration + +// RootObjectApplyConfiguration represents a declarative configuration of the RootObject type for use +// with apply. +type RootObjectApplyConfiguration struct { + Nested *NestedObjectApplyConfiguration `json:"nested,omitempty"` +} + +// RootObjectApplyConfiguration represents a declarative configuration of the RootObject type for use +// with apply. +func RootObject() *RootObjectApplyConfiguration { + return &RootObjectApplyConfiguration{} +} + +// RootObjectList represents a listAlias of RootObjectApplyConfiguration. +type RootObjectList []*RootObjectApplyConfiguration + +// RootObjectMap represents a map of RootObjectApplyConfiguration. +type RootObjectMap map[string]RootObjectApplyConfiguration diff --git a/pkg/applyconfigurations/testdata/zz_generated.applyconfigurations_builder.go b/pkg/applyconfigurations/testdata/zz_generated.applyconfigurations_builder.go new file mode 100644 index 000000000..55666a89f --- /dev/null +++ b/pkg/applyconfigurations/testdata/zz_generated.applyconfigurations_builder.go @@ -0,0 +1,1601 @@ +// +build !ignore_autogenerated + +// Code generated by controller-gen. DO NOT EDIT. + +package cronjob + +import ( + "encoding/json" + "k8s.io/api/batch/v1beta1" + "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// AssociativeTypeApplyConfiguration represents a declarative configuration of the AssociativeType type for use +// with apply. +type AssociativeTypeApplyConfiguration struct { + fields associativeTypeFields +} + +// associativeType owns all fields except inlined fields +type associativeTypeFields struct { + Name *string `json:"name,omitempty"` + Secondary *int `json:"secondary,omitempty"` + Foo *string `json:"foo,omitempty"` +} + +// SetName sets the Name field in the declarative configuration to the given value +func (b *AssociativeTypeApplyConfiguration) SetName(value string) *AssociativeTypeApplyConfiguration { + b.fields.Name = &value + return b +} + +// RemoveName removes the Name field in the declarative configuration +func (b *AssociativeTypeApplyConfiguration) RemoveName(value string) *AssociativeTypeApplyConfiguration { + b.fields.Name = nil + return b +} + +// GetName gets the Name field in the declarative configuration +func (b *AssociativeTypeApplyConfiguration) GetName() (value string, ok bool) { + if v := b.fields.Name; v != nil { + return *v, true + } + return value, false +} + +// SetSecondary sets the Secondary field in the declarative configuration to the given value +func (b *AssociativeTypeApplyConfiguration) SetSecondary(value int) *AssociativeTypeApplyConfiguration { + b.fields.Secondary = &value + return b +} + +// RemoveSecondary removes the Secondary field in the declarative configuration +func (b *AssociativeTypeApplyConfiguration) RemoveSecondary(value int) *AssociativeTypeApplyConfiguration { + b.fields.Secondary = nil + return b +} + +// GetSecondary gets the Secondary field in the declarative configuration +func (b *AssociativeTypeApplyConfiguration) GetSecondary() (value int, ok bool) { + if v := b.fields.Secondary; v != nil { + return *v, true + } + return value, false +} + +// SetFoo sets the Foo field in the declarative configuration to the given value +func (b *AssociativeTypeApplyConfiguration) SetFoo(value string) *AssociativeTypeApplyConfiguration { + b.fields.Foo = &value + return b +} + +// RemoveFoo removes the Foo field in the declarative configuration +func (b *AssociativeTypeApplyConfiguration) RemoveFoo(value string) *AssociativeTypeApplyConfiguration { + b.fields.Foo = nil + return b +} + +// GetFoo gets the Foo field in the declarative configuration +func (b *AssociativeTypeApplyConfiguration) GetFoo() (value string, ok bool) { + if v := b.fields.Foo; v != nil { + return *v, true + } + return value, false +} + +// ToUnstructured converts AssociativeType to unstructured. +func (b *AssociativeTypeApplyConfiguration) ToUnstructured() interface{} { + if b == nil { + return nil + } + b.preMarshal() + u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&b.fields) + if err != nil { + panic(err) + } + return u +} + +// FromUnstructured converts unstructured to AssociativeTypeApplyConfiguration, replacing the contents +// of AssociativeTypeApplyConfiguration. +func (b *AssociativeTypeApplyConfiguration) FromUnstructured(u map[string]interface{}) error { + m := &associativeTypeFields{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(u, m) + if err != nil { + return err + } + b.fields = *m + b.postUnmarshal() + return nil +} + +// MarshalJSON marshals AssociativeTypeApplyConfiguration to JSON. +func (b *AssociativeTypeApplyConfiguration) MarshalJSON() ([]byte, error) { + b.preMarshal() + return json.Marshal(b.fields) +} + +// UnmarshalJSON unmarshals JSON into AssociativeTypeApplyConfiguration, replacing the contents of +// AssociativeTypeApplyConfiguration. +func (b *AssociativeTypeApplyConfiguration) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, &b.fields); err != nil { + return err + } + b.postUnmarshal() + return nil +} + +func (b *AssociativeTypeApplyConfiguration) preMarshal() { +} +func (b *AssociativeTypeApplyConfiguration) postUnmarshal() { +} + +// AssociativeTypeList represents a listAlias of AssociativeTypeApplyConfiguration. +type AssociativeTypeList []*AssociativeTypeApplyConfiguration + +// AssociativeTypeMap represents a map of AssociativeTypeApplyConfiguration. +type AssociativeTypeMap map[string]AssociativeTypeApplyConfiguration + +// CronJobApplyConfiguration represents a declarative configuration of the CronJob type for use +// with apply. +type CronJobApplyConfiguration struct { + metav1.TypeMeta // inlined type + fields cronJobFields +} + +// cronJob owns all fields except inlined fields +type cronJobFields struct { + *metav1.ObjectMeta `json:"metadata,omitempty"` + Spec *CronJobSpecApplyConfiguration `json:"spec,omitempty"` + Status *CronJobStatusApplyConfiguration `json:"status,omitempty"` +} + +// SetSpec sets the Spec field in the declarative configuration to the given value +func (b *CronJobApplyConfiguration) SetSpec(value CronJobSpecApplyConfiguration) *CronJobApplyConfiguration { + b.fields.Spec = &value + return b +} + +// RemoveSpec removes the Spec field in the declarative configuration +func (b *CronJobApplyConfiguration) RemoveSpec(value CronJobSpecApplyConfiguration) *CronJobApplyConfiguration { + b.fields.Spec = nil + return b +} + +// GetSpec gets the Spec field in the declarative configuration +func (b *CronJobApplyConfiguration) GetSpec() (value CronJobSpecApplyConfiguration, ok bool) { + if v := b.fields.Spec; v != nil { + return *v, true + } + return value, false +} + +// SetStatus sets the Status field in the declarative configuration to the given value +func (b *CronJobApplyConfiguration) SetStatus(value CronJobStatusApplyConfiguration) *CronJobApplyConfiguration { + b.fields.Status = &value + return b +} + +// RemoveStatus removes the Status field in the declarative configuration +func (b *CronJobApplyConfiguration) RemoveStatus(value CronJobStatusApplyConfiguration) *CronJobApplyConfiguration { + b.fields.Status = nil + return b +} + +// GetStatus gets the Status field in the declarative configuration +func (b *CronJobApplyConfiguration) GetStatus() (value CronJobStatusApplyConfiguration, ok bool) { + if v := b.fields.Status; v != nil { + return *v, true + } + return value, false +} + +// ToUnstructured converts CronJob to unstructured. +func (b *CronJobApplyConfiguration) ToUnstructured() interface{} { + if b == nil { + return nil + } + b.preMarshal() + u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&b.fields) + if err != nil { + panic(err) + } + return u +} + +// FromUnstructured converts unstructured to CronJobApplyConfiguration, replacing the contents +// of CronJobApplyConfiguration. +func (b *CronJobApplyConfiguration) FromUnstructured(u map[string]interface{}) error { + m := &cronJobFields{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(u, m) + if err != nil { + return err + } + b.fields = *m + b.postUnmarshal() + return nil +} + +// MarshalJSON marshals CronJobApplyConfiguration to JSON. +func (b *CronJobApplyConfiguration) MarshalJSON() ([]byte, error) { + b.preMarshal() + return json.Marshal(b.fields) +} + +// UnmarshalJSON unmarshals JSON into CronJobApplyConfiguration, replacing the contents of +// CronJobApplyConfiguration. +func (b *CronJobApplyConfiguration) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, &b.fields); err != nil { + return err + } + b.postUnmarshal() + return nil +} + +func (b *CronJobApplyConfiguration) preMarshal() { +} +func (b *CronJobApplyConfiguration) postUnmarshal() { +} + +// CronJobList represents a listAlias of CronJobApplyConfiguration. +type CronJobList []*CronJobApplyConfiguration + +// CronJobMap represents a map of CronJobApplyConfiguration. +type CronJobMap map[string]CronJobApplyConfiguration + +// CronJobListApplyConfiguration represents a declarative configuration of the CronJobList type for use +// with apply. +type CronJobListApplyConfiguration struct { + metav1.TypeMeta // inlined type + fields cronJobListFields +} + +// cronJobList owns all fields except inlined fields +type cronJobListFields struct { + *metav1.ListMeta `json:"metadata,omitempty"` + Items *[]CronJobApplyConfiguration `json:"items,omitempty"` +} + +// SetItems sets the Items field in the declarative configuration to the given value +func (b *CronJobListApplyConfiguration) SetItems(value []CronJobApplyConfiguration) *CronJobListApplyConfiguration { + b.fields.Items = &value + return b +} + +// RemoveItems removes the Items field in the declarative configuration +func (b *CronJobListApplyConfiguration) RemoveItems(value []CronJobApplyConfiguration) *CronJobListApplyConfiguration { + b.fields.Items = nil + return b +} + +// GetItems gets the Items field in the declarative configuration +func (b *CronJobListApplyConfiguration) GetItems() (value []CronJobApplyConfiguration, ok bool) { + if v := b.fields.Items; v != nil { + return *v, true + } + return value, false +} + +// ToUnstructured converts CronJobList to unstructured. +func (b *CronJobListApplyConfiguration) ToUnstructured() interface{} { + if b == nil { + return nil + } + b.preMarshal() + u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&b.fields) + if err != nil { + panic(err) + } + return u +} + +// FromUnstructured converts unstructured to CronJobListApplyConfiguration, replacing the contents +// of CronJobListApplyConfiguration. +func (b *CronJobListApplyConfiguration) FromUnstructured(u map[string]interface{}) error { + m := &cronJobListFields{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(u, m) + if err != nil { + return err + } + b.fields = *m + b.postUnmarshal() + return nil +} + +// MarshalJSON marshals CronJobListApplyConfiguration to JSON. +func (b *CronJobListApplyConfiguration) MarshalJSON() ([]byte, error) { + b.preMarshal() + return json.Marshal(b.fields) +} + +// UnmarshalJSON unmarshals JSON into CronJobListApplyConfiguration, replacing the contents of +// CronJobListApplyConfiguration. +func (b *CronJobListApplyConfiguration) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, &b.fields); err != nil { + return err + } + b.postUnmarshal() + return nil +} + +func (b *CronJobListApplyConfiguration) preMarshal() { +} +func (b *CronJobListApplyConfiguration) postUnmarshal() { +} + +// CronJobListList represents a listAlias of CronJobListApplyConfiguration. +type CronJobListList []*CronJobListApplyConfiguration + +// CronJobListMap represents a map of CronJobListApplyConfiguration. +type CronJobListMap map[string]CronJobListApplyConfiguration + +// CronJobSpecApplyConfiguration represents a declarative configuration of the CronJobSpec type for use +// with apply. +type CronJobSpecApplyConfiguration struct { + fields cronJobSpecFields +} + +// cronJobSpec owns all fields except inlined fields +type cronJobSpecFields struct { + Schedule *string `json:"schedule,omitempty"` + StartingDeadlineSeconds **int64 `json:"startingDeadlineSeconds,omitempty"` + ConcurrencyPolicy *ConcurrencyPolicy `json:"concurrencyPolicy,omitempty"` + Suspend **bool `json:"suspend,omitempty"` + NoReallySuspend **TotallyABool `json:"noReallySuspend,omitempty"` + BinaryName *[]byte `json:"binaryName,omitempty"` + CanBeNull *string `json:"canBeNull,omitempty"` + JobTemplate *v1beta1.JobTemplateSpec `json:"jobTemplate,omitempty"` + SuccessfulJobsHistoryLimit **int32 `json:"successfulJobsHistoryLimit,omitempty"` + FailedJobsHistoryLimit **int32 `json:"failedJobsHistoryLimit,omitempty"` + ByteSliceData *map[string][]byte `json:"byteSliceData,omitempty"` + StringSliceData *map[string][]string `json:"stringSliceData,omitempty"` + PtrData *map[string]*string `json:"ptrData,omitempty"` + TwoOfAKindPart0 *string `json:"twoOfAKindPart0,omitempty"` + TwoOfAKindPart1 *LongerString `json:"twoOfAKindPart1,omitempty"` + DefaultedString *string `json:"defaultedString,omitempty"` + DefaultedSlice *[]string `json:"defaultedSlice,omitempty"` + DefaultedObject *[]RootObjectApplyConfiguration `json:"defaultedObject,omitempty"` + PatternObject *string `json:"patternObject,omitempty"` + EmbeddedResource *runtime.RawExtension `json:"embeddedResource,omitempty"` + UnprunedJSON *NestedObjectApplyConfiguration `json:"unprunedJSON,omitempty"` + UnprunedEmbeddedResource *runtime.RawExtension `json:"unprunedEmbeddedResource,omitempty"` + UnprunedFromType *PreservedApplyConfiguration `json:"unprunedFomType,omitempty"` + AssociativeList *[]AssociativeTypeApplyConfiguration `json:"associativeList,omitempty"` + MapOfInfo *map[string][]byte `json:"mapOfInfo,omitempty"` + StructWithSeveralFields *NestedObjectApplyConfiguration `json:"structWithSeveralFields,omitempty"` + JustNestedObject **JustNestedObjectApplyConfiguration `json:"justNestedObject,omitempty"` + MinMaxProperties *MinMaxObjectApplyConfiguration `json:"minMaxProperties,omitempty"` +} + +// SetSchedule sets the Schedule field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetSchedule(value string) *CronJobSpecApplyConfiguration { + b.fields.Schedule = &value + return b +} + +// RemoveSchedule removes the Schedule field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveSchedule(value string) *CronJobSpecApplyConfiguration { + b.fields.Schedule = nil + return b +} + +// GetSchedule gets the Schedule field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetSchedule() (value string, ok bool) { + if v := b.fields.Schedule; v != nil { + return *v, true + } + return value, false +} + +// SetStartingDeadlineSeconds sets the StartingDeadlineSeconds field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetStartingDeadlineSeconds(value *int64) *CronJobSpecApplyConfiguration { + b.fields.StartingDeadlineSeconds = &value + return b +} + +// RemoveStartingDeadlineSeconds removes the StartingDeadlineSeconds field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveStartingDeadlineSeconds(value *int64) *CronJobSpecApplyConfiguration { + b.fields.StartingDeadlineSeconds = nil + return b +} + +// GetStartingDeadlineSeconds gets the StartingDeadlineSeconds field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetStartingDeadlineSeconds() (value *int64, ok bool) { + if v := b.fields.StartingDeadlineSeconds; v != nil { + return *v, true + } + return value, false +} + +// SetConcurrencyPolicy sets the ConcurrencyPolicy field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetConcurrencyPolicy(value ConcurrencyPolicy) *CronJobSpecApplyConfiguration { + b.fields.ConcurrencyPolicy = &value + return b +} + +// RemoveConcurrencyPolicy removes the ConcurrencyPolicy field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveConcurrencyPolicy(value ConcurrencyPolicy) *CronJobSpecApplyConfiguration { + b.fields.ConcurrencyPolicy = nil + return b +} + +// GetConcurrencyPolicy gets the ConcurrencyPolicy field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetConcurrencyPolicy() (value ConcurrencyPolicy, ok bool) { + if v := b.fields.ConcurrencyPolicy; v != nil { + return *v, true + } + return value, false +} + +// SetSuspend sets the Suspend field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetSuspend(value *bool) *CronJobSpecApplyConfiguration { + b.fields.Suspend = &value + return b +} + +// RemoveSuspend removes the Suspend field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveSuspend(value *bool) *CronJobSpecApplyConfiguration { + b.fields.Suspend = nil + return b +} + +// GetSuspend gets the Suspend field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetSuspend() (value *bool, ok bool) { + if v := b.fields.Suspend; v != nil { + return *v, true + } + return value, false +} + +// SetInternalData sets the InternalData field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetInternalData(value string) *CronJobSpecApplyConfiguration { + return b +} + +// RemoveInternalData removes the InternalData field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveInternalData(value string) *CronJobSpecApplyConfiguration { + b.fields.InternalData = nil + return b +} + +// GetInternalData gets the InternalData field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetInternalData() (value string, ok bool) { +} + +// SetNoReallySuspend sets the NoReallySuspend field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetNoReallySuspend(value *TotallyABool) *CronJobSpecApplyConfiguration { + b.fields.NoReallySuspend = &value + return b +} + +// RemoveNoReallySuspend removes the NoReallySuspend field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveNoReallySuspend(value *TotallyABool) *CronJobSpecApplyConfiguration { + b.fields.NoReallySuspend = nil + return b +} + +// GetNoReallySuspend gets the NoReallySuspend field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetNoReallySuspend() (value *TotallyABool, ok bool) { + if v := b.fields.NoReallySuspend; v != nil { + return *v, true + } + return value, false +} + +// SetBinaryName sets the BinaryName field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetBinaryName(value []byte) *CronJobSpecApplyConfiguration { + b.fields.BinaryName = &value + return b +} + +// RemoveBinaryName removes the BinaryName field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveBinaryName(value []byte) *CronJobSpecApplyConfiguration { + b.fields.BinaryName = nil + return b +} + +// GetBinaryName gets the BinaryName field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetBinaryName() (value []byte, ok bool) { + if v := b.fields.BinaryName; v != nil { + return *v, true + } + return value, false +} + +// SetCanBeNull sets the CanBeNull field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetCanBeNull(value string) *CronJobSpecApplyConfiguration { + b.fields.CanBeNull = &value + return b +} + +// RemoveCanBeNull removes the CanBeNull field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveCanBeNull(value string) *CronJobSpecApplyConfiguration { + b.fields.CanBeNull = nil + return b +} + +// GetCanBeNull gets the CanBeNull field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetCanBeNull() (value string, ok bool) { + if v := b.fields.CanBeNull; v != nil { + return *v, true + } + return value, false +} + +// SetJobTemplate sets the JobTemplate field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetJobTemplate(value v1beta1.JobTemplateSpec) *CronJobSpecApplyConfiguration { + b.fields.JobTemplate = &value + return b +} + +// RemoveJobTemplate removes the JobTemplate field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveJobTemplate(value v1beta1.JobTemplateSpec) *CronJobSpecApplyConfiguration { + b.fields.JobTemplate = nil + return b +} + +// GetJobTemplate gets the JobTemplate field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetJobTemplate() (value v1beta1.JobTemplateSpec, ok bool) { + if v := b.fields.JobTemplate; v != nil { + return *v, true + } + return value, false +} + +// SetSuccessfulJobsHistoryLimit sets the SuccessfulJobsHistoryLimit field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetSuccessfulJobsHistoryLimit(value *int32) *CronJobSpecApplyConfiguration { + b.fields.SuccessfulJobsHistoryLimit = &value + return b +} + +// RemoveSuccessfulJobsHistoryLimit removes the SuccessfulJobsHistoryLimit field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveSuccessfulJobsHistoryLimit(value *int32) *CronJobSpecApplyConfiguration { + b.fields.SuccessfulJobsHistoryLimit = nil + return b +} + +// GetSuccessfulJobsHistoryLimit gets the SuccessfulJobsHistoryLimit field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetSuccessfulJobsHistoryLimit() (value *int32, ok bool) { + if v := b.fields.SuccessfulJobsHistoryLimit; v != nil { + return *v, true + } + return value, false +} + +// SetFailedJobsHistoryLimit sets the FailedJobsHistoryLimit field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetFailedJobsHistoryLimit(value *int32) *CronJobSpecApplyConfiguration { + b.fields.FailedJobsHistoryLimit = &value + return b +} + +// RemoveFailedJobsHistoryLimit removes the FailedJobsHistoryLimit field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveFailedJobsHistoryLimit(value *int32) *CronJobSpecApplyConfiguration { + b.fields.FailedJobsHistoryLimit = nil + return b +} + +// GetFailedJobsHistoryLimit gets the FailedJobsHistoryLimit field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetFailedJobsHistoryLimit() (value *int32, ok bool) { + if v := b.fields.FailedJobsHistoryLimit; v != nil { + return *v, true + } + return value, false +} + +// SetByteSliceData sets the ByteSliceData field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetByteSliceData(value map[string][]byte) *CronJobSpecApplyConfiguration { + b.fields.ByteSliceData = &value + return b +} + +// RemoveByteSliceData removes the ByteSliceData field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveByteSliceData(value map[string][]byte) *CronJobSpecApplyConfiguration { + b.fields.ByteSliceData = nil + return b +} + +// GetByteSliceData gets the ByteSliceData field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetByteSliceData() (value map[string][]byte, ok bool) { + if v := b.fields.ByteSliceData; v != nil { + return *v, true + } + return value, false +} + +// SetStringSliceData sets the StringSliceData field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetStringSliceData(value map[string][]string) *CronJobSpecApplyConfiguration { + b.fields.StringSliceData = &value + return b +} + +// RemoveStringSliceData removes the StringSliceData field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveStringSliceData(value map[string][]string) *CronJobSpecApplyConfiguration { + b.fields.StringSliceData = nil + return b +} + +// GetStringSliceData gets the StringSliceData field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetStringSliceData() (value map[string][]string, ok bool) { + if v := b.fields.StringSliceData; v != nil { + return *v, true + } + return value, false +} + +// SetPtrData sets the PtrData field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetPtrData(value map[string]*string) *CronJobSpecApplyConfiguration { + b.fields.PtrData = &value + return b +} + +// RemovePtrData removes the PtrData field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemovePtrData(value map[string]*string) *CronJobSpecApplyConfiguration { + b.fields.PtrData = nil + return b +} + +// GetPtrData gets the PtrData field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetPtrData() (value map[string]*string, ok bool) { + if v := b.fields.PtrData; v != nil { + return *v, true + } + return value, false +} + +// SetTwoOfAKindPart0 sets the TwoOfAKindPart0 field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetTwoOfAKindPart0(value string) *CronJobSpecApplyConfiguration { + b.fields.TwoOfAKindPart0 = &value + return b +} + +// RemoveTwoOfAKindPart0 removes the TwoOfAKindPart0 field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveTwoOfAKindPart0(value string) *CronJobSpecApplyConfiguration { + b.fields.TwoOfAKindPart0 = nil + return b +} + +// GetTwoOfAKindPart0 gets the TwoOfAKindPart0 field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetTwoOfAKindPart0() (value string, ok bool) { + if v := b.fields.TwoOfAKindPart0; v != nil { + return *v, true + } + return value, false +} + +// SetTwoOfAKindPart1 sets the TwoOfAKindPart1 field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetTwoOfAKindPart1(value LongerString) *CronJobSpecApplyConfiguration { + b.fields.TwoOfAKindPart1 = &value + return b +} + +// RemoveTwoOfAKindPart1 removes the TwoOfAKindPart1 field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveTwoOfAKindPart1(value LongerString) *CronJobSpecApplyConfiguration { + b.fields.TwoOfAKindPart1 = nil + return b +} + +// GetTwoOfAKindPart1 gets the TwoOfAKindPart1 field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetTwoOfAKindPart1() (value LongerString, ok bool) { + if v := b.fields.TwoOfAKindPart1; v != nil { + return *v, true + } + return value, false +} + +// SetDefaultedString sets the DefaultedString field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetDefaultedString(value string) *CronJobSpecApplyConfiguration { + b.fields.DefaultedString = &value + return b +} + +// RemoveDefaultedString removes the DefaultedString field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveDefaultedString(value string) *CronJobSpecApplyConfiguration { + b.fields.DefaultedString = nil + return b +} + +// GetDefaultedString gets the DefaultedString field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetDefaultedString() (value string, ok bool) { + if v := b.fields.DefaultedString; v != nil { + return *v, true + } + return value, false +} + +// SetDefaultedSlice sets the DefaultedSlice field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetDefaultedSlice(value []string) *CronJobSpecApplyConfiguration { + b.fields.DefaultedSlice = &value + return b +} + +// RemoveDefaultedSlice removes the DefaultedSlice field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveDefaultedSlice(value []string) *CronJobSpecApplyConfiguration { + b.fields.DefaultedSlice = nil + return b +} + +// GetDefaultedSlice gets the DefaultedSlice field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetDefaultedSlice() (value []string, ok bool) { + if v := b.fields.DefaultedSlice; v != nil { + return *v, true + } + return value, false +} + +// SetDefaultedObject sets the DefaultedObject field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetDefaultedObject(value []RootObjectApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.DefaultedObject = &value + return b +} + +// RemoveDefaultedObject removes the DefaultedObject field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveDefaultedObject(value []RootObjectApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.DefaultedObject = nil + return b +} + +// GetDefaultedObject gets the DefaultedObject field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetDefaultedObject() (value []RootObjectApplyConfiguration, ok bool) { + if v := b.fields.DefaultedObject; v != nil { + return *v, true + } + return value, false +} + +// SetPatternObject sets the PatternObject field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetPatternObject(value string) *CronJobSpecApplyConfiguration { + b.fields.PatternObject = &value + return b +} + +// RemovePatternObject removes the PatternObject field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemovePatternObject(value string) *CronJobSpecApplyConfiguration { + b.fields.PatternObject = nil + return b +} + +// GetPatternObject gets the PatternObject field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetPatternObject() (value string, ok bool) { + if v := b.fields.PatternObject; v != nil { + return *v, true + } + return value, false +} + +// SetEmbeddedResource sets the EmbeddedResource field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetEmbeddedResource(value runtime.RawExtension) *CronJobSpecApplyConfiguration { + b.fields.EmbeddedResource = &value + return b +} + +// RemoveEmbeddedResource removes the EmbeddedResource field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveEmbeddedResource(value runtime.RawExtension) *CronJobSpecApplyConfiguration { + b.fields.EmbeddedResource = nil + return b +} + +// GetEmbeddedResource gets the EmbeddedResource field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetEmbeddedResource() (value runtime.RawExtension, ok bool) { + if v := b.fields.EmbeddedResource; v != nil { + return *v, true + } + return value, false +} + +// SetUnprunedJSON sets the UnprunedJSON field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetUnprunedJSON(value NestedObjectApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.UnprunedJSON = &value + return b +} + +// RemoveUnprunedJSON removes the UnprunedJSON field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveUnprunedJSON(value NestedObjectApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.UnprunedJSON = nil + return b +} + +// GetUnprunedJSON gets the UnprunedJSON field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetUnprunedJSON() (value NestedObjectApplyConfiguration, ok bool) { + if v := b.fields.UnprunedJSON; v != nil { + return *v, true + } + return value, false +} + +// SetUnprunedEmbeddedResource sets the UnprunedEmbeddedResource field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetUnprunedEmbeddedResource(value runtime.RawExtension) *CronJobSpecApplyConfiguration { + b.fields.UnprunedEmbeddedResource = &value + return b +} + +// RemoveUnprunedEmbeddedResource removes the UnprunedEmbeddedResource field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveUnprunedEmbeddedResource(value runtime.RawExtension) *CronJobSpecApplyConfiguration { + b.fields.UnprunedEmbeddedResource = nil + return b +} + +// GetUnprunedEmbeddedResource gets the UnprunedEmbeddedResource field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetUnprunedEmbeddedResource() (value runtime.RawExtension, ok bool) { + if v := b.fields.UnprunedEmbeddedResource; v != nil { + return *v, true + } + return value, false +} + +// SetUnprunedFromType sets the UnprunedFromType field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetUnprunedFromType(value PreservedApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.UnprunedFromType = &value + return b +} + +// RemoveUnprunedFromType removes the UnprunedFromType field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveUnprunedFromType(value PreservedApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.UnprunedFromType = nil + return b +} + +// GetUnprunedFromType gets the UnprunedFromType field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetUnprunedFromType() (value PreservedApplyConfiguration, ok bool) { + if v := b.fields.UnprunedFromType; v != nil { + return *v, true + } + return value, false +} + +// SetAssociativeList sets the AssociativeList field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetAssociativeList(value []AssociativeTypeApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.AssociativeList = &value + return b +} + +// RemoveAssociativeList removes the AssociativeList field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveAssociativeList(value []AssociativeTypeApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.AssociativeList = nil + return b +} + +// GetAssociativeList gets the AssociativeList field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetAssociativeList() (value []AssociativeTypeApplyConfiguration, ok bool) { + if v := b.fields.AssociativeList; v != nil { + return *v, true + } + return value, false +} + +// SetMapOfInfo sets the MapOfInfo field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetMapOfInfo(value map[string][]byte) *CronJobSpecApplyConfiguration { + b.fields.MapOfInfo = &value + return b +} + +// RemoveMapOfInfo removes the MapOfInfo field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveMapOfInfo(value map[string][]byte) *CronJobSpecApplyConfiguration { + b.fields.MapOfInfo = nil + return b +} + +// GetMapOfInfo gets the MapOfInfo field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetMapOfInfo() (value map[string][]byte, ok bool) { + if v := b.fields.MapOfInfo; v != nil { + return *v, true + } + return value, false +} + +// SetStructWithSeveralFields sets the StructWithSeveralFields field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetStructWithSeveralFields(value NestedObjectApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.StructWithSeveralFields = &value + return b +} + +// RemoveStructWithSeveralFields removes the StructWithSeveralFields field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveStructWithSeveralFields(value NestedObjectApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.StructWithSeveralFields = nil + return b +} + +// GetStructWithSeveralFields gets the StructWithSeveralFields field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetStructWithSeveralFields() (value NestedObjectApplyConfiguration, ok bool) { + if v := b.fields.StructWithSeveralFields; v != nil { + return *v, true + } + return value, false +} + +// SetJustNestedObject sets the JustNestedObject field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetJustNestedObject(value *JustNestedObjectApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.JustNestedObject = &value + return b +} + +// RemoveJustNestedObject removes the JustNestedObject field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveJustNestedObject(value *JustNestedObjectApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.JustNestedObject = nil + return b +} + +// GetJustNestedObject gets the JustNestedObject field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetJustNestedObject() (value *JustNestedObjectApplyConfiguration, ok bool) { + if v := b.fields.JustNestedObject; v != nil { + return *v, true + } + return value, false +} + +// SetMinMaxProperties sets the MinMaxProperties field in the declarative configuration to the given value +func (b *CronJobSpecApplyConfiguration) SetMinMaxProperties(value MinMaxObjectApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.MinMaxProperties = &value + return b +} + +// RemoveMinMaxProperties removes the MinMaxProperties field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) RemoveMinMaxProperties(value MinMaxObjectApplyConfiguration) *CronJobSpecApplyConfiguration { + b.fields.MinMaxProperties = nil + return b +} + +// GetMinMaxProperties gets the MinMaxProperties field in the declarative configuration +func (b *CronJobSpecApplyConfiguration) GetMinMaxProperties() (value MinMaxObjectApplyConfiguration, ok bool) { + if v := b.fields.MinMaxProperties; v != nil { + return *v, true + } + return value, false +} + +// ToUnstructured converts CronJobSpec to unstructured. +func (b *CronJobSpecApplyConfiguration) ToUnstructured() interface{} { + if b == nil { + return nil + } + b.preMarshal() + u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&b.fields) + if err != nil { + panic(err) + } + return u +} + +// FromUnstructured converts unstructured to CronJobSpecApplyConfiguration, replacing the contents +// of CronJobSpecApplyConfiguration. +func (b *CronJobSpecApplyConfiguration) FromUnstructured(u map[string]interface{}) error { + m := &cronJobSpecFields{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(u, m) + if err != nil { + return err + } + b.fields = *m + b.postUnmarshal() + return nil +} + +// MarshalJSON marshals CronJobSpecApplyConfiguration to JSON. +func (b *CronJobSpecApplyConfiguration) MarshalJSON() ([]byte, error) { + b.preMarshal() + return json.Marshal(b.fields) +} + +// UnmarshalJSON unmarshals JSON into CronJobSpecApplyConfiguration, replacing the contents of +// CronJobSpecApplyConfiguration. +func (b *CronJobSpecApplyConfiguration) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, &b.fields); err != nil { + return err + } + b.postUnmarshal() + return nil +} + +func (b *CronJobSpecApplyConfiguration) preMarshal() { +} +func (b *CronJobSpecApplyConfiguration) postUnmarshal() { +} + +// CronJobSpecList represents a listAlias of CronJobSpecApplyConfiguration. +type CronJobSpecList []*CronJobSpecApplyConfiguration + +// CronJobSpecMap represents a map of CronJobSpecApplyConfiguration. +type CronJobSpecMap map[string]CronJobSpecApplyConfiguration + +// CronJobStatusApplyConfiguration represents a declarative configuration of the CronJobStatus type for use +// with apply. +type CronJobStatusApplyConfiguration struct { + fields cronJobStatusFields +} + +// cronJobStatus owns all fields except inlined fields +type cronJobStatusFields struct { + Active *[]v1.ObjectReference `json:"active,omitempty"` + LastScheduleTime **metav1.Time `json:"lastScheduleTime,omitempty"` + LastScheduleMicroTime **metav1.MicroTime `json:"lastScheduleMicroTime,omitempty"` +} + +// SetActive sets the Active field in the declarative configuration to the given value +func (b *CronJobStatusApplyConfiguration) SetActive(value []v1.ObjectReference) *CronJobStatusApplyConfiguration { + b.fields.Active = &value + return b +} + +// RemoveActive removes the Active field in the declarative configuration +func (b *CronJobStatusApplyConfiguration) RemoveActive(value []v1.ObjectReference) *CronJobStatusApplyConfiguration { + b.fields.Active = nil + return b +} + +// GetActive gets the Active field in the declarative configuration +func (b *CronJobStatusApplyConfiguration) GetActive() (value []v1.ObjectReference, ok bool) { + if v := b.fields.Active; v != nil { + return *v, true + } + return value, false +} + +// SetLastScheduleTime sets the LastScheduleTime field in the declarative configuration to the given value +func (b *CronJobStatusApplyConfiguration) SetLastScheduleTime(value *metav1.Time) *CronJobStatusApplyConfiguration { + b.fields.LastScheduleTime = &value + return b +} + +// RemoveLastScheduleTime removes the LastScheduleTime field in the declarative configuration +func (b *CronJobStatusApplyConfiguration) RemoveLastScheduleTime(value *metav1.Time) *CronJobStatusApplyConfiguration { + b.fields.LastScheduleTime = nil + return b +} + +// GetLastScheduleTime gets the LastScheduleTime field in the declarative configuration +func (b *CronJobStatusApplyConfiguration) GetLastScheduleTime() (value *metav1.Time, ok bool) { + if v := b.fields.LastScheduleTime; v != nil { + return *v, true + } + return value, false +} + +// SetLastScheduleMicroTime sets the LastScheduleMicroTime field in the declarative configuration to the given value +func (b *CronJobStatusApplyConfiguration) SetLastScheduleMicroTime(value *metav1.MicroTime) *CronJobStatusApplyConfiguration { + b.fields.LastScheduleMicroTime = &value + return b +} + +// RemoveLastScheduleMicroTime removes the LastScheduleMicroTime field in the declarative configuration +func (b *CronJobStatusApplyConfiguration) RemoveLastScheduleMicroTime(value *metav1.MicroTime) *CronJobStatusApplyConfiguration { + b.fields.LastScheduleMicroTime = nil + return b +} + +// GetLastScheduleMicroTime gets the LastScheduleMicroTime field in the declarative configuration +func (b *CronJobStatusApplyConfiguration) GetLastScheduleMicroTime() (value *metav1.MicroTime, ok bool) { + if v := b.fields.LastScheduleMicroTime; v != nil { + return *v, true + } + return value, false +} + +// ToUnstructured converts CronJobStatus to unstructured. +func (b *CronJobStatusApplyConfiguration) ToUnstructured() interface{} { + if b == nil { + return nil + } + b.preMarshal() + u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&b.fields) + if err != nil { + panic(err) + } + return u +} + +// FromUnstructured converts unstructured to CronJobStatusApplyConfiguration, replacing the contents +// of CronJobStatusApplyConfiguration. +func (b *CronJobStatusApplyConfiguration) FromUnstructured(u map[string]interface{}) error { + m := &cronJobStatusFields{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(u, m) + if err != nil { + return err + } + b.fields = *m + b.postUnmarshal() + return nil +} + +// MarshalJSON marshals CronJobStatusApplyConfiguration to JSON. +func (b *CronJobStatusApplyConfiguration) MarshalJSON() ([]byte, error) { + b.preMarshal() + return json.Marshal(b.fields) +} + +// UnmarshalJSON unmarshals JSON into CronJobStatusApplyConfiguration, replacing the contents of +// CronJobStatusApplyConfiguration. +func (b *CronJobStatusApplyConfiguration) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, &b.fields); err != nil { + return err + } + b.postUnmarshal() + return nil +} + +func (b *CronJobStatusApplyConfiguration) preMarshal() { +} +func (b *CronJobStatusApplyConfiguration) postUnmarshal() { +} + +// CronJobStatusList represents a listAlias of CronJobStatusApplyConfiguration. +type CronJobStatusList []*CronJobStatusApplyConfiguration + +// CronJobStatusMap represents a map of CronJobStatusApplyConfiguration. +type CronJobStatusMap map[string]CronJobStatusApplyConfiguration + +// JustNestedObjectApplyConfiguration represents a declarative configuration of the JustNestedObject type for use +// with apply. +type JustNestedObjectApplyConfiguration struct { + fields justNestedObjectFields +} + +// justNestedObject owns all fields except inlined fields +type justNestedObjectFields struct { +} + +// ToUnstructured converts JustNestedObject to unstructured. +func (b *JustNestedObjectApplyConfiguration) ToUnstructured() interface{} { + if b == nil { + return nil + } + b.preMarshal() + u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&b.fields) + if err != nil { + panic(err) + } + return u +} + +// FromUnstructured converts unstructured to JustNestedObjectApplyConfiguration, replacing the contents +// of JustNestedObjectApplyConfiguration. +func (b *JustNestedObjectApplyConfiguration) FromUnstructured(u map[string]interface{}) error { + m := &justNestedObjectFields{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(u, m) + if err != nil { + return err + } + b.fields = *m + b.postUnmarshal() + return nil +} + +// MarshalJSON marshals JustNestedObjectApplyConfiguration to JSON. +func (b *JustNestedObjectApplyConfiguration) MarshalJSON() ([]byte, error) { + b.preMarshal() + return json.Marshal(b.fields) +} + +// UnmarshalJSON unmarshals JSON into JustNestedObjectApplyConfiguration, replacing the contents of +// JustNestedObjectApplyConfiguration. +func (b *JustNestedObjectApplyConfiguration) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, &b.fields); err != nil { + return err + } + b.postUnmarshal() + return nil +} + +func (b *JustNestedObjectApplyConfiguration) preMarshal() { +} +func (b *JustNestedObjectApplyConfiguration) postUnmarshal() { +} + +// JustNestedObjectList represents a listAlias of JustNestedObjectApplyConfiguration. +type JustNestedObjectList []*JustNestedObjectApplyConfiguration + +// JustNestedObjectMap represents a map of JustNestedObjectApplyConfiguration. +type JustNestedObjectMap map[string]JustNestedObjectApplyConfiguration + +// MinMaxObjectApplyConfiguration represents a declarative configuration of the MinMaxObject type for use +// with apply. +type MinMaxObjectApplyConfiguration struct { + fields minMaxObjectFields +} + +// minMaxObject owns all fields except inlined fields +type minMaxObjectFields struct { + Foo *string `json:"foo,omitempty"` + Bar *string `json:"bar,omitempty"` + Baz *string `json:"baz,omitempty"` +} + +// SetFoo sets the Foo field in the declarative configuration to the given value +func (b *MinMaxObjectApplyConfiguration) SetFoo(value string) *MinMaxObjectApplyConfiguration { + b.fields.Foo = &value + return b +} + +// RemoveFoo removes the Foo field in the declarative configuration +func (b *MinMaxObjectApplyConfiguration) RemoveFoo(value string) *MinMaxObjectApplyConfiguration { + b.fields.Foo = nil + return b +} + +// GetFoo gets the Foo field in the declarative configuration +func (b *MinMaxObjectApplyConfiguration) GetFoo() (value string, ok bool) { + if v := b.fields.Foo; v != nil { + return *v, true + } + return value, false +} + +// SetBar sets the Bar field in the declarative configuration to the given value +func (b *MinMaxObjectApplyConfiguration) SetBar(value string) *MinMaxObjectApplyConfiguration { + b.fields.Bar = &value + return b +} + +// RemoveBar removes the Bar field in the declarative configuration +func (b *MinMaxObjectApplyConfiguration) RemoveBar(value string) *MinMaxObjectApplyConfiguration { + b.fields.Bar = nil + return b +} + +// GetBar gets the Bar field in the declarative configuration +func (b *MinMaxObjectApplyConfiguration) GetBar() (value string, ok bool) { + if v := b.fields.Bar; v != nil { + return *v, true + } + return value, false +} + +// SetBaz sets the Baz field in the declarative configuration to the given value +func (b *MinMaxObjectApplyConfiguration) SetBaz(value string) *MinMaxObjectApplyConfiguration { + b.fields.Baz = &value + return b +} + +// RemoveBaz removes the Baz field in the declarative configuration +func (b *MinMaxObjectApplyConfiguration) RemoveBaz(value string) *MinMaxObjectApplyConfiguration { + b.fields.Baz = nil + return b +} + +// GetBaz gets the Baz field in the declarative configuration +func (b *MinMaxObjectApplyConfiguration) GetBaz() (value string, ok bool) { + if v := b.fields.Baz; v != nil { + return *v, true + } + return value, false +} + +// ToUnstructured converts MinMaxObject to unstructured. +func (b *MinMaxObjectApplyConfiguration) ToUnstructured() interface{} { + if b == nil { + return nil + } + b.preMarshal() + u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&b.fields) + if err != nil { + panic(err) + } + return u +} + +// FromUnstructured converts unstructured to MinMaxObjectApplyConfiguration, replacing the contents +// of MinMaxObjectApplyConfiguration. +func (b *MinMaxObjectApplyConfiguration) FromUnstructured(u map[string]interface{}) error { + m := &minMaxObjectFields{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(u, m) + if err != nil { + return err + } + b.fields = *m + b.postUnmarshal() + return nil +} + +// MarshalJSON marshals MinMaxObjectApplyConfiguration to JSON. +func (b *MinMaxObjectApplyConfiguration) MarshalJSON() ([]byte, error) { + b.preMarshal() + return json.Marshal(b.fields) +} + +// UnmarshalJSON unmarshals JSON into MinMaxObjectApplyConfiguration, replacing the contents of +// MinMaxObjectApplyConfiguration. +func (b *MinMaxObjectApplyConfiguration) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, &b.fields); err != nil { + return err + } + b.postUnmarshal() + return nil +} + +func (b *MinMaxObjectApplyConfiguration) preMarshal() { +} +func (b *MinMaxObjectApplyConfiguration) postUnmarshal() { +} + +// MinMaxObjectList represents a listAlias of MinMaxObjectApplyConfiguration. +type MinMaxObjectList []*MinMaxObjectApplyConfiguration + +// MinMaxObjectMap represents a map of MinMaxObjectApplyConfiguration. +type MinMaxObjectMap map[string]MinMaxObjectApplyConfiguration + +// NestedObjectApplyConfiguration represents a declarative configuration of the NestedObject type for use +// with apply. +type NestedObjectApplyConfiguration struct { + fields nestedObjectFields +} + +// nestedObject owns all fields except inlined fields +type nestedObjectFields struct { + Foo *string `json:"foo,omitempty"` + Bar *bool `json:"bar,omitempty"` +} + +// SetFoo sets the Foo field in the declarative configuration to the given value +func (b *NestedObjectApplyConfiguration) SetFoo(value string) *NestedObjectApplyConfiguration { + b.fields.Foo = &value + return b +} + +// RemoveFoo removes the Foo field in the declarative configuration +func (b *NestedObjectApplyConfiguration) RemoveFoo(value string) *NestedObjectApplyConfiguration { + b.fields.Foo = nil + return b +} + +// GetFoo gets the Foo field in the declarative configuration +func (b *NestedObjectApplyConfiguration) GetFoo() (value string, ok bool) { + if v := b.fields.Foo; v != nil { + return *v, true + } + return value, false +} + +// SetBar sets the Bar field in the declarative configuration to the given value +func (b *NestedObjectApplyConfiguration) SetBar(value bool) *NestedObjectApplyConfiguration { + b.fields.Bar = &value + return b +} + +// RemoveBar removes the Bar field in the declarative configuration +func (b *NestedObjectApplyConfiguration) RemoveBar(value bool) *NestedObjectApplyConfiguration { + b.fields.Bar = nil + return b +} + +// GetBar gets the Bar field in the declarative configuration +func (b *NestedObjectApplyConfiguration) GetBar() (value bool, ok bool) { + if v := b.fields.Bar; v != nil { + return *v, true + } + return value, false +} + +// ToUnstructured converts NestedObject to unstructured. +func (b *NestedObjectApplyConfiguration) ToUnstructured() interface{} { + if b == nil { + return nil + } + b.preMarshal() + u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&b.fields) + if err != nil { + panic(err) + } + return u +} + +// FromUnstructured converts unstructured to NestedObjectApplyConfiguration, replacing the contents +// of NestedObjectApplyConfiguration. +func (b *NestedObjectApplyConfiguration) FromUnstructured(u map[string]interface{}) error { + m := &nestedObjectFields{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(u, m) + if err != nil { + return err + } + b.fields = *m + b.postUnmarshal() + return nil +} + +// MarshalJSON marshals NestedObjectApplyConfiguration to JSON. +func (b *NestedObjectApplyConfiguration) MarshalJSON() ([]byte, error) { + b.preMarshal() + return json.Marshal(b.fields) +} + +// UnmarshalJSON unmarshals JSON into NestedObjectApplyConfiguration, replacing the contents of +// NestedObjectApplyConfiguration. +func (b *NestedObjectApplyConfiguration) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, &b.fields); err != nil { + return err + } + b.postUnmarshal() + return nil +} + +func (b *NestedObjectApplyConfiguration) preMarshal() { +} +func (b *NestedObjectApplyConfiguration) postUnmarshal() { +} + +// NestedObjectList represents a listAlias of NestedObjectApplyConfiguration. +type NestedObjectList []*NestedObjectApplyConfiguration + +// NestedObjectMap represents a map of NestedObjectApplyConfiguration. +type NestedObjectMap map[string]NestedObjectApplyConfiguration + +// PreservedApplyConfiguration represents a declarative configuration of the Preserved type for use +// with apply. +type PreservedApplyConfiguration struct { + fields preservedFields +} + +// preserved owns all fields except inlined fields +type preservedFields struct { + ConcreteField *string `json:"concreteField,omitempty"` +} + +// SetConcreteField sets the ConcreteField field in the declarative configuration to the given value +func (b *PreservedApplyConfiguration) SetConcreteField(value string) *PreservedApplyConfiguration { + b.fields.ConcreteField = &value + return b +} + +// RemoveConcreteField removes the ConcreteField field in the declarative configuration +func (b *PreservedApplyConfiguration) RemoveConcreteField(value string) *PreservedApplyConfiguration { + b.fields.ConcreteField = nil + return b +} + +// GetConcreteField gets the ConcreteField field in the declarative configuration +func (b *PreservedApplyConfiguration) GetConcreteField() (value string, ok bool) { + if v := b.fields.ConcreteField; v != nil { + return *v, true + } + return value, false +} + +// SetRest sets the Rest field in the declarative configuration to the given value +func (b *PreservedApplyConfiguration) SetRest(value map[string]interface{}) *PreservedApplyConfiguration { + return b +} + +// RemoveRest removes the Rest field in the declarative configuration +func (b *PreservedApplyConfiguration) RemoveRest(value map[string]interface{}) *PreservedApplyConfiguration { + b.fields.Rest = nil + return b +} + +// GetRest gets the Rest field in the declarative configuration +func (b *PreservedApplyConfiguration) GetRest() (value map[string]interface{}, ok bool) { +} + +// ToUnstructured converts Preserved to unstructured. +func (b *PreservedApplyConfiguration) ToUnstructured() interface{} { + if b == nil { + return nil + } + b.preMarshal() + u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&b.fields) + if err != nil { + panic(err) + } + return u +} + +// FromUnstructured converts unstructured to PreservedApplyConfiguration, replacing the contents +// of PreservedApplyConfiguration. +func (b *PreservedApplyConfiguration) FromUnstructured(u map[string]interface{}) error { + m := &preservedFields{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(u, m) + if err != nil { + return err + } + b.fields = *m + b.postUnmarshal() + return nil +} + +// MarshalJSON marshals PreservedApplyConfiguration to JSON. +func (b *PreservedApplyConfiguration) MarshalJSON() ([]byte, error) { + b.preMarshal() + return json.Marshal(b.fields) +} + +// UnmarshalJSON unmarshals JSON into PreservedApplyConfiguration, replacing the contents of +// PreservedApplyConfiguration. +func (b *PreservedApplyConfiguration) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, &b.fields); err != nil { + return err + } + b.postUnmarshal() + return nil +} + +func (b *PreservedApplyConfiguration) preMarshal() { +} +func (b *PreservedApplyConfiguration) postUnmarshal() { +} + +// PreservedList represents a listAlias of PreservedApplyConfiguration. +type PreservedList []*PreservedApplyConfiguration + +// PreservedMap represents a map of PreservedApplyConfiguration. +type PreservedMap map[string]PreservedApplyConfiguration + +// RootObjectApplyConfiguration represents a declarative configuration of the RootObject type for use +// with apply. +type RootObjectApplyConfiguration struct { + fields rootObjectFields +} + +// rootObject owns all fields except inlined fields +type rootObjectFields struct { + Nested *NestedObjectApplyConfiguration `json:"nested,omitempty"` +} + +// SetNested sets the Nested field in the declarative configuration to the given value +func (b *RootObjectApplyConfiguration) SetNested(value NestedObjectApplyConfiguration) *RootObjectApplyConfiguration { + b.fields.Nested = &value + return b +} + +// RemoveNested removes the Nested field in the declarative configuration +func (b *RootObjectApplyConfiguration) RemoveNested(value NestedObjectApplyConfiguration) *RootObjectApplyConfiguration { + b.fields.Nested = nil + return b +} + +// GetNested gets the Nested field in the declarative configuration +func (b *RootObjectApplyConfiguration) GetNested() (value NestedObjectApplyConfiguration, ok bool) { + if v := b.fields.Nested; v != nil { + return *v, true + } + return value, false +} + +// ToUnstructured converts RootObject to unstructured. +func (b *RootObjectApplyConfiguration) ToUnstructured() interface{} { + if b == nil { + return nil + } + b.preMarshal() + u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&b.fields) + if err != nil { + panic(err) + } + return u +} + +// FromUnstructured converts unstructured to RootObjectApplyConfiguration, replacing the contents +// of RootObjectApplyConfiguration. +func (b *RootObjectApplyConfiguration) FromUnstructured(u map[string]interface{}) error { + m := &rootObjectFields{} + err := runtime.DefaultUnstructuredConverter.FromUnstructured(u, m) + if err != nil { + return err + } + b.fields = *m + b.postUnmarshal() + return nil +} + +// MarshalJSON marshals RootObjectApplyConfiguration to JSON. +func (b *RootObjectApplyConfiguration) MarshalJSON() ([]byte, error) { + b.preMarshal() + return json.Marshal(b.fields) +} + +// UnmarshalJSON unmarshals JSON into RootObjectApplyConfiguration, replacing the contents of +// RootObjectApplyConfiguration. +func (b *RootObjectApplyConfiguration) UnmarshalJSON(data []byte) error { + if err := json.Unmarshal(data, &b.fields); err != nil { + return err + } + b.postUnmarshal() + return nil +} + +func (b *RootObjectApplyConfiguration) preMarshal() { +} +func (b *RootObjectApplyConfiguration) postUnmarshal() { +} + +// RootObjectList represents a listAlias of RootObjectApplyConfiguration. +type RootObjectList []*RootObjectApplyConfiguration + +// RootObjectMap represents a map of RootObjectApplyConfiguration. +type RootObjectMap map[string]RootObjectApplyConfiguration diff --git a/pkg/applyconfigurations/testdata/zz_generated.deepcopy.go b/pkg/applyconfigurations/testdata/zz_generated.deepcopy.go new file mode 100644 index 000000000..c3f4864d0 --- /dev/null +++ b/pkg/applyconfigurations/testdata/zz_generated.deepcopy.go @@ -0,0 +1,84 @@ +// +build !ignore_autogenerated + +/* +Copyright The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by controller-gen. DO NOT EDIT. + +package cronjob + +import ( + "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CronJob) DeepCopyInto(out *CronJob) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CronJob. +func (in *CronJob) DeepCopy() *CronJob { + if in == nil { + return nil + } + out := new(CronJob) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CronJob) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CronJobList) DeepCopyInto(out *CronJobList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]CronJob, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CronJobList. +func (in *CronJobList) DeepCopy() *CronJobList { + if in == nil { + return nil + } + out := new(CronJobList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *CronJobList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} diff --git a/pkg/applyconfigurations/traverse.go b/pkg/applyconfigurations/traverse.go index 3c8bb1bb9..f5b60a25f 100644 --- a/pkg/applyconfigurations/traverse.go +++ b/pkg/applyconfigurations/traverse.go @@ -137,7 +137,7 @@ type namingInfo struct { } // Syntax calculates the code representation of the given type or name, -// and marks that is used (potentially marking an import as used). +// and returns the apply representation func (n *namingInfo) Syntax(basePkg *loader.Package, imports *importsList) string { if n.nameOverride != "" { return n.nameOverride @@ -149,11 +149,20 @@ func (n *namingInfo) Syntax(basePkg *loader.Package, imports *importsList) strin case *types.Named: // register that we need an import for this type, // so we can get the appropriate alias to use. + + var lastType types.Type + appendString := "ApplyConfiguration" + for underlyingType := typeInfo.Underlying(); underlyingType != lastType; lastType, underlyingType = underlyingType, underlyingType.Underlying() { + if _, isBasic := underlyingType.(*types.Basic); isBasic { + appendString = "" + } + } + typeName := typeInfo.Obj() otherPkg := typeName.Pkg() if otherPkg == basePkg.Types { // local import - return typeName.Name() + return typeName.Name() + appendString } alias := imports.NeedImport(loader.NonVendorPath(otherPkg.Path())) return alias + "." + typeName.Name() @@ -168,6 +177,8 @@ func (n *namingInfo) Syntax(basePkg *loader.Package, imports *importsList) strin "map[%s]%s", (&namingInfo{typeInfo: typeInfo.Key()}).Syntax(basePkg, imports), (&namingInfo{typeInfo: typeInfo.Elem()}).Syntax(basePkg, imports)) + case *types.Interface: + return "interface{}" default: basePkg.AddError(fmt.Errorf("name requested for invalid type: %s", typeInfo)) return typeInfo.String() @@ -191,7 +202,263 @@ func (c *applyConfigurationMaker) GenerateTypesFor(root *loader.Package, info *m // TODO(jpbetz): Generate output here - c.Linef("type %sApplyConfiguration struct {}", info.Name) + c.Linef("// %sApplyConfiguration represents a declarative configuration of the %s type for use", info.Name, info.Name) + c.Linef("// with apply.") + c.Linef("type %sApplyConfiguration struct {", info.Name) + if len(info.Fields) > 0 { + for _, field := range info.Fields { + fieldName := field.Name + fieldType := root.TypesInfo.TypeOf(field.RawField.Type) + fieldNamingInfo := namingInfo{typeInfo: fieldType} + fieldTypeString := fieldNamingInfo.Syntax(root, c.importsList) + if tags, ok := lookupJsonTags(field); ok { + if tags.inline { + c.Linef("%s %s `json:\"%s\"`", fieldName, fieldTypeString, tags.String()) + } else { + tags.omitempty = true + c.Linef("%s *%s `json:\"%s\"`", fieldName, fieldTypeString, tags.String()) + } + } + } + } + c.Linef("}") +} + +func generatePrivateName(s string) string { + if len(s) == 0 { + return s + } + s2 := []byte(s) + s2[0] = s2[0] | ('a' - 'A') + return fmt.Sprintf("%s", s2) +} + +func (c *applyConfigurationMaker) GenerateStruct(root *loader.Package, info *markers.TypeInfo) { + typeInfo := root.TypesInfo.TypeOf(info.RawSpec.Name) + if typeInfo == types.Typ[types.Invalid] { + root.AddError(loader.ErrFromNode(fmt.Errorf("unknown type: %s", info.Name), info.RawSpec)) + } + + c.Linef("// %sApplyConfiguration represents a declarative configuration of the %s type for use", info.Name, info.Name) + c.Linef("// with apply.") + c.Linef("type %sApplyConfiguration struct {", info.Name) + for _, field := range info.Fields { + privateFieldName := generatePrivateName(field.Name) + fieldType := root.TypesInfo.TypeOf(field.RawField.Type) + fieldNamingInfo := namingInfo{typeInfo: fieldType} + fieldTypeString := fieldNamingInfo.Syntax(root, c.importsList) + if tags, ok := lookupJsonTags(field); ok { + if !tags.inline { + continue + } + c.Linef("%s %s // inlined type", privateFieldName, fieldTypeString) + } + } + c.Linef("fields %sFields", generatePrivateName(info.Name)) + c.Linef("}") +} + +func (c *applyConfigurationMaker) GenerateFieldsStruct(root *loader.Package, info *markers.TypeInfo) { + typeInfo := root.TypesInfo.TypeOf(info.RawSpec.Name) + if typeInfo == types.Typ[types.Invalid] { + root.AddError(loader.ErrFromNode(fmt.Errorf("unknown type: %s", info.Name), info.RawSpec)) + } + + privateTypeName := generatePrivateName(info.Name) + c.Linef("// %s owns all fields except inlined fields", privateTypeName) + // TODO|jefftree: Copy over rest of documentation + c.Linef("type %sFields struct {", privateTypeName) + if len(info.Fields) > 0 { + for _, field := range info.Fields { + fieldName := field.Name + fieldType := root.TypesInfo.TypeOf(field.RawField.Type) + fieldNamingInfo := namingInfo{typeInfo: fieldType} + fieldTypeString := fieldNamingInfo.Syntax(root, c.importsList) + if tags, ok := lookupJsonTags(field); ok { + // TODO:jefftree: Handle inline objects + if tags.inline { + continue + } + tags.omitempty = true + c.Linef("%s *%s `json:\"%s\"`", fieldName, fieldTypeString, tags.String()) + } + } + } + c.Linef("}") +} + +func (c *applyConfigurationMaker) GenerateStructConstructor(root *loader.Package, info *markers.TypeInfo) { + c.Linef("// %sApplyConfiguration represents a declarative configuration of the %s type for use", info.Name, info.Name) + c.Linef("// with apply.") + c.Linef("func %s() *%sApplyConfiguration {", info.Name, info.Name) + c.Linef("return &%sApplyConfiguration{}", info.Name) + c.Linef("}") +} + +func (c *applyConfigurationMaker) GenerateMemberSet(field markers.FieldInfo, root *loader.Package, info *markers.TypeInfo) { + fieldType := root.TypesInfo.TypeOf(field.RawField.Type) + fieldNamingInfo := namingInfo{typeInfo: fieldType} + fieldTypeString := fieldNamingInfo.Syntax(root, c.importsList) + + c.Linef("// Set%s sets the %s field in the declarative configuration to the given value", field.Name, field.Name) + c.Linef("func (b *%sApplyConfiguration) Set%s(value %s) *%sApplyConfiguration {", info.Name, field.Name, fieldTypeString, info.Name) + + if tags, ok := lookupJsonTags(field); ok { + // TODO|jefftree: Do we support double pointers? + if tags.inline { + c.Linef("if value != nil {") + c.Linef("b.%s = *value", field.Name) + c.Linef("}") + } else { + // TODO|jefftree: Confirm with jpbetz on how to handle fields that are already pointers + c.Linef("b.fields.%s = &value", field.Name) + } + } + c.Linef("return b") + c.Linef("}") +} + +func (c *applyConfigurationMaker) GenerateMemberRemove(field markers.FieldInfo, root *loader.Package, info *markers.TypeInfo) { + fieldType := root.TypesInfo.TypeOf(field.RawField.Type) + fieldNamingInfo := namingInfo{typeInfo: fieldType} + fieldTypeString := fieldNamingInfo.Syntax(root, c.importsList) + + if tags, ok := lookupJsonTags(field); ok { + if tags.inline { + return + } + } + + c.Linef("// Remove%s removes the %s field in the declarative configuration", field.Name, field.Name) + c.Linef("func (b *%sApplyConfiguration) Remove%s(value %s) *%sApplyConfiguration {", info.Name, field.Name, fieldTypeString, info.Name) + c.Linef("b.fields.%s = nil", field.Name) + c.Linef("return b") + c.Linef("}") +} + +func (c *applyConfigurationMaker) GenerateMemberGet(field markers.FieldInfo, root *loader.Package, info *markers.TypeInfo) { + fieldType := root.TypesInfo.TypeOf(field.RawField.Type) + fieldNamingInfo := namingInfo{typeInfo: fieldType} + fieldTypeString := fieldNamingInfo.Syntax(root, c.importsList) + + c.Linef("// Get%s gets the %s field in the declarative configuration", field.Name, field.Name) + c.Linef("func (b *%sApplyConfiguration) Get%s() (value %s, ok bool) {", info.Name, field.Name, fieldTypeString) + + if tags, ok := lookupJsonTags(field); ok { + if tags.inline { + c.Linef("return b.%s, true", field.Name) + } else { + // TODO|jefftree: Confirm with jpbetz on how to handle fields that are already pointers + + // c.Linef("return b.fields.%s, b.fields.%s != nil", field.Name, field.Name) + c.Linef("if v := b.fields.%s; v != nil {", field.Name) + c.Linef("return *v, true") + c.Linef("}") + c.Linef("return value, false") + } + } + c.Linef("}") +} + +func (c *applyConfigurationMaker) GenerateToUnstructured(root *loader.Package, info *markers.TypeInfo) { + runtime := c.NeedImport("k8s.io/apimachinery/pkg/runtime") + var toUnstructured = ` +// ToUnstructured converts %s to unstructured. +func (b *%sApplyConfiguration) ToUnstructured() interface{} { + if b == nil { + return nil + } + b.preMarshal() + u, err := %s.DefaultUnstructuredConverter.ToUnstructured(&b.fields) + if err != nil { + panic(err) + } + return u +} +` + c.Linef(toUnstructured, info.Name, info.Name, runtime) +} + +func (c *applyConfigurationMaker) GenerateFromUnstructured(root *loader.Package, info *markers.TypeInfo) { + runtime := c.NeedImport("k8s.io/apimachinery/pkg/runtime") + var fromUnstructured = ` +// FromUnstructured converts unstructured to %sApplyConfiguration, replacing the contents +// of %sApplyConfiguration. +func (b *%sApplyConfiguration) FromUnstructured(u map[string]interface{}) error { + m := &%sFields{} + err := %s.DefaultUnstructuredConverter.FromUnstructured(u, m) + if err != nil { + return err + } + b.fields = *m + b.postUnmarshal() + return nil +} +` + c.Linef(fromUnstructured, info.Name, info.Name, info.Name, generatePrivateName(info.Name), runtime) +} + +func (c *applyConfigurationMaker) GenerateMarshal(root *loader.Package, info *markers.TypeInfo) { + jsonImport := c.NeedImport("encoding/json") + var marshal = ` +// MarshalJSON marshals %sApplyConfiguration to JSON. +func (b *%sApplyConfiguration) MarshalJSON() ([]byte, error) { + b.preMarshal() + return %s.Marshal(b.fields) +} +` + c.Linef(marshal, info.Name, info.Name, jsonImport) + +} + +func (c *applyConfigurationMaker) GenerateUnmarshal(root *loader.Package, info *markers.TypeInfo) { + jsonImport := c.NeedImport("encoding/json") + var unmarshal = ` +// UnmarshalJSON unmarshals JSON into %sApplyConfiguration, replacing the contents of +// %sApplyConfiguration. +func (b *%sApplyConfiguration) UnmarshalJSON(data []byte) error { + if err := %s.Unmarshal(data, &b.fields); err != nil { + return err + } + b.postUnmarshal() + return nil +} +` + c.Linef(unmarshal, info.Name, info.Name, info.Name, jsonImport) +} + +func (c *applyConfigurationMaker) GeneratePrePostFunctions(root *loader.Package, info *markers.TypeInfo) { + c.Linef("func (b *%sApplyConfiguration) preMarshal() {", info.Name) + for _, field := range info.Fields { + // fieldName := field.Name + // privateName := generatePrivateName(fieldName) + // fieldType := root.TypesInfo.TypeOf(field.RawField.Type) + // fieldNamingInfo := namingInfo{typeInfo: fieldType} + // fieldTypeString := fieldNamingInfo.Syntax(root, c.importsList) + if tags, ok := lookupJsonTags(field); ok { + if !tags.inline { + continue + } + // c.Linef("if v, ok := b.%s.Get", privateName) + } + } + c.Linef("}") + c.Linef("func (b *%sApplyConfiguration) postUnmarshal() {", info.Name) + c.Linef("}") +} + +func (c *applyConfigurationMaker) GenerateListMapAlias(root *loader.Package, info *markers.TypeInfo) { + var listAlias = ` +// %[1]sList represents a listAlias of %[1]sApplyConfiguration. +type %[1]sList []*%[1]sApplyConfiguration +` + var mapAlias = ` +// %[1]sMap represents a map of %[1]sApplyConfiguration. +type %[1]sMap map[string]%[1]sApplyConfiguration +` + + c.Linef(listAlias, info.Name) + c.Linef(mapAlias, info.Name) } // shouldBeApplyConfiguration checks if we're supposed to make apply configurations for the given type. @@ -243,9 +510,10 @@ func shouldBeApplyConfiguration(pkg *loader.Package, info *markers.TypeInfo) boo } var ( - rawExtension = "k8s.io/apimachinery/pkg/runtime/RawExtension" - unknown = "k8s.io/apimachinery/pkg/runtime/Unknown" + rawExtension = "k8s.io/apimachinery/pkg/runtime/RawExtension" + unknown = "k8s.io/apimachinery/pkg/runtime/Unknown" ) + // excludeTypes contains well known types that we do not generate apply configurations for. // Hard coding because we only have two, very specific types that serve a special purpose // in the type system here. diff --git a/pkg/crd/testdata/go.sum b/pkg/crd/testdata/go.sum index 6d8a67959..173aadda4 100644 --- a/pkg/crd/testdata/go.sum +++ b/pkg/crd/testdata/go.sum @@ -1,3 +1,4 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= @@ -7,6 +8,7 @@ github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415 h1:WSBJMqJbLxsn+bTCP github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf h1:+RRA9JqSOZFfKrOeqr2z77+8R2RKyh8PG66dcu1V0ck= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= @@ -14,14 +16,19 @@ github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be h1:AHimNtVIpiBjPUhEF5KNCkrUyqTSA5zWUl8sQ2bfGBE= github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v0.0.0-20190113212917-5533ce8a0da3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190206173232-65e2d4e15006 h1:bfLnR+k0tq5Lqt6dflRLcZiz6UaXCMt3vhYJ1l4FQ80= @@ -39,6 +46,7 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy gopkg.in/inf.v0 v0.9.0 h1:3zYtXIO92bvsdS3ggAdA8Gb4Azj0YU+TVY1uGYNFA8o= gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= k8s.io/api v0.0.0-20190615205754-1d1b8b084b30 h1:/0Fr/sqn9cXa/R8CSlgq8Fy0Wp1wR2cNTSlHvrN78K4= k8s.io/api v0.0.0-20190615205754-1d1b8b084b30/go.mod h1:SR4nMi8IQTDnEi4768MsMCoZ9DyfRls7wy+TbRrFicA= @@ -47,4 +55,5 @@ k8s.io/apimachinery v0.0.0-20190612125636-6a5db36e93ad/go.mod h1:I4A+glKBHiTgiEj k8s.io/klog v0.3.1 h1:RVgyDHY/kFKtLqh67NvEWIgkMneNoIrdkN0CxDSQc68= k8s.io/klog v0.3.1/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc= +sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= diff --git a/pkg/deepcopy/testdata/go.sum b/pkg/deepcopy/testdata/go.sum index 703670a92..61983ec6d 100644 --- a/pkg/deepcopy/testdata/go.sum +++ b/pkg/deepcopy/testdata/go.sum @@ -3,6 +3,7 @@ github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= @@ -19,6 +20,7 @@ github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw= @@ -29,13 +31,16 @@ github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsC github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= @@ -45,11 +50,13 @@ github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -75,6 +82,7 @@ gopkg.in/inf.v0 v0.9.0 h1:3zYtXIO92bvsdS3ggAdA8Gb4Azj0YU+TVY1uGYNFA8o= gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= k8s.io/api v0.0.0-20190722141453-b90922c02518 h1:mShu41WQl4VJGAd7fbhhH0tsy+KMjZRnC/OcFYF8RVc= k8s.io/api v0.0.0-20190722141453-b90922c02518/go.mod h1:1O0xzX/RAtnm7l+5VEUxZ1ysO2ghatfq/OZED4zM9kA= @@ -86,4 +94,5 @@ k8s.io/klog v0.3.1 h1:RVgyDHY/kFKtLqh67NvEWIgkMneNoIrdkN0CxDSQc68= k8s.io/klog v0.3.1/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= k8s.io/kube-openapi v0.0.0-20190709113604-33be087ad058/go.mod h1:nfDlWeOsu3pUf4yWGL+ERqohP4YsZcBJXWMK+gkzOA4= sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= +sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=