@@ -249,3 +249,61 @@ func TestOperatorSyncClusterAPIControllerHealthCheckController(t *testing.T) {
249249 }
250250 }
251251}
252+
253+ func TestEnableDisableOperatorSyncClusterAPIControllerHealthCheckController (t * testing.T ) {
254+ infra := & v1.Infrastructure {
255+ ObjectMeta : metav1.ObjectMeta {
256+ Name : "cluster" ,
257+ },
258+ Status : v1.InfrastructureStatus {
259+ Platform : v1 .AWSPlatformType ,
260+ },
261+ }
262+ stopCh := make (chan struct {})
263+ defer close (stopCh )
264+
265+ optr := newFakeOperator (nil , []runtime.Object {newFeatureGate (v1 .TechPreviewNoUpgrade ), infra }, stopCh )
266+ go optr .Run (2 , stopCh )
267+
268+ if err := wait .PollImmediate (1 * time .Second , 5 * time .Second , func () (bool , error ) {
269+ d , err := optr .deployLister .Deployments (targetNamespace ).Get (deploymentName )
270+ if err != nil {
271+ t .Logf ("Failed to get %q deployment: %v" , deploymentName , err )
272+ return false , nil
273+ }
274+ if ! deploymentHasContainer (d , hcControllerName ) {
275+ t .Logf ("Failed to verify that deployment %q has container %q" , deploymentName , hcControllerName )
276+ return false , nil
277+ }
278+ return true , nil
279+ }); err != nil {
280+ t .Fatalf ("Failed to verify that deployment %q has container %q" , deploymentName , hcControllerName )
281+ }
282+
283+ t .Logf ("Found %q container in %q deployment" , hcControllerName , deploymentName )
284+
285+ hcFeatureGate , err := optr .osClient .ConfigV1 ().FeatureGates ().Get (MachineAPIFeatureGateName , metav1.GetOptions {})
286+ if err != nil {
287+ t .Fatalf ("Unable to get %q feature gate: %v" , MachineAPIFeatureGateName , err )
288+ }
289+ hcFeatureGate .Spec .FeatureSet = v1 .Default
290+ if _ , err := optr .osClient .ConfigV1 ().FeatureGates ().Update (hcFeatureGate ); err != nil {
291+ t .Fatalf ("Unable to update %q feature gate and set default feature set: %v" , MachineAPIFeatureGateName , err )
292+ }
293+
294+ if err := wait .PollImmediate (1 * time .Second , 15 * time .Second , func () (bool , error ) {
295+ d , err := optr .deployLister .Deployments (targetNamespace ).Get (deploymentName )
296+ if err != nil {
297+ t .Logf ("Failed to get %q deployment: %v" , deploymentName , err )
298+ return false , nil
299+ }
300+ if deploymentHasContainer (d , hcControllerName ) {
301+ t .Logf ("Failed to verify that deployment %q has no container with name %q" , deploymentName , hcControllerName )
302+ return false , nil
303+ }
304+ return true , nil
305+ }); err != nil {
306+ t .Errorf ("Failed to verify that deployment %q has no container with name %q " , deploymentName , hcControllerName )
307+ }
308+
309+ }
0 commit comments