-
Notifications
You must be signed in to change notification settings - Fork 892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add test for pkg/controllers/cluster #5467
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #5467 +/- ##
==========================================
+ Coverage 31.70% 32.33% +0.62%
==========================================
Files 643 643
Lines 44444 44445 +1
==========================================
+ Hits 14093 14371 +278
+ Misses 29322 28983 -339
- Partials 1029 1091 +62
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
if tt.cluster != nil { | ||
if err := tc.Client.Create(context.Background(), tt.cluster, &client.CreateOptions{}); err != nil { | ||
t.Fatal(err) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add deletion of these resources at the end of the test if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi, thanks for the review. i cant understand why we need to add the delete operation at the end. my understand is that the obj created by fakeclient should be automatically released after each test case is completed. can you help me understand? thanks~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh right, i misunderstood it. the remaining pr looks good to me. Thanks for correction.
/lgtm |
@anujagrawal699: changing LGTM is restricted to collaborators In response to this:
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-sigs/prow repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
} | ||
} | ||
|
||
got, err := c.Reconcile(context.Background(), req) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to checking err and result, can you determine whether cluster resources are expected?
Other tests are similar.
hi @XiShanYongYe-Chang, i have made some changes based on your comment. please check it~ |
Thanks @xovoxy |
wantErr: false, | ||
}, | ||
{ | ||
name: "cluster with ready condition", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case run failed on my local side:
=== RUN TestController_monitorClusterHealth
=== RUN TestController_monitorClusterHealth/cluster_with_ready_condition
cluster_controller_test.go:441: Cluster resource get test-cluster, want false
--- FAIL: TestController_monitorClusterHealth (0.00s)
--- FAIL: TestController_monitorClusterHealth/cluster_with_ready_condition (0.00s)
FAIL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, let me take a look again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I update the code to print the detail cluster object:
--- a/pkg/controllers/cluster/cluster_controller_test.go
+++ b/pkg/controllers/cluster/cluster_controller_test.go
@@ -438,7 +438,7 @@ func TestController_monitorClusterHealth(t *testing.T) {
cleanUpCluster(cluster)
if !reflect.DeepEqual(cluster, tt.wCluster) {
- t.Errorf("Cluster resource get %+v, want %+v", cluster, tt.wCluster)
+ t.Errorf("Cluster resource get %+v, want %+v", *cluster, *tt.wCluster)
return
}
Then I run the test, it still failed(No matter how many times I run), the command output shows that the conditions of the cluster are different.
Cluster resource get
{TypeMeta:{Kind: APIVersion:} ObjectMeta:{Name:test-cluster GenerateName: Namespace: SelfLink: UID: ResourceVersion: Generation:0 CreationTimestamp:0001-01-01 00:00:00 +0000 UTC DeletionTimestamp:<nil> DeletionGracePeriodSeconds:<nil> Labels:map[] Annotations:map[] OwnerReferences:[] Finalizers:[karmada.io/cluster-controller] ManagedFields:[]} Spec:{ID: SyncMode:Pull APIEndpoint: SecretRef:<nil> ImpersonatorSecretRef:<nil> InsecureSkipTLSVerification:false ProxyURL: ProxyHeader:map[] Provider: Region: Zone: Zones:[] Taints:[] ResourceModels:[]} Status:{KubernetesVersion: APIEnablements:[] Conditions:[{Type:Ready Status:True ObservedGeneration:0 LastTransitionTime:0001-01-01 00:00:00 +0000 UTC Reason: Message:}] NodeSummary:<nil> ResourceSummary:<nil> RemedyActions:[]}}, want
{TypeMeta:{Kind: APIVersion:} ObjectMeta:{Name:test-cluster GenerateName: Namespace: SelfLink: UID: ResourceVersion: Generation:0 CreationTimestamp:0001-01-01 00:00:00 +0000 UTC DeletionTimestamp:<nil> DeletionGracePeriodSeconds:<nil> Labels:map[] Annotations:map[] OwnerReferences:[] Finalizers:[karmada.io/cluster-controller] ManagedFields:[]} Spec:{ID: SyncMode:Pull APIEndpoint: SecretRef:<nil> ImpersonatorSecretRef:<nil> InsecureSkipTLSVerification:false ProxyURL: ProxyHeader:map[] Provider: Region: Zone: Zones:[] Taints:[] ResourceModels:[]} Status:{KubernetesVersion: APIEnablements:[] Conditions:[{Type:Ready Status:Unknown ObservedGeneration:0 LastTransitionTime:0001-01-01 00:00:00 +0000 UTC Reason:ClusterStatusUnknown Message:Cluster status controller stopped posting cluster status.}] NodeSummary:<nil> ResourceSummary:<nil> RemedyActions:[]}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, i will check it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Step 5: Check whether the probe timestamp has timed out.
if metav1.Now().After(clusterHealth.probeTimestamp.Add(gracePeriod)) {
based on the different in the test results, i suspect this section of logic is causing the issue, but I still dont fully understand why. the previous test cases are still passing on my local.
finally, I set the c.ClusterMonitorGracePeriod = 40 * time.Second
and modified the test cases. therefor within the timeout period, controller wont change the condition.
please take a look at this, thanks~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @xovoxy, let me have a try.
9d6eb1b
to
6df9222
Compare
Namespace: "default", | ||
}, | ||
} | ||
if err := tc.syncBindingEviction(key); (err != nil) != tt.wantErr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not enough to judge err.
How about moving the addition of taint_manager_test.go to the next PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me add some detail for this test case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi, i have added some details about this, could you check it ? if it still not enough, i will consider your suggestion and moving the taint_manager_test.go to the next pr.
Signed-off-by: xovoxy <xilovele@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks~
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: XiShanYongYe-Chang The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind failing-test
What this PR does / why we need it:
add some test for /pkg/controllers/cluster, improve test coverage to 60 above
Which issue(s) this PR fixes:
Parts of ##5235
Special notes for your reviewer:
Does this PR introduce a user-facing change?: