1
1
package webhook
2
2
3
3
import (
4
+ "os"
5
+ "path/filepath"
6
+
4
7
"github.com/kyma-project/kyma/components/function-controller/pkg/apis/serverless/v1alpha2"
5
8
"github.com/pkg/errors"
6
9
"gopkg.in/yaml.v2"
7
10
"k8s.io/apimachinery/pkg/util/json"
8
- "os"
9
- "path/filepath"
10
- "strconv"
11
11
)
12
12
13
- type ReplicasPreset map [string ]struct {
14
- Min int32 `yaml:"min"`
15
- Max int32 `yaml:"max"`
16
- }
17
-
18
13
type Replicas struct {
19
- MinValue string `yaml:"minValue"`
20
- DefaultPreset string `yaml:"defaultPreset"`
21
- Presets ReplicasPreset `yaml:"presets"`
14
+ MinValue string `yaml:"minValue"`
22
15
}
23
16
24
17
type ResourcePreset map [string ]struct {
@@ -65,7 +58,6 @@ func LoadWebhookCfg(path string) (WebhookConfig, error) {
65
58
cfg := WebhookConfig {
66
59
DefaultRuntime : string (v1alpha2 .NodeJs18 ),
67
60
Function : FunctionCfg {
68
- Replicas : Replicas {DefaultPreset : "S" },
69
61
Resources : FunctionResources {DefaultPreset : "M" }},
70
62
BuildJob : BuildJob {Resources : BuildResources {DefaultPreset : "normal" }},
71
63
}
@@ -93,18 +85,6 @@ func (r *ResourcePreset) UnmarshalYAML(unmarshal func(interface{}) error) error
93
85
return nil
94
86
}
95
87
96
- func (rp * ReplicasPreset ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
97
- rawPresets := ""
98
- err := unmarshal (& rawPresets )
99
- if err != nil {
100
- return err
101
- }
102
- if err := json .Unmarshal ([]byte (rawPresets ), rp ); err != nil {
103
- return err
104
- }
105
- return nil
106
- }
107
-
108
88
func (rp * RuntimePreset ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
109
89
rawPresets := ""
110
90
err := unmarshal (& rawPresets )
@@ -117,17 +97,10 @@ func (rp *RuntimePreset) UnmarshalYAML(unmarshal func(interface{}) error) error
117
97
return nil
118
98
}
119
99
120
- func (wc WebhookConfig ) ToValidationConfig () (v1alpha2.ValidationConfig , error ) {
121
- minReplicas , err := strconv .Atoi (wc .Function .Replicas .MinValue )
122
- if err != nil {
123
- return v1alpha2.ValidationConfig {}, nil
124
- }
125
- cfg := v1alpha2.ValidationConfig {
100
+ func (wc WebhookConfig ) ToValidationConfig () v1alpha2.ValidationConfig {
101
+ return v1alpha2.ValidationConfig {
126
102
ReservedEnvs : wc .ReservedEnvs ,
127
103
Function : v1alpha2.MinFunctionValues {
128
- Replicas : v1alpha2.MinFunctionReplicasValues {
129
- MinValue : int32 (minReplicas ),
130
- },
131
104
Resources : v1alpha2.MinFunctionResourcesValues {
132
105
MinRequestCPU : wc .Function .Resources .MinRequestCpu ,
133
106
MinRequestMemory : wc .Function .Resources .MinRequestMemory ,
@@ -140,17 +113,12 @@ func (wc WebhookConfig) ToValidationConfig() (v1alpha2.ValidationConfig, error)
140
113
},
141
114
},
142
115
}
143
- return cfg , nil
144
116
}
145
117
146
118
func (wc WebhookConfig ) ToDefaultingConfig () (v1alpha2.DefaultingConfig , error ) {
147
119
cfg := v1alpha2.DefaultingConfig {
148
120
Runtime : v1alpha2 .Runtime (wc .DefaultRuntime ),
149
121
Function : v1alpha2.FunctionDefaulting {
150
- Replicas : v1alpha2.FunctionReplicasDefaulting {
151
- DefaultPreset : wc .Function .Replicas .DefaultPreset ,
152
- Presets : wc .Function .Replicas .Presets .toDefaultingReplicaPreset (),
153
- },
154
122
Resources : v1alpha2.FunctionResourcesDefaulting {
155
123
DefaultPreset : wc .Function .Resources .DefaultPreset ,
156
124
Presets : wc .Function .Resources .Presets .toDefaultingResourcePreset (),
@@ -167,17 +135,6 @@ func (wc WebhookConfig) ToDefaultingConfig() (v1alpha2.DefaultingConfig, error)
167
135
return cfg , nil
168
136
}
169
137
170
- func (rp ReplicasPreset ) toDefaultingReplicaPreset () map [string ]v1alpha2.ReplicasPreset {
171
- out := map [string ]v1alpha2.ReplicasPreset {}
172
- for k , v := range rp {
173
- out [k ] = v1alpha2.ReplicasPreset {
174
- Min : v .Min ,
175
- Max : v .Max ,
176
- }
177
- }
178
- return out
179
- }
180
-
181
138
func (rp ResourcePreset ) toDefaultingResourcePreset () map [string ]v1alpha2.ResourcesPreset {
182
139
out := map [string ]v1alpha2.ResourcesPreset {}
183
140
for k , v := range rp {
0 commit comments