From 46d068f019dcf3691badcad24207abbecb928027 Mon Sep 17 00:00:00 2001 From: Damian Badura Date: Thu, 14 Sep 2023 14:43:31 +0200 Subject: [PATCH 1/3] remove code and add tests --- .../function-controller/cmd/webhook/main.go | 6 - .../internal/webhook/defaulting_webhook.go | 24 +- .../webhook/defaulting_webhook_test.go | 195 ------- .../internal/webhook/webhook_config.go | 33 -- .../serverless/v1alpha2/function_defaults.go | 122 ----- .../v1alpha2/function_defaults_test.go | 474 ------------------ .../v1alpha2/function_resources_test.go | 125 +++++ 7 files changed, 131 insertions(+), 848 deletions(-) delete mode 100644 components/function-controller/internal/webhook/defaulting_webhook_test.go delete mode 100644 components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults_test.go create mode 100644 components/function-controller/pkg/apis/serverless/v1alpha2/function_resources_test.go diff --git a/components/function-controller/cmd/webhook/main.go b/components/function-controller/cmd/webhook/main.go index 531b6c96741a..2ab0fb8ccef7 100644 --- a/components/function-controller/cmd/webhook/main.go +++ b/components/function-controller/cmd/webhook/main.go @@ -117,14 +117,8 @@ func main() { whs.CertName = resources.CertFile whs.KeyName = resources.KeyFile - defaultCfg, err := webhookCfg.ToDefaultingConfig() - if err != nil { - setupLog.Error(err, "while creating of defaulting configuration") - os.Exit(1) - } whs.Register(resources.FunctionDefaultingWebhookPath, &ctrlwebhook.Admission{ Handler: webhook.NewDefaultingWebhook( - &defaultCfg, mgr.GetClient(), logWithCtx.Named("defaulting-webhook")), }) diff --git a/components/function-controller/internal/webhook/defaulting_webhook.go b/components/function-controller/internal/webhook/defaulting_webhook.go index 24d99018b4e3..5c4d22d31ad0 100644 --- a/components/function-controller/internal/webhook/defaulting_webhook.go +++ b/components/function-controller/internal/webhook/defaulting_webhook.go @@ -16,17 +16,15 @@ import ( ) type DefaultingWebHook struct { - configAlphaV2 *serverlessv1alpha2.DefaultingConfig - client ctrlclient.Client - decoder *admission.Decoder - log *zap.SugaredLogger + client ctrlclient.Client + decoder *admission.Decoder + log *zap.SugaredLogger } -func NewDefaultingWebhook(configV1Alpha2 *serverlessv1alpha2.DefaultingConfig, client ctrlclient.Client, log *zap.SugaredLogger) *DefaultingWebHook { +func NewDefaultingWebhook(client ctrlclient.Client, log *zap.SugaredLogger) *DefaultingWebHook { return &DefaultingWebHook{ - configAlphaV2: configV1Alpha2, - client: client, - log: log, + client: client, + log: log, } } @@ -39,11 +37,6 @@ func (w *DefaultingWebHook) Handle(_ context.Context, req admission.Request) adm log.Debug("defaulting finished for function") return res } - if req.Kind.Kind == "GitRepository" { - res := w.handleGitRepoDefaulting() - log.Debug("defaulting finished for gitrepository") - return res - } log.Debug("request object invalid kind") return admission.Errored(http.StatusBadRequest, fmt.Errorf("invalid kind: %v", req.Kind.Kind)) @@ -63,7 +56,6 @@ func (w *DefaultingWebHook) handleFunctionDefaulting(req admission.Request) admi if err := w.decoder.Decode(req, fn); err != nil { return admission.Errored(http.StatusBadRequest, err) } - fn.Default(w.configAlphaV2) f = fn } default: @@ -76,7 +68,3 @@ func (w *DefaultingWebHook) handleFunctionDefaulting(req admission.Request) admi } return admission.PatchResponseFromRaw(req.Object.Raw, fBytes) } - -func (w *DefaultingWebHook) handleGitRepoDefaulting() admission.Response { - return admission.Allowed("") -} diff --git a/components/function-controller/internal/webhook/defaulting_webhook_test.go b/components/function-controller/internal/webhook/defaulting_webhook_test.go deleted file mode 100644 index 776fd9f99b15..000000000000 --- a/components/function-controller/internal/webhook/defaulting_webhook_test.go +++ /dev/null @@ -1,195 +0,0 @@ -package webhook - -import ( - "context" - "fmt" - "net/http" - "testing" - - "github.com/stretchr/testify/assert" - "go.uber.org/zap" - - serverlessv1alpha2 "github.com/kyma-project/kyma/components/function-controller/pkg/apis/serverless/v1alpha2" - "github.com/stretchr/testify/require" - v1 "k8s.io/api/admission/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - "k8s.io/apimachinery/pkg/runtime" - ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/client/fake" - "sigs.k8s.io/controller-runtime/pkg/webhook/admission" -) - -func TestDefaultingWebHook_Handle(t *testing.T) { - type fields struct { - configv1alpha2 *serverlessv1alpha2.DefaultingConfig - client ctrlclient.Client - decoder *admission.Decoder - } - type args struct { - ctx context.Context - req admission.Request - } - type want struct { - operationsCount int - statusCode int32 - } - scheme := runtime.NewScheme() - _ = serverlessv1alpha2.AddToScheme(scheme) - decoder, err := admission.NewDecoder(scheme) - require.NoError(t, err) - - tests := []struct { - name string - fields fields - args args - want want - }{ - { - name: "Set function defaults successfully v1alpha2", - fields: fields{ - configv1alpha2: &serverlessv1alpha2.DefaultingConfig{ - Function: serverlessv1alpha2.FunctionDefaulting{ - Resources: serverlessv1alpha2.FunctionResourcesDefaulting{ - DefaultPreset: "S", - Presets: map[string]serverlessv1alpha2.ResourcesPreset{ - "S": { - RequestCPU: "100m", - RequestMemory: "128Mi", - LimitCPU: "200m", - LimitMemory: "256Mi", - }, - }, - }, - }, - BuildJob: serverlessv1alpha2.BuildJobDefaulting{ - Resources: serverlessv1alpha2.BuildJobResourcesDefaulting{ - DefaultPreset: "normal", - Presets: map[string]serverlessv1alpha2.ResourcesPreset{ - "normal": { - RequestCPU: "700m", - RequestMemory: "700Mi", - LimitCPU: "1100m", - LimitMemory: "1100Mi", - }, - }, - }, - }, - }, - client: fake.NewClientBuilder().Build(), - decoder: decoder, - }, - args: args{ - ctx: context.Background(), - req: admission.Request{ - AdmissionRequest: v1.AdmissionRequest{ - Kind: metav1.GroupVersionKind{Kind: "Function", Version: serverlessv1alpha2.FunctionVersion}, - Object: runtime.RawExtension{ - Raw: []byte(`{ - "apiVersion": "serverless.kyma-project.io/v1alpha2", - "kind": "Function", - "metadata": { - "labels": { - "serverless.kyma-project.io/function-resources-preset": "S" - }, - "name": "testfunc", - "namespace": "default" - }, - "spec": { - "runtime": "python39", - "source": { - "inline": { - "source": "def main(event, context):\n return \"hello world\"\n" - } - } - } - }`), - }, - }, - }, - }, - want: want{ - // add /status - // add /metadata/creationTimestamp - operationsCount: 2, - }, - }, - { - name: "Bad request", - fields: fields{ - configv1alpha2: &serverlessv1alpha2.DefaultingConfig{}, - client: fake.NewClientBuilder().Build(), - decoder: decoder, - }, - args: args{ - ctx: context.Background(), - req: admission.Request{ - AdmissionRequest: v1.AdmissionRequest{ - Kind: metav1.GroupVersionKind{Kind: "Function", Version: serverlessv1alpha2.FunctionVersion}, - Object: runtime.RawExtension{ - Raw: []byte(`bad request`), - }, - }, - }, - }, - want: want{ - statusCode: http.StatusBadRequest, - }, - }, - { - name: "Fail on invalid kind", - fields: fields{ - - client: fake.NewClientBuilder().Build(), - decoder: decoder, - }, - args: args{ - ctx: context.Background(), - req: admission.Request{ - AdmissionRequest: v1.AdmissionRequest{ - Kind: metav1.GroupVersionKind{Kind: "Function", Version: serverlessv1alpha2.FunctionVersion}, - Object: runtime.RawExtension{ - Raw: []byte(`{ - "apiVersion": "serverless.kyma-project.io/v1alpha2", - "kind": "NotFunction", - "metadata": { - "labels": { - "serverless.kyma-project.io/function-resources-preset": "S" - }, - "name": "testfunc", - "namespace": "default" - }, - "spec": { - "runtime": "python39" - } - }`), - }, - }, - }, - }, - want: want{ - statusCode: http.StatusBadRequest, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - w := &DefaultingWebHook{ - configAlphaV2: tt.fields.configv1alpha2, - client: tt.fields.client, - decoder: tt.fields.decoder, - log: zap.NewNop().Sugar(), - } - got := w.Handle(tt.args.ctx, tt.args.req) - - if tt.want.operationsCount != 0 { - require.True(t, got.Allowed) - assert.Equal(t, tt.want.operationsCount, len(got.Patches), fmt.Sprintf("%+v", got.Patches)) - } - if tt.want.statusCode != 0 { - require.False(t, got.Allowed) - require.Equal(t, tt.want.statusCode, got.Result.Code) - } - }) - } -} diff --git a/components/function-controller/internal/webhook/webhook_config.go b/components/function-controller/internal/webhook/webhook_config.go index 040f6422690d..1824f4550111 100644 --- a/components/function-controller/internal/webhook/webhook_config.go +++ b/components/function-controller/internal/webhook/webhook_config.go @@ -114,36 +114,3 @@ func (wc WebhookConfig) ToValidationConfig() v1alpha2.ValidationConfig { }, } } - -func (wc WebhookConfig) ToDefaultingConfig() (v1alpha2.DefaultingConfig, error) { - cfg := v1alpha2.DefaultingConfig{ - Runtime: v1alpha2.Runtime(wc.DefaultRuntime), - Function: v1alpha2.FunctionDefaulting{ - Resources: v1alpha2.FunctionResourcesDefaulting{ - DefaultPreset: wc.Function.Resources.DefaultPreset, - Presets: wc.Function.Resources.Presets.toDefaultingResourcePreset(), - RuntimePresets: wc.Function.Resources.RuntimePresets, - }, - }, - BuildJob: v1alpha2.BuildJobDefaulting{ - Resources: v1alpha2.BuildJobResourcesDefaulting{ - DefaultPreset: wc.BuildJob.Resources.DefaultPreset, - Presets: wc.BuildJob.Resources.Presets.toDefaultingResourcePreset(), - }, - }, - } - return cfg, nil -} - -func (rp ResourcePreset) toDefaultingResourcePreset() map[string]v1alpha2.ResourcesPreset { - out := map[string]v1alpha2.ResourcesPreset{} - for k, v := range rp { - out[k] = v1alpha2.ResourcesPreset{ - RequestCPU: v.RequestCpu, - RequestMemory: v.RequestMemory, - LimitCPU: v.LimitCpu, - LimitMemory: v.LimitMemory, - } - } - return out -} diff --git a/components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults.go b/components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults.go index 88802d1d02c7..56f331b7aac5 100644 --- a/components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults.go +++ b/components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults.go @@ -1,11 +1,5 @@ package v1alpha2 -import ( - "k8s.io/apimachinery/pkg/api/resource" - - corev1 "k8s.io/api/core/v1" -) - const DefaultingConfigKey = "defaulting-config" type ResourcesPreset struct { @@ -39,119 +33,3 @@ type DefaultingConfig struct { BuildJob BuildJobDefaulting Runtime Runtime } - -func (fn *Function) Default(config *DefaultingConfig) { -} - -func (spec *FunctionSpec) defaultFunctionResources(config *DefaultingConfig, fn *Function) { - var resources *corev1.ResourceRequirements - var profile string - if spec.ResourceConfiguration != nil && spec.ResourceConfiguration.Function != nil { - functionResourceCfg := *spec.ResourceConfiguration.Function - if functionResourceCfg.Resources != nil { - resources = functionResourceCfg.Resources - } - profile = functionResourceCfg.Profile - } - defaultingConfig := config.Function.Resources - calculatedResources := calculateResources(fn, resources, profile, FunctionResourcesPresetLabel, defaultingConfig.Presets, defaultingConfig.DefaultPreset, defaultingConfig.RuntimePresets) - setFunctionResources(spec, calculatedResources) -} - -func setFunctionResources(spec *FunctionSpec, resources *corev1.ResourceRequirements) { - - if spec.ResourceConfiguration == nil { - spec.ResourceConfiguration = &ResourceConfiguration{} - } - - if spec.ResourceConfiguration.Function == nil { - spec.ResourceConfiguration.Function = &ResourceRequirements{} - } - - spec.ResourceConfiguration.Function.Resources = resources -} - -func (spec *FunctionSpec) defaultBuildResources(config *DefaultingConfig, fn *Function) { - // if build resources are not set by the user we don't default them. - // However, if only a part is set or the preset label is set, we should correctly set missing defaults. - if shouldSkipBuildResourcesDefault(fn) { - return - } - - var buildResourceCfg ResourceRequirements - if spec.ResourceConfiguration != nil && spec.ResourceConfiguration.Build != nil { - buildResourceCfg = *spec.ResourceConfiguration.Build - } - - defaultingConfig := config.BuildJob.Resources - calculatedResources := calculateResources(fn, buildResourceCfg.Resources, buildResourceCfg.Profile, BuildResourcesPresetLabel, defaultingConfig.Presets, defaultingConfig.DefaultPreset, nil) - - setBuildResources(spec, calculatedResources) -} - -func setBuildResources(spec *FunctionSpec, resources *corev1.ResourceRequirements) { - - if spec.ResourceConfiguration == nil { - spec.ResourceConfiguration = &ResourceConfiguration{} - } - - if spec.ResourceConfiguration.Build == nil { - spec.ResourceConfiguration.Build = &ResourceRequirements{} - } - - spec.ResourceConfiguration.Build.Resources = resources -} - -func shouldSkipBuildResourcesDefault(fn *Function) bool { - resourceCfg := fn.Spec.ResourceConfiguration.Build - _, hasPresetLabel := fn.Labels[BuildResourcesPresetLabel] - if hasPresetLabel { - return false - } - - if resourceCfg != nil { - if resourceCfg.Profile != "" { - return false - } - if resourceCfg.Resources != nil { - return resourceCfg.Resources.Limits == nil && resourceCfg.Resources.Requests == nil - } - } - return true -} - -func calculateResources(fn *Function, resourceRequirements *corev1.ResourceRequirements, profile string, presetLabel string, presets map[string]ResourcesPreset, defaultPreset string, runtimePreset map[string]string) *corev1.ResourceRequirements { - // profile has the highest priority - preset := profile - // we can use profile from label (deprecated) instead of new profile - if preset == "" { - preset = fn.GetLabels()[presetLabel] - } - if preset != "" { - return presetsToRequirements(presets[preset]) - } - // when no profile we use user defined resources - if resourceRequirements != nil { - return resourceRequirements - } - // we use default preset only when no profile and no resources - rtmPreset, ok := runtimePreset[string(fn.Spec.Runtime)] - if ok { - return presetsToRequirements(presets[rtmPreset]) - } - return presetsToRequirements(presets[defaultPreset]) -} - -func presetsToRequirements(preset ResourcesPreset) *corev1.ResourceRequirements { - result := corev1.ResourceRequirements{ - Limits: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse(preset.LimitCPU), - corev1.ResourceMemory: resource.MustParse(preset.LimitMemory), - }, - Requests: corev1.ResourceList{ - corev1.ResourceCPU: resource.MustParse(preset.RequestCPU), - corev1.ResourceMemory: resource.MustParse(preset.RequestMemory), - }, - } - return &result -} diff --git a/components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults_test.go b/components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults_test.go deleted file mode 100644 index fef1f7746dcb..000000000000 --- a/components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults_test.go +++ /dev/null @@ -1,474 +0,0 @@ -package v1alpha2 - -import ( - "testing" - - "github.com/stretchr/testify/require" - - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" -) - -func TestSetDefaults(t *testing.T) { - // these tests are not working right now and there is no sense in refactoring them - // because in the near future tests will be refactored - t.Skip() - - zero := int32(0) - one := int32(1) - two := int32(2) - - MRuntimeResourcesBuilder := ResourceRequirementsBuilder{}.Limits("100m", "128Mi").Requests("50m", "64Mi") - SRuntimeResourcesBuilder := ResourceRequirementsBuilder{}.Limits("50m", "64Mi").Requests("25m", "32Mi") - LRuntimeResources := ResourceRequirementsBuilder{}.Limits("200m", "256Mi").Requests("100m", "128Mi").BuildCoreV1() - MRuntimeResources := MRuntimeResourcesBuilder.BuildCoreV1() - - slowBuildResourcesBuilder := ResourceRequirementsBuilder{}.Limits("700m", "700Mi").Requests("350m", "350Mi") - - for testName, testData := range map[string]struct { - givenFunc Function - expectedFunc Function - }{ - "Should do nothing": { - givenFunc: Function{ - Spec: FunctionSpec{ - Runtime: NodeJs18, - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Limits("150m", "158Mi").Requests("90m", "84Mi").Build(), - Build: ResourceRequirementsBuilder{}.Limits("400m", "321Mi").Requests("374m", "300Mi").Build(), - }, - ScaleConfig: &ScaleConfig{ - MinReplicas: &two, - MaxReplicas: &two, - }, - }, - }, - expectedFunc: Function{Spec: FunctionSpec{ - Runtime: NodeJs18, - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Limits("150m", "158Mi").Requests("90m", "84Mi").Build(), - Build: ResourceRequirementsBuilder{}.Limits("400m", "321Mi").Requests("374m", "300Mi").Build(), - }, - ScaleConfig: &ScaleConfig{ - MinReplicas: &two, - MaxReplicas: &two, - }, - - Replicas: &two, - }, - }, - }, - "Should not change runtime type": { - givenFunc: Function{ - Spec: FunctionSpec{ - Runtime: Python39, - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Limits("150m", "158Mi").Requests("90m", "84Mi").Build(), - Build: ResourceRequirementsBuilder{}.Limits("400m", "321Mi").Requests("374m", "300Mi").Build(), - }, - ScaleConfig: &ScaleConfig{ - MinReplicas: &two, - MaxReplicas: &two, - }, - }, - }, - expectedFunc: Function{ - Spec: FunctionSpec{ - Runtime: Python39, - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Limits("150m", "158Mi").Requests("90m", "84Mi").Build(), - Build: ResourceRequirementsBuilder{}.Limits("400m", "321Mi").Requests("374m", "300Mi").Build(), - }, - ScaleConfig: &ScaleConfig{ - MinReplicas: &two, - MaxReplicas: &two, - }, - Replicas: &two, - }, - }, - }, - "Should not change empty runtime type to default": { - givenFunc: Function{ - Spec: FunctionSpec{ - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Limits("150m", "158Mi").Requests("90m", "84Mi").Build(), - Build: ResourceRequirementsBuilder{}.Limits("400m", "321Mi").Requests("374m", "300Mi").Build(), - }, - ScaleConfig: &ScaleConfig{ - MinReplicas: &two, - MaxReplicas: &two, - }, - }, - }, - expectedFunc: Function{ - Spec: FunctionSpec{ - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Limits("150m", "158Mi").Requests("90m", "84Mi").Build(), - Build: ResourceRequirementsBuilder{}.Limits("400m", "321Mi").Requests("374m", "300Mi").Build(), - }, - ScaleConfig: &ScaleConfig{ - MinReplicas: &two, - MaxReplicas: &two, - }, - Replicas: &two, - }, - }, - }, - "Should default minimal function": { - givenFunc: Function{}, - expectedFunc: Function{ - Spec: FunctionSpec{ - ResourceConfiguration: &ResourceConfiguration{ - Function: MRuntimeResourcesBuilder.Build(), - }, - Replicas: &one, - }, - }, - }, - "Should not fill missing resources": { - givenFunc: Function{ - Spec: FunctionSpec{ - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Requests("150m", "150Mi").Build(), - Build: ResourceRequirementsBuilder{}.Requests("1200m", "12000Mi").Build(), - }, - Replicas: &two, - }, - }, - expectedFunc: Function{ - Spec: FunctionSpec{ - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Requests("150m", "150Mi").Build(), - Build: ResourceRequirementsBuilder{}.Requests("1200m", "12000Mi").Build(), - }, - Replicas: &two, - }, - }, - }, - "should consider maxReplicas and limits": { - givenFunc: Function{ - Spec: FunctionSpec{ - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Limits("15m", "15Mi").Build(), - Build: ResourceRequirementsBuilder{}.Limits("800m", "800Mi").Build(), - }, - ScaleConfig: &ScaleConfig{ - MaxReplicas: &zero, - }, - }, - }, - expectedFunc: Function{ - Spec: FunctionSpec{ - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Limits("15m", "15Mi").Build(), - Build: ResourceRequirementsBuilder{}.Limits("800m", "800Mi").Build(), - }, - ScaleConfig: &ScaleConfig{ - MinReplicas: &zero, - MaxReplicas: &zero, - }, - Replicas: &zero, - }, - }, - }, - } { - t.Run(testName, func(t *testing.T) { - // given - config := fixDefaultingConfig() - - // when - testData.givenFunc.Default(config) - - // then - require.EqualValues(t, testData.expectedFunc, testData.givenFunc) - }) - } - - testCases := map[string]struct { - givenFunc Function - expectedFunc Function - }{ - "Should properly set resources presets (using labels) - case with all fields": { - givenFunc: Function{ - ObjectMeta: v1.ObjectMeta{ - Labels: map[string]string{ - FunctionResourcesPresetLabel: "S", - BuildResourcesPresetLabel: "slow", - }, - }, - Spec: FunctionSpec{ - Runtime: NodeJs18, - }, - }, - expectedFunc: Function{ - ObjectMeta: v1.ObjectMeta{ - Labels: map[string]string{ - FunctionResourcesPresetLabel: "S", - BuildResourcesPresetLabel: "slow", - }, - }, Spec: FunctionSpec{ - Runtime: NodeJs18, - ResourceConfiguration: &ResourceConfiguration{ - Function: SRuntimeResourcesBuilder.Build(), - Build: slowBuildResourcesBuilder.Build(), - }, - Replicas: &one, - }, - }, - }, - "Should properly set resources presets (using ResourceConfiguration..Preset) - case with all fields": { - givenFunc: Function{ - ObjectMeta: v1.ObjectMeta{}, - Spec: FunctionSpec{ - Runtime: NodeJs18, - ResourceConfiguration: &ResourceConfiguration{ - Build: &ResourceRequirements{ - Profile: "slow", - }, - Function: &ResourceRequirements{ - Profile: "S", - }, - }, - }, - }, - expectedFunc: Function{ - ObjectMeta: v1.ObjectMeta{}, Spec: FunctionSpec{ - Runtime: NodeJs18, - ResourceConfiguration: &ResourceConfiguration{ - Function: SRuntimeResourcesBuilder.Profile("S").Build(), - Build: slowBuildResourcesBuilder.Profile("slow").Build(), - }, - Replicas: &one, - }, - }, - }, - "Should overwrite custom resources by presets (using labels) - case with all fields": { - givenFunc: Function{ - ObjectMeta: v1.ObjectMeta{ - Labels: map[string]string{ - FunctionResourcesPresetLabel: "S", - BuildResourcesPresetLabel: "slow", - }, - }, - Spec: FunctionSpec{ - Runtime: NodeJs18, - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Requests("15m", "15Mi").Build(), - Build: ResourceRequirementsBuilder{}.Requests("250m", "250Mi").Build(), - }, - ScaleConfig: &ScaleConfig{ - MinReplicas: &two, - }, - }, - }, - expectedFunc: Function{ - ObjectMeta: v1.ObjectMeta{ - Labels: map[string]string{ - FunctionResourcesPresetLabel: "S", - BuildResourcesPresetLabel: "slow", - }, - }, Spec: FunctionSpec{ - Runtime: NodeJs18, - ResourceConfiguration: &ResourceConfiguration{ - Function: SRuntimeResourcesBuilder.Build(), - Build: slowBuildResourcesBuilder.Build(), - }, - Replicas: &two, - ScaleConfig: &ScaleConfig{ - MinReplicas: &two, - MaxReplicas: &two, - }, - }, - }, - }, - "Should overwrite custom resources by presets (using ResourceConfiguration..Preset) - case with all fields": { - givenFunc: Function{ - ObjectMeta: v1.ObjectMeta{}, - Spec: FunctionSpec{ - Runtime: NodeJs18, - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Requests("15m", "15Mi").Profile("S").Build(), - Build: ResourceRequirementsBuilder{}.Requests("250m", "250Mi").Profile("slow").Build(), - }, - Replicas: &two, - }, - }, - expectedFunc: Function{ - ObjectMeta: v1.ObjectMeta{}, - Spec: FunctionSpec{ - Runtime: NodeJs18, - ResourceConfiguration: &ResourceConfiguration{ - Function: SRuntimeResourcesBuilder.Profile("S").Build(), - Build: slowBuildResourcesBuilder.Profile("slow").Build(), - }, - Replicas: &two, - }, - }, - }, - "Should set function profile to function presets M instead of default L value (using labels)": { - givenFunc: Function{ - ObjectMeta: v1.ObjectMeta{ - Labels: map[string]string{ - FunctionResourcesPresetLabel: "M", - }, - }, - Spec: FunctionSpec{ - Runtime: Python39, - }, - }, - expectedFunc: Function{ - ObjectMeta: v1.ObjectMeta{ - Labels: map[string]string{ - FunctionResourcesPresetLabel: "M", - }, - }, - Spec: FunctionSpec{ - Runtime: Python39, - ResourceConfiguration: &ResourceConfiguration{ - Function: &ResourceRequirements{ - Resources: &MRuntimeResources, - }, - }, - Replicas: &one, - }}, - }, - "Should set function profile to function presets M instead of default L value (using ResourceConfiguration..Preset)": { - givenFunc: Function{ - ObjectMeta: v1.ObjectMeta{}, - Spec: FunctionSpec{ - Runtime: Python39, - ResourceConfiguration: &ResourceConfiguration{ - Function: ResourceRequirementsBuilder{}.Profile("M").Build(), - }, - }, - }, - expectedFunc: Function{ - ObjectMeta: v1.ObjectMeta{}, - Spec: FunctionSpec{ - Runtime: Python39, - ResourceConfiguration: &ResourceConfiguration{ - Function: &ResourceRequirements{ - Profile: "M", - Resources: &MRuntimeResources, - }, - }, - Replicas: &one, - }}, - }, - "Should set function profile to function default preset L": { - givenFunc: Function{ - ObjectMeta: v1.ObjectMeta{}, - Spec: FunctionSpec{ - Runtime: Python39, - }, - }, - expectedFunc: Function{ - ObjectMeta: v1.ObjectMeta{}, - Spec: FunctionSpec{ - Runtime: Python39, - ResourceConfiguration: &ResourceConfiguration{ - Function: &ResourceRequirements{ - Resources: &LRuntimeResources, - }, - }, - Replicas: &one, - }}, - }, - } - - for testName, testData := range testCases { - t.Run(testName, func(t *testing.T) { - // given - config := fixDefaultingConfig() - // when - testData.givenFunc.Default(config) - - // then - require.EqualValues(t, testData.expectedFunc, testData.givenFunc) - }) - } -} - -func fixDefaultingConfig() *DefaultingConfig { - return &DefaultingConfig{ - Function: FunctionDefaulting{ - Resources: FunctionResourcesDefaulting{ - DefaultPreset: "M", - Presets: map[string]ResourcesPreset{ - "S": {RequestCPU: "25m", RequestMemory: "32Mi", LimitCPU: "50m", LimitMemory: "64Mi"}, - "M": {RequestCPU: "50m", RequestMemory: "64Mi", LimitCPU: "100m", LimitMemory: "128Mi"}, - "L": {RequestCPU: "100m", RequestMemory: "128Mi", LimitCPU: "200m", LimitMemory: "256Mi"}, - }, - RuntimePresets: map[string]string{"python39": "L"}, - }, - }, - BuildJob: BuildJobDefaulting{ - Resources: BuildJobResourcesDefaulting{ - DefaultPreset: "normal", - Presets: map[string]ResourcesPreset{ - "slow": {RequestCPU: "350m", RequestMemory: "350Mi", LimitCPU: "700m", LimitMemory: "700Mi"}, - "normal": {RequestCPU: "700m", RequestMemory: "700Mi", LimitCPU: "1100m", LimitMemory: "1100Mi"}, - "fast": {RequestCPU: "1100m", RequestMemory: "1100Mi", LimitCPU: "1800m", LimitMemory: "1800Mi"}, - }, - }, - }, - } -} - -type ResourceRequirementsBuilder struct { - limitsCpu, limitsMemory, requestsCpu, requestsMemory, profile string -} - -func (b ResourceRequirementsBuilder) Limits(cpu, memory string) ResourceRequirementsBuilder { - b.limitsCpu = cpu - b.limitsMemory = memory - return b -} - -func (b ResourceRequirementsBuilder) Requests(cpu, memory string) ResourceRequirementsBuilder { - b.requestsCpu = cpu - b.requestsMemory = memory - return b -} - -func (b ResourceRequirementsBuilder) Profile(profile string) ResourceRequirementsBuilder { - b.profile = profile - return b -} - -func (b ResourceRequirementsBuilder) BuildCoreV1() corev1.ResourceRequirements { - limits := corev1.ResourceList{} - if b.limitsCpu != "" { - limits[corev1.ResourceCPU] = resource.MustParse(b.limitsCpu) - } - if b.limitsMemory != "" { - limits[corev1.ResourceMemory] = resource.MustParse(b.limitsMemory) - } - if len(limits) == 0 { - limits = nil - } - requests := corev1.ResourceList{} - if b.requestsCpu != "" { - requests[corev1.ResourceCPU] = resource.MustParse(b.requestsCpu) - } - if b.requestsMemory != "" { - requests[corev1.ResourceMemory] = resource.MustParse(b.requestsMemory) - } - if len(requests) == 0 { - requests = nil - } - return corev1.ResourceRequirements{ - Limits: limits, - Requests: requests, - } -} - -func (b ResourceRequirementsBuilder) Build() *ResourceRequirements { - res := b.BuildCoreV1() - return &ResourceRequirements{ - Resources: &res, - Profile: b.profile, - } -} diff --git a/components/function-controller/pkg/apis/serverless/v1alpha2/function_resources_test.go b/components/function-controller/pkg/apis/serverless/v1alpha2/function_resources_test.go new file mode 100644 index 000000000000..d16990fa5407 --- /dev/null +++ b/components/function-controller/pkg/apis/serverless/v1alpha2/function_resources_test.go @@ -0,0 +1,125 @@ +package v1alpha2_test + +import ( + serverlessv1alpha2 "github.com/kyma-project/kyma/components/function-controller/pkg/apis/serverless/v1alpha2" + "testing" + + "github.com/stretchr/testify/require" + + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" +) + +func Test_EffectiveResource(t *testing.T) { + + MRuntimeResourcesBuilder := ResourceRequirementsBuilder{}.Limits("100m", "128Mi").Requests("50m", "64Mi") + LRuntimeResources := ResourceRequirementsBuilder{}.Limits("200m", "256Mi").Requests("100m", "128Mi").BuildCoreV1() + MRuntimeResources := MRuntimeResourcesBuilder.BuildCoreV1() + + testCases := map[string]struct { + given *serverlessv1alpha2.ResourceRequirements + expected corev1.ResourceRequirements + }{ + "Should choose custom": { + given: ResourceRequirementsBuilder{}.Limits("150m", "158Mi").Requests("90m", "84Mi").Build(), + expected: ResourceRequirementsBuilder{}.Limits("150m", "158Mi").Requests("90m", "84Mi").BuildCoreV1(), + }, + "Should choose default profile": { + given: nil, + expected: MRuntimeResources, + }, + "Should choose declared profile ": { + given: &serverlessv1alpha2.ResourceRequirements{Profile: "L"}, + expected: LRuntimeResources, + }, + "Should choose default profile in case of not existing profile": { + given: &serverlessv1alpha2.ResourceRequirements{Profile: "NOT EXISTS"}, + expected: MRuntimeResources, + }, + } + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + // given + presets, defaultPreset := fixPresetsConfig() + + // when + effectiveResource := tc.given.EffectiveResource(defaultPreset, presets) + + // then + require.EqualValues(t, tc.expected, effectiveResource) + }) + } +} + +func fixPresetsConfig() (map[string]corev1.ResourceRequirements, string) { + return map[string]corev1.ResourceRequirements{ + "S": { + Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("50m"), corev1.ResourceMemory: resource.MustParse("64Mi")}, + Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("25m"), corev1.ResourceMemory: resource.MustParse("32Mi")}, + }, + "M": { + Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m"), corev1.ResourceMemory: resource.MustParse("128Mi")}, + Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("50m"), corev1.ResourceMemory: resource.MustParse("64Mi")}, + }, + "L": { + Limits: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("200m"), corev1.ResourceMemory: resource.MustParse("256Mi")}, + Requests: corev1.ResourceList{corev1.ResourceCPU: resource.MustParse("100m"), corev1.ResourceMemory: resource.MustParse("128Mi")}, + }, + }, "M" +} + +type ResourceRequirementsBuilder struct { + limitsCpu, limitsMemory, requestsCpu, requestsMemory, profile string +} + +func (b ResourceRequirementsBuilder) Limits(cpu, memory string) ResourceRequirementsBuilder { + b.limitsCpu = cpu + b.limitsMemory = memory + return b +} + +func (b ResourceRequirementsBuilder) Requests(cpu, memory string) ResourceRequirementsBuilder { + b.requestsCpu = cpu + b.requestsMemory = memory + return b +} + +func (b ResourceRequirementsBuilder) Profile(profile string) ResourceRequirementsBuilder { + b.profile = profile + return b +} + +func (b ResourceRequirementsBuilder) BuildCoreV1() corev1.ResourceRequirements { + limits := corev1.ResourceList{} + if b.limitsCpu != "" { + limits[corev1.ResourceCPU] = resource.MustParse(b.limitsCpu) + } + if b.limitsMemory != "" { + limits[corev1.ResourceMemory] = resource.MustParse(b.limitsMemory) + } + if len(limits) == 0 { + limits = nil + } + requests := corev1.ResourceList{} + if b.requestsCpu != "" { + requests[corev1.ResourceCPU] = resource.MustParse(b.requestsCpu) + } + if b.requestsMemory != "" { + requests[corev1.ResourceMemory] = resource.MustParse(b.requestsMemory) + } + if len(requests) == 0 { + requests = nil + } + return corev1.ResourceRequirements{ + Limits: limits, + Requests: requests, + } +} + +func (b ResourceRequirementsBuilder) Build() *serverlessv1alpha2.ResourceRequirements { + res := b.BuildCoreV1() + return &serverlessv1alpha2.ResourceRequirements{ + Resources: &res, + Profile: b.profile, + } +} From 24720af6a089cc2c1960c64b466cef0207ca5485 Mon Sep 17 00:00:00 2001 From: Damian Badura Date: Thu, 14 Sep 2023 14:47:31 +0200 Subject: [PATCH 2/3] bump image and remove old code --- .../internal/webhook/webhook_config.go | 60 ++--------------- .../serverless/charts/webhook/values.yaml | 64 +------------------ resources/serverless/values.yaml | 6 +- 3 files changed, 9 insertions(+), 121 deletions(-) diff --git a/components/function-controller/internal/webhook/webhook_config.go b/components/function-controller/internal/webhook/webhook_config.go index 1824f4550111..97acc2106a38 100644 --- a/components/function-controller/internal/webhook/webhook_config.go +++ b/components/function-controller/internal/webhook/webhook_config.go @@ -7,40 +7,20 @@ import ( "github.com/kyma-project/kyma/components/function-controller/pkg/apis/serverless/v1alpha2" "github.com/pkg/errors" "gopkg.in/yaml.v2" - "k8s.io/apimachinery/pkg/util/json" ) -type Replicas struct { - MinValue string `yaml:"minValue"` -} - -type ResourcePreset map[string]struct { - RequestCpu string `yaml:"requestCpu"` - RequestMemory string `yaml:"requestMemory"` - LimitMemory string `yaml:"limitMemory"` - LimitCpu string `yaml:"limitCpu"` -} - -type RuntimePreset map[string]string - type FunctionResources struct { - MinRequestCpu string `yaml:"minRequestCpu"` - MinRequestMemory string `yaml:"minRequestMemory"` - DefaultPreset string `yaml:"defaultPreset"` - Presets ResourcePreset `yaml:"presets"` - RuntimePresets RuntimePreset `yaml:"runtimePresets"` + MinRequestCpu string `yaml:"minRequestCpu"` + MinRequestMemory string `yaml:"minRequestMemory"` } type FunctionCfg struct { - Replicas Replicas `yaml:"replicas"` Resources FunctionResources `yaml:"resources"` } type BuildResources struct { - MinRequestCpu string `yaml:"minRequestCpu"` - MinRequestMemory string `yaml:"minRequestMemory"` - DefaultPreset string `yaml:"defaultPreset"` - Presets ResourcePreset `yaml:"presets"` + MinRequestCpu string `yaml:"minRequestCpu"` + MinRequestMemory string `yaml:"minRequestMemory"` } type BuildJob struct { @@ -55,12 +35,7 @@ type WebhookConfig struct { } func LoadWebhookCfg(path string) (WebhookConfig, error) { - cfg := WebhookConfig{ - DefaultRuntime: string(v1alpha2.NodeJs18), - Function: FunctionCfg{ - Resources: FunctionResources{DefaultPreset: "M"}}, - BuildJob: BuildJob{Resources: BuildResources{DefaultPreset: "normal"}}, - } + cfg := WebhookConfig{DefaultRuntime: string(v1alpha2.NodeJs18)} cleanPath := filepath.Clean(path) yamlFile, err := os.ReadFile(cleanPath) @@ -72,31 +47,6 @@ func LoadWebhookCfg(path string) (WebhookConfig, error) { return cfg, errors.Wrap(err, "while unmarshalling yaml") } -func (r *ResourcePreset) UnmarshalYAML(unmarshal func(interface{}) error) error { - rawPresets := "" - err := unmarshal(&rawPresets) - if err != nil { - return err - } - - if err := json.Unmarshal([]byte(rawPresets), r); err != nil { - return err - } - return nil -} - -func (rp *RuntimePreset) UnmarshalYAML(unmarshal func(interface{}) error) error { - rawPresets := "" - err := unmarshal(&rawPresets) - if err != nil { - return err - } - if err := json.Unmarshal([]byte(rawPresets), rp); err != nil { - return err - } - return nil -} - func (wc WebhookConfig) ToValidationConfig() v1alpha2.ValidationConfig { return v1alpha2.ValidationConfig{ ReservedEnvs: wc.ReservedEnvs, diff --git a/resources/serverless/charts/webhook/values.yaml b/resources/serverless/charts/webhook/values.yaml index ecb7067c1f69..e36380f6532c 100644 --- a/resources/serverless/charts/webhook/values.yaml +++ b/resources/serverless/charts/webhook/values.yaml @@ -107,71 +107,9 @@ values: resources: minRequestCpu: "10m" minRequestMemory: "16Mi" - defaultPreset: "L" - presets: |- - { - "XS": { - "requestCpu": "50m", - "requestMemory": "64Mi", - "limitCpu": "100m", - "limitMemory": "128Mi" - }, - "S": { - "requestCpu": "100m", - "requestMemory": "128Mi", - "limitCpu": "200m", - "limitMemory": "256Mi" - }, - "M": { - "requestCpu": "200m", - "requestMemory": "256Mi", - "limitCpu": "400m", - "limitMemory": "512Mi" - }, - "L": { - "requestCpu": "400m", - "requestMemory": "512Mi", - "limitCpu": "800m", - "limitMemory": "1024Mi" - }, - "XL": { - "requestCpu": "800m", - "requestMemory": "1024Mi", - "limitCpu": "1600m", - "limitMemory": "2048Mi" - } - } - runtimePresets: "{}" buildJob: resources: minRequestCpu: "200m" minRequestMemory: "200Mi" - defaultPreset: "fast" - presets: |- - { - "local-dev": { - "requestCpu": "200m", - "requestMemory": "200Mi", - "limitCpu": "400m", - "limitMemory": "400Mi" - }, - "slow": { - "requestCpu": "200m", - "requestMemory": "200Mi", - "limitCpu": "700m", - "limitMemory": "700Mi" - }, - "normal": { - "requestCpu": "700m", - "requestMemory": "700Mi", - "limitCpu": "1100m", - "limitMemory": "1100Mi" - }, - "fast": { - "requestCpu": "1100m", - "requestMemory": "1100Mi", - "limitCpu": "1700m", - "limitMemory": "1100Mi" - } - } + diff --git a/resources/serverless/values.yaml b/resources/serverless/values.yaml index 70591748c6c3..13bf66c95465 100644 --- a/resources/serverless/values.yaml +++ b/resources/serverless/values.yaml @@ -82,15 +82,15 @@ global: directory: "prod" function_controller: name: "function-controller" - version: "PR-18202" + version: "PR-18164" directory: "dev" function_webhook: name: "function-webhook" - version: "PR-18202" + version: "PR-18164" directory: "dev" function_build_init: name: "function-build-init" - version: "PR-18202" + version: "PR-18164" directory: "dev" function_registry_gc: name: "function-registry-gc" From 3e1ce58ec8b361322f7f27b876445f53d84c50d0 Mon Sep 17 00:00:00 2001 From: Damian Badura Date: Wed, 20 Sep 2023 10:49:04 +0200 Subject: [PATCH 3/3] remove code --- .../serverless/v1alpha2/function_defaults.go | 35 ------ .../v1alpha2/zz_generated.deepcopy.go | 115 ------------------ 2 files changed, 150 deletions(-) delete mode 100644 components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults.go diff --git a/components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults.go b/components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults.go deleted file mode 100644 index 56f331b7aac5..000000000000 --- a/components/function-controller/pkg/apis/serverless/v1alpha2/function_defaults.go +++ /dev/null @@ -1,35 +0,0 @@ -package v1alpha2 - -const DefaultingConfigKey = "defaulting-config" - -type ResourcesPreset struct { - RequestCPU string - RequestMemory string - LimitCPU string - LimitMemory string -} - -type FunctionResourcesDefaulting struct { - DefaultPreset string - Presets map[string]ResourcesPreset - RuntimePresets map[string]string -} - -type BuildJobResourcesDefaulting struct { - DefaultPreset string - Presets map[string]ResourcesPreset -} - -type FunctionDefaulting struct { - Resources FunctionResourcesDefaulting -} - -type BuildJobDefaulting struct { - Resources BuildJobResourcesDefaulting -} - -type DefaultingConfig struct { - Function FunctionDefaulting - BuildJob BuildJobDefaulting - Runtime Runtime -} diff --git a/components/function-controller/pkg/apis/serverless/v1alpha2/zz_generated.deepcopy.go b/components/function-controller/pkg/apis/serverless/v1alpha2/zz_generated.deepcopy.go index c559db327852..fe730d97137e 100644 --- a/components/function-controller/pkg/apis/serverless/v1alpha2/zz_generated.deepcopy.go +++ b/components/function-controller/pkg/apis/serverless/v1alpha2/zz_generated.deepcopy.go @@ -10,44 +10,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *BuildJobDefaulting) DeepCopyInto(out *BuildJobDefaulting) { - *out = *in - in.Resources.DeepCopyInto(&out.Resources) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BuildJobDefaulting. -func (in *BuildJobDefaulting) DeepCopy() *BuildJobDefaulting { - if in == nil { - return nil - } - out := new(BuildJobDefaulting) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *BuildJobResourcesDefaulting) DeepCopyInto(out *BuildJobResourcesDefaulting) { - *out = *in - if in.Presets != nil { - in, out := &in.Presets, &out.Presets - *out = make(map[string]ResourcesPreset, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BuildJobResourcesDefaulting. -func (in *BuildJobResourcesDefaulting) DeepCopy() *BuildJobResourcesDefaulting { - if in == nil { - return nil - } - out := new(BuildJobResourcesDefaulting) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Condition) DeepCopyInto(out *Condition) { *out = *in @@ -64,23 +26,6 @@ func (in *Condition) DeepCopy() *Condition { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DefaultingConfig) DeepCopyInto(out *DefaultingConfig) { - *out = *in - in.Function.DeepCopyInto(&out.Function) - in.BuildJob.DeepCopyInto(&out.BuildJob) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefaultingConfig. -func (in *DefaultingConfig) DeepCopy() *DefaultingConfig { - if in == nil { - return nil - } - out := new(DefaultingConfig) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Function) DeepCopyInto(out *Function) { *out = *in @@ -108,22 +53,6 @@ func (in *Function) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FunctionDefaulting) DeepCopyInto(out *FunctionDefaulting) { - *out = *in - in.Resources.DeepCopyInto(&out.Resources) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FunctionDefaulting. -func (in *FunctionDefaulting) DeepCopy() *FunctionDefaulting { - if in == nil { - return nil - } - out := new(FunctionDefaulting) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *FunctionList) DeepCopyInto(out *FunctionList) { *out = *in @@ -156,35 +85,6 @@ func (in *FunctionList) DeepCopyObject() runtime.Object { return nil } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FunctionResourcesDefaulting) DeepCopyInto(out *FunctionResourcesDefaulting) { - *out = *in - if in.Presets != nil { - in, out := &in.Presets, &out.Presets - *out = make(map[string]ResourcesPreset, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - if in.RuntimePresets != nil { - in, out := &in.RuntimePresets, &out.RuntimePresets - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FunctionResourcesDefaulting. -func (in *FunctionResourcesDefaulting) DeepCopy() *FunctionResourcesDefaulting { - if in == nil { - return nil - } - out := new(FunctionResourcesDefaulting) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *FunctionSpec) DeepCopyInto(out *FunctionSpec) { *out = *in @@ -443,21 +343,6 @@ func (in *ResourceRequirements) DeepCopy() *ResourceRequirements { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ResourcesPreset) DeepCopyInto(out *ResourcesPreset) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ResourcesPreset. -func (in *ResourcesPreset) DeepCopy() *ResourcesPreset { - if in == nil { - return nil - } - out := new(ResourcesPreset) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ScaleConfig) DeepCopyInto(out *ScaleConfig) { *out = *in