← Back to Pull requests

Fix a flaky test on changing namespace annotation #636

Merged
yiqigao217 merged 1 files (43 lines) on Apr 09, 2020 18:41 UTC
View on GitHub
yiqigao217 yiqigao217 commented on Apr 09, 2020 15:24 UTC
Author

Instead of changing the annotation of the namespace created by the hns
instance, this PR creates a conflict hns instance with the name of an
already-existing namespace.

Tested by 'make test'.

Fixes #560

Diff: 43 lines (+9 / -34) across 1 files Reviewer: adrianchung Review duration: 196m
All Vouch review confidence checks passed
Residual risk 0.02 = Change Risk (0.26) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.26 · 43 lines diff across 1 files
0.26
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.90 · 5 substantive comment(s)
0.90
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
90%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.226
Real PR Conversation Timeline
13 items
yiqigao217 yiqigao217 commented on Apr 09, 2020 15:25 UTC
Author

/assign @adrianludwin
cc @sophieliu15 , @adrianchung

adrianchung adrianchung commented on code on Apr 09, 2020 17:20 UTC
Code Review
incubator/hnc/pkg/reconcilers/hierarchical_namespace_test.go:1
@@ -57,24 +56,14 @@ var _ = Describe("HierarchicalNamespace", func() {
 	})
 
 	It("should set the hns.status.state to Conflict if the namespace's owner annotation is wrong", func() {
-		// Create "bar" hns in "foo" namespace.
-		foo_hns_bar := newHierarchicalNamespace(barName, fooName)
-		updateHierarchicalNamespace(ctx, foo_hns_bar)
-
-		// It should set the self-serve subnamespace's owner annotation to the owner
-		// namespace (should set bar's owner annotation to "foo").
-		Eventually(func() string {
-			return getNamespace(ctx, barName).GetAnnotations()[api.AnnotationOwner]
-		}).Should(Equal(fooName))
-
-		// Todo fix this flacky test on changing the namespace annotation. See issue:
-		//	 https://github.com/kubernetes-sigs/multi-tenancy/issues/560
-		// Sleep 1 second to avoid updating the namespace instance too quickly.
-		time.Sleep(1 * time.Second)
-
-		// Clear the owner annotation and the HNS state should be set to "Conflict".
-		clearAnnotations(ctx, barName)
-		Eventually(getHNSState(ctx, fooName, barName)).Should(Equal(api.Conflict))
+		// Create "baz" namespace.
+		bazName := createNS(ctx, "baz")
+		// Create "baz" hns in "foo" namespace. Even "baz" namespace has already existed, we can
+		// still create the hns instance using HNC SA to bypass the webhook here. However, we
+		// should get conflict state on the newly created "baz" hns instance.

I see that the end result here is that we end up with an api conflict. However, I'm unclear how this ties into the test name because I don't see anything in here about annotations anymore. Could you clarify please?

adrianchung adrianchung commented on code on Apr 09, 2020 17:21 UTC
Code Review
incubator/hnc/pkg/reconcilers/hierarchical_namespace_test.go:1
@@ -57,24 +56,14 @@ var _ = Describe("HierarchicalNamespace", func() {
 	})
 
 	It("should set the hns.status.state to Conflict if the namespace's owner annotation is wrong", func() {
-		// Create "bar" hns in "foo" namespace.
-		foo_hns_bar := newHierarchicalNamespace(barName, fooName)
-		updateHierarchicalNamespace(ctx, foo_hns_bar)
-
-		// It should set the self-serve subnamespace's owner annotation to the owner
-		// namespace (should set bar's owner annotation to "foo").
-		Eventually(func() string {
-			return getNamespace(ctx, barName).GetAnnotations()[api.AnnotationOwner]
-		}).Should(Equal(fooName))
-
-		// Todo fix this flacky test on changing the namespace annotation. See issue:
-		//	 https://github.com/kubernetes-sigs/multi-tenancy/issues/560
-		// Sleep 1 second to avoid updating the namespace instance too quickly.
-		time.Sleep(1 * time.Second)
-
-		// Clear the owner annotation and the HNS state should be set to "Conflict".
-		clearAnnotations(ctx, barName)
-		Eventually(getHNSState(ctx, fooName, barName)).Should(Equal(api.Conflict))
+		// Create "baz" namespace.
+		bazName := createNS(ctx, "baz")
+		// Create "baz" hns in "foo" namespace. Even "baz" namespace has already existed, we can

Nit.. grammar. "Even though "baz" namespace already exists"

adrianchung adrianchung commented on Apr 09, 2020 17:21 UTC
Contributor

Less flaky tests = great :D Thanks for doing this Yiqi!

sophieliu15 sophieliu15 commented on code on Apr 09, 2020 17:25 UTC
Code Review
incubator/hnc/pkg/reconcilers/hierarchical_namespace_test.go:1
@@ -57,24 +56,14 @@ var _ = Describe("HierarchicalNamespace", func() {
 	})
 
 	It("should set the hns.status.state to Conflict if the namespace's owner annotation is wrong", func() {

Maybe specify why the owner annotation is wrong, e.g., IIUC,
"should set the hns.status.state to Conflict if a namespace of the same name already exists"

yiqigao217 yiqigao217 commented on code on Apr 09, 2020 17:30 UTC
Code Review
incubator/hnc/pkg/reconcilers/hierarchical_namespace_test.go:1
@@ -57,24 +56,14 @@ var _ = Describe("HierarchicalNamespace", func() {
 	})
 
 	It("should set the hns.status.state to Conflict if the namespace's owner annotation is wrong", func() {
-		// Create "bar" hns in "foo" namespace.
-		foo_hns_bar := newHierarchicalNamespace(barName, fooName)
-		updateHierarchicalNamespace(ctx, foo_hns_bar)
-
-		// It should set the self-serve subnamespace's owner annotation to the owner
-		// namespace (should set bar's owner annotation to "foo").
-		Eventually(func() string {
-			return getNamespace(ctx, barName).GetAnnotations()[api.AnnotationOwner]
-		}).Should(Equal(fooName))
-
-		// Todo fix this flacky test on changing the namespace annotation. See issue:
-		//	 https://github.com/kubernetes-sigs/multi-tenancy/issues/560
-		// Sleep 1 second to avoid updating the namespace instance too quickly.
-		time.Sleep(1 * time.Second)
-
-		// Clear the owner annotation and the HNS state should be set to "Conflict".
-		clearAnnotations(ctx, barName)
-		Eventually(getHNSState(ctx, fooName, barName)).Should(Equal(api.Conflict))
+		// Create "baz" namespace.
+		bazName := createNS(ctx, "baz")
+		// Create "baz" hns in "foo" namespace. Even "baz" namespace has already existed, we can
+		// still create the hns instance using HNC SA to bypass the webhook here. However, we
+		// should get conflict state on the newly created "baz" hns instance.

Ah right, I will make it clearer in the code and comment that baz namespace has an empty owner annotation since it's not created by HNS reconciler. Therefore, the baz hns instance in foo namespace should have a conflict since the owner annotation of baz doesn't point to foo.

yiqigao217 yiqigao217 commented on code on Apr 09, 2020 17:31 UTC
Code Review
incubator/hnc/pkg/reconcilers/hierarchical_namespace_test.go:1
@@ -57,24 +56,14 @@ var _ = Describe("HierarchicalNamespace", func() {
 	})
 
 	It("should set the hns.status.state to Conflict if the namespace's owner annotation is wrong", func() {
-		// Create "bar" hns in "foo" namespace.
-		foo_hns_bar := newHierarchicalNamespace(barName, fooName)
-		updateHierarchicalNamespace(ctx, foo_hns_bar)
-
-		// It should set the self-serve subnamespace's owner annotation to the owner
-		// namespace (should set bar's owner annotation to "foo").
-		Eventually(func() string {
-			return getNamespace(ctx, barName).GetAnnotations()[api.AnnotationOwner]
-		}).Should(Equal(fooName))
-
-		// Todo fix this flacky test on changing the namespace annotation. See issue:
-		//	 https://github.com/kubernetes-sigs/multi-tenancy/issues/560
-		// Sleep 1 second to avoid updating the namespace instance too quickly.
-		time.Sleep(1 * time.Second)
-
-		// Clear the owner annotation and the HNS state should be set to "Conflict".
-		clearAnnotations(ctx, barName)
-		Eventually(getHNSState(ctx, fooName, barName)).Should(Equal(api.Conflict))
+		// Create "baz" namespace.
+		bazName := createNS(ctx, "baz")
+		// Create "baz" hns in "foo" namespace. Even "baz" namespace has already existed, we can

Thanks will update it!

yiqigao217 yiqigao217 commented on code on Apr 09, 2020 17:38 UTC
Code Review
incubator/hnc/pkg/reconcilers/hierarchical_namespace_test.go:1
@@ -57,24 +56,14 @@ var _ = Describe("HierarchicalNamespace", func() {
 	})
 
 	It("should set the hns.status.state to Conflict if the namespace's owner annotation is wrong", func() {

Yes, for the hns instance perspective, the conflict is only when the annotation doesn't match. It could be the reason you mentioned or someone with higher privileges changes the owner annotation. Here I wanted to introduce a mismatch to trigger the conflict.

yiqigao217 yiqigao217 commented on Apr 09, 2020 18:37 UTC
Author

Thanks for the reviews! I overthought about it in my first commit. Now I just simplified the comments and it should be easy to explain or understand now. @sophieliu15 @adrianchung

adrianludwin adrianludwin commented on Apr 09, 2020 18:39 UTC
Reviewer

/lgtm
/approve

adrianludwin adrianludwin commented on Apr 09, 2020 18:40 UTC
Contributor

Ugh, I can't Git today

/lgtm
/approve

k8s-ci-robot k8s-ci-robot commented on Apr 09, 2020 18:40 UTC
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: <a href="https://github.com/kubernetes-sigs/multi-tenancy/pull/636#issuecomment-611689615" title="Approved">adrianludwin</a>, <a href="https://github.com/kubernetes-sigs/multi-tenancy/pull/636#" title="Author self-approved">yiqigao217</a>

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:

  • ~~OWNERS~~ [adrianludwin]
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":[]} -->

    Reviewers
    Assignees
    yiqigao217 yiqigao217
    Labels
    risk: low confidence: 90.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 25.6% (LOW) · Higher = larger blast radius
    25.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.8% · Lower = rushed or shallow review
    90.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 2.4% · Safe to merge
    2.4%