@@ -679,22 +679,30 @@ func TestServerSideApplyWithDefaulting(t *testing.T) {
679
679
g .Expect (env .CleanupAndWait (ctx , mutatingWebhookConfiguration )).To (Succeed ())
680
680
}()
681
681
682
+ // Test if web hook is working
683
+ // NOTE: we are doing this no matter of defaultOriginal to make sure that the web hook is up and running
684
+ // before calling NewServerSidePatchHelper down below.
685
+ g .Eventually (ctx , func (g Gomega ) {
686
+ kct2 := kct .DeepCopy ()
687
+ kct2 .Name = fmt .Sprintf ("%s-2" , kct .Name )
688
+ g .Expect (env .Create (ctx , kct2 , client .DryRunAll )).To (Succeed ())
689
+ g .Expect (kct2 .Spec .Template .Spec .Users ).To (BeComparableTo ([]bootstrapv1.User {{Name : "default-user" }}))
690
+ }, 5 * time .Second ).Should (Succeed ())
691
+
682
692
// Run defaulting on the KubeadmConfigTemplate (triggered by an "external controller")
683
- // Note: We have to retry this with eventually as it seems to take a bit of time until
684
- // the webhook is active.
685
693
if tt .defaultOriginal {
686
- g .Eventually (ctx , func (g Gomega ) {
687
- patchKCT := & bootstrapv1.KubeadmConfigTemplate {}
688
- g .Expect (env .Get (ctx , client .ObjectKeyFromObject (kct ), patchKCT )).To (Succeed ())
694
+ patchKCT := & bootstrapv1.KubeadmConfigTemplate {}
695
+ g .Expect (env .Get (ctx , client .ObjectKeyFromObject (kct ), patchKCT )).To (Succeed ())
689
696
690
- if patchKCT .Labels == nil {
691
- patchKCT .Labels = map [string ]string {}
692
- }
693
- patchKCT .Labels ["trigger" ] = "update"
697
+ if patchKCT .Labels == nil {
698
+ patchKCT .Labels = map [string ]string {}
699
+ }
700
+ patchKCT .Labels ["trigger" ] = "update"
694
701
695
- g .Expect (env .Patch (ctx , patchKCT , client .MergeFrom (kct ))).To (Succeed ())
702
+ g .Expect (env .Patch (ctx , patchKCT , client .MergeFrom (kct ))).To (Succeed ())
696
703
697
- // Ensure patchKCT was defaulted.
704
+ // Wait for cache to be updated with the defaulted object
705
+ g .Eventually (ctx , func (g Gomega ) {
698
706
g .Expect (env .Get (ctx , client .ObjectKeyFromObject (kct ), patchKCT )).To (Succeed ())
699
707
g .Expect (patchKCT .Spec .Template .Spec .Users ).To (BeComparableTo ([]bootstrapv1.User {{Name : "default-user" }}))
700
708
}, 5 * time .Second ).Should (Succeed ())
@@ -716,7 +724,7 @@ func TestServerSideApplyWithDefaulting(t *testing.T) {
716
724
// Apply modified.
717
725
p0 , err = NewServerSidePatchHelper (ctx , original , modified , env .GetClient (), ssaCache )
718
726
g .Expect (err ).ToNot (HaveOccurred ())
719
- g .Expect (p0 .HasChanges ()).To (Equal (tt .expectChanges ))
727
+ g .Expect (p0 .HasChanges ()).To (Equal (tt .expectChanges ), fmt . Sprintf ( "changes: %s" , string ( p0 . Changes ())) )
720
728
g .Expect (p0 .HasSpecChanges ()).To (Equal (tt .expectSpecChanges ))
721
729
g .Expect (p0 .Patch (ctx )).To (Succeed ())
722
730
0 commit comments