@@ -402,25 +402,22 @@ public async Task<T> ReplaceAsync<T>(
402
402
{
403
403
if ( modify == null ) throw new ArgumentNullException ( nameof ( modify ) ) ;
404
404
if ( _watchVersion != null ) throw new InvalidOperationException ( "Watches cannot be updated." ) ;
405
- KubernetesRequest putReq = null ;
406
- while ( true )
405
+ KubernetesRequest req = Clone ( ) ;
406
+ while ( true )
407
407
{
408
- if ( obj == null ) // if we need to load the resource...
408
+ if ( obj == null ) // if we need to load the resource...
409
409
{
410
- cancelToken . ThrowIfCancellationRequested ( ) ;
411
- HttpRequestMessage getMsg = await CreateRequestMessage ( cancelToken ) . ConfigureAwait ( false ) ; // load it with a GET request
412
- getMsg . Method = HttpMethod . Get ;
413
- obj = await ExecuteMessageAsync < T > ( getMsg , failIfMissing , cancelToken ) . ConfigureAwait ( false ) ;
410
+ cancelToken . ThrowIfCancellationRequested ( ) ; // load it with a GET request
411
+ obj = await req . Get ( ) . Body ( null ) . ExecuteAsync < T > ( failIfMissing , cancelToken ) . ConfigureAwait ( false ) ;
414
412
}
415
413
cancelToken . ThrowIfCancellationRequested ( ) ;
416
- // if the resource is missing or no changes are needed, return it as-is
417
- if ( obj == null || ! await modify ( obj , cancelToken ) . ConfigureAwait ( false ) ) return obj ;
418
- if ( putReq == null ) putReq = Clone ( ) . Put ( ) ;
419
- KubernetesResponse resp = await putReq . Body ( obj ) . ExecuteAsync ( cancelToken ) . ConfigureAwait ( false ) ; // otherwise, update it
420
- if ( resp . StatusCode != HttpStatusCode . Conflict ) // if there was no conflict, return the result
414
+ // if the resource is missing or no changes are needed, return it as-is. otherwise, update it with a PUT request
415
+ if ( obj == null || ! await modify ( obj , cancelToken ) . ConfigureAwait ( false ) ) return obj ;
416
+ KubernetesResponse resp = await req . Put ( ) . Body ( obj ) . ExecuteAsync ( cancelToken ) . ConfigureAwait ( false ) ;
417
+ if ( resp . StatusCode != HttpStatusCode . Conflict ) // if there was no conflict, return the result
421
418
{
422
- if ( resp . IsNotFound && ! failIfMissing ) return null ;
423
- else if ( resp . IsError ) throw new KubernetesException ( await resp . GetStatusAsync ( ) . ConfigureAwait ( false ) ) ;
419
+ if ( resp . IsNotFound && ! failIfMissing ) return null ;
420
+ else if ( resp . IsError ) throw new KubernetesException ( await resp . GetStatusAsync ( ) . ConfigureAwait ( false ) ) ;
424
421
else return await resp . GetBodyAsync < T > ( ) . ConfigureAwait ( false ) ;
425
422
}
426
423
obj = null ; // otherwise, there was a conflict, so reload the item
0 commit comments