Git Product home page Git Product logo

floaty's Introduction

Floaty

Cloud provider API integration for Keepalived

Floaty is a program suitable for use by a Keepalived notification script. By regularily enforcing the destination of a floating or elastic IP address it ensures that split-brain situations or external modifications to the destination have little impact.

For VRRP instances in MASTER status Floaty reads the Keepalived configuration. When no addresses are configured in the Floaty configuration the IP addresses assigned to the given VRRP instance are managed. Managing an IP address means to refresh its target host via a provider-specific API in a regular interval. Failures are handled gracefully.

For instances in BACKUP and FAULT status any existing instance for a previous MASTER status is terminated by sending a signal and waiting for its termination.

Logs are written to standard error.

Command line flags

  • --verbose: Produce more log messages. May also be enabled by setting the FLOATY_LOG_VERBOSE environment variable to a non-empty value.

  • --json-log: Output log messages in JSON format for further processing.

  • --dry-run: Updates to Floating IPs are only logged and not performed.

Configuration

Configuration data must be supplied as a YAML file. The top level is a map.

  • lock-file-template: Template for path to lock file for each VRRP instance. Must contain a single %s to be replaced by VRRP instance name. Defaults to /var/lock/floaty-%s.lock.

  • lock-timeout: How long to wait for lock as a duration. Defaults to 10 seconds.

  • keepalived-config: Path to Keepalived configuration. Defaults to /etc/keepalived/keepalived.conf. The configuration is parsed to verify the existence of the VRRP instance name given on the command line. If managed-addresses is not used the IP addresses assigned to the VRRP instance are used.

  • managed-addresses: Array with IP addresses to manage.

  • refresh-interval: How long to wait between refreshes of individual addresses as a duration. Defaults to 1 minute. Minimal jitter is automatically added to avoid the thundering herd problem.

  • refresh-timeout: How long refreshing an individual address may take at most as a duration. Defaults to 10 seconds. Refreshes are parallelized and do not wait for each other.

  • back-off: A map configuring the back-off behaviour for retries of failing address refreshes. Jitter is automatically added to avoid the thundering herd problem.

    • initial-interval: How long to wait for the first retry as a duration. Defaults to 1 second.
    • multiplier: Multiply backoff period by given number before retries. Defaults to 1.1.
    • max-interval: Maximum duration of backoff period. Defaults to 10 seconds.
    • max-elapsed-time: Give up on retries and revert to normal interval after given amount of time. Defaults to zero for infinite retries.
  • provider: Cloud API provider, must be either cloudscale or exoscale. Provider-specific settings are in separate keys.

  • cloudscale: Cloudscale.ch-specific settings as a map. When neither server-uuid nor hostname-to-server-uuid is specified a metadata service is used to automatically discover the instance UUID of a server.

    • endpoint: URL for API endpoint. Defaults to production URL.
    • token: API authentication token as a string. Must have write access.
    • server-uuid: UUID of next-hop server for IP address(es). Overrides hostname-to-server-uuid if both are given.
    • hostname-to-server-uuid: Map with hostname as key and next-hop server UUID as value. Hostname as reported by kernel is used for lookup.
  • exoscale: Exoscale-specific settings as a map.

    • endpoint: URL for API endpoint. Defaults to production URL.
    • key: API access key (starts with EXO).
    • secret: API access secret.
    • instance-id: Virtual machine ID as string; if not given a metadata service is used to automatically retrieve the ID of the machine running the program.

Hostnames

Hostnames used in the configuration must match the kernel's hostname as returned by Go's os.Hostname function. Depending on the system the name may or may not be a fully qualified domain name (FQDN).

On Linux systems the hostname command without parameters will return the configured name which is also retrievable from the /proc/sys/kernel/hostname pseudo file.

Example configuration

The configuration shown is for demonstration, not a recommendation.

lock-file-template: "/var/run/floaty.%s.lock"

refresh-interval: 2m

back-off:
  max-elapsed-time: 30s

provider: cloudscale
cloudscale:
  token: HELPIMTRAPPEDINATOKENGENERATOR
  hostname-to-server-uuid:
    lb1.example.net: 96defb88-002c-4985-b795-5c929bab23da
    lb2.example.net: 7d37a073-e84c-4fc6-b631-cc2e29d9d4ea
    lb3.example.net: e1dfe126-bc14-494e-998f-d221b02941b4

exoscale:
  key: EXOLICIOUS
  secret: NomNomNom

# See description: use only if Keepalived configuration doesn't contain
# addresses
managed-addresses:
  - 192.0.2.1/24
  - 192.0.2.2/24

Usage

Keepalived as of version 1.2.24 always redirects the output of notification scripts to /dev/null and does not support passing custom parameters. Because floaty requires a configuration file a wrapper needs to be used. In most cases a shell script is suitable. Example:

#!/bin/sh

/usr/bin/floaty /etc/keepalived/floaty-prod.yml "$@" 2>&1 | \
  logger --tag floaty-prod

Docker container

Docker only collects logs from PID 1 (init). As of Docker 1.13 there is no other way to emit runtime logs than to redirect into the file descriptors of PID 1.

#!/bin/sh

exec /bin/floaty --json-log /etc/floaty.yml "$@" \
  >>/proc/1/fd/1 2>>/proc/1/fd/2

Test mode

Floaty implements provider-specific self-tests which can be run outside of Keepalived.

/bin/floaty --json-log --verbose --test /etc/floaty.yml

FIFO mode

Floaty can run in FIFO mode allowing it to process notification events through a FIFO instead of using notify scrips

/bin/floaty --fifo /etc/floaty.yml /tmp/fifo

External links

floaty's People

Contributors

bastjan avatar ccremer avatar corvus-ch avatar glrf avatar renovate-bot avatar renovate[bot] avatar simu avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

floaty's Issues

Race condition / flakyness in E2E tests

Describe the bug

Tests panic with a slice bounds out of range [512:0] from time to time. Check if this is the tests or floaty itself.

--- FAIL: TestE2E_Master (0.00s)
panic: runtime error: slice bounds out of range [512:0] [recovered]
	panic: runtime error: slice bounds out of range [5[12](https://github.com/vshn/floaty/actions/runs/8187580972/job/22388362353#step:7:13):0]

goroutine 6 [running]:
testing.tRunner.func1.2({0x702f80, 0xc0000224c8})
	/home/runner/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1631 +0x24a
testing.tRunner.func1()
	/home/runner/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:1634 +0x377
panic({0x702f80?, 0xc0000224c8?})
	/home/runner/go/pkg/mod/golang.org/[email protected]/src/runtime/panic.go:770 +0x[13](https://github.com/vshn/floaty/actions/runs/8187580972/job/22388362353#step:7:14)2
bytes.(*Buffer).readSlice(0x7a80c0?, 0x50?)
	/home/runner/go/pkg/mod/golang.org/[email protected]/src/bytes/buffer.go:440 +0x105
bytes.(*Buffer).ReadString(...)
	/home/runner/go/pkg/mod/golang.org/[email protected]/src/bytes/buffer.go:459
github.com/vshn/floaty.expectUpdate(0xc00012a9c0, 0xc00007f9b0, {0x724f53, 0xe}, 0x3)
	/home/runner/work/floaty/floaty/e2e_test.go:130 +0x2fb
github.com/vshn/floaty.TestE2E_Master(0xc00012a9c0)
	/home/runner/work/floaty/floaty/e2e_test.go:34 +0x22e
testing.tRunner(0xc00012a9c0, 0x7546e8)
	/home/runner/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:[16](https://github.com/vshn/floaty/actions/runs/8187580972/job/22388362353#step:7:17)89 +0xfb
created by testing.(*T).Run in goroutine 1
	/home/runner/go/pkg/mod/golang.org/[email protected]/src/testing/testing.go:[17](https://github.com/vshn/floaty/actions/runs/8187580972/job/22388362353#step:7:18)42 +0x390
exit status 2
FAIL	github.com/vshn/floaty	0.005s

Expected behavior

Non-flakey tests.

To Reproduce

Run tests.

Environment (please complete the following information):

https://github.com/vshn/floaty/actions/runs/8187515308/job/22388153353
https://github.com/vshn/floaty/actions/runs/8187580972/job/22388362353

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

dockerfile
Dockerfile
  • docker.io/library/alpine 3.19
github-actions
.github/workflows/lint.yml
  • actions/checkout v4
  • actions/setup-go v5
  • actions/cache v4
.github/workflows/release.yml
  • actions/checkout v4
  • actions/setup-go v5
  • actions/cache v4
  • crazy-max/ghaction-import-gpg v6
  • docker/login-action v3
  • mikepenz/release-changelog-builder-action v4
  • goreleaser/goreleaser-action v5
  • actions/upload-artifact v4
  • actions/upload-artifact v4
  • actions/upload-artifact v4
.github/workflows/test.yml
  • actions/checkout v4
  • actions/setup-go v5
  • actions/cache v4
gomod
go.mod
  • go 1.22
  • go 1.22.1
  • github.com/cenkalti/backoff/v4 v4.2.1
  • github.com/cloudscale-ch/cloudscale-go-sdk/v4 v4.0.0
  • github.com/exoscale/egoscale v0.102.3
  • github.com/exoscale/exoip v0.4.3
  • github.com/fsnotify/fsnotify v1.7.0
  • github.com/gofrs/uuid v4.4.0+incompatible
  • github.com/mitchellh/go-ps v1.0.0
  • github.com/nightlyone/lockfile v1.0.0
  • github.com/sirupsen/logrus v1.9.3
  • github.com/stretchr/testify v1.9.0
  • go.uber.org/multierr v1.11.0
  • gopkg.in/yaml.v3 v3.0.1

  • Check this box to trigger a request for Renovate to run again on this repository

Support different `managed-addresses` for different VRRP instances in FIFO mode

Summary

As an operator of Keepalived+Floaty setups
I want to be able to use Floaty's FIFO mode for configurations with multiple independent VRRP instances with different VIPs
So that I can profit from the advantages of FIFO mode without being restricted in the possible configurations that work with FIFO mode.

Context

We've added initial support for FIFO mode in #51, but didn't consider more complex Keepalived setups with multiple VRRP instances which may transition between states independently. Currently, Floaty in FIFO mode only works correctly for Keepalived configurations with a single VRRP instance which contains all addresses specified in Floaty's managed-addresses configuration.

We should extend Floaty's config to allow configuration files to contain multiple managed-addresses configurations for different VRRP instances so that Floaty can manage those VIP sets independently when the corresponding VRRP instance's state changes.

Out of Scope

  • Extend the VSHN-internal Puppet profile to support the new feature

Further links

Acceptance criteria

  • Floaty FIFO mode can manage multiple sets of VIPs (one set per VRRP instance) independently

Implementation Ideas

  • Change config to have a new key which is only read in FIFO mode which contains a map from VRRP instance name to VIPs (similar to managed-addresses currently)
  • Fix or replace Floaty's keepalived config parsing to support extracting the VIPs associated with a VRRP instance directly from the Keepalived config

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.