diff --git a/pkg/apis/settings/settings.go b/pkg/apis/settings/settings.go index 45aab3af3734..ab6bd9b2c6d5 100644 --- a/pkg/apis/settings/settings.go +++ b/pkg/apis/settings/settings.go @@ -36,6 +36,7 @@ var defaultSettings = &Settings{ DriftEnabled: false, } +// +k8s:deepcopy-gen=true type Settings struct { BatchMaxDuration metav1.Duration BatchIdleDuration metav1.Duration @@ -49,7 +50,7 @@ func (*Settings) ConfigMap() string { // Inject creates a Settings from the supplied ConfigMap func (*Settings) Inject(ctx context.Context, cm *v1.ConfigMap) (context.Context, error) { - s := defaultSettings + s := defaultSettings.DeepCopy() if err := configmap.Parse(cm.Data, AsMetaDuration("batchMaxDuration", &s.BatchMaxDuration), @@ -70,15 +71,15 @@ func (*Settings) Inject(ctx context.Context, cm *v1.ConfigMap) (context.Context, // type ExampleStruct struct { // Example metav1.Duration `json:"example" validate:"required,min=10m"` // } -func (s *Settings) Validate() (err error) { +func (in *Settings) Validate() (err error) { validate := validator.New() - if s.BatchMaxDuration.Duration <= 0 { + if in.BatchMaxDuration.Duration <= 0 { err = multierr.Append(err, fmt.Errorf("batchMaxDuration cannot be negative")) } - if s.BatchIdleDuration.Duration <= 0 { + if in.BatchIdleDuration.Duration <= 0 { err = multierr.Append(err, fmt.Errorf("batchMaxDuration cannot be negative")) } - return multierr.Append(err, validate.Struct(s)) + return multierr.Append(err, validate.Struct(in)) } // AsMetaDuration parses the value at key as a time.Duration into the target, if it exists. diff --git a/pkg/apis/settings/zz_generated.deepcopy.go b/pkg/apis/settings/zz_generated.deepcopy.go new file mode 100644 index 000000000000..d7643cf2f737 --- /dev/null +++ b/pkg/apis/settings/zz_generated.deepcopy.go @@ -0,0 +1,39 @@ +//go:build !ignore_autogenerated +// +build !ignore_autogenerated + +/* +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 settings + +import () + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Settings) DeepCopyInto(out *Settings) { + *out = *in + out.BatchMaxDuration = in.BatchMaxDuration + out.BatchIdleDuration = in.BatchIdleDuration +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Settings. +func (in *Settings) DeepCopy() *Settings { + if in == nil { + return nil + } + out := new(Settings) + in.DeepCopyInto(out) + return out +}