-
Notifications
You must be signed in to change notification settings - Fork 301
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
Firewall CR migration #1626
Firewall CR migration #1626
Conversation
Hi @sugangli. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
Welcome @sugangli! |
/ok-to-test |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
/remove-lifecycle rotten |
cd340f6
to
23bbc02
Compare
4602de8
to
d0fe810
Compare
3fb41b5
to
46f25a7
Compare
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 think this mostly looks good to me. I have thought about the two flags, and I think the enforcement flag should be renamed to indicate a behavior in ingress-gce instead of a behavior on an external component.
Thanks Sugang!
pkg/controller/controller_test.go
Outdated
@@ -72,7 +74,7 @@ func newLoadBalancerController() *LoadBalancerController { | |||
DefaultBackendSvcPort: test.DefaultBeSvcPort, | |||
HealthCheckPath: "/", | |||
} | |||
ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, nil, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig) | |||
ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, firewallClient, nil, nil, nil, fakeGCE, namer, "" /*kubeSystemUID*/, ctxConfig) |
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.
Trying to understand why this was necessary for the tests? Is there something that is depending on the firewallClient even when the flag is disabled?
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.
Updated.
cmd/glbc/main.go
Outdated
@@ -279,7 +287,7 @@ func runControllers(ctx *ingctx.ControllerContext) { | |||
}) | |||
} | |||
|
|||
fwc := firewalls.NewFirewallController(ctx, flags.F.NodePortRanges.Values()) | |||
fwc := firewalls.NewFirewallController(ctx, flags.F.NodePortRanges.Values(), flags.F.EnableFirewallCR, flags.F.EnableFWControllerEnforcement) |
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.
should this pass in !flags.F.EnableFWControllerEnforcement
since the field in the FirewallController is enforceCR?
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.
Per discussion, I renamed it to DisableFWEnforcement. Since they mean the same thing (disable ingress controller FW enforcement = enable FW controller enforcement), I renamed all of them without changing the logic.
pkg/firewalls/controller.go
Outdated
@@ -56,20 +57,25 @@ type FirewallController struct { | |||
translator *translator.Translator | |||
nodeLister cache.Indexer | |||
hasSynced func() bool | |||
enableCR bool | |||
enforceCR bool |
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.
similar to the flag, enforceCR
is confusing to understand in the code. Maybe disableFWEnforcement
? I am assuming in this case disable will be easier to right the logic for than the other way.
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.
See the comment above.
pkg/firewalls/firewalls.go
Outdated
if err != nil { | ||
// Create the CR if it is not found. | ||
if api_errors.IsNotFound(err) { | ||
klog.V(3).Infof("ensureFirewallCR Create CR :%+v", expectedFWCR) |
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 think we should update the others to be like Creating
or Created
depending on whether the action we are logging has happened or not. If you think the error has enough context, I am fine with this as is.
pkg/firewalls/firewalls.go
Outdated
klog.V(3).Infof("ensureFirewallCR Create CR :%+v", expectedFW) | ||
_, err = fw.Create(context.Background(), expectedFW, metav1.CreateOptions{}) | ||
} | ||
return err |
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 was more wondering if the error by itself has enough context, so whatever is consuming, we should be able to understand in the logs what caused it.
46f25a7
to
b97fbd4
Compare
pkg/firewalls/firewalls.go
Outdated
@@ -116,13 +150,126 @@ func (fr *FirewallRules) Sync(nodeNames, additionalPorts, additionalRanges []str | |||
return fr.updateFirewall(expectedFirewall) | |||
} | |||
|
|||
// ensureFirewallCR creates/updates the firewall CR | |||
// On CR update, it will read the conditions to see if there are errors updated by PFW controller. |
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.
please use full name for 'PFW'
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.
Done.
@@ -119,6 +125,29 @@ func NewFirewallController( | |||
}, | |||
}) | |||
|
|||
if enableCR { | |||
// FW CRs will be updated/deleted by the PFW controller or the user. Ingress controller need to watch such events |
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.
please use full name for 'PFW'
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.
Done.
cmd/glbc/main.go
Outdated
@@ -41,6 +41,7 @@ import ( | |||
"k8s.io/client-go/tools/leaderelection" | |||
"k8s.io/client-go/tools/leaderelection/resourcelock" | |||
"k8s.io/client-go/tools/record" | |||
firewallclient "k8s.io/cloud-provider-gcp/crd/client/gcpfirewall/clientset/versioned" |
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.
please rename to firewallcrclient
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.
Done.
cmd/glbc/main.go
Outdated
@@ -133,6 +134,13 @@ func main() { | |||
} | |||
} | |||
|
|||
var firewallClient firewallclient.Interface |
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.
firewallCRClient
here and further
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.
firewallClient would suggest this is provisioning resources on the GCP
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.
Done.
cmd/glbc/main.go
Outdated
@@ -279,7 +287,12 @@ func runControllers(ctx *ingctx.ControllerContext) { | |||
}) | |||
} | |||
|
|||
fwc := firewalls.NewFirewallController(ctx, flags.F.NodePortRanges.Values()) | |||
if !flags.F.EnableFirewallCR { |
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 think we should panic here
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.
Agreed. Updated.
@@ -257,6 +259,8 @@ L7 load balancing. CSV values accepted. Example: -node-port-ranges=80,8080,400-5 | |||
flag.BoolVar(&F.EnableMultipleIGs, "enable-multiple-igs", false, "Enable using multiple unmanaged instance groups") | |||
flag.IntVar(&F.MaxIGSize, "max-ig-size", 1000, "Max number of instances in Instance Group") | |||
flag.DurationVar(&F.MetricsExportInterval, "metrics-export-interval", 10*time.Minute, `Period for calculating and exporting metrics related to state of managed objects.`) | |||
flag.BoolVar(&F.EnableFirewallCR, "enable-firewall-cr", false, "Enable generating firewall CR") |
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.
why not StringVar with 3 valid values?
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.
Technically I am fine with either way. But StringVar does not validate the values and we need to check it by ourselves? Plus, the other features flags are using Bool so it might be more consistent?
if enableCR { | ||
// FW CRs will be updated/deleted by the PFW controller or the user. Ingress controller need to watch such events | ||
// and act accordingly. | ||
ctx.FirewallInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ |
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.
ctx.FirewallInformer.AddEventHandler
what we get updates on? Firewall CRs rigth?
when the Platform Firewall Controller changes the CR?
or when customer changes something there?
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.
The PFW controller will update the status of the CR, and some status requires the ingress controller to take actions. For example, the ingress controller needs to populate gcloud command for the user if there is an XPNPermission error.
if name != curFW.Name { | ||
return | ||
} | ||
fwc.queue.Enqueue(queueKey) |
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.
what should be the queueKey?
I am confused why we always use the fake?
// queueKey is a "fake" key which can be enqueued to a task queue.
queueKey = &v1.Ingress{
ObjectMeta: metav1.ObjectMeta{Name: "queueKey"},
}
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.
Because we won't have more than one ingress firewall at any given time?
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 didn't catch this initially. Even if we will only have one, I think it makes sense to either have a constant for the name of the single firewall CR or to just enqueue the CR from the cur
in update func.
My preference is for the later, because I think it makes the most sense.
We should be checking that the firewall cr that we see is the one we expect before adding the queueKey.
b97fbd4
to
0256084
Compare
0256084
to
2d02964
Compare
2d02964
to
1194adb
Compare
What is the status of this change? |
I refactored L7 firewall pool code path according to what @cezarygerard proposed. Waiting for his comment. We have few more PRs to come after this. But I am only able to spend 20% of my time on this project. |
it's LGTM overall thank you for applying my suggestions let's just let's just remove this comment "//// if we had enum-like flag 'crMode' to guard the firewall CR creation the above code would look ~like:" |
1194adb
to
9c46823
Compare
/retest |
Addressed the comments Refactor firewall CR into a separate FW pool
9c46823
to
44b787c
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cezarygerard, sugangli 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 |
This PR is for migrating existing direct GCE FW configuration to our firewall CR approach. Only L7 firewall changes are included here. L4 changes will come later. Major changes:
Here is the algorithm in high-level: