-
Notifications
You must be signed in to change notification settings - Fork 303
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 V2 frontend namer #892
Conversation
Hi @skmatti. 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. |
/assign @freehan |
/assign @bowei |
/ok-to-test |
9aac2ff
to
1ae1340
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.
more to come
aa060b9
to
74dad25
Compare
} | ||
|
||
// ForwardingRule returns the name of forwarding rule based on given protocol. | ||
func (vn *V2IngressFrontendNamer) ForwardingRule(protocol NamerProtocol) string { |
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 address this.
"%s2-um-ksuid123-012345678901234567-012345678901234567-4mwbp6m5", | ||
}, | ||
} | ||
for _, prefix := range []string{"k8s", "mci"} { |
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 is "mci" 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.
Testing this with different prefixes, it could have been any random word.
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 would change it to "arbitrary-prefix" to make that clear.
pkg/test/utils.go
Outdated
@@ -80,3 +86,27 @@ func DecodeIngress(data []byte) (*v1beta1.Ingress, error) { | |||
|
|||
return obj.(*v1beta1.Ingress), nil | |||
} | |||
|
|||
// Flag is a type representing controller flag. | |||
type Flag string |
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 is this used for? I don't see it used anywhere in this 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.
This is used for saving flags when overriding them in unit tests. This potentially other tests from using the value set by a test.
Made this variable private as all of its uses are within the file.
efc27ee
to
a3d1201
Compare
pkg/controller/controller.go
Outdated
|
||
var syncErr error | ||
// Perform GC as a deferred function. | ||
defer func() { |
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 very much dislike doing complex actions like this in a defer call as it is very hard to understand the code flow (almost like exception handling in C++/Java).
Can we make this a helper function and call it on the appropriate error paths?
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.
We wanted to have a single function to handle all GC paths. But, I guess this makes it very hard to understand. Modified this back to the original workflow.
pkg/controller/controller.go
Outdated
lbc.ctx.Recorder(ing.Namespace).Eventf(ing, apiv1.EventTypeWarning, "Translate", msg.Error()) | ||
return msg | ||
err = fmt.Errorf("error while evaluating the ingress spec: %v", utils.JoinErrs(errs)) | ||
lbc.ctx.Recorder(ing.Namespace).Eventf(ing, apiv1.EventTypeWarning, "Translate", err.Error()) |
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.
Is there a reason why we don't always emit an event on all error paths?
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.
Add events for GC errors
pkg/controller/controller.go
Outdated
// ensureFinalizer ensures that a finalizer is attached. | ||
func (lbc *LoadBalancerController) ensureFinalizer(ing *v1beta1.Ingress) error { | ||
if !flags.F.FinalizerAdd { | ||
klog.V(4).Infof("Adding finalizers not enabled") |
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.
Error log
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.
Do we need to error out if finalizer is not enabled. Moved this check outside so this function does what the name says.
Can we make sure that all major actions (deleting, adding finalizer) will result in a log line at V(2)? |
pkg/controller/controller.go
Outdated
return err | ||
} | ||
if err := common.EnsureFinalizer(ing, ingClient, finalizerKey); err != nil { | ||
klog.Errorf("common.EnsureFinalizer(%q, _, %q) = %v, want nil", ingKey, finalizerKey, 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.
leave out ", want nil", it's redundant
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.
Does this use the optimistic concurrency control on write? (see https://github.com/eBay/Kubernetes/blob/master/docs/devel/api-conventions.md#concurrency-control-and-consistency)
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.
Seems like underlying call should be a "PATCH" -- can fix this later, file a bug.
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.
Added a TODO
pkg/controller/controller.go
Outdated
// - Does not need cleanup | ||
// - Finalizer enabled : all backends | ||
// - Finalizer disabled : v1 frontends and all backends | ||
func gcPath(ingExists bool, ing *v1beta1.Ingress) (namer.Scheme, 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.
shouldn't we call this gcNamingScheme?
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 we make the return value less error prone? I think you want to return one of three values, but it's being expressed as a pair ({v1|v2}, bool)
type gcAlgorithm int
const (
noCleanupNeeded gcAlgorithm = iota
cleanupV1FrontendResources
cleanupV2FrontendResources
)
func gcAlgorithmForIngress(ingExists ...) gcAlgorithm {
...
}
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
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
pkg/firewalls/controller_test.go
Outdated
@@ -46,7 +46,7 @@ func newFirewallController() *FirewallController { | |||
DefaultBackendSvcPort: test.DefaultBeSvcPort, | |||
} | |||
|
|||
ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, fakeGCE, defaultNamer, ctxConfig) | |||
ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, fakeGCE, defaultNamer, "", 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.
for raw consts empty string, we usually put the name of the variable to aid the reader:
ctx := context.NewControllerContext(nil, kubeClient, backendConfigClient, nil, fakeGCE, defaultNamer, /*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.
Not sure if this needed for tests. gofmt changes this to,
"" /*kubeSystemUID*/
Added this anyway.
Looks pretty good, almost there |
b371731
to
86fe9a5
Compare
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// EnsureDeleteV2Finalizer implements Controller. | ||
func (lbc *LoadBalancerController) EnsureDeleteV2Finalizer(ing *v1beta1.Ingress) error { |
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 function never returns anything but nil for error.
Either remove the return value or figure out if the error needs to be propagated.
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 return error. Fixed
pkg/utils/utils.go
Outdated
@@ -70,8 +70,21 @@ const ( | |||
// ToBeDeletedTaint is the taint that the autoscaler adds when a node is scheduled to be deleted | |||
// https://github.com/kubernetes/autoscaler/blob/cluster-autoscaler-0.5.2/cluster-autoscaler/utils/deletetaint/delete.go#L33 | |||
ToBeDeletedTaint = "ToBeDeletedByClusterAutoscaler" | |||
|
|||
// NoCleanUpNeeded, CleanupV1FrontendResources and CleanupV2FrontendResources | |||
// are used to specify the frontend GC algorithm. |
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.
does this type have to be in util package (or exported)
put the constants with the type so the reader doesn't have to search around to find where they are defined.
type FrontendGCAlgorithm int
const (
// NoCleanUpNeeded ...
...
)
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.
Yes, needs to used in both controller and sync packages.
return false | ||
} | ||
|
||
// LbName returns loadbalancer name. |
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.
You should document what LbName is used for. Is it the name of a GCP resource or something else?
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 is used for generating GCP resource names, added a comment.
@@ -65,7 +65,7 @@ func fakeTranslator() *Translator { | |||
HealthCheckPath: "/", | |||
DefaultBackendHealthCheckPath: "/healthz", | |||
} | |||
ctx := context.NewControllerContext(nil, client, backendConfigClient, nil, nil, defaultNamer, ctxConfig) | |||
ctx := context.NewControllerContext(nil, client, backendConfigClient, nil, nil, defaultNamer, "" /*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.
the style is to put the comment in front of the value.
/*kubeSystemUID*/""
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bowei, skmatti 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 part4 of V2 Namer Migration: #858.
Fixes: #537
This PR introduces a new naming scheme for for the following frontend resources:
This should resolve frontend resource naming collision issues.
The changes made in v2 naming scheme:
k8s{version-id}-{resource-prefix}-{8-char-hash-of-kube-system-uid}-{namespace}-{name}-{8-char-hash}
Namespace and Name are truncated evenly until their combined length is 36 in case of overflows. The 8 character suffix hash is created from full namespace and name.
Example http target proxy:
k8s2-tp-ksuid123-namespace-name-wddys49o
Frontend GC workflow changes:
GC workflow