@@ -15,19 +15,23 @@ import (
1515
1616func ConvertToPlatformMap (infraProfileConfigurationEntities []* repository.InfraProfileConfigurationEntity , profileName string ) (map [string ][]* bean.ConfigurationBean , error ) {
1717 // Validate input parameters
18- if infraProfileConfigurationEntities == nil {
18+ if len ( infraProfileConfigurationEntities ) == 0 {
1919 return nil , fmt .Errorf ("input infraProfileConfigurationEntities is empty" )
2020 }
2121 if profileName == "" {
2222 return nil , fmt .Errorf ("profileName cannot be empty" )
2323 }
2424 platformMap := make (map [string ][]* bean.ConfigurationBean )
2525 for _ , infraProfileConfiguration := range infraProfileConfigurationEntities {
26- configurationBean , err := getConfigurationBean (infraProfileConfiguration , profileName )
26+ if infraProfileConfiguration == nil {
27+ return nil , fmt .Errorf ("infraProfileConfiguration for profile %s is nil" , profileName )
28+ }
29+
30+ configurationBean , err := GetConfigurationBean (infraProfileConfiguration , profileName )
2731 if err != nil {
2832 return nil , fmt .Errorf ("failed to get configuration bean for profile from infraConfiguration '%s': %w" , profileName , err )
2933 }
30- platform := infraProfileConfiguration .Platform
34+ platform := infraProfileConfiguration .ProfilePlatformMapping . Platform
3135 if len (platform ) == 0 {
3236 platform = bean .RUNNER_PLATFORM
3337 }
@@ -72,25 +76,25 @@ func convertValueStringToInterface(configKey bean.ConfigKeyStr, valueString stri
7276 }
7377}
7478
75- func getConfigurationBean (infraProfileConfiguration * repository.InfraProfileConfigurationEntity , profileName string ) (* bean.ConfigurationBean , error ) {
79+ func GetConfigurationBean (infraProfileConfiguration * repository.InfraProfileConfigurationEntity , profileName string ) (* bean.ConfigurationBean , error ) {
7680 valueString := infraProfileConfiguration .ValueString
7781 //handle old values
7882 if len (valueString ) == 0 && infraProfileConfiguration .Unit > 0 {
7983 valueString = strconv .FormatFloat (infraProfileConfiguration .Value , 'f' , - 1 , 64 )
8084 }
81- valueInterface , err := convertValueStringToInterface (util .GetConfigKeyStr (infraProfileConfiguration .Key ), valueString )
85+ valueInterface , err := convertValueStringToInterface (utils .GetConfigKeyStr (infraProfileConfiguration .Key ), valueString )
8286 if err != nil {
8387 return & bean.ConfigurationBean {}, err
8488 }
8589 return & bean.ConfigurationBean {
8690 ConfigurationBeanAbstract : bean.ConfigurationBeanAbstract {
87- Id : infraProfileConfiguration .Id ,
88- Key : util .GetConfigKeyStr (infraProfileConfiguration .Key ),
89-
90- Unit : util . GetUnitSuffixStr ( infraProfileConfiguration . Key , infraProfileConfiguration .Unit ) ,
91- ProfileId : infraProfileConfiguration .ProfileId ,
92- Active : infraProfileConfiguration . Active ,
93- ProfileName : profileName ,
91+ Id : infraProfileConfiguration .Id ,
92+ Key : utils .GetConfigKeyStr (infraProfileConfiguration .Key ),
93+ Unit : utils . GetUnitSuffixStr ( infraProfileConfiguration . Key , infraProfileConfiguration . Unit ),
94+ Active : infraProfileConfiguration .Active ,
95+ ProfileId : infraProfileConfiguration . ProfilePlatformMapping .ProfileId ,
96+ ProfileName : profileName ,
97+ ProfilePlatformMappingId : infraProfileConfiguration . ProfilePlatformMapping . Id ,
9498 },
9599 Value : valueInterface ,
96100 }, nil
@@ -100,14 +104,19 @@ func getInfraProfileEntity(configurationBean *bean.ConfigurationBean, profileBea
100104
101105 infraProfile := & repository.InfraProfileConfigurationEntity {
102106 Id : configurationBean .Id ,
103- Key : util .GetConfigKey (configurationBean .Key ),
107+ Key : utils .GetConfigKey (configurationBean .Key ),
104108 ValueString : FormatTypedValueAsString (configurationBean .Key , configurationBean .Value ),
105- Unit : util .GetUnitSuffix (configurationBean .Key , configurationBean .Unit ),
106- ProfileId : profileBean .Id ,
107- Platform : platform ,
109+ Unit : utils .GetUnitSuffix (configurationBean .Key , configurationBean .Unit ),
108110 Active : configurationBean .Active ,
109- AuditLog : sql .NewDefaultAuditLog (userId ),
111+ UniqueId : repository .GetUniqueId (profileBean .Id , platform ),
112+ ProfileId : profileBean .Id , // maintained for backward compatibility
113+ ProfilePlatformMapping : & repository.ProfilePlatformMapping {
114+ ProfileId : profileBean .Id ,
115+ Platform : platform ,
116+ },
117+ AuditLog : sql .NewDefaultAuditLog (userId ),
110118 }
119+ setProfilePlatformMappingId (profileBean , infraProfile )
111120 if profileBean .Name == bean .GLOBAL_PROFILE_NAME {
112121 infraProfile .Active = true
113122 }
@@ -166,18 +175,19 @@ func GetV0ProfileBean(profileBean *bean.ProfileBeanDto) *bean.ProfileBeanV0 {
166175 ciRunnerConfig := profileBean .Configurations [bean .RUNNER_PLATFORM ]
167176 return & bean.ProfileBeanV0 {
168177 ProfileBeanAbstract : bean.ProfileBeanAbstract {
169- Id : profileBean .Id ,
170- Name : profileName ,
171- Description : profileBean .Description ,
172- Active : profileBean .Active ,
173- Type : profileType ,
174- AppCount : profileBean .AppCount ,
175- CreatedBy : profileBean .CreatedBy ,
176- CreatedOn : profileBean .CreatedOn ,
177- UpdatedBy : profileBean .UpdatedBy ,
178- UpdatedOn : profileBean .UpdatedOn ,
178+ Id : profileBean .Id ,
179+ Name : profileName ,
180+ Description : profileBean .Description ,
181+ BuildxDriverType : profileBean .BuildxDriverType ,
182+ Active : profileBean .Active ,
183+ Type : profileType ,
184+ AppCount : profileBean .AppCount ,
185+ CreatedBy : profileBean .CreatedBy ,
186+ CreatedOn : profileBean .CreatedOn ,
187+ UpdatedBy : profileBean .UpdatedBy ,
188+ UpdatedOn : profileBean .UpdatedOn ,
179189 },
180- Configurations : GetV0ConfigurationBeans (ciRunnerConfig , profileName ),
190+ Configurations : GetV0ConfigurationBeans (ciRunnerConfig ),
181191 }
182192
183193}
@@ -191,21 +201,22 @@ func GetV1ProfileBean(profileBean *bean.ProfileBeanV0) *bean.ProfileBeanDto {
191201 profileName = bean .GLOBAL_PROFILE_NAME
192202 }
193203 profileType := profileBean .Type
194- if profileType == bean .GLOBAL {
195- profileType = bean .DEFAULT
204+ if profileType == bean .DEFAULT {
205+ profileType = bean .GLOBAL
196206 }
197207 return & bean.ProfileBeanDto {
198208 ProfileBeanAbstract : bean.ProfileBeanAbstract {
199- Id : profileBean .Id ,
200- Name : profileName ,
201- Description : profileBean .Description ,
202- Active : profileBean .Active ,
203- Type : profileType ,
204- AppCount : profileBean .AppCount ,
205- CreatedBy : profileBean .CreatedBy ,
206- CreatedOn : profileBean .CreatedOn ,
207- UpdatedBy : profileBean .UpdatedBy ,
208- UpdatedOn : profileBean .UpdatedOn ,
209+ Id : profileBean .Id ,
210+ Name : profileName ,
211+ Description : profileBean .Description ,
212+ Active : profileBean .Active ,
213+ Type : profileType ,
214+ AppCount : profileBean .AppCount ,
215+ CreatedBy : profileBean .CreatedBy ,
216+ CreatedOn : profileBean .CreatedOn ,
217+ UpdatedBy : profileBean .UpdatedBy ,
218+ UpdatedOn : profileBean .UpdatedOn ,
219+ BuildxDriverType : profileBean .BuildxDriverType ,
209220 },
210221 Configurations : map [string ][]* bean.ConfigurationBean {bean .RUNNER_PLATFORM : GetV1ConfigurationBeans (profileBean .Configurations , profileName )},
211222 }
@@ -225,9 +236,9 @@ func GetV1ConfigurationBeans(configBeans []bean.ConfigurationBeanV0, profileName
225236 Id : configBean .Id ,
226237 Key : configBean .Key ,
227238 Unit : configBean .Unit ,
228- ProfileName : profileName ,
229- ProfileId : configBean .ProfileId ,
230239 Active : configBean .Active ,
240+ ProfileId : configBean .ProfileId ,
241+ ProfileName : profileName ,
231242 },
232243 Value : valueString ,
233244 }
@@ -236,24 +247,34 @@ func GetV1ConfigurationBeans(configBeans []bean.ConfigurationBeanV0, profileName
236247 return resp
237248}
238249
239- func GetV0ConfigurationBeans (configBeans []* bean.ConfigurationBean , profileName string ) []bean.ConfigurationBeanV0 {
250+ func GetV0ConfigurationBeans (configBeans []* bean.ConfigurationBean ) []bean.ConfigurationBeanV0 {
240251 if len (configBeans ) == 0 {
241252 return []bean.ConfigurationBeanV0 {}
242253 }
243254
244255 resp := make ([]bean.ConfigurationBeanV0 , 0 )
245256 for _ , configBean := range configBeans {
246- valueFloat , _ := configBean .Value .(float64 )
247- //valueFloat, _ := strconv.ParseFloat(configBean.Value, 64)
257+ // Use the GetTypedValue function to decode the value
258+ typedValue , _ := utils .GetTypedValue (configBean .Key , configBean .Value )
259+ // Cast the returned value to float64 for supported keys
260+ valueFloat , ok := typedValue .(float64 )
261+ if ! ok {
262+ //here skipping the value for the NodeSelectors and TolerationsKey
263+ continue
264+ }
265+ profileName := configBean .ProfileName
266+ if profileName == bean .GLOBAL_PROFILE_NAME {
267+ profileName = bean .DEFAULT_PROFILE_NAME
268+ }
248269
249270 beanv0 := bean.ConfigurationBeanV0 {
250271 ConfigurationBeanAbstract : bean.ConfigurationBeanAbstract {
251272 Id : configBean .Id ,
252273 Key : configBean .Key ,
253274 Unit : configBean .Unit ,
254- ProfileName : profileName ,
255- ProfileId : configBean .ProfileId ,
256275 Active : configBean .Active ,
276+ ProfileId : configBean .ProfileId ,
277+ ProfileName : profileName ,
257278 },
258279 Value : valueFloat ,
259280 }
@@ -269,24 +290,26 @@ func ConvertToProfileBean(infraProfile *repository.InfraProfileEntity) bean.Prof
269290 }
270291 return bean.ProfileBeanDto {
271292 ProfileBeanAbstract : bean.ProfileBeanAbstract {
272- Id : infraProfile .Id ,
273- Name : infraProfile .Name ,
274- Type : profileType ,
275- Description : infraProfile .Description ,
276- Active : infraProfile .Active ,
277- CreatedBy : infraProfile .CreatedBy ,
278- CreatedOn : infraProfile .CreatedOn ,
279- UpdatedBy : infraProfile .UpdatedBy ,
280- UpdatedOn : infraProfile .UpdatedOn ,
293+ Id : infraProfile .Id ,
294+ Name : infraProfile .Name ,
295+ Type : profileType ,
296+ Description : infraProfile .Description ,
297+ BuildxDriverType : infraProfile .BuildxDriverType ,
298+ Active : infraProfile .Active ,
299+ CreatedBy : infraProfile .CreatedBy ,
300+ CreatedOn : infraProfile .CreatedOn ,
301+ UpdatedBy : infraProfile .UpdatedBy ,
302+ UpdatedOn : infraProfile .UpdatedOn ,
281303 },
282304 }
283305}
284306
285307func ConvertToInfraProfileEntity (profileBean * bean.ProfileBeanDto ) * repository.InfraProfileEntity {
286308 return & repository.InfraProfileEntity {
287- Id : profileBean .Id ,
288- Name : profileBean .Name ,
289- Description : profileBean .Description ,
309+ Id : profileBean .Id ,
310+ Name : profileBean .Name ,
311+ Description : profileBean .Description ,
312+ BuildxDriverType : profileBean .BuildxDriverType ,
290313 }
291314}
292315
@@ -299,42 +322,25 @@ func LoadCiLimitCpu(infraConfig *bean.InfraConfig) (*repository.InfraProfileConf
299322 Key : bean .CPULimitKey ,
300323 ValueString : strconv .FormatFloat (val , 'f' , - 1 , 64 ),
301324 Unit : units .CPUUnitStr (suffix ).GetCPUUnit (),
302- Platform : bean .RUNNER_PLATFORM ,
325+ ProfilePlatformMapping : & repository.ProfilePlatformMapping {
326+ Platform : bean .RUNNER_PLATFORM ,
327+ },
303328 }, nil
304329
305330}
306331
307- func LoadInfraConfigInEntities (infraConfig * bean.InfraConfig ) ([]* repository.InfraProfileConfigurationEntity , error ) {
308- cpuLimit , err := LoadCiLimitCpu (infraConfig )
309- if err != nil {
310- return nil , err
311- }
312- memLimit , err := LoadCiLimitMem (infraConfig )
313- if err != nil {
314- return nil , err
315- }
316- cpuReq , err := LoadCiReqCpu (infraConfig )
317- if err != nil {
318- return nil , err
319- }
320- memReq , err := LoadCiReqMem (infraConfig )
321- if err != nil {
322- return nil , err
323- }
324- timeout , err := LoadDefaultTimeout (infraConfig )
332+ func LoadCiLimitMem (infraConfig * bean.InfraConfig ) (* repository.InfraProfileConfigurationEntity , error ) {
333+ val , suffix , err := units .ParseValAndUnit (infraConfig .CiLimitMem )
325334 if err != nil {
326335 return nil , err
327336 }
328- defaultConfigurations := []* repository.InfraProfileConfigurationEntity {cpuLimit , memLimit , cpuReq , memReq , timeout }
329- return defaultConfigurations , nil
330- }
331-
332- func LoadDefaultTimeout (infraConfig * bean.InfraConfig ) (* repository.InfraProfileConfigurationEntity , error ) {
333337 return & repository.InfraProfileConfigurationEntity {
334- Key : bean .TimeOutKey ,
335- ValueString : strconv .FormatInt (infraConfig .CiDefaultTimeout , 10 ),
336- Unit : units .SecondStr .GetTimeUnit (),
337- Platform : bean .RUNNER_PLATFORM ,
338+ Key : bean .MemoryLimitKey ,
339+ ValueString : strconv .FormatFloat (val , 'f' , - 1 , 64 ),
340+ Unit : units .MemoryUnitStr (suffix ).GetMemoryUnit (),
341+ ProfilePlatformMapping : & repository.ProfilePlatformMapping {
342+ Platform : bean .RUNNER_PLATFORM ,
343+ },
338344 }, nil
339345}
340346
@@ -347,7 +353,9 @@ func LoadCiReqCpu(infraConfig *bean.InfraConfig) (*repository.InfraProfileConfig
347353 Key : bean .CPURequestKey ,
348354 ValueString : strconv .FormatFloat (val , 'f' , - 1 , 64 ),
349355 Unit : units .CPUUnitStr (suffix ).GetCPUUnit (),
350- Platform : bean .RUNNER_PLATFORM ,
356+ ProfilePlatformMapping : & repository.ProfilePlatformMapping {
357+ Platform : bean .RUNNER_PLATFORM ,
358+ },
351359 }, nil
352360}
353361
@@ -361,20 +369,53 @@ func LoadCiReqMem(infraConfig *bean.InfraConfig) (*repository.InfraProfileConfig
361369 Key : bean .MemoryRequestKey ,
362370 ValueString : strconv .FormatFloat (val , 'f' , - 1 , 64 ),
363371 Unit : units .MemoryUnitStr (suffix ).GetMemoryUnit (),
364- Platform : bean .RUNNER_PLATFORM ,
372+ ProfilePlatformMapping : & repository.ProfilePlatformMapping {
373+ Platform : bean .RUNNER_PLATFORM ,
374+ },
365375 }, nil
366376}
367377
368- func LoadCiLimitMem (infraConfig * bean.InfraConfig ) (* repository.InfraProfileConfigurationEntity , error ) {
369- val , suffix , err := units .ParseValAndUnit (infraConfig .CiLimitMem )
378+ func LoadDefaultTimeout (infraConfig * bean.InfraConfig ) (* repository.InfraProfileConfigurationEntity , error ) {
379+ return & repository.InfraProfileConfigurationEntity {
380+ Key : bean .TimeOutKey ,
381+ ValueString : strconv .FormatInt (infraConfig .CiDefaultTimeout , 10 ),
382+ Unit : units .SecondStr .GetTimeUnit (),
383+ ProfilePlatformMapping : & repository.ProfilePlatformMapping {
384+ Platform : bean .RUNNER_PLATFORM ,
385+ },
386+ }, nil
387+ }
388+ func LoadInfraConfigInEntities (infraConfig * bean.InfraConfig , nodeSelectorLabel []string , taintKey , taintValue string ) ([]* repository.InfraProfileConfigurationEntity , error ) {
389+ cpuLimit , err := LoadCiLimitCpu (infraConfig )
370390 if err != nil {
371391 return nil , err
372392 }
373- return & repository.InfraProfileConfigurationEntity {
374- Key : bean .MemoryLimitKey ,
375- ValueString : strconv .FormatFloat (val , 'f' , - 1 , 64 ),
376- Unit : units .MemoryUnitStr (suffix ).GetMemoryUnit (),
377- Platform : bean .RUNNER_PLATFORM ,
378- }, nil
393+ memLimit , err := LoadCiLimitMem (infraConfig )
394+ if err != nil {
395+ return nil , err
396+ }
397+ cpuReq , err := LoadCiReqCpu (infraConfig )
398+ if err != nil {
399+ return nil , err
400+ }
401+ memReq , err := LoadCiReqMem (infraConfig )
402+ if err != nil {
403+ return nil , err
404+ }
405+ timeout , err := LoadDefaultTimeout (infraConfig )
406+ if err != nil {
407+ return nil , err
408+ }
409+ defaultConfigurations := []* repository.InfraProfileConfigurationEntity {cpuLimit , memLimit , cpuReq , memReq , timeout }
410+ return defaultConfigurations , nil
411+ }
412+ func setProfilePlatformMappingId (defaultProfile * bean.ProfileBeanDto , infraConfiguration * repository.InfraProfileConfigurationEntity ) {
379413
414+ runnerPlatformConfig := defaultProfile .Configurations [bean .RUNNER_PLATFORM ]
415+ for _ , runnerConfig := range runnerPlatformConfig {
416+ if runnerConfig .Key == utils .GetConfigKeyStr (infraConfiguration .Key ) {
417+ //setting hte ppm id and Profile Id
418+ infraConfiguration .ProfilePlatformMappingId = runnerConfig .ProfilePlatformMappingId
419+ }
420+ }
380421}
0 commit comments