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 support for Internal/Regional Static IP for L7-ILB #1174

Merged
merged 2 commits into from
Jul 29, 2020

Conversation

spencerhance
Copy link
Contributor

@spencerhance spencerhance commented Jul 6, 2020

This is implemented via an annotation "kubernetes.io/ingress.regional-static-ip-name". This uses the same prefix as the existing annotation, "global-static-ip-name."

This PR also depends on the update of k8s-cloud-provider in #1173

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 6, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @spencerhance. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 6, 2020
@k8s-ci-robot k8s-ci-robot requested review from freehan and thockin July 6, 2020 20:33
@freehan
Copy link
Contributor

freehan commented Jul 6, 2020

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 6, 2020
@spencerhance
Copy link
Contributor Author

Rebased since #1173 has merged. The tests should pass now.

"k8s.io/ingress-gce/pkg/flags"
"k8s.io/ingress-gce/pkg/utils"
"k8s.io/ingress-gce/pkg/utils/namer"
"k8s.io/klog"
)

// checkStaticIP reserves a static IP allocated to the Forwarding Rule.
// checkStaticIP reserves a regional or global static IP allocated to the Forwarding Rule.
func (l *L7) checkStaticIP() (err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

func TestCreateHTTPILBLoadBalancerStaticIp(t *testing.T) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The tests for checkStaticIP() are sort of included in loadbalancers_test.go right now since it also creates/gets resources from the GCE API, and piggybacks off of those mocks

globalIp := ing.GlobalStaticIPName()
regionalIp := ing.RegionalStaticIPName()

if globalIp != "" && regionalIp != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you need to validate if this is a L7 ILB then just return regionalStaticIP and ignore GlobalStaticIP?

vice versa for L7 XLB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, but I wanted to have a check for if the user specified both by accident

return "", false, fmt.Errorf("the given static IP name %v doesn't translate to an existing global static IP.",
// TODO(shance): Replace version
if ip, err := composite.GetAddress(l.cloud, key, meta.VersionGA); err != nil || ip == nil {
return "", false, fmt.Errorf("The given static IP name %v doesn't translate to an existing static IP.",
Copy link
Contributor

Choose a reason for hiding this comment

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

lower case for the initial character for error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -163,10 +163,16 @@ func (l *L7) getEffectiveIP() (string, bool, error) {
// TODO: Handle the last case better.

if l.runtimeInfo.StaticIPName != "" {
key, err := l.CreateKey(l.runtimeInfo.StaticIPName)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't you need to handle the L7 ILB for this case as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh I see. CreateKey handles it already.

if ip == nil {
klog.V(3).Infof("Creating static ip %v", managedStaticIPName)
err = l.cloud.ReserveGlobalAddress(&compute.Address{Name: managedStaticIPName, Address: l.fw.IPAddress})
address := &composite.Address{Name: managedStaticIPName, Address: l.fw.IPAddress, Version: meta.VersionGA}
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably worth having a l.newStaticAddress() function to output a composite.Address based on the L7 config.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I'm hesitant to split this out into a function since it's fairly short and we only use it once

Copy link
Contributor

Choose a reason for hiding this comment

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

having a separate function makes this a bit more self contained. Which means the special handling for ILB is invisible to the main flow.

if isInternal {
	// Used for L7 ILB
	address.AddressType = "INTERNAL"
}

Next time when changes are needed, it can just piggy back to the new function and do not touch the main flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay done, also added a unit test

This is done via a regional-static-ip annotation on the ingress
Copy link
Contributor

@freehan freehan left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 29, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: freehan, spencerhance

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 29, 2020
@k8s-ci-robot k8s-ci-robot merged commit 6c3ddf6 into kubernetes:master Jul 29, 2020
@spencerhance spencerhance deleted the internal-static-ip branch July 29, 2020 04:37
k8s-ci-robot added a commit that referenced this pull request Jul 31, 2020
Cherry pick #1174 [Implement support for Internal/Regional Static IP for L7-ILB] into release-1.9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants