11using RestEase ;
22using SmoothSailing ;
33using WireMock . Client ;
4+ using System . Text ;
45
56namespace GrpcTestKit . TestConnectors . Kubernetes ;
67
@@ -25,17 +26,60 @@ public async Task<GrpcMockServerConnectionInfo> Install()
2526 {
2627 var allProtoFile = Directory . EnumerateFiles ( _protoDirectory , "*.proto" , SearchOption . AllDirectories ) ;
2728
29+ const int maxConfigMapSizeBytes = 512 * 1024 ; // 0.5 MB
30+ var configMaps = new List < object > ( ) ;
31+ var currentConfigMapFiles = new List < object > ( ) ;
32+ var currentConfigMapSize = 0 ;
33+ var configMapIndex = 0 ;
34+
35+ foreach ( var protoFile in allProtoFile )
36+ {
37+ var content = File . ReadAllText ( protoFile ) ;
38+ var path = protoFile . Remove ( 0 , _protoDirectory . Length ) . Replace ( "\\ " , "/" ) . Trim ( '/' ) ;
39+ var key = Guid . NewGuid ( ) . ToString ( "N" ) ;
40+
41+ // Estimate size (content + some overhead for YAML structure)
42+ var estimatedSize = Encoding . UTF8 . GetByteCount ( content ) + Encoding . UTF8 . GetByteCount ( key ) + Encoding . UTF8 . GetByteCount ( path ) + 100 ;
43+
44+ // If adding this file would exceed the limit and we already have files, start a new ConfigMap
45+ if ( currentConfigMapFiles . Count > 0 && currentConfigMapSize + estimatedSize > maxConfigMapSizeBytes )
46+ {
47+ configMaps . Add ( new
48+ {
49+ index = configMapIndex ,
50+ files = currentConfigMapFiles . ToArray ( )
51+ } ) ;
52+
53+ currentConfigMapFiles = new List < object > ( ) ;
54+ currentConfigMapSize = 0 ;
55+ configMapIndex ++ ;
56+ }
57+
58+ currentConfigMapFiles . Add ( new
59+ {
60+ key = key ,
61+ path = path ,
62+ content = content
63+ } ) ;
64+ currentConfigMapSize += estimatedSize ;
65+ }
66+
67+ // Add the last ConfigMap if it has any files
68+ if ( currentConfigMapFiles . Count > 0 )
69+ {
70+ configMaps . Add ( new
71+ {
72+ index = configMapIndex ,
73+ files = currentConfigMapFiles . ToArray ( )
74+ } ) ;
75+ }
76+
2877 var overrides = new
2978 {
3079 dockerImage = _settings . DockerImage ,
3180 grpcPort = _settings . GrpcPort ,
3281 stubbingPort = _settings . StubbingPort ,
33- protoFiles = allProtoFile . Select ( x => new
34- {
35- key = Guid . NewGuid ( ) . ToString ( "N" ) ,
36- path = x . Remove ( 0 , _protoDirectory . Length ) . Replace ( "\\ " , "/" ) . Trim ( '/' ) ,
37- content = File . ReadAllText ( x )
38- } ) . ToArray ( )
82+ configMaps = configMaps . ToArray ( )
3983 } ;
4084
4185 _release = await _chartInstaller . Install ( _chart , _settings . ReleaseName , overrides , context : _settings . Context ) ;
0 commit comments