@@ -33,7 +33,6 @@ import (
33
33
34
34
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
35
35
"sigs.k8s.io/cluster-api/controllers/external"
36
- "sigs.k8s.io/cluster-api/internal/util/ssa"
37
36
"sigs.k8s.io/cluster-api/util"
38
37
v1beta1conditions "sigs.k8s.io/cluster-api/util/conditions/deprecated/v1beta1"
39
38
"sigs.k8s.io/cluster-api/util/patch"
@@ -500,196 +499,6 @@ func TestMachineDeploymentReconciler(t *testing.T) {
500
499
})
501
500
}
502
501
503
- func TestMachineDeploymentReconciler_CleanUpManagedFieldsForSSAAdoption (t * testing.T ) {
504
- setup := func (t * testing.T , g * WithT ) (* corev1.Namespace , * clusterv1.Cluster ) {
505
- t .Helper ()
506
-
507
- t .Log ("Creating the namespace" )
508
- ns , err := env .CreateNamespace (ctx , machineDeploymentNamespace )
509
- g .Expect (err ).ToNot (HaveOccurred ())
510
-
511
- t .Log ("Creating the Cluster" )
512
- cluster := & clusterv1.Cluster {
513
- ObjectMeta : metav1.ObjectMeta {
514
- Namespace : ns .Name ,
515
- Name : "test-cluster" ,
516
- },
517
- Spec : clusterv1.ClusterSpec {
518
- ControlPlaneRef : clusterv1.ContractVersionedObjectReference {
519
- APIGroup : builder .ControlPlaneGroupVersion .Group ,
520
- Kind : builder .GenericControlPlaneKind ,
521
- Name : "cp1" ,
522
- },
523
- },
524
- }
525
- g .Expect (env .Create (ctx , cluster )).To (Succeed ())
526
-
527
- t .Log ("Creating the Cluster Kubeconfig Secret" )
528
- g .Expect (env .CreateKubeconfigSecret (ctx , cluster )).To (Succeed ())
529
-
530
- return ns , cluster
531
- }
532
-
533
- teardown := func (t * testing.T , g * WithT , ns * corev1.Namespace , cluster * clusterv1.Cluster ) {
534
- t .Helper ()
535
-
536
- t .Log ("Deleting the Cluster" )
537
- g .Expect (env .Delete (ctx , cluster )).To (Succeed ())
538
- t .Log ("Deleting the namespace" )
539
- g .Expect (env .Delete (ctx , ns )).To (Succeed ())
540
- }
541
-
542
- g := NewWithT (t )
543
- namespace , testCluster := setup (t , g )
544
- defer teardown (t , g , namespace , testCluster )
545
-
546
- labels := map [string ]string {
547
- "foo" : "bar" ,
548
- clusterv1 .ClusterNameLabel : testCluster .Name ,
549
- }
550
- version := "v1.10.3"
551
- deployment := & clusterv1.MachineDeployment {
552
- ObjectMeta : metav1.ObjectMeta {
553
- GenerateName : "md-" ,
554
- Namespace : namespace .Name ,
555
- Labels : map [string ]string {
556
- clusterv1 .ClusterNameLabel : testCluster .Name ,
557
- },
558
- },
559
- Spec : clusterv1.MachineDeploymentSpec {
560
- Paused : ptr .To (true ), // Set this to true as we do not want to test the other parts of the reconciler in this test.
561
- ClusterName : testCluster .Name ,
562
- Replicas : ptr.To [int32 ](2 ),
563
- Selector : metav1.LabelSelector {
564
- // We're using the same labels for spec.selector and spec.template.labels.
565
- MatchLabels : labels ,
566
- },
567
- Rollout : clusterv1.MachineDeploymentRolloutSpec {
568
- Strategy : clusterv1.MachineDeploymentRolloutStrategy {
569
- Type : clusterv1 .RollingUpdateMachineDeploymentStrategyType ,
570
- RollingUpdate : clusterv1.MachineDeploymentRolloutStrategyRollingUpdate {
571
- MaxUnavailable : intOrStrPtr (0 ),
572
- MaxSurge : intOrStrPtr (1 ),
573
- },
574
- },
575
- },
576
- Deletion : clusterv1.MachineDeploymentDeletionSpec {
577
- Order : clusterv1 .OldestMachineSetDeletionOrder ,
578
- },
579
- Template : clusterv1.MachineTemplateSpec {
580
- ObjectMeta : clusterv1.ObjectMeta {
581
- Labels : labels ,
582
- },
583
- Spec : clusterv1.MachineSpec {
584
- ClusterName : testCluster .Name ,
585
- Version : version ,
586
- InfrastructureRef : clusterv1.ContractVersionedObjectReference {
587
- APIGroup : clusterv1 .GroupVersionInfrastructure .Group ,
588
- Kind : "GenericInfrastructureMachineTemplate" ,
589
- Name : "md-template" ,
590
- },
591
- Bootstrap : clusterv1.Bootstrap {
592
- DataSecretName : ptr .To ("data-secret-name" ),
593
- },
594
- },
595
- },
596
- },
597
- }
598
- msListOpts := []client.ListOption {
599
- client .InNamespace (namespace .Name ),
600
- client .MatchingLabels (labels ),
601
- }
602
-
603
- // Create infrastructure template resource.
604
- infraResource := map [string ]interface {}{
605
- "kind" : "GenericInfrastructureMachine" ,
606
- "apiVersion" : clusterv1 .GroupVersionInfrastructure .String (),
607
- "metadata" : map [string ]interface {}{},
608
- "spec" : map [string ]interface {}{
609
- "size" : "3xlarge" ,
610
- },
611
- }
612
- infraTmpl := & unstructured.Unstructured {
613
- Object : map [string ]interface {}{
614
- "kind" : "GenericInfrastructureMachineTemplate" ,
615
- "apiVersion" : clusterv1 .GroupVersionInfrastructure .String (),
616
- "metadata" : map [string ]interface {}{
617
- "name" : "md-template" ,
618
- "namespace" : namespace .Name ,
619
- },
620
- "spec" : map [string ]interface {}{
621
- "template" : infraResource ,
622
- },
623
- },
624
- }
625
- t .Log ("Creating the infrastructure template" )
626
- g .Expect (env .Create (ctx , infraTmpl )).To (Succeed ())
627
-
628
- // Create the MachineDeployment object and expect Reconcile to be called.
629
- t .Log ("Creating the MachineDeployment" )
630
- g .Expect (env .Create (ctx , deployment )).To (Succeed ())
631
-
632
- // Create a MachineSet for the MachineDeployment.
633
- classicManagerMS := & clusterv1.MachineSet {
634
- TypeMeta : metav1.TypeMeta {
635
- Kind : "MachineSet" ,
636
- APIVersion : clusterv1 .GroupVersion .String (),
637
- },
638
- ObjectMeta : metav1.ObjectMeta {
639
- Name : deployment .Name + "-" + "classic-ms" ,
640
- Namespace : testCluster .Namespace ,
641
- Labels : labels ,
642
- },
643
- Spec : clusterv1.MachineSetSpec {
644
- ClusterName : testCluster .Name ,
645
- Replicas : ptr.To [int32 ](0 ),
646
- Selector : metav1.LabelSelector {
647
- MatchLabels : labels ,
648
- },
649
- Template : clusterv1.MachineTemplateSpec {
650
- ObjectMeta : clusterv1.ObjectMeta {
651
- Labels : labels ,
652
- },
653
- Spec : clusterv1.MachineSpec {
654
- ClusterName : testCluster .Name ,
655
- InfrastructureRef : clusterv1.ContractVersionedObjectReference {
656
- APIGroup : clusterv1 .GroupVersionInfrastructure .Group ,
657
- Kind : "GenericInfrastructureMachineTemplate" ,
658
- Name : "md-template" ,
659
- },
660
- Bootstrap : clusterv1.Bootstrap {
661
- DataSecretName : ptr .To ("data-secret-name" ),
662
- },
663
- Version : version ,
664
- },
665
- },
666
- },
667
- }
668
- ssaManagerMS := classicManagerMS .DeepCopy ()
669
- ssaManagerMS .Name = deployment .Name + "-" + "ssa-ms"
670
-
671
- // Create one using the "old manager".
672
- g .Expect (env .Create (ctx , classicManagerMS , client .FieldOwner ("manager" ))).To (Succeed ())
673
-
674
- // Create one using SSA.
675
- g .Expect (env .Patch (ctx , ssaManagerMS , client .Apply , client .FieldOwner (machineDeploymentManagerName ), client .ForceOwnership )).To (Succeed ())
676
-
677
- // Verify that for both the MachineSets the ManagedFields are updated.
678
- g .Eventually (func (g Gomega ) {
679
- machineSets := & clusterv1.MachineSetList {}
680
- g .Expect (env .List (ctx , machineSets , msListOpts ... )).To (Succeed ())
681
-
682
- g .Expect (machineSets .Items ).To (HaveLen (2 ))
683
- for _ , ms := range machineSets .Items {
684
- // Verify the ManagedFields are updated.
685
- g .Expect (ms .GetManagedFields ()).Should (
686
- ContainElement (ssa .MatchManagedFieldsEntry (machineDeploymentManagerName , metav1 .ManagedFieldsOperationApply )))
687
- g .Expect (ms .GetManagedFields ()).ShouldNot (
688
- ContainElement (ssa .MatchManagedFieldsEntry ("manager" , metav1 .ManagedFieldsOperationUpdate )))
689
- }
690
- }).Should (Succeed ())
691
- }
692
-
693
502
func TestMachineSetToDeployments (t * testing.T ) {
694
503
g := NewWithT (t )
695
504
0 commit comments