Skip to content
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

Implement --watch-namespace flag #1317

Merged
merged 6 commits into from
May 18, 2021
Merged

Implement --watch-namespace flag #1317

merged 6 commits into from
May 18, 2021

Conversation

rainest
Copy link
Contributor

@rainest rainest commented May 13, 2021

Implement the --watch-namespace flag for Railgun's manager. The initial commit implements the same behavior as the 1.x flag; the second commit implements additional support for watching multiple discrete namespaces (as requested internally in FTI-2395 and frequent chat requests) while maintaining compatibility with 1.x behavior.

The improved version is simple to implement (almost everything is handled by controller-runtime), so I suggest we go with it and squash these into a single commit before merging. The first commit is mostly just to showcase how we would implement this if we want to implement only the 1.x behavior.

Note that MultiNamespacedCacheBuilder does not work independent of Namespace in Manager options, and notably cannot handle the default "watch all namespaces" behavior, hence the "determine how to configure namespace watchers" bit in run.go (adapted from an Operator Framework example).

Integration tests for the first option would be a bit difficult since they'd limit us to a single test namespace. However, I assert that it does at least work--the following change to existing tests will make everything fail by excluding the default namespace:

diff --git a/railgun/test/integration/suite_test.go b/railgun/test/integration/suite_test.go
index 17bb239a..a1ca5d0f 100644
--- a/railgun/test/integration/suite_test.go
+++ b/railgun/test/integration/suite_test.go
@@ -210,6 +210,7 @@ func deployControllers(ctx context.Context, ready chan ktfkind.ProxyReadinessEve
                                "--controller-kongplugin=disabled",
                                "--controller-kongconsumer=disabled",
                                "--election-id=integrationtests.konghq.com",
+                               "--watch-namespace=kube-system",
                                fmt.Sprintf("--ingress-class=%s", ingressClass),
                                "--log-level=trace",
                                "--log-format=text",

The second option is a bit more reasonable to test, though we do now need to maintain a list of namespaces with test content and can't test the default without an additional controller instance. The negative test is also a bit hand-wavy, as there's not really a good way to confirm that we don't see that config specifically because the Ingress is in another namespace. Unlike ingress class, we can't modify an existing Ingress to watch its routes flip on and off again.

Fix #1299

Add a --watch-namespace flag that mimics the 1.x flag behavior (watch
all namespaces by default and allow limiting the controller to one, and
only one namespace).
@rainest rainest requested a review from a team as a code owner May 13, 2021 21:23
@codecov
Copy link

codecov bot commented May 13, 2021

Codecov Report

Merging #1317 (1e148c2) into next (60c106a) will increase coverage by 3.28%.
The diff coverage is 28.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #1317      +/-   ##
==========================================
+ Coverage   52.90%   56.18%   +3.28%     
==========================================
  Files          35       35              
  Lines        3272     3394     +122     
==========================================
+ Hits         1731     1907     +176     
+ Misses       1408     1347      -61     
- Partials      133      140       +7     
Impacted Files Coverage Δ
cli/ingress-controller/main.go 0.24% <0.00%> (+0.01%) ⬆️
cli/ingress-controller/util.go 37.93% <ø> (ø)
internal/ingress/status/status.go 40.56% <ø> (ø)
pkg/kongstate/consumer.go 100.00% <ø> (ø)
pkg/kongstate/kongstate.go 37.64% <ø> (+12.94%) ⬆️
pkg/kongstate/route.go 88.13% <ø> (ø)
pkg/kongstate/service.go 80.00% <ø> (ø)
pkg/kongstate/upstream.go 55.00% <ø> (ø)
pkg/sendconfig/sendconfig.go 20.00% <0.00%> (ø)
pkg/util/logging.go 0.00% <0.00%> (ø)
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1118f04...1e148c2. Read the comment docs.

Implement support for watching multiple distinct namespaces using a
controller-runtime MultiNamespacedCacheBuilder.
Copy link
Contributor

@shaneutt shaneutt left a comment

Choose a reason for hiding this comment

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

Ultimately I have no blockers, but please do see my comments and let me know what you think.

railgun/manager/config.go Outdated Show resolved Hide resolved
@@ -105,6 +107,9 @@ func (c *Config) FlagSet() *pflag.FlagSet {
flagSet.StringVar(&c.LeaderElectionID, "election-id", "5b374a9e.konghq.com", `Election id to use for status update.`)
flagSet.StringVar(&c.FilterTag, "kong-filter-tag", "managed-by-railgun", "TODO")
flagSet.IntVar(&c.Concurrency, "kong-concurrency", 10, "TODO")
flagSet.StringVar(&c.WatchNamespace, "watch-namespace", apiv1.NamespaceAll,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Comment on lines +80 to +82
// this mode does not set the Namespace option, so the manager will default to watching all namespaces
// MultiNamespacedCacheBuilder imposes a filter on top of that watch to retrieve scoped resources
// from the watched namespaces only.
Copy link
Contributor

Choose a reason for hiding this comment

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

Good comments thanks 👍

Comment on lines +314 to +316
if useLegacyKIC() {
t.Skip("support for distinct namespace watches is not supported in legacy KIC")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're adding a compelling new option that wasn't available before, would this PR be a good a time as any to start up some 2.0 release notes and add this functionality as a bullet point for new gains?

railgun/test/integration/ingress_test.go Show resolved Hide resolved
railgun/test/integration/ingress_test.go Show resolved Hide resolved
railgun/test/integration/suite_test.go Outdated Show resolved Hide resolved
railgun/test/integration/suite_test.go Outdated Show resolved Hide resolved
@shaneutt shaneutt linked an issue May 18, 2021 that may be closed by this pull request
3 tasks
Travis Raines added 4 commits May 18, 2021 12:46
- Move supplemental namespace creation to test.
- Replace magic string with constant.
- Clean up extra created namespaces.
@rainest rainest merged commit ba0e0d1 into next May 18, 2021
@rainest rainest deleted the feat/rg-namespace-watch branch May 18, 2021 20:25
@shaneutt shaneutt changed the title Implement --watch-namespace flag for Railgun Implement --watch-namespace flag Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KIC 2.0: support watch-namespace flag
2 participants