@@ -861,7 +861,9 @@ var _ = Describe("Recovery from a non-clean state", func() {
861
861
// General definitions for tests
862
862
var (
863
863
onload onloadv1alpha1.Onload
864
+ devicePlugin appsv1.DaemonSet
864
865
devicePluginName types.NamespacedName
866
+ module kmm.Module
865
867
)
866
868
867
869
BeforeEach (func () {
@@ -875,7 +877,7 @@ var _ = Describe("Recovery from a non-clean state", func() {
875
877
},
876
878
Spec : onloadv1alpha1.Spec {
877
879
Selector : map [string ]string {
878
- "key" : "" ,
880
+ "key" : "value " ,
879
881
},
880
882
Onload : onloadv1alpha1.OnloadSpec {
881
883
KernelMappings : []onloadv1alpha1.OnloadKernelMapping {
@@ -885,7 +887,7 @@ var _ = Describe("Recovery from a non-clean state", func() {
885
887
},
886
888
},
887
889
UserImage : "image:tag" ,
888
- Version : "" ,
890
+ Version : "old " ,
889
891
},
890
892
DevicePlugin : onloadv1alpha1.DevicePluginSpec {
891
893
DevicePluginImage : "image:tag" ,
@@ -898,18 +900,9 @@ var _ = Describe("Recovery from a non-clean state", func() {
898
900
Name : onload .Name + "-onload-device-plugin-ds" ,
899
901
Namespace : onload .Namespace ,
900
902
}
901
- })
902
-
903
- AfterEach (func () {
904
- cancel ()
905
- err := testEnv .Stop ()
906
- Expect (err ).NotTo (HaveOccurred ())
907
- })
908
-
909
- It ("shouldn't remove existing operands" , func () {
910
903
911
904
dsLabels := map [string ]string {"onload.amd.com/name" : devicePluginName .Name }
912
- dp : = appsv1.DaemonSet {
905
+ devicePlugin = appsv1.DaemonSet {
913
906
ObjectMeta : metav1.ObjectMeta {
914
907
Name : devicePluginName .Name ,
915
908
Namespace : devicePluginName .Namespace ,
@@ -925,26 +918,203 @@ var _ = Describe("Recovery from a non-clean state", func() {
925
918
Containers : []corev1.Container {
926
919
{Name : "foo" , Image : "bar" },
927
920
},
921
+ InitContainers : []corev1.Container {
922
+ {
923
+ Name : "init" , Image : onload .Spec .Onload .UserImage ,
924
+ },
925
+ },
928
926
},
929
927
},
930
928
},
931
929
}
932
930
931
+ module = kmm.Module {
932
+ ObjectMeta : metav1.ObjectMeta {
933
+ Name : onload .Name + onloadModuleNameSuffix ,
934
+ Namespace : onload .Namespace ,
935
+ },
936
+ Spec : kmm.ModuleSpec {
937
+ Selector : onload .Spec .Selector ,
938
+ ModuleLoader : kmm.ModuleLoaderSpec {
939
+ Container : kmm.ModuleLoaderContainerSpec {
940
+ KernelMappings : []kmm.KernelMapping {{}},
941
+ },
942
+ },
943
+ },
944
+ }
945
+ })
946
+
947
+ AfterEach (func () {
948
+ cancel ()
949
+ err := testEnv .Stop ()
950
+ Expect (err ).NotTo (HaveOccurred ())
951
+ })
952
+
953
+ It ("shouldn't remove existing operands" , func () {
933
954
Expect (k8sClient .Create (ctx , & onload )).Should (Succeed ())
934
955
935
- Expect (ctrl .SetControllerReference (& onload , & dp , testEnv .Scheme )).Should (Succeed ())
936
- Expect (k8sClient .Create (ctx , & dp )).Should (Succeed ())
956
+ Expect (ctrl .SetControllerReference (& onload , & devicePlugin , testEnv .Scheme )).Should (Succeed ())
957
+ Expect (k8sClient .Create (ctx , & devicePlugin )).Should (Succeed ())
937
958
938
959
startReconciler (k8sManager , ctx )
939
960
940
- devicePlugin := appsv1.DaemonSet {}
961
+ // Create a new object so we can compare the old and new versions of the
962
+ // object
963
+ newDevicePlugin := appsv1.DaemonSet {}
941
964
942
965
Eventually (func () bool {
943
- err := k8sClient .Get (ctx , devicePluginName , & devicePlugin )
966
+ err := k8sClient .Get (ctx , devicePluginName , & newDevicePlugin )
944
967
return err == nil
945
968
}, timeout , pollingInterval ).Should (BeTrue ())
946
969
947
- Expect (dp .UID ).To (Equal (devicePlugin .UID ))
970
+ Expect (newDevicePlugin .UID ).To (Equal (devicePlugin .UID ))
971
+ })
972
+
973
+ // Currently we can't test the node labelling which has the bulk of the
974
+ // upgrade logic. So we are restricted to testing the upgrading of the
975
+ // operands.
976
+ It ("should continue upgrade process (device plugin)" , func () {
977
+
978
+ // Fake the upgrade, the device plugin is still using the old values
979
+ onload .Spec .Onload .Version = "new"
980
+ onload .Spec .Onload .UserImage = "foo:bar"
981
+
982
+ Expect (onload .Spec .Onload .Version ).ShouldNot (Equal (devicePlugin .Labels [onloadVersionLabel ]))
983
+
984
+ Expect (k8sClient .Create (ctx , & onload )).Should (Succeed ())
985
+
986
+ Expect (ctrl .SetControllerReference (& onload , & devicePlugin , testEnv .Scheme )).Should (Succeed ())
987
+ Expect (k8sClient .Create (ctx , & devicePlugin )).Should (Succeed ())
988
+
989
+ startReconciler (k8sManager , ctx )
990
+
991
+ // Create a new object so we can compare the old and new versions of the
992
+ // object
993
+ newDevicePlugin := appsv1.DaemonSet {}
994
+
995
+ Eventually (func (g Gomega ) {
996
+ g .Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (& devicePlugin ), & newDevicePlugin )).Should (Succeed ())
997
+ g .Expect (newDevicePlugin .UID ).To (Equal (devicePlugin .UID ))
998
+ g .Expect (newDevicePlugin .Labels [onloadVersionLabel ]).ShouldNot (Equal (devicePlugin .Labels [onloadVersionLabel ]))
999
+ g .Expect (newDevicePlugin .Labels [onloadVersionLabel ]).Should (Equal (onload .Spec .Onload .Version ))
1000
+ }, timeout , pollingInterval ).Should (Succeed ())
1001
+
1002
+ })
1003
+
1004
+ It ("should continue upgrade process (module)" , func () {
1005
+ // Fake the upgrade, the operand is still using the old values
1006
+ onload .Spec .Onload .Version = "new"
1007
+ onload .Spec .Onload .UserImage = "foo:bar"
1008
+
1009
+ Expect (onload .Spec .Onload .Version ).ShouldNot (Equal (module .Spec .ModuleLoader .Container .Version ))
1010
+
1011
+ Expect (k8sClient .Create (ctx , & onload )).Should (Succeed ())
1012
+
1013
+ Expect (ctrl .SetControllerReference (& onload , & module , testEnv .Scheme )).Should (Succeed ())
1014
+ Expect (k8sClient .Create (ctx , & module )).Should (Succeed ())
1015
+
1016
+ startReconciler (k8sManager , ctx )
1017
+
1018
+ // Create a new object so we can compare the old and new versions of the
1019
+ // object
1020
+ newModule := kmm.Module {}
1021
+
1022
+ Eventually (func (g Gomega ) {
1023
+ g .Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (& module ), & newModule )).Should (Succeed ())
1024
+ g .Expect (newModule .UID ).To (Equal (module .UID ))
1025
+ g .Expect (newModule .Spec .ModuleLoader .Container .Version ).ShouldNot (Equal (module .Spec .ModuleLoader .Container .Version ))
1026
+ g .Expect (newModule .Spec .ModuleLoader .Container .Version ).Should (Equal (onload .Spec .Onload .Version ))
1027
+ }, timeout , pollingInterval ).Should (Succeed ())
1028
+
1029
+ })
1030
+
1031
+ Describe ("Node-based tests" , func () {
1032
+
1033
+ var (
1034
+ node corev1.Node
1035
+ kmmOnloadLabel string
1036
+ dpOnloadLabel string
1037
+ )
1038
+
1039
+ BeforeEach (func () {
1040
+ node = corev1.Node {
1041
+ ObjectMeta : metav1.ObjectMeta {
1042
+ Name : "test-node" ,
1043
+ Labels : map [string ]string {
1044
+ "key" : "value" ,
1045
+ },
1046
+ },
1047
+ }
1048
+
1049
+ kmmOnloadLabel = kmmOnloadLabelName (onload .Name , onload .Namespace )
1050
+ dpOnloadLabel = onloadLabelName (onload .Name , onload .Namespace )
1051
+ })
1052
+
1053
+ It ("should add the initial labels" , func () {
1054
+
1055
+ Expect (k8sClient .Create (ctx , & node )).Should (Succeed ())
1056
+
1057
+ Expect (k8sClient .Create (ctx , & onload )).Should (Succeed ())
1058
+
1059
+ startReconciler (k8sManager , ctx )
1060
+
1061
+ newNode := corev1.Node {}
1062
+ Eventually (func (g Gomega ) {
1063
+ g .Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (& node ), & newNode )).Should (Succeed ())
1064
+ g .Expect (newNode .Labels [kmmOnloadLabel ]).Should (Equal (onload .Spec .Onload .Version ))
1065
+ g .Expect (newNode .Labels [dpOnloadLabel ]).Should (Equal (onload .Spec .Onload .Version ))
1066
+ }, timeout , pollingInterval ).Should (Succeed ())
1067
+ })
1068
+
1069
+ // Want to test 3 different values for each label/version: unset, old and new
1070
+ DescribeTable ("controller starting at different points during upgrade" ,
1071
+ func (label1 , label2 string ) {
1072
+ if label1 != "" {
1073
+ node .Labels [kmmOnloadLabel ] = label1
1074
+ }
1075
+
1076
+ if label2 != "" {
1077
+ node .Labels [dpOnloadLabel ] = label2
1078
+ }
1079
+
1080
+ Expect (k8sClient .Create (ctx , & node )).Should (Succeed ())
1081
+
1082
+ onload .Spec .Onload .Version = "new"
1083
+ onload .Spec .Onload .UserImage = "foo:bar"
1084
+ Expect (k8sClient .Create (ctx , & onload )).Should (Succeed ())
1085
+
1086
+ if label1 != "" {
1087
+ module .Spec .ModuleLoader .Container .Version = label1
1088
+ }
1089
+ Expect (ctrl .SetControllerReference (& onload , & module , testEnv .Scheme )).Should (Succeed ())
1090
+
1091
+ if label2 != "" {
1092
+ devicePlugin .Labels [onloadVersionLabel ] = label2
1093
+ }
1094
+ Expect (ctrl .SetControllerReference (& onload , & devicePlugin , testEnv .Scheme )).Should (Succeed ())
1095
+
1096
+ Expect (k8sClient .Create (ctx , & module )).Should (Succeed ())
1097
+ Expect (k8sClient .Create (ctx , & devicePlugin )).Should (Succeed ())
1098
+
1099
+ startReconciler (k8sManager , ctx )
1100
+
1101
+ newNode := corev1.Node {}
1102
+ Eventually (func (g Gomega ) {
1103
+ g .Expect (k8sClient .Get (ctx , client .ObjectKeyFromObject (& node ), & newNode )).Should (Succeed ())
1104
+ g .Expect (newNode .Labels [kmmOnloadLabel ]).Should (Equal (onload .Spec .Onload .Version ))
1105
+ g .Expect (newNode .Labels [dpOnloadLabel ]).Should (Equal (onload .Spec .Onload .Version ))
1106
+ }, timeout , pollingInterval ).Should (Succeed ())
1107
+ },
1108
+ Entry ("00" , "" , "" ),
1109
+ Entry ("01" , "" , "old" ), // I don't think this should be able to happen
1110
+ Entry ("02" , "" , "new" ),
1111
+ Entry ("10" , "old" , "" ),
1112
+ Entry ("11" , "old" , "old" ),
1113
+ Entry ("12" , "old" , "new" ),
1114
+ Entry ("20" , "new" , "" ),
1115
+ Entry ("21" , "new" , "old" ), // I don't think this should be able to happen
1116
+ Entry ("22" , "new" , "new" ),
1117
+ )
948
1118
})
949
1119
950
1120
})
0 commit comments