@@ -49,45 +49,63 @@ func proveBenchmarkReferenceFenceOnServingAPIs(ctx context.Context, c client, re
4949}
5050
5151func proveBenchmarkFenceOnServingAPIs (ctx context.Context , c client , record benchmarkRecord , policy object , receipt benchmarkFenceReceipt , probe func (context.Context , * http.Client , * url.URL ) error ) error {
52- source := record .mutationSource ()
52+ originalRun := ""
53+ if record .Recovery != nil {
54+ originalRun = record .Run
55+ }
56+ return proveReferenceFenceOnServingAPIs (ctx , c , record .mutationSource (), originalRun , policy , receipt , probe )
57+ }
58+
59+ func proveReferenceFenceOnServingAPIs (ctx context.Context , c client , source , originalRun string , policy object , receipt benchmarkFenceReceipt , probe func (context.Context , * http.Client , * url.URL ) error ) error {
60+ _ , err := proveReferenceFenceForRoster (ctx , c , source , originalRun , policy , receipt , nil , probe )
61+ return err
62+ }
63+
64+ func proveReferenceFenceForRoster (ctx context.Context , c client , source , originalRun string , policy object , receipt benchmarkFenceReceipt , expected []benchmarkAPIServer , probe func (context.Context , * http.Client , * url.URL ) error ) (benchmarkAdmissionEpoch , error ) {
5365 if err := sourceCurrent (ctx , c .run , source ); err != nil {
54- return err
66+ return benchmarkAdmissionEpoch {}, err
5567 }
5668 before , err := observeBenchmarkReferenceFence (ctx , c , policy , receipt )
5769 if err != nil {
58- return err
70+ return benchmarkAdmissionEpoch {}, err
5971 }
6072 roster , err := observeBenchmarkAPIServers (ctx , c )
6173 if err != nil {
62- return err
74+ return benchmarkAdmissionEpoch {}, err
6375 }
64- if err := verifyBenchmarkProviderEndpoints ( ctx , os . Getenv ( "HCLOUD_TOKEN" ) , roster ); err != nil {
65- return err
76+ if expected != nil && ! slices . Equal ( expected , roster ) {
77+ return benchmarkAdmissionEpoch {}, errors . New ( "serving API processes changed between admission proofs" )
6678 }
67- originalRun := ""
68- if record .Recovery != nil {
69- originalRun = record .Run
79+ if err := verifyBenchmarkProviderEndpoints (ctx , os .Getenv ("HCLOUD_TOKEN" ), roster ); err != nil {
80+ return benchmarkAdmissionEpoch {}, err
7081 }
7182 for _ , endpoint := range roster {
7283 direct , address , err := namespaceinventory .LoadBenchmarkAdmissionClient (os .Getenv , endpoint .ExternalIP , originalRun )
7384 if err != nil {
74- return err
85+ return benchmarkAdmissionEpoch {}, err
7586 }
7687 proof := probe (ctx , direct , address )
7788 direct .CloseIdleConnections ()
7889 if proof != nil {
79- return proof
90+ return benchmarkAdmissionEpoch {}, proof
8091 }
8192 }
82- after , err := observeBenchmarkAPIServers (ctx , c )
83- if err != nil || ! slices .Equal (roster , after ) {
84- return errors .New ("serving API processes changed during benchmark admission proof" )
93+ if err := rebindBenchmarkAPIServers (ctx , c , roster ); err != nil {
94+ return benchmarkAdmissionEpoch {}, err
8595 }
8696 bound , err := observeBenchmarkReferenceFence (ctx , c , policy , receipt )
8797 if err != nil || before != bound {
88- return errors .New ("the benchmark reference fence changed during native admission proof" )
98+ return benchmarkAdmissionEpoch {}, errors .New ("the benchmark reference fence changed during native admission proof" )
99+ }
100+ return before , sourceCurrent (ctx , c .run , source )
101+ }
102+
103+ func rebindBenchmarkAPIServers (ctx context.Context , c client , expected []benchmarkAPIServer ) error {
104+ actual , err := observeBenchmarkAPIServers (ctx , c )
105+ if err != nil || len (expected ) != benchmarkControlPlaneCount || ! slices .Equal (expected , actual ) {
106+ return errors .New ("serving API processes changed during benchmark admission proof" )
89107 }
90- return sourceCurrent ( ctx , c . run , source )
108+ return nil
91109}
92110
93111func observeBenchmarkReferenceFence (ctx context.Context , c client , desired object , receipt benchmarkFenceReceipt ) (benchmarkAdmissionEpoch , error ) {
@@ -182,22 +200,26 @@ func probeBenchmarkDetachedBackendAdmission(ctx context.Context, client *http.Cl
182200// Keep the native response in bounded memory. The caller accepts only its
183201// fixed object or admission-policy status and never emits the response.
184202func benchmarkAdmissionDryRun (ctx context.Context , client * http.Client , endpoint * url.URL , path string , operations []object ) (int , []byte , error ) {
203+ return benchmarkAdmissionRequest (ctx , client , endpoint , path , http .MethodPatch , "application/json-patch+json" , operations )
204+ }
205+
206+ func benchmarkAdmissionRequest (ctx context.Context , client * http.Client , endpoint * url.URL , path , method , contentType string , body any ) (int , []byte , error ) {
185207 const limit = 2 << 20
186208 unverified := errors .New ("native admission dry-run did not return a bounded response" )
187209 if client == nil || endpoint == nil || endpoint .Scheme != "https" || endpoint .Host == "" || endpoint .User != nil {
188210 return 0 , nil , unverified
189211 }
190212 destination := url.URL {Scheme : "https" , Host : endpoint .Host , Path : path , RawQuery : "dryRun=All" }
191- payload , err := json .Marshal (operations )
213+ payload , err := json .Marshal (body )
192214 if err != nil {
193215 return 0 , nil , unverified
194216 }
195- req , err := http .NewRequestWithContext (ctx , http . MethodPatch , destination .String (), bytes .NewReader (payload ))
217+ req , err := http .NewRequestWithContext (ctx , method , destination .String (), bytes .NewReader (payload ))
196218 if err != nil {
197219 return 0 , nil , unverified
198220 }
199221 req .Header .Set ("Accept" , "application/json" )
200- req .Header .Set ("Content-Type" , "application/json-patch+json" )
222+ req .Header .Set ("Content-Type" , contentType )
201223 res , err := client .Do (req )
202224 if err != nil {
203225 return 0 , nil , unverified
0 commit comments