Skip to content

Conversation

@vikaschoudhary16
Copy link
Contributor

This unit test verifies that if hc feature-gate is disabled after enabling it, hc-controller gets removed.

@openshift-ci-robot openshift-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Apr 25, 2019
},
},
expectedMachineHealthCheckController: true,
}, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this verify the feature is disable after it's enabled? The operator is initialized from scratch for every test case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@michaelgugino michaelgugino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 25, 2019
@michaelgugino
Copy link
Contributor

/lgtm cancel

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Apr 25, 2019
@vikaschoudhary16 vikaschoudhary16 force-pushed the hc-featuregate-enabledisable branch from fe3595f to b75620e Compare April 26, 2019 09:15
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Apr 26, 2019
@vikaschoudhary16 vikaschoudhary16 force-pushed the hc-featuregate-enabledisable branch from b75620e to 8b75de8 Compare April 26, 2019 10:08
}, nil
}

func (optr *Operator) getImages() (string, string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to implement and mock getImages(). You can create Configv1.Infrastructure object and have the fake client return it.

}
ensureContainer(modified, existingCurr, required)
}
var requiredContainers []corev1.Container
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this change related to the unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syncHandler func(ic string) error
syncHandler func(ic string) error
imageGetterFunc imageGetterFuncType
statusProgressingFunc func() error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to mock optr.statusProgressing given you can have fake clients return expected objects. Please, give fake client osconfigv1.ClusterOperator object with pre-populated testing values.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented here: #304

@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 26, 2019
@vikaschoudhary16 vikaschoudhary16 force-pushed the hc-featuregate-enabledisable branch from 8b75de8 to 3bc2f43 Compare April 29, 2019 18:01
@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 29, 2019
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 10, 2019
@enxebre
Copy link
Member

enxebre commented May 14, 2019

@vikaschoudhary16 needs rebase

@vikaschoudhary16 vikaschoudhary16 force-pushed the hc-featuregate-enabledisable branch from 3bc2f43 to a56b76f Compare June 28, 2019 05:23
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 28, 2019
@vikaschoudhary16
Copy link
Contributor Author

@vikaschoudhary16 vikaschoudhary16 force-pushed the hc-featuregate-enabledisable branch from a56b76f to 0ad7f34 Compare July 1, 2019 04:09
@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 1, 2019
@vikaschoudhary16 vikaschoudhary16 force-pushed the hc-featuregate-enabledisable branch from 0ad7f34 to dd00275 Compare July 1, 2019 06:27
@vikaschoudhary16
Copy link
Contributor Author

/test e2e-aws

Status: v1.InfrastructureStatus{
Platform: v1.AWSPlatformType,
},
err := initFeatureGateInformer([]runtime.Object{tc.featureGate}, optr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still wrong. All tests in the list (tests) are supposed to assume clean/vanilla environment. Initializing fg informer only once leaves previous fg object in the cache. Which might (or might not) influence result of each test in the last. If you want to assume dependency between fg objects, you need to create separate unit test for it.

@vikaschoudhary16 vikaschoudhary16 force-pushed the hc-featuregate-enabledisable branch from dd00275 to 5bc06f5 Compare July 1, 2019 11:06
stopCh := make(<-chan struct{})
optr := newFakeOperator(nil, []runtime.Object{infra}, stopCh)

for _, tc := range tests {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the unit test will always have two steps (first enable fg, then disable fg), there is no need to iterate through both tests. It's sufficient to initialize newFakeOperator as it was before, remove initFeatureGateInformer and just call optr.sync two times. After the first call validating the fg is enable, after the second call validating it is not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove initFeatureGateInformer

This is not possible because modifying the FeatureGate object which is passed to the fake clientset, will not work. Eventually it makes a copy of the object and therefor any changes to the object will not be reflected back in the object returned by informer in response to the listing operation.

Updated the PR to address other parts. PTAL!

Copy link
Member

@ingvagabund ingvagabund Jul 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/pkg/operator/operator_test.go b/pkg/operator/operator_test.go
index 289f4c9..24c6688 100644
--- a/pkg/operator/operator_test.go
+++ b/pkg/operator/operator_test.go
@@ -15,7 +15,6 @@ import (
 	"k8s.io/apimachinery/pkg/util/wait"
 	"k8s.io/client-go/informers"
 	fakekube "k8s.io/client-go/kubernetes/fake"
-	"k8s.io/client-go/tools/cache"
 	"k8s.io/client-go/tools/record"
 	"k8s.io/client-go/util/workqueue"
 
@@ -261,10 +260,11 @@ func TestEnableDisableOperatorSyncClusterAPIControllerHealthCheckController(t *t
 			Platform: v1.AWSPlatformType,
 		},
 	}
-	hcFeatureGate := newFeatureGate(v1.TechPreviewNoUpgrade)
 	stopCh := make(chan struct{})
-	optr := newFakeOperator(nil, []runtime.Object{hcFeatureGate, infra}, stopCh)
-	optr.sync("test-key")
+	defer close(stopCh)
+
+	optr := newFakeOperator(nil, []runtime.Object{newFeatureGate(v1.TechPreviewNoUpgrade), infra}, stopCh)
+	go optr.Run(2, stopCh)
 
 	if err := wait.PollImmediate(1*time.Second, 5*time.Second, func() (bool, error) {
 		d, err := optr.deployLister.Deployments(targetNamespace).Get(deploymentName)
@@ -272,28 +272,33 @@ func TestEnableDisableOperatorSyncClusterAPIControllerHealthCheckController(t *t
 			t.Logf("Failed to get %q deployment: %v", deploymentName, err)
 			return false, nil
 		}
-		if deploymentHasContainer(d, hcControllerName) != true {
+		if !deploymentHasContainer(d, hcControllerName) {
 			t.Logf("Expected deploymentHasContainer for %q container to be true", hcControllerName)
 			return false, nil
 		}
 		return true, nil
 	}); err != nil {
-		t.Errorf("Failed to verify %q deployment", deploymentName)
+		t.Fatalf("Failed to verify %q deployment", deploymentName)
 	}
-	close(stopCh)
-	err := initFeatureGateInformer([]runtime.Object{newFeatureGate(v1.Default)}, optr)
+
+	t.Logf("Found %q container in %q deployment", hcControllerName, deploymentName)
+
+	hcFeatureGate, err := optr.osClient.ConfigV1().FeatureGates().Get(MachineAPIFeatureGateName, metav1.GetOptions{})
 	if err != nil {
-		t.Errorf("Failed to set featuregate 'Default' : %v", err)
+		t.Fatalf("Unable to get %q feature gate: %v", MachineAPIFeatureGateName, err)
+	}
+	hcFeatureGate.Spec.FeatureSet = v1.Default
+	if _, err := optr.osClient.ConfigV1().FeatureGates().Update(hcFeatureGate); err != nil {
+		t.Fatalf("Unable to update %q feature gate and set default feature set: %v", MachineAPIFeatureGateName, err)
 	}
-	optr.sync("test-key")
 
-	if err := wait.PollImmediate(1*time.Second, 5*time.Second, func() (bool, error) {
+	if err := wait.PollImmediate(1*time.Second, 15*time.Second, func() (bool, error) {
 		d, err := optr.deployLister.Deployments(targetNamespace).Get(deploymentName)
 		if err != nil {
 			t.Logf("Failed to get %q deployment: %v", deploymentName, err)
 			return false, nil
 		}
-		if deploymentHasContainer(d, hcControllerName) != false {
+		if deploymentHasContainer(d, hcControllerName) {
 			t.Logf("Expected deploymentHasContainer for %q container to be false", hcControllerName)
 			return false, nil
 		}
@@ -303,16 +308,3 @@ func TestEnableDisableOperatorSyncClusterAPIControllerHealthCheckController(t *t
 	}
 
 }
-
-func initFeatureGateInformer(featureGate []runtime.Object, op *Operator) error {
-	configClient := fakeos.NewSimpleClientset(featureGate...)
-	configSharedInformer := configinformersv1.NewSharedInformerFactoryWithOptions(configClient, 2*time.Minute)
-	featureGateInformer := configSharedInformer.Config().V1().FeatureGates()
-	op.featureGateLister = featureGateInformer.Lister()
-	stopCh := make(<-chan struct{})
-	configSharedInformer.Start(stopCh)
-	if !cache.WaitForCacheSync(stopCh, featureGateInformer.Informer().HasSynced) {
-		return fmt.Errorf("unable to wait for cache to sync")
-	}
-	return nil
-}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vikaschoudhary16 also please improve the messages to be more human readable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, thanks!

optr := newFakeOperator(nil, []runtime.Object{infra}, stopCh)
err := initFeatureGateInformer([]runtime.Object{tc.featureGate}, optr)
if err != nil {
t.Errorf("Failed to set featuregate %v : %v", tc.featureGate, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this fatal?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with Errorf this test will be reported failed but others will be executed. Is not that we want?

@vikaschoudhary16 vikaschoudhary16 force-pushed the hc-featuregate-enabledisable branch from 5bc06f5 to 02ef72f Compare July 2, 2019 06:45

configSharedInformer.Start(stopCh)
kubeNamespacedSharedInformer.Start(stopCh)
kubeInformerstopCh := make(<-chan struct{})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this separate channel? Shouldn't the following line use stopCh?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, please undo the change.

}

func newFakeOperator(kubeObjects []runtime.Object, osObjects []runtime.Object, stopCh <-chan struct{}) *Operator {
func newFakeOperator(kubeObjects []runtime.Object, osObjects []runtime.Object, stopCh chan struct{}) *Operator {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for s/<-chan/chan/.

@vikaschoudhary16 vikaschoudhary16 force-pushed the hc-featuregate-enabledisable branch from 02ef72f to 970bc97 Compare July 2, 2019 10:11

configSharedInformer.Start(stopCh)
kubeNamespacedSharedInformer.Start(stopCh)
kubeInformerstopCh := make(<-chan struct{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, please undo the change.

}

stopCh := make(<-chan struct{})
stopCh := make(chan struct{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo

}

stopCh := make(<-chan struct{})
stopCh := make(chan struct{})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please undo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why should not the stop channel be closed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undo = s/<-//. Channel only for reading is all that is needed.

return false, nil
}
if !deploymentHasContainer(d, hcControllerName) {
t.Logf("Expected deploymentHasContainer for %q container to be true", hcControllerName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected to found no %q container in %q deployment, got one.

}
return true, nil
}); err != nil {
t.Fatalf("Failed to verify %q deployment", deploymentName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Failed to verify %q deployment has %q container"

return false, nil
}
if deploymentHasContainer(d, hcControllerName) {
t.Logf("Expected deploymentHasContainer for %q container to be false", hcControllerName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected to found %q container in %q deployment, found none.

}
return true, nil
}); err != nil {
t.Errorf("Failed to verify %q deployment", deploymentName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Failed to verify %q deployment has no %q container"

@vikaschoudhary16 vikaschoudhary16 force-pushed the hc-featuregate-enabledisable branch 3 times, most recently from be7e3a7 to 5d14dd1 Compare July 2, 2019 11:56
}

func newFakeOperator(kubeObjects []runtime.Object, osObjects []runtime.Object, stopCh <-chan struct{}) *Operator {
func newFakeOperator(kubeObjects []runtime.Object, osObjects []runtime.Object, stopCh <-chan struct{}, wq string) *Operator {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is wq?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is the way to fix the flake, please open another PR for it. This is irrelevant for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it be ok if i create a new commit for this flake fix. Actually with the changes in this PR, this flake has become almost 100% reproducible and thus will be difficult to merge this PR without this fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can different name for a working queue be a fix for the flake?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does the name, or a different name, fix the flake?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still, it's unrelated to this PR. Please, open another one.

@vikaschoudhary16 vikaschoudhary16 force-pushed the hc-featuregate-enabledisable branch from 5d14dd1 to d45cf1b Compare July 2, 2019 14:06
@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Jul 2, 2019

@vikaschoudhary16: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/actuator-pkg-staleness 3bc2f43 link /test actuator-pkg-staleness

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@vikaschoudhary16
Copy link
Contributor Author

/test e2e-aws-operator

@ingvagabund
Copy link
Member

/approve
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 2, 2019
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ingvagabund

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 2, 2019
@openshift-merge-robot openshift-merge-robot merged commit 99f8484 into openshift:master Jul 2, 2019
@vikaschoudhary16 vikaschoudhary16 deleted the hc-featuregate-enabledisable branch July 2, 2019 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants