@@ -61,6 +61,13 @@ def set_installed_kueue_version(
6161 )
6262
6363
64+ @pytest .fixture (autouse = True )
65+ def mock_ask_for_user_consent (mocker : MockerFixture ) -> MagicMock :
66+ return mocker .patch (
67+ "xpk.core.kueue_manager.ask_for_user_consent" , return_value = True
68+ )
69+
70+
6471@pytest .fixture (autouse = True )
6572def mock_commands (mocker : MockerFixture ) -> CommandsTester :
6673 return CommandsTester (
@@ -102,7 +109,7 @@ def test_install_or_upgrade_when_outdated(
102109 result = kueue_manager .install_or_upgrade (KUEUE_CONFIG )
103110
104111 assert result == 0
105- mock_commands .assert_command_run ("kubectl apply" , "v0.12.2 /manifests.yaml" )
112+ mock_commands .assert_command_run ("kubectl apply" , "v0.14.3 /manifests.yaml" )
106113 mock_commands .assert_command_run ("kubectl apply -f" , "/tmp/" )
107114
108115
@@ -115,10 +122,84 @@ def test_install_or_upgrade_when_not_installed(
115122 result = kueue_manager .install_or_upgrade (KUEUE_CONFIG )
116123
117124 assert result == 0
118- mock_commands .assert_command_run ("kubectl apply" , "v0.12.2 /manifests.yaml" )
125+ mock_commands .assert_command_run ("kubectl apply" , "v0.14.3 /manifests.yaml" )
119126 mock_commands .assert_command_run ("kubectl apply -f" , "/tmp/" )
120127
121128
129+ def test_upgrade_when_no_breaking_changes_between_versions_no_preparation_needed (
130+ mock_commands : CommandsTester ,
131+ kueue_manager : KueueManager ,
132+ mock_ask_for_user_consent : MagicMock ,
133+ ):
134+ set_installed_kueue_version (mock_commands , Version ("0.14.0" ))
135+
136+ kueue_manager .install_or_upgrade (KUEUE_CONFIG )
137+
138+ mock_ask_for_user_consent .assert_not_called ()
139+
140+
141+ def test_upgrade_with_breaking_changes_between_versions_runs_preparation (
142+ mock_commands : CommandsTester ,
143+ kueue_manager : KueueManager ,
144+ mock_ask_for_user_consent : MagicMock ,
145+ ):
146+ set_installed_kueue_version (mock_commands , Version ("0.11.0" ))
147+ fake_crds = (
148+ "customresourcedefinition.apiextensions.k8s.io/kueue-crd-1.kueue.x-k8s.io\n "
149+ "customresourcedefinition.apiextensions.k8s.io/kueue-crd-2.kueue.x-k8s.io"
150+ )
151+ mock_commands .set_result_for_command (
152+ (0 , fake_crds ), "kubectl get crd -o name"
153+ )
154+ mock_ask_for_user_consent .return_value = True
155+
156+ result = kueue_manager .install_or_upgrade (KUEUE_CONFIG )
157+
158+ assert result == 0
159+ mock_ask_for_user_consent .assert_called_once ()
160+ assert (
161+ "CHANGELOG/CHANGELOG-0.14.md"
162+ in mock_ask_for_user_consent .mock_calls [0 ].args [0 ]
163+ )
164+ mock_commands .assert_command_run (
165+ "kubectl delete kueue-crd-1.kueue.x-k8s.io --all"
166+ )
167+ mock_commands .assert_command_run (
168+ "kubectl delete kueue-crd-2.kueue.x-k8s.io --all"
169+ )
170+ mock_commands .assert_command_run (
171+ "kubectl delete crd kueue-crd-1.kueue.x-k8s.io"
172+ )
173+ mock_commands .assert_command_run (
174+ "kubectl delete crd kueue-crd-2.kueue.x-k8s.io"
175+ )
176+ mock_commands .assert_command_run (
177+ "kubectl delete deployment kueue-controller-manager"
178+ )
179+
180+
181+ def test_upgrade_with_breaking_changes_between_versions_does_not_run_preparation_without_consent (
182+ mock_commands : CommandsTester ,
183+ kueue_manager : KueueManager ,
184+ mock_ask_for_user_consent : MagicMock ,
185+ ):
186+ set_installed_kueue_version (mock_commands , Version ("0.11.0" ))
187+ mock_commands .set_result_for_command (
188+ (
189+ 0 ,
190+ "customresourcedefinition.apiextensions.k8s.io/kueue-crd-1.kueue.x-k8s.io" ,
191+ ),
192+ "kubectl get crd -o name" ,
193+ )
194+ mock_ask_for_user_consent .return_value = False
195+
196+ result = kueue_manager .install_or_upgrade (KUEUE_CONFIG )
197+
198+ assert result == 1
199+ # Assert there was no command run for the Kueue crd:
200+ mock_commands .assert_command_not_run ("kueue-crd-1.kueue.x-k8s.io" )
201+
202+
122203def test_installation_with_tolerations (
123204 mock_commands : CommandsTester , kueue_manager : KueueManager
124205):
0 commit comments