@@ -504,45 +504,78 @@ void Cleanup()
504
504
{
505
505
Cleanup ( ) ;
506
506
507
- await genericPods . CreateNamespacedAsync (
508
- new V1Pod ( )
509
- {
510
- Metadata = new V1ObjectMeta { Name = podName , } ,
511
- Spec = new V1PodSpec
507
+ // create + list
508
+ {
509
+ await genericPods . CreateNamespacedAsync (
510
+ new V1Pod ( )
512
511
{
513
- Containers = new [ ] { new V1Container ( ) { Name = "k8scsharp-e2e" , Image = "nginx" , } , } ,
512
+ Metadata = new V1ObjectMeta { Name = podName , Labels = new Dictionary < string , string > { { "place" , "holder" } , } , } ,
513
+ Spec = new V1PodSpec
514
+ {
515
+ Containers = new [ ] { new V1Container ( ) { Name = "k8scsharp-e2e" , Image = "nginx" , } , } ,
516
+ } ,
514
517
} ,
515
- } ,
516
- namespaceParameter ) . ConfigureAwait ( false ) ;
518
+ namespaceParameter ) . ConfigureAwait ( false ) ;
517
519
518
- var pods = await genericPods . ListNamespacedAsync < V1PodList > ( namespaceParameter ) . ConfigureAwait ( false ) ;
519
- Assert . Contains ( pods . Items , p => p . Metadata . Name == podName ) ;
520
+ var pods = await genericPods . ListNamespacedAsync < V1PodList > ( namespaceParameter ) . ConfigureAwait ( false ) ;
521
+ Assert . Contains ( pods . Items , p => p . Metadata . Name == podName ) ;
522
+ }
520
523
521
- int retry = 5 ;
522
- while ( retry -- > 0 )
524
+ // replace + get
523
525
{
524
- try
525
- {
526
- await genericPods . DeleteNamespacedAsync < V1Pod > ( namespaceParameter , podName ) . ConfigureAwait ( false ) ;
527
- }
528
- catch ( HttpOperationException e )
526
+ var pod = await genericPods . ReadNamespacedAsync < V1Pod > ( namespaceParameter , podName ) . ConfigureAwait ( false ) ;
527
+ var old = JsonSerializer . SerializeToDocument ( pod ) ;
528
+
529
+ var newlabels = new Dictionary < string , string > ( pod . Metadata . Labels ) { [ "test" ] = "generic-test-jsonpatch" } ;
530
+ pod . Metadata . Labels = newlabels ;
531
+
532
+ var expected = JsonSerializer . SerializeToDocument ( pod ) ;
533
+ var patch = old . CreatePatch ( expected ) ;
534
+
535
+ await genericPods . PatchNamespacedAsync < V1Pod > ( new V1Patch ( patch , V1Patch . PatchType . JsonPatch ) , namespaceParameter , podName ) . ConfigureAwait ( false ) ;
536
+ var pods = await genericPods . ListNamespacedAsync < V1PodList > ( namespaceParameter ) . ConfigureAwait ( false ) ;
537
+ Assert . Contains ( pods . Items , p => p . Labels ( ) . Contains ( new KeyValuePair < string , string > ( "test" , "generic-test-jsonpatch" ) ) ) ;
538
+ }
539
+
540
+ // replace + get
541
+ {
542
+ var pod = await genericPods . ReadNamespacedAsync < V1Pod > ( namespaceParameter , podName ) . ConfigureAwait ( false ) ;
543
+ pod . Spec . Containers [ 0 ] . Image = "httpd" ;
544
+ await genericPods . ReplaceNamespacedAsync ( pod , namespaceParameter , podName ) . ConfigureAwait ( false ) ;
545
+
546
+ pod = await genericPods . ReadNamespacedAsync < V1Pod > ( namespaceParameter , podName ) . ConfigureAwait ( false ) ;
547
+ Assert . Equal ( "httpd" , pod . Spec . Containers [ 0 ] . Image ) ;
548
+ }
549
+
550
+ // delete + list
551
+ {
552
+ V1PodList pods = new V1PodList ( ) ;
553
+ int retry = 5 ;
554
+ while ( retry -- > 0 )
529
555
{
530
- if ( e . Response . StatusCode == System . Net . HttpStatusCode . NotFound )
556
+ try
531
557
{
532
- return ;
558
+ await genericPods . DeleteNamespacedAsync < V1Pod > ( namespaceParameter , podName ) . ConfigureAwait ( false ) ;
559
+ }
560
+ catch ( HttpOperationException e )
561
+ {
562
+ if ( e . Response . StatusCode == System . Net . HttpStatusCode . NotFound )
563
+ {
564
+ return ;
565
+ }
533
566
}
534
- }
535
567
536
- pods = await genericPods . ListNamespacedAsync < V1PodList > ( namespaceParameter ) . ConfigureAwait ( false ) ;
537
- if ( ! pods . Items . Any ( p => p . Metadata . Name == podName ) )
538
- {
539
- break ;
568
+ pods = await genericPods . ListNamespacedAsync < V1PodList > ( namespaceParameter ) . ConfigureAwait ( false ) ;
569
+ if ( ! pods . Items . Any ( p => p . Metadata . Name == podName ) )
570
+ {
571
+ break ;
572
+ }
573
+
574
+ await Task . Delay ( TimeSpan . FromSeconds ( 2.5 ) ) . ConfigureAwait ( false ) ;
540
575
}
541
576
542
- await Task . Delay ( TimeSpan . FromSeconds ( 2.5 ) ) . ConfigureAwait ( false ) ;
577
+ Assert . DoesNotContain ( pods . Items , p => p . Metadata . Name == podName ) ;
543
578
}
544
-
545
- Assert . DoesNotContain ( pods . Items , p => p . Metadata . Name == podName ) ;
546
579
}
547
580
finally
548
581
{
0 commit comments