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

Add check for iptables rule to keepalived-monitor #70

Merged

Conversation

cybertron
Copy link
Member

In order to have keepalived use the loadbalanced api endpoint, we need to know whether the iptables rule to redirect traffic to haproxy is present. Since the keepalived container doesn't have the necessary bits to work with iptables itself, we can instead do it in the monitor container and just use a file to indicate whether the rule is present. This also allows us to reuse the haproxy-monitor code for inspecting iptables, which means it should be less likely to get out of sync.

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 2, 2020
Copy link
Member Author

@cybertron cybertron left a comment

Choose a reason for hiding this comment

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

/hold

There are one or two things I'd like to clean up before this merges. I believe it is working now though.

cmd/dynkeepalived/dynkeepalived.go Outdated Show resolved Hide resolved
pkg/monitor/dynkeepalived.go Outdated Show resolved Hide resolved
@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 2, 2020
Copy link
Member

@bcrochet bcrochet left a comment

Choose a reason for hiding this comment

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

Couple of comments. Otherwise lgtm.

cmd/dynkeepalived/dynkeepalived.go Outdated Show resolved Hide resolved
pkg/monitor/dynkeepalived.go Outdated Show resolved Hide resolved
pkg/monitor/iptables.go Outdated Show resolved Hide resolved
if err != nil {
log.Error("Failed to check for haproxy firewall rule")
} else {
filePath := "/var/run/keepalived/iptables-rule-exists"
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 it will be better to set filename only once and not every loop iteration

Copy link
Contributor

@yboaron yboaron Jul 5, 2020

Choose a reason for hiding this comment

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

IIRC, Keepalived monitor runs also in worker nodes, I guess we shouldn't run this check for worker nodes.

Maybe I'm missing something here, but it seems to me that haproxy-monitor is the right place to add this logic to.

Copy link
Member Author

Choose a reason for hiding this comment

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

haproxy-monitor doesn't share its /var/run mount with keepalived. I would also argue that haproxy doesn't care about this file. It's consumed by keepalived, so it should be done in the keepalived monitor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, and I moved the filename to a const at the top of the file. Good suggestion.

}
}
} else {
_, err := os.Stat(filePath)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we just call to os.remove and consider err=nil and err = file not exist as OK?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably, but once I DRY the file existence logic it's one more if statement versus a second clause in another. Plus this way the logic for both creation and removal is the same.

cybertron added a commit to cybertron/baremetal-runtimecfg that referenced this pull request Jul 10, 2020
Addressing some review comments on openshift#70. No functional changes, just
some grammar/naming/efficiency improvements.
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 11, 2020
cybertron added a commit to cybertron/baremetal-runtimecfg that referenced this pull request Jul 14, 2020
Addressing some review comments on openshift#70. No functional changes, just
some grammar/naming/efficiency improvements.
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 14, 2020
@cybertron
Copy link
Member Author

/retest

cybertron added a commit to cybertron/baremetal-runtimecfg that referenced this pull request Jul 17, 2020
Addressing some review comments on openshift#70. No functional changes, just
some grammar/naming/efficiency improvements.
@celebdor
Copy link
Contributor

/retest

@bcrochet
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 22, 2020
The keepalived container is missing the shim script that allows us
to call the host iptables. However, we can do the check in the
monitor container and just use a file to indicate whether the rule
is present.
A PREROUTING rule does not apply to traffic originating from the
same host, and as a result our redirect doesn't apply when the node
holding the API VIP attempts to contact it. This adds an OUTPUT rule
to handle that case. The only difference is that it goes to the
OUTPUT chain instead of PREROUTING, and a "-o lo" param needs to be
added to the rule spec.
Addressing some review comments on openshift#70. No functional changes, just
some grammar/naming/efficiency improvements.
We need these fields to avoid hard-coding ports in the keepalived
healthchecks.
We are now templating scripts, which means we need to keep their
executable bit set when rendering them. This will ensure the
permissions set on the template are maintained for the rendered
version.
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 28, 2020
@cybertron
Copy link
Member Author

/retest

packet failure

@cybertron
Copy link
Member Author

/retest

Copy link
Member

@bcrochet bcrochet left a comment

Choose a reason for hiding this comment

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

Just a couple of cleanups. I can be convinced to move those to another PR.

pkg/monitor/iptables.go Outdated Show resolved Hide resolved
pkg/monitor/iptables.go Outdated Show resolved Hide resolved
return false, err
}

ruleSpec, err := getHAProxyRuleSpec(apiVip, apiPort, lbPort, false)
Copy link
Member

Choose a reason for hiding this comment

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

The magic param at the end doesn't really convey what it is for. One would have to look at the function definition to know, and even then it's not totally clear. Can we change it to maybe add a type for it?

@cybertron
Copy link
Member Author

/retest

I'm told metal-ipi is working again...

@cybertron
Copy link
Member Author

/hold cancel

The reasons for the original hold have long since been addressed.

@openshift-ci-robot openshift-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 30, 2020
@celebdor
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 31, 2020
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bcrochet, celebdor, cybertron

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:
  • OWNERS [bcrochet,celebdor,cybertron]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 986ace1 into openshift:master Jul 31, 2020
mandre added a commit to mandre/baremetal-runtimecfg that referenced this pull request Oct 15, 2020
In order to have keepalived use the loadbalanced api endpoint, we need
to know whether the iptables rule to redirect traffic to haproxy is
present. Since the keepalived container doesn't have the necessary bits
to work with iptables itself, we can instead do it in the monitor
container and just use a file to indicate whether the rule is present.
This also allows us to reuse the haproxy-monitor code for inspecting
iptables, which means it should be less likely to get out of sync.

This backports openshift#70
to release-4.5.
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants