initial commit
This commit is contained in:
commit
7715fcf373
37 changed files with 2957 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
data/
|
||||
/vipman
|
||||
674
LICENSE
Normal file
674
LICENSE
Normal file
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
55
Makefile
Normal file
55
Makefile
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
CC=go
|
||||
BUILD=build -v -trimpath
|
||||
VERSION=$(shell cat VERSION)
|
||||
GCFLAGS=-gcflags '-e'
|
||||
LDFLAGS=-ldflags '-X main.version=$(VERSION) -s -w'
|
||||
PROGRAM=vipman
|
||||
CMD=-o vipman cmd/vipman/main.go
|
||||
ENV=CGO_ENABLED=0 GO111MODULE=on
|
||||
|
||||
all: $(PROGRAM)
|
||||
|
||||
setup:
|
||||
$(CC) get -u github.com/client9/misspell
|
||||
|
||||
release: clean generate gofmt codeqa
|
||||
$(ENV) $(CC) $(BUILD) $(GCFLAGS) $(LDFLAGS) $(CMD)
|
||||
|
||||
release-vendor: clean generate gofmt codeqa
|
||||
$(ENV) $(CC) $(BUILD) -mod=vendor $(GCFLAGS) $(LDFLAGS) $(CMD)
|
||||
|
||||
vendor: clean generate gofmt
|
||||
$(ENV) $(CC) $(BUILD) -mod=vendor $(GCFLAGS) $(LDFLAGS) $(CMD)
|
||||
|
||||
$(PROGRAM): clean generate gofmt
|
||||
$(ENV) $(CC) $(BUILD) $(GCFLAGS) $(LDFLAGS) $(CMD)
|
||||
|
||||
clean:
|
||||
$(CC) clean -x
|
||||
|
||||
codeqa: misspell golint test
|
||||
|
||||
generate:
|
||||
$(CC) generate
|
||||
|
||||
gofmt:
|
||||
gofmt -w pkg/ cmd/
|
||||
|
||||
golint:
|
||||
$(GOPATH)/bin/golint .
|
||||
|
||||
misspell:
|
||||
$(GOPATH)/bin/misspell pkg/* cmd/* Makefile README.md vipman.yaml
|
||||
|
||||
test:
|
||||
ifeq ($(shell go env GOARCH), $(shell go env GOHOSTARCH))
|
||||
ifeq ($(shell go env GOOS), $(shell go env GOHOSTOS))
|
||||
$(CC) test ./...
|
||||
else
|
||||
$(info skipping tests of other platforms)
|
||||
endif
|
||||
else
|
||||
$(info skipping tests of other platforms)
|
||||
endif
|
||||
|
||||
.PHONY: setup release release-vendor vendor build clean codeqa generate gofmt golint misspell test
|
||||
7
TODO
Normal file
7
TODO
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
test etcd
|
||||
* user/password
|
||||
* multi node
|
||||
|
||||
usr arp lib https://godoc.org/github.com/mdlayher/arp ?
|
||||
* https://github.com/metallb/metallb/blob/main/internal/layer2/arp.go#L50
|
||||
add google copyright to arp ocde?
|
||||
1
VERSION
Normal file
1
VERSION
Normal file
|
|
@ -0,0 +1 @@
|
|||
0.1
|
||||
72
cmd/vipman/main.go
Normal file
72
cmd/vipman/main.go
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"git.giftfish.de/ston1th/vipman/pkg/cluster"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/config"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/controller"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/etcd"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/raft"
|
||||
"github.com/go-logr/logr"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/klog/v2/klogr"
|
||||
)
|
||||
|
||||
var (
|
||||
configFile string
|
||||
version string
|
||||
log logr.Logger
|
||||
)
|
||||
|
||||
func main() {
|
||||
klog.InitFlags(nil)
|
||||
flag.StringVar(&configFile, "config", "vipman.yaml", "vipman config file")
|
||||
flag.Parse()
|
||||
log = klogr.New().WithName("main")
|
||||
log.Info("starting vipman", "version", version)
|
||||
cfg, err := config.ParseFile(configFile)
|
||||
if err != nil {
|
||||
klog.Fatalf("init failed: %s", err)
|
||||
}
|
||||
|
||||
var c cluster.Cluster
|
||||
if cfg.Cluster.Raft != nil {
|
||||
log.Info("creating cluster", "mode", "raft")
|
||||
c = raft.NewCluster(klogr.New().WithName("raft"))
|
||||
} else if cfg.Cluster.Etcd != nil {
|
||||
log.Info("creating cluster", "mode", "etcd")
|
||||
c = etcd.NewCluster(klogr.New().WithName("etcd"))
|
||||
}
|
||||
callbacks, err := controller.NewVIPController(cfg)
|
||||
if err != nil {
|
||||
klog.Fatalf("init failed: %s", err)
|
||||
}
|
||||
err = c.SetCallbacks(callbacks)
|
||||
if err != nil {
|
||||
klog.Fatalf("init failed: %s", err)
|
||||
}
|
||||
go func() {
|
||||
err = c.Start(cfg)
|
||||
if err != nil {
|
||||
klog.Fatalf("init failed: %s", err)
|
||||
}
|
||||
}()
|
||||
go func() {
|
||||
sig := make(chan os.Signal)
|
||||
signal.Notify(sig, syscall.SIGHUP)
|
||||
for {
|
||||
<-sig
|
||||
c.Stepdown()
|
||||
}
|
||||
}()
|
||||
sigs := make(chan os.Signal)
|
||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-sigs
|
||||
log.Info("vipman shutdown")
|
||||
c.Stop()
|
||||
log.Info("vipman stopped")
|
||||
}
|
||||
30
config.tpl
Normal file
30
config.tpl
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
global
|
||||
daemon
|
||||
chroot /var/lib/haproxy
|
||||
user haproxy
|
||||
group haproxy
|
||||
maxconn 5000
|
||||
defaults
|
||||
mode tcp
|
||||
log global
|
||||
retries 2
|
||||
timeout connect 3000ms
|
||||
timeout server 5000ms
|
||||
timeout client 5000ms
|
||||
timeout tunnel 3600s
|
||||
timeout check 10s
|
||||
{{ range $item := .Data -}}
|
||||
frontend fr_{{ $item.Name }}
|
||||
bind {{ $item.IP }}:{{ $item.Port }}
|
||||
option tcplog
|
||||
option splice-request
|
||||
default_backend ba_{{ $item.Name }}
|
||||
backend ba_{{ $item.Name }}
|
||||
balance roundrobin
|
||||
option splice-response
|
||||
default-server inter 3s downinter 10s fall 2 rise 2 on-marked-down shutdown-sessions {{ $item.Options }}
|
||||
# send-proxy-v2
|
||||
{{ range $srv := $item.Servers -}}
|
||||
server {{ $srv.Name }} {{ $srv.IP }}:{{ $srv.Port }} check
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
12
etcd.sh
Executable file
12
etcd.sh
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
REGISTRY=gcr.io/etcd-development/etcd
|
||||
NODE1=127.0.0.1
|
||||
docker run \
|
||||
--rm -ti \
|
||||
-p 2379:2379 \
|
||||
-p 2380:2380 \
|
||||
--name etcd ${REGISTRY}:latest \
|
||||
/usr/local/bin/etcd \
|
||||
--data-dir=/etcd-data --name node1 \
|
||||
--initial-advertise-peer-urls http://${NODE1}:2380 --listen-peer-urls http://0.0.0.0:2380 \
|
||||
--advertise-client-urls http://${NODE1}:2379 --listen-client-urls http://0.0.0.0:2379 \
|
||||
--initial-cluster node1=http://${NODE1}:2380
|
||||
29
go.mod
Normal file
29
go.mod
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
module git.giftfish.de/ston1th/vipman
|
||||
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
git.giftfish.de/ston1th/raftbbolt v0.0.0-20201114165203-b85c94bfc9b0
|
||||
github.com/coreos/etcd v3.3.25+incompatible
|
||||
github.com/coreos/go-semver v0.3.0 // indirect
|
||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
|
||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
|
||||
github.com/envoyproxy/go-control-plane v0.9.4 // indirect
|
||||
github.com/go-logr/logr v0.3.0
|
||||
github.com/gogo/protobuf v1.3.1 // indirect
|
||||
github.com/golang/protobuf v1.4.3 // indirect
|
||||
github.com/google/go-cmp v0.5.0 // indirect
|
||||
github.com/google/uuid v1.1.2 // indirect
|
||||
github.com/hashicorp/go-hclog v0.15.0
|
||||
github.com/hashicorp/raft v1.2.0
|
||||
github.com/mdlayher/arp v0.0.0-20191213142603-f72070a231fc
|
||||
github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7
|
||||
github.com/vishvananda/netlink v1.1.0
|
||||
go.etcd.io/etcd v3.3.25+incompatible
|
||||
go.uber.org/zap v1.16.0
|
||||
google.golang.org/grpc v1.26.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
k8s.io/klog/v2 v2.4.0
|
||||
)
|
||||
|
||||
replace github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.5
|
||||
210
go.sum
Normal file
210
go.sum
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
git.giftfish.de/ston1th/raftbbolt v0.0.0-20201114165203-b85c94bfc9b0 h1:DU0PVdA2EHz2LFGEdkwgJopL9HQh5nFC9GJ7oqzZ300=
|
||||
git.giftfish.de/ston1th/raftbbolt v0.0.0-20201114165203-b85c94bfc9b0/go.mod h1:9dF/aHYkXts6/6oVyJ+vzXCn7NURDaoREaanX0aspx0=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/DataDog/datadog-go v2.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878 h1:EFSB7Zo9Eg91v7MJPVsifUysc/wPdN+NOnVe6bWbdBM=
|
||||
github.com/armon/go-metrics v0.0.0-20190430140413-ec5e00d3c878/go.mod h1:3AMJUQhVx52RsWOnlkpikZr01T/yAVN2gn0861vByNg=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
|
||||
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/coreos/etcd v0.5.0-alpha.5 h1:0Qi6Jzjk2CDuuGlIeecpu+em2nrjhOgz2wsIwCmQHmc=
|
||||
github.com/coreos/etcd v3.3.25+incompatible h1:0GQEw6h3YnuOVdtwygkIfJ+Omx0tZ8/QkVyXI4LkbeY=
|
||||
github.com/coreos/etcd v3.3.25+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
|
||||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU=
|
||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg=
|
||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
|
||||
github.com/go-logr/logr v0.3.0 h1:q4c+kbcR0d5rSurhBR8dIgieOaYpXtsdTYfx22Cu6rs=
|
||||
github.com/go-logr/logr v0.3.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
|
||||
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-hclog v0.9.1/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
|
||||
github.com/hashicorp/go-hclog v0.15.0 h1:qMuK0wxsoW4D0ddCCYwPSTm4KQv1X1ke3WmPWZ0Mvsk=
|
||||
github.com/hashicorp/go-hclog v0.15.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
github.com/hashicorp/go-msgpack v0.5.5/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
||||
github.com/hashicorp/go-msgpack v1.1.5 h1:9byZdVjKTe5mce63pRVNP1L7UAmdHOTEMGehn6KvJWs=
|
||||
github.com/hashicorp/go-msgpack v1.1.5/go.mod h1:gWVc3sv/wbDmR3rQsj1CAktEZzoz1YNK9NfGLXJ69/4=
|
||||
github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/golang-lru v0.5.0 h1:CL2msUPvZTLb5O648aiLNJw3hnBxN2+1Jq8rCOH9wdo=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/raft v1.2.0 h1:mHzHIrF0S91d3A7RPBvuqkgB4d/7oFJZyvf1Q4m7GA0=
|
||||
github.com/hashicorp/raft v1.2.0/go.mod h1:vPAJM8Asw6u8LxC3eJCUZmRP/E4QmUGE1R7g7k8sG/8=
|
||||
github.com/hashicorp/raft-boltdb v0.0.0-20171010151810-6e5ba93211ea/go.mod h1:pNv7Wc3ycL6F5oOWn+tPGo2gWD4a5X+yp/ntwdKLjRk=
|
||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.10 h1:qxFzApOv4WsAL965uUPIsXzAKCZxN2p9UqdhFS4ZW10=
|
||||
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mdlayher/arp v0.0.0-20191213142603-f72070a231fc h1:m7rJJJeXrYCFpsxXYapkDW53wJCDmf9bsIXUg0HoeQY=
|
||||
github.com/mdlayher/arp v0.0.0-20191213142603-f72070a231fc/go.mod h1:eOj1DDj3NAZ6yv+WafaKzY37MFZ58TdfIhQ+8nQbiis=
|
||||
github.com/mdlayher/ethernet v0.0.0-20190313224307-5b5fc417d966/go.mod h1:5s5p/sMJ6sNsFl6uCh85lkFGV8kLuIYJCRJLavVJwvg=
|
||||
github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7 h1:lez6TS6aAau+8wXUP3G9I3TGlmPFEq2CTxBaRqY6AGE=
|
||||
github.com/mdlayher/ethernet v0.0.0-20190606142754-0394541c37b7/go.mod h1:U6ZQobyTjI/tJyq2HG+i/dfSoFUt8/aZCM+GKtmFk/Y=
|
||||
github.com/mdlayher/raw v0.0.0-20190313224157-43dbcdd7739d/go.mod h1:r1fbeITl2xL/zLbVnNHFyOzQJTgr/3fpf1lJX/cjzR8=
|
||||
github.com/mdlayher/raw v0.0.0-20190606142536-fef19f00fc18 h1:zwOa3e/13D6veNIz6zzuqrd3eZEMF0dzD0AQWKcYSs4=
|
||||
github.com/mdlayher/raw v0.0.0-20190606142536-fef19f00fc18/go.mod h1:7EpbotpCmVZcu+KCX4g9WaRNuu11uyhiW7+Le1dKawg=
|
||||
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
|
||||
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
|
||||
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
|
||||
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df h1:OviZH7qLw/7ZovXvuNyL3XQl8UFofeikI1NW1Gypu7k=
|
||||
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
|
||||
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
|
||||
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||
go.etcd.io/etcd v0.5.0-alpha.5 h1:VOolFSo3XgsmnYDLozjvZ6JL6AAwIDu1Yx1y+4EYLDo=
|
||||
go.etcd.io/etcd v3.3.25+incompatible h1:V1RzkZJj9LqsJRy+TUBgpWSbZXITLB819lstuTFoZOY=
|
||||
go.etcd.io/etcd v3.3.25+incompatible/go.mod h1:yaeTdrJi5lOmYerz05bd8+V7KubZs8YSFZfzsF9A6aI=
|
||||
go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
|
||||
go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
|
||||
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
|
||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
||||
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
|
||||
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190313220215-9f648a60d977/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190419010253-1f3472d942ba/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190418153312-f0ce4c0180be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190606122018-79a91cf218c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 h1:LfCXLvNmTYH9kEmVgqbnsWfruoXZIrh4YBgqVHtDvw0=
|
||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190424220101-1e8e1cfdf96b/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg=
|
||||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.27.0 h1:rRYRFMVgRv6E0D70Skyfsr28tDXIuuPZyWGMPdMcnXg=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.33.2 h1:EQyQC3sa8M+p6Ulc8yy9SWSS2GVwyRc83gAbG8lrl4o=
|
||||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
|
||||
k8s.io/klog/v2 v2.4.0 h1:7+X0fUguPyrKEC4WjH8iGDg3laWgMo5tMnRTIGTTxGQ=
|
||||
k8s.io/klog/v2 v2.4.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
|
||||
7
pkg/api/api.go
Normal file
7
pkg/api/api.go
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package api
|
||||
|
||||
type Route struct {
|
||||
Path string
|
||||
Handler http.HandlerFunc
|
||||
Methods []string
|
||||
}
|
||||
34
pkg/api/v1/schema/schema.go
Normal file
34
pkg/api/v1/schema/schema.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package schema
|
||||
|
||||
/*
|
||||
healthCheckNodePort
|
||||
|
||||
*/
|
||||
|
||||
type LBConfig struct {
|
||||
LoadBalancers []LoadBalancer
|
||||
}
|
||||
|
||||
type LoadBalancer struct {
|
||||
Name string `json:"name"`
|
||||
IP string `json:"ip"`
|
||||
Options Options `json:"options,omitempty"`
|
||||
Ports []Port `json:"ports,omitempty"`
|
||||
}
|
||||
|
||||
type Options struct {
|
||||
Frontend []string `json:"frontend,omitempty"`
|
||||
Backend []string `json:"backend,omitempty"`
|
||||
DefaultServer string `json:"defaultServer,omitempty`
|
||||
}
|
||||
|
||||
type Port struct {
|
||||
Port int `json:"port,omitempty"`
|
||||
Servers []Server `json:"servers,omitempty"`
|
||||
}
|
||||
|
||||
type Server struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
IP string `json:"ip,omitempty"`
|
||||
Port int `json:"port,omitempty"`
|
||||
}
|
||||
103
pkg/api/v1/server/context.go
Normal file
103
pkg/api/v1/server/context.go
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func newContext(w http.ResponseWriter, r *http.Request, srv *Server) *Context {
|
||||
h := w.Header()
|
||||
h.Set("Content-Type", "application/json")
|
||||
return &Context{
|
||||
Status: http.StatusOK,
|
||||
Request: r,
|
||||
Response: w,
|
||||
s: srv,
|
||||
}
|
||||
}
|
||||
|
||||
// Context is the context object shared between http handlers
|
||||
type Context struct {
|
||||
Body []byte
|
||||
Status int
|
||||
|
||||
Request *http.Request
|
||||
Response http.ResponseWriter
|
||||
s *Server
|
||||
}
|
||||
|
||||
// Method returns the request method
|
||||
func (c *Context) Method() string {
|
||||
return c.Request.Method
|
||||
}
|
||||
|
||||
// GetHeader returns the given http header
|
||||
func (c *Context) GetHeader(name string) string {
|
||||
return c.Request.Header.Get(name)
|
||||
}
|
||||
|
||||
// SetHeader sets the given http header
|
||||
func (c *Context) SetHeader(name, value string) {
|
||||
h := c.Response.Header()
|
||||
h.Set(name, value)
|
||||
}
|
||||
|
||||
// Form returns the given form value
|
||||
func (c *Context) Form(name string) string {
|
||||
return c.Request.FormValue(name)
|
||||
}
|
||||
|
||||
// Var returns the given url variable
|
||||
func (c *Context) Var(name string) (ret string) {
|
||||
ret, _ = mux.Vars(c.Request)[name]
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Context) log() {
|
||||
c.s.log.Info("access",
|
||||
"addr", c.Request.RemoteAddr,
|
||||
"method", c.Request.Method,
|
||||
"url", c.Request.URL,
|
||||
"status", c.Status,
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Context) NotFound() {
|
||||
c.Status = http.StatusNotFound
|
||||
c.Response.WriteHeader(http.StatusNotFound)
|
||||
c.Response.Write([]byte(`{"message":"not found","status":404}`))
|
||||
c.log()
|
||||
}
|
||||
|
||||
// OK is a empty HTTP 200 JSON response
|
||||
func (c *Context) OK() {
|
||||
c.Response.Write([]byte("{}"))
|
||||
c.log()
|
||||
}
|
||||
|
||||
// JSON is a json response
|
||||
func (c *Context) JSON(v interface{}) {
|
||||
err := json.NewEncoder(c.Response).Encode(v)
|
||||
if err != nil {
|
||||
c.Err(ise)
|
||||
return
|
||||
}
|
||||
c.log()
|
||||
}
|
||||
|
||||
// Err is a HTTPErr wrapper for the custom Error type
|
||||
func (c *Context) Err(err Error) {
|
||||
c.HTTPErr(err.Error(), err.Status())
|
||||
}
|
||||
|
||||
// HTTPErr is a http.Error wrapper
|
||||
func (c *Context) HTTPErr(err string, status int) {
|
||||
c.Status = status
|
||||
http.Error(c.Response, err, status)
|
||||
c.log()
|
||||
}
|
||||
|
||||
type ctxHandler func(*Context)
|
||||
24
pkg/api/v1/server/handler.go
Normal file
24
pkg/api/v1/server/handler.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type notFoundHandler struct {
|
||||
s *Server
|
||||
}
|
||||
|
||||
func (nf *notFoundHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
newContext(w, r, nf.s).NotFound()
|
||||
}
|
||||
|
||||
func authHandler(h ctxHandler) ctxHandler {
|
||||
return func(ctx *Context) {
|
||||
// TODO
|
||||
h(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
func healthzHandler(ctx *Context) {
|
||||
ctx.OK()
|
||||
}
|
||||
21
pkg/api/v1/server/routes.go
Normal file
21
pkg/api/v1/server/routes.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"git.giftfish.de/ston1th/haproxy-lb/pkg/api"
|
||||
"git.giftfish.de/ston1th/haproxy-lb/pkg/api/v1/schema"
|
||||
)
|
||||
|
||||
const version = "/" + schema.Version
|
||||
|
||||
var routes = []api.Route{
|
||||
{
|
||||
"/healthz",
|
||||
healthzHandler,
|
||||
[]string{"GET"},
|
||||
},
|
||||
{
|
||||
version + "/alloc",
|
||||
authHandler(allocHandler),
|
||||
[]string{"POST"},
|
||||
},
|
||||
}
|
||||
92
pkg/api/v1/server/server.go
Normal file
92
pkg/api/v1/server/server.go
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
stdtls "crypto/tls"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
// Server is the webapp and api server
|
||||
type Server struct {
|
||||
srv *http.Server
|
||||
mux *mux.Router
|
||||
log logr.Logger
|
||||
|
||||
stop chan struct{}
|
||||
stopKeyReset chan struct{}
|
||||
|
||||
cert string
|
||||
key string
|
||||
laddr string
|
||||
|
||||
debug bool
|
||||
}
|
||||
|
||||
// NewHTTPServer returns a new HTTPServer
|
||||
func NewServer(log logr.Logger) *Server {
|
||||
s := &Server{
|
||||
mux: mux.NewRouter(),
|
||||
log: log,
|
||||
|
||||
stop: make(chan struct{}),
|
||||
stopKeyReset: make(chan struct{}),
|
||||
|
||||
cert: filepath.Join(core.C.DataDir, core.C.HTTP.Cert),
|
||||
key: filepath.Join(core.C.DataDir, core.C.HTTP.Key),
|
||||
laddr: net.JoinHostPort(core.C.HTTP.Address, core.C.HTTP.Port),
|
||||
|
||||
debug: core.C.Debug,
|
||||
}
|
||||
s.mux.NotFoundHandler = ¬FoundHandler{s}
|
||||
for _, v := range routes {
|
||||
s.mux.HandleFunc(v.Path, s.contextWrapper(v.Handler)).Methods(v.Methods...)
|
||||
}
|
||||
s.start()
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Server) start() error {
|
||||
l, err := tls.Listen("tcp", h.laddr, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
h.srv = &http.Server{
|
||||
Handler: h.mux,
|
||||
TLSConfig: cfg,
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 10 * time.Second,
|
||||
}
|
||||
go func() {
|
||||
err := h.srv.Serve(l)
|
||||
if err != nil {
|
||||
s.log.Error(err, "")
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) contextWrapper(h ctxHandler) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
h(newContext(w, r, s))
|
||||
}
|
||||
}
|
||||
|
||||
// Stop stops listening for incoming connections and closes currently open connections
|
||||
func (s *Server) Stop() {
|
||||
s.log.Info("stopping")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
err := h.srv.Shutdown(ctx)
|
||||
if err != nil {
|
||||
s.log.Error(err, "")
|
||||
}
|
||||
s.log.Info("stopped")
|
||||
}
|
||||
33
pkg/cluster/cluster.go
Normal file
33
pkg/cluster/cluster.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package cluster
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.giftfish.de/ston1th/vipman/pkg/config"
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
type Cluster interface {
|
||||
Start(*config.Config) error
|
||||
SetCallbacks(Callbacks) error
|
||||
Stepdown()
|
||||
Stop()
|
||||
}
|
||||
|
||||
type KV interface {
|
||||
Get(k string) ([]byte, error)
|
||||
Set(k string, v []byte) error
|
||||
Delete(k string) error
|
||||
}
|
||||
|
||||
type CallbackContext interface {
|
||||
logr.Logger
|
||||
KV
|
||||
ID() string
|
||||
}
|
||||
|
||||
type Callbacks struct {
|
||||
Leader func(context.Context, CallbackContext)
|
||||
Follower func(context.Context, CallbackContext)
|
||||
Cleanup func(context.Context, CallbackContext)
|
||||
}
|
||||
19
pkg/config/ca.go
Normal file
19
pkg/config/ca.go
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func LoadCertPool(file string) (p *x509.CertPool, err error) {
|
||||
if file == "" {
|
||||
return
|
||||
}
|
||||
buf, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
p = x509.NewCertPool()
|
||||
p.AppendCertsFromPEM(buf)
|
||||
return
|
||||
}
|
||||
159
pkg/config/config.go
Normal file
159
pkg/config/config.go
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
RaftDir = "raft"
|
||||
RaftPort = 7001
|
||||
RaftLogLevel = "off"
|
||||
|
||||
EtcdLogLevel = "error"
|
||||
EtcdPrefix = "/vipman"
|
||||
)
|
||||
|
||||
func ParseFile(file string) (cfg *Config, err error) {
|
||||
if file == "" {
|
||||
return nil, errors.New("missing config file")
|
||||
}
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
cfg = new(Config)
|
||||
err = yaml.NewDecoder(f).Decode(cfg)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = Validate(cfg)
|
||||
return
|
||||
}
|
||||
|
||||
func Validate(c *Config) error {
|
||||
if len(c.VirtualIPs) == 0 {
|
||||
return errors.New("missing virtualIPs config")
|
||||
}
|
||||
if c.LeaderHook != "" {
|
||||
if !filepath.IsAbs(c.LeaderHook) {
|
||||
return errors.New("leaderHook path must be absolute")
|
||||
}
|
||||
}
|
||||
if c.FollowerHook != "" {
|
||||
if !filepath.IsAbs(c.FollowerHook) {
|
||||
return errors.New("followerHook path must be absolute")
|
||||
}
|
||||
}
|
||||
raft := c.Cluster.Raft
|
||||
if raft != nil {
|
||||
if raft.LogLevel == "" {
|
||||
raft.LogLevel = RaftLogLevel
|
||||
}
|
||||
if raft.Dir == "" {
|
||||
raft.Dir = RaftDir
|
||||
}
|
||||
if raft.ID == "" {
|
||||
return errors.New("missing raft.id config")
|
||||
}
|
||||
if raft.Address == "" {
|
||||
return errors.New("missing raft.address config")
|
||||
}
|
||||
if len(raft.Peers) < 2 {
|
||||
return errors.New("minimum number of remote peers: 2")
|
||||
}
|
||||
for i, v := range raft.Peers {
|
||||
if v.ID == "" {
|
||||
return fmt.Errorf("missing raft.peers[%d].id config", i)
|
||||
}
|
||||
if v.Address == "" {
|
||||
return fmt.Errorf("missing raft.peers[%d].address config", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
etcd := c.Cluster.Etcd
|
||||
if etcd != nil {
|
||||
if etcd.LogLevel == "" {
|
||||
etcd.LogLevel = EtcdLogLevel
|
||||
}
|
||||
if len(etcd.Endpoints) == 0 {
|
||||
return errors.New("missing etcd.endpoints config")
|
||||
}
|
||||
if etcd.Prefix == "" {
|
||||
etcd.Prefix = EtcdPrefix
|
||||
} else {
|
||||
if !strings.HasPrefix(etcd.Prefix, "/") {
|
||||
etcd.Prefix = "/" + etcd.Prefix
|
||||
}
|
||||
if strings.HasSuffix(etcd.Prefix, "/") {
|
||||
etcd.Prefix = strings.TrimSuffix(etcd.Prefix, "/")
|
||||
}
|
||||
}
|
||||
if etcd.ClusterName == "" {
|
||||
return errors.New("missing etcd.clusterName config")
|
||||
} else {
|
||||
if strings.HasSuffix(etcd.ClusterName, "/") {
|
||||
etcd.ClusterName = strings.TrimSuffix(etcd.ClusterName, "/")
|
||||
}
|
||||
}
|
||||
}
|
||||
if raft == nil && etcd == nil {
|
||||
return errors.New("missing cluster config: raft or etcd")
|
||||
}
|
||||
if raft != nil && etcd != nil {
|
||||
return errors.New("only one cluster config allowed: raft or etcd")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
VirtualIPs []string `yaml:"virtualIPs"`
|
||||
Interface string `yaml:"interface,omitempty"`
|
||||
Label string `yaml:"label,omitempty"`
|
||||
LeaderHook string `yaml:"leaderHook,omitempty"`
|
||||
FollowerHook string `yaml:"followerHook,omitempty"`
|
||||
Cluster Cluster `yaml:"cluster"`
|
||||
}
|
||||
|
||||
type Cluster struct {
|
||||
Raft *Raft `yaml:"raft,omitempty"`
|
||||
Etcd *Etcd `yaml:"etcd,omitempty"`
|
||||
}
|
||||
|
||||
type Raft struct {
|
||||
Dir string `yaml:"dir,omitempty"`
|
||||
ID string `yaml:"id"`
|
||||
Address string `yaml:"address"`
|
||||
Peers []RaftPeer `yaml:"peers"`
|
||||
TLS *TLS `yaml:"tls,omitempty"`
|
||||
LogLevel string `yaml:"logLevel,omitempty"`
|
||||
}
|
||||
|
||||
type TLS struct {
|
||||
Cert string `yaml:"cert,omitempty"`
|
||||
Key string `yaml:"key,omitempty"`
|
||||
CA string `yaml:"ca,omitempty"`
|
||||
Insecure bool `yaml:"insecure,omitempty"`
|
||||
}
|
||||
|
||||
// RaftPeer details the configuration of all cluster peers
|
||||
type RaftPeer struct {
|
||||
ID string `yaml:"id"`
|
||||
Address string `yaml:"address"`
|
||||
}
|
||||
|
||||
type Etcd struct {
|
||||
Endpoints []string `yaml:"endpoints"`
|
||||
Prefix string `yaml:"prefix"`
|
||||
ClusterName string `yaml:"clusterName"`
|
||||
Username string `yaml:"username,omitempty"`
|
||||
Password string `yaml:"password,omitempty"`
|
||||
TLS *TLS `yaml:"tls,omitempty"`
|
||||
LogLevel string `yaml:"logLevel,omitempty"`
|
||||
}
|
||||
91
pkg/controller/vip.go
Normal file
91
pkg/controller/vip.go
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"git.giftfish.de/ston1th/vipman/pkg/cluster"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/config"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/vip"
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
func NewVIPController(cfg *config.Config) (callbacks cluster.Callbacks, err error) {
|
||||
n, err := vip.NewNetworkWithLabel(cfg.Interface, cfg.Label)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
callbacks = cluster.Callbacks{
|
||||
Leader: func(ctx context.Context, cc cluster.CallbackContext) {
|
||||
t := time.NewTicker(time.Second * 10)
|
||||
if cfg.LeaderHook != "" {
|
||||
go func() {
|
||||
err := exec.CommandContext(ctx, cfg.LeaderHook).Run()
|
||||
if err != nil {
|
||||
cc.Error(err, "error running hook", "leaderHook", cfg.LeaderHook)
|
||||
}
|
||||
}()
|
||||
}
|
||||
for {
|
||||
cc.Info("leading", "id", cc.ID())
|
||||
addIPs(cc, n, cfg.VirtualIPs)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Stop()
|
||||
deleteIPs(cc, n, cfg.VirtualIPs)
|
||||
cc.Info("leading canceled", "id", cc.ID())
|
||||
return
|
||||
case <-t.C:
|
||||
}
|
||||
}
|
||||
},
|
||||
Follower: func(ctx context.Context, cc cluster.CallbackContext) {
|
||||
t := time.NewTicker(time.Second * 10)
|
||||
if cfg.FollowerHook != "" {
|
||||
go func() {
|
||||
err := exec.CommandContext(ctx, cfg.FollowerHook).Run()
|
||||
if err != nil {
|
||||
cc.Error(err, "error running hook", "followerHook", cfg.FollowerHook)
|
||||
}
|
||||
}()
|
||||
}
|
||||
for {
|
||||
cc.Info("following", "id", cc.ID())
|
||||
//TODO
|
||||
//deleteIPs(cc, n, cfg.VirtualIPs)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
t.Stop()
|
||||
cc.Info("following canceled", "id", cc.ID())
|
||||
return
|
||||
case <-t.C:
|
||||
}
|
||||
}
|
||||
},
|
||||
Cleanup: func(ctx context.Context, cc cluster.CallbackContext) {
|
||||
deleteIPs(cc, n, cfg.VirtualIPs)
|
||||
},
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func addIPs(log logr.Logger, n *vip.Network, cidrs []string) error {
|
||||
for _, cidr := range cidrs {
|
||||
err := n.AddIP(cidr)
|
||||
if err != nil {
|
||||
log.Error(err, "adding ip", "interface", n.Interface(), "ip", cidr)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteIPs(log logr.Logger, n *vip.Network, cidrs []string) error {
|
||||
for _, cidr := range cidrs {
|
||||
err := n.DeleteIP(cidr)
|
||||
if err != nil {
|
||||
log.Error(err, "deleting ip", "interface", n.Interface(), "ip", cidr)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
82
pkg/etcd/cluster.go
Normal file
82
pkg/etcd/cluster.go
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
package etcd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.giftfish.de/ston1th/vipman/pkg/cluster"
|
||||
//"go.etcd.io/etcd/clientv3"
|
||||
"github.com/coreos/etcd/clientv3"
|
||||
"github.com/go-logr/logr"
|
||||
)
|
||||
|
||||
var ErrKeyNotFound = errors.New("key not found")
|
||||
|
||||
type Cluster struct {
|
||||
logr.Logger
|
||||
cli *clientv3.Client
|
||||
ctx context.Context
|
||||
|
||||
stepdown chan struct{}
|
||||
stop chan struct{}
|
||||
done chan struct{}
|
||||
callbacks cluster.Callbacks
|
||||
|
||||
kvPrefix string
|
||||
id string
|
||||
keyID string
|
||||
session bool
|
||||
cancelSession func()
|
||||
}
|
||||
|
||||
func NewCluster(log logr.Logger) cluster.Cluster {
|
||||
return &Cluster{
|
||||
Logger: log,
|
||||
ctx: context.Background(),
|
||||
stepdown: make(chan struct{}, 1),
|
||||
stop: make(chan struct{}, 1),
|
||||
done: make(chan struct{}, 1),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cluster) Get(k string) (v []byte, err error) {
|
||||
r, err := c.cli.Get(c.ctx, c.kvPrefix+"/"+k)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(r.Kvs) == 0 {
|
||||
err = ErrKeyNotFound
|
||||
return
|
||||
}
|
||||
v = r.Kvs[0].Value
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Cluster) Set(k string, v []byte) (err error) {
|
||||
_, err = c.cli.Put(c.ctx, c.kvPrefix+"/"+k, string(v))
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Cluster) Delete(k string) (err error) {
|
||||
_, err = c.cli.Delete(c.ctx, c.kvPrefix+"/"+k)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Cluster) SetCallbacks(callbacks cluster.Callbacks) error {
|
||||
c.callbacks = callbacks
|
||||
return c.checkConfig()
|
||||
}
|
||||
|
||||
func (c *Cluster) ID() string {
|
||||
return c.id
|
||||
}
|
||||
|
||||
func (c *Cluster) checkConfig() error {
|
||||
if c.callbacks.Leader == nil {
|
||||
return errors.New("Leader callback is nil")
|
||||
}
|
||||
if c.callbacks.Follower == nil {
|
||||
return errors.New("Follower callback is nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
223
pkg/etcd/etcd.go
Normal file
223
pkg/etcd/etcd.go
Normal file
|
|
@ -0,0 +1,223 @@
|
|||
package etcd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.giftfish.de/ston1th/vipman/pkg/config"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/util"
|
||||
"github.com/coreos/etcd/clientv3"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
//"go.etcd.io/etcd/clientv3"
|
||||
"go.etcd.io/etcd/clientv3/concurrency"
|
||||
)
|
||||
|
||||
func (c *Cluster) Start(etcdcfg *config.Config) error {
|
||||
err := c.checkConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg := etcdcfg.Cluster.Etcd
|
||||
var level zapcore.Level
|
||||
err = level.Set(cfg.LogLevel)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
al := zap.NewAtomicLevel()
|
||||
al.SetLevel(level)
|
||||
var tlsConfig *tls.Config
|
||||
if cfg.TLS != nil {
|
||||
ca, err := config.LoadCertPool(cfg.TLS.CA)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tlsConfig = &tls.Config{
|
||||
MinVersion: tls.VersionTLS12,
|
||||
InsecureSkipVerify: cfg.TLS.Insecure,
|
||||
RootCAs: ca,
|
||||
}
|
||||
}
|
||||
|
||||
c.cli, err = clientv3.New(clientv3.Config{
|
||||
Endpoints: cfg.Endpoints,
|
||||
TLS: tlsConfig,
|
||||
DialTimeout: time.Second * 5,
|
||||
Username: cfg.Username,
|
||||
Password: cfg.Password,
|
||||
LogConfig: &zap.Config{
|
||||
Level: al,
|
||||
Encoding: "console",
|
||||
DisableCaller: true,
|
||||
DisableStacktrace: true,
|
||||
EncoderConfig: zap.NewDevelopmentEncoderConfig(),
|
||||
OutputPaths: []string{"stderr"},
|
||||
ErrorOutputPaths: []string{"stderr"},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ctxSsession, cancelSession := context.WithCancel(context.Background())
|
||||
c.cancelSession = cancelSession
|
||||
s, err := concurrency.NewSession(c.cli,
|
||||
concurrency.WithContext(ctxSsession),
|
||||
concurrency.WithTTL(10),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.session = true
|
||||
|
||||
prefix := cfg.Prefix + "/" + cfg.ClusterName
|
||||
c.kvPrefix = prefix + "/kv"
|
||||
ePrefix := prefix + "/e"
|
||||
c.id = fmt.Sprintf("%x", s.Lease())
|
||||
c.keyID = ePrefix + "/" + c.id
|
||||
|
||||
e := concurrency.NewElection(s, ePrefix)
|
||||
ctxCampaign, cancelCampaign := context.WithCancel(context.Background())
|
||||
go func() {
|
||||
errc := make(chan error, 1)
|
||||
for {
|
||||
go func() {
|
||||
errc <- e.Campaign(ctxCampaign, "")
|
||||
}()
|
||||
select {
|
||||
case err := <-errc:
|
||||
if err != nil {
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
case <-ctxCampaign.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
t := time.NewTicker(time.Second)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ctxObserve, cancelObserve := context.WithCancel(context.Background())
|
||||
leading := false
|
||||
following := false
|
||||
leaderChan := c.observe(ctxObserve, e.Observe(ctxObserve))
|
||||
for {
|
||||
if !leading && c.leaderID(e.Leader(ctxObserve)) == c.keyID {
|
||||
leading = true
|
||||
go c.leader(ctx)
|
||||
} else if !following && !leading {
|
||||
following = true
|
||||
go c.follower(ctx)
|
||||
}
|
||||
|
||||
select {
|
||||
case <-t.C:
|
||||
case leader := <-leaderChan:
|
||||
if leader {
|
||||
if following {
|
||||
cancel()
|
||||
following = false
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
}
|
||||
if !leading {
|
||||
leading = true
|
||||
go c.leader(ctx)
|
||||
}
|
||||
} else {
|
||||
if leading {
|
||||
cancel()
|
||||
leading = false
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
}
|
||||
if !following {
|
||||
following = true
|
||||
go c.follower(ctx)
|
||||
}
|
||||
}
|
||||
case <-c.stepdown:
|
||||
cancel()
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
ctxResign, _ := context.WithTimeout(context.Background(), time.Second*2)
|
||||
e.Resign(ctxResign)
|
||||
case <-c.stop:
|
||||
t.Stop()
|
||||
cancel()
|
||||
cancelObserve()
|
||||
cancelCampaign()
|
||||
if leading {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Second*2)
|
||||
e.Resign(ctx)
|
||||
}
|
||||
if c.callbacks.Cleanup != nil {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Second*2)
|
||||
c.callbacks.Cleanup(ctx, c)
|
||||
}
|
||||
s.Close()
|
||||
close(c.done)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cluster) leaderID(r *clientv3.GetResponse, err error) string {
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if len(r.Kvs) == 0 {
|
||||
return ""
|
||||
}
|
||||
return string(r.Kvs[0].Key)
|
||||
}
|
||||
|
||||
func (c *Cluster) observe(ctx context.Context, resp <-chan clientv3.GetResponse) <-chan bool {
|
||||
leader := make(chan bool)
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case r := <-resp:
|
||||
if c.leaderID(&r, nil) == c.keyID {
|
||||
leader <- true
|
||||
} else {
|
||||
leader <- false
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
return leader
|
||||
}
|
||||
|
||||
func (c *Cluster) Stepdown() {
|
||||
select {
|
||||
case c.stepdown <- struct{}{}:
|
||||
case <-time.After(time.Second * 2):
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cluster) Stop() {
|
||||
if !c.session {
|
||||
c.cancelSession()
|
||||
return
|
||||
}
|
||||
close(c.stop)
|
||||
<-c.done
|
||||
c.cli.Close()
|
||||
}
|
||||
|
||||
func (c *Cluster) leader(ctx context.Context) {
|
||||
defer func() {
|
||||
util.HandleCrash()
|
||||
}()
|
||||
c.callbacks.Leader(ctx, c)
|
||||
}
|
||||
|
||||
func (c *Cluster) follower(ctx context.Context) {
|
||||
defer func() {
|
||||
util.HandleCrash()
|
||||
}()
|
||||
c.callbacks.Follower(ctx, c)
|
||||
}
|
||||
67
pkg/haproxy/haproxy.go
Normal file
67
pkg/haproxy/haproxy.go
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
package haproxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sync"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
type ServiceManager interface {
|
||||
Reload()
|
||||
}
|
||||
|
||||
type HAProxyManager struct {
|
||||
sync.Mutex
|
||||
|
||||
configFile string
|
||||
serviceManager ServiceManager
|
||||
template *template.Template
|
||||
}
|
||||
|
||||
func NewHAProxyManager(configFile string) (*HAProxyManager, error) {
|
||||
t, err := template.New("haproxy").Parse(haproxyTemplate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &HAProxyManager{
|
||||
configFile: configFile,
|
||||
serviceManager: NewSystemdManager("haproxy"),
|
||||
template: t,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (ha *HAProxyManager) checkConfig(ctx context.Context, configFile string) error {
|
||||
return exec.CommandContext(ctx, "haproxy", "-c", "-f", configFile).Run()
|
||||
}
|
||||
|
||||
func (ha *HAProxyManager) UpdateConfig(ctx context.Context, lbs []config.LoadBalancer) error {
|
||||
ha.Lock()
|
||||
defer ha.Unlock()
|
||||
tmp, err := ioutil.TempFile(os.TempDir(), "haproxy_")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tmp.Close()
|
||||
defer os.Remove(tmp.Name())
|
||||
err = ha.template.Execute(tmp, lbs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ha.checkConfig(ctx, tmp.Name())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file, err := os.OpenFile(ha.configFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ha.template.Execute(file, lbs)
|
||||
if err != nil {
|
||||
file.Close()
|
||||
return err
|
||||
}
|
||||
file.Close()
|
||||
return ha.serviceManager.Reload()
|
||||
}
|
||||
20
pkg/haproxy/systemd.go
Normal file
20
pkg/haproxy/systemd.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package haproxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
const systemctl = "systemctl"
|
||||
|
||||
type SystemdManager struct {
|
||||
service string
|
||||
}
|
||||
|
||||
func NewSystemdManager(service string) *SystemdManager {
|
||||
return &SystemdManager{service}
|
||||
}
|
||||
|
||||
func (sm *SystemdManager) Reload(ctx context.Context) error {
|
||||
return exec.CommandContext(ctx, systemctl, "reload", sm.service).Run()
|
||||
}
|
||||
43
pkg/haproxy/template.go
Normal file
43
pkg/haproxy/template.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package haproxy
|
||||
|
||||
const haproxyConfigTemplate = `global
|
||||
daemon
|
||||
chroot /var/lib/haproxy
|
||||
user haproxy
|
||||
group haproxy
|
||||
maxconn 5000
|
||||
defaults
|
||||
mode tcp
|
||||
log global
|
||||
retries 2
|
||||
timeout connect 3000ms
|
||||
timeout server 5000ms
|
||||
timeout client 5000ms
|
||||
timeout tunnel 3600s
|
||||
timeout check 10s
|
||||
{{ range $item := . -}}
|
||||
{{ range $port := $item.Ports -}}
|
||||
frontend fr_{{ $item.Name }}_{{ $port.Port }}
|
||||
bind {{ $item.IP }}:{{ $port.Port }}
|
||||
{{ range $opt := $item.Options.Frontend -}}
|
||||
option {{ $opt }}
|
||||
{{ end -}}
|
||||
# option tcplog
|
||||
# option splice-request
|
||||
default_backend ba_{{ $item.Name }}_{{ $port.Port }}
|
||||
backend ba_{{ $item.Name }}_{{ $port.Port }}
|
||||
balance roundrobin
|
||||
{{ range $opt := $item.Options.Backend -}}
|
||||
option {{ $opt }}
|
||||
{{ end -}}
|
||||
# option splice-response
|
||||
# option httpchk GET /
|
||||
default-server inter 3s downinter 10s fall 2 rise 2 on-marked-down shutdown-sessions {{ $item.Options.DefaultServer }}
|
||||
# send-proxy-v2
|
||||
# check-send-proxy
|
||||
# port <healthCheckNodePort>
|
||||
{{ range $srv := $port.Servers -}}
|
||||
server {{ $srv.Name }} {{ $srv.IP }}:{{ $srv.Port }} check
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
{{ end -}}`
|
||||
56
pkg/raft/cluster.go
Normal file
56
pkg/raft/cluster.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package raft
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.giftfish.de/ston1th/vipman/pkg/cluster"
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/hashicorp/raft"
|
||||
)
|
||||
|
||||
type Cluster struct {
|
||||
logr.Logger
|
||||
cluster.KV
|
||||
r *raft.Raft
|
||||
|
||||
kvm *kv
|
||||
stepdown chan struct{}
|
||||
stop chan struct{}
|
||||
done chan struct{}
|
||||
callbacks cluster.Callbacks
|
||||
|
||||
id string
|
||||
}
|
||||
|
||||
func NewCluster(log logr.Logger) cluster.Cluster {
|
||||
kvm := &kv{
|
||||
m: make(map[string][]byte),
|
||||
}
|
||||
return &Cluster{
|
||||
Logger: log,
|
||||
KV: kvm,
|
||||
kvm: kvm,
|
||||
stepdown: make(chan struct{}, 1),
|
||||
stop: make(chan struct{}, 1),
|
||||
done: make(chan struct{}, 1),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cluster) ID() string {
|
||||
return c.id
|
||||
}
|
||||
|
||||
func (c *Cluster) SetCallbacks(callbacks cluster.Callbacks) error {
|
||||
c.callbacks = callbacks
|
||||
return c.checkConfig()
|
||||
}
|
||||
|
||||
func (c *Cluster) checkConfig() error {
|
||||
if c.callbacks.Leader == nil {
|
||||
return errors.New("Leader callback is nil")
|
||||
}
|
||||
if c.callbacks.Follower == nil {
|
||||
return errors.New("Follower callback is nil")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
99
pkg/raft/fsm.go
Normal file
99
pkg/raft/fsm.go
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
package raft
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"git.giftfish.de/ston1th/raftbbolt/msgpack"
|
||||
"github.com/hashicorp/raft"
|
||||
)
|
||||
|
||||
const (
|
||||
retainSnapshotCount = 2
|
||||
raftTimeout = 10 * time.Second
|
||||
)
|
||||
|
||||
type Op uint8
|
||||
|
||||
const (
|
||||
SET Op = iota
|
||||
DELETE
|
||||
)
|
||||
|
||||
type raftCmd struct {
|
||||
Op Op
|
||||
K string
|
||||
V []byte
|
||||
}
|
||||
|
||||
type fsm kv
|
||||
|
||||
func (f *fsm) Apply(l *raft.Log) interface{} {
|
||||
var c raftCmd
|
||||
if err := msgpack.Unmarshal(l.Data, &c); err != nil {
|
||||
panic(fmt.Sprintf("failed to unmarshal command: %s", err.Error()))
|
||||
}
|
||||
|
||||
switch c.Op {
|
||||
case SET:
|
||||
f.applySet(c.K, c.V)
|
||||
case DELETE:
|
||||
f.applyDelete(c.K)
|
||||
default:
|
||||
panic(fmt.Sprintf("unrecognized command op: %d", c.Op))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fsm) Snapshot() (raft.FSMSnapshot, error) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
m := make(kvm)
|
||||
for k, v := range f.m {
|
||||
m[k] = v
|
||||
}
|
||||
return &fsmSnapshot{m: m}, nil
|
||||
}
|
||||
|
||||
func (f *fsm) Restore(rc io.ReadCloser) error {
|
||||
o := make(kvm)
|
||||
if err := msgpack.NewDecoder(rc).Decode(&o); err != nil {
|
||||
return err
|
||||
}
|
||||
f.m = o
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *fsm) applySet(k string, v []byte) {
|
||||
f.mu.Lock()
|
||||
f.m[k] = v
|
||||
f.mu.Unlock()
|
||||
}
|
||||
|
||||
func (f *fsm) applyDelete(k string) {
|
||||
f.mu.Lock()
|
||||
delete(f.m, k)
|
||||
f.mu.Unlock()
|
||||
}
|
||||
|
||||
type fsmSnapshot struct {
|
||||
m kvm
|
||||
}
|
||||
|
||||
func (f *fsmSnapshot) Persist(sink raft.SnapshotSink) error {
|
||||
err := func() error {
|
||||
err := msgpack.NewEncoder(sink).Encode(f.m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return sink.Close()
|
||||
}()
|
||||
|
||||
if err != nil {
|
||||
sink.Cancel()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (f *fsmSnapshot) Release() {}
|
||||
56
pkg/raft/kv.go
Normal file
56
pkg/raft/kv.go
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
package raft
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"git.giftfish.de/ston1th/raftbbolt/msgpack"
|
||||
"github.com/hashicorp/raft"
|
||||
)
|
||||
|
||||
var ErrNotLeader = errors.New("not leader")
|
||||
|
||||
type kvm map[string][]byte
|
||||
|
||||
type kv struct {
|
||||
mu sync.Mutex
|
||||
m kvm
|
||||
r *raft.Raft
|
||||
}
|
||||
|
||||
func (kv *kv) Get(k string) ([]byte, error) {
|
||||
kv.mu.Lock()
|
||||
defer kv.mu.Unlock()
|
||||
return kv.m[k], nil
|
||||
}
|
||||
|
||||
func (kv *kv) Set(k string, v []byte) error {
|
||||
if kv.r.State() != raft.Leader {
|
||||
return ErrNotLeader
|
||||
}
|
||||
|
||||
c := &raftCmd{SET, k, v}
|
||||
b, err := msgpack.Marshal(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f := kv.r.Apply(b, raftTimeout)
|
||||
return f.Error()
|
||||
}
|
||||
|
||||
// Delete deletes the given key.
|
||||
func (kv *kv) Delete(k string) error {
|
||||
if kv.r.State() != raft.Leader {
|
||||
return ErrNotLeader
|
||||
}
|
||||
|
||||
c := &raftCmd{Op: DELETE, K: k}
|
||||
b, err := msgpack.Marshal(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
f := kv.r.Apply(b, raftTimeout)
|
||||
return f.Error()
|
||||
}
|
||||
202
pkg/raft/raft.go
Normal file
202
pkg/raft/raft.go
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
package raft
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"git.giftfish.de/ston1th/raftbbolt"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/config"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/raft/tls"
|
||||
"git.giftfish.de/ston1th/vipman/pkg/util"
|
||||
hclog "github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/raft"
|
||||
)
|
||||
|
||||
func (c *Cluster) Start(raftcfg *config.Config) error {
|
||||
err := c.checkConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg := raftcfg.Cluster.Raft
|
||||
hcl := hclog.New(&hclog.LoggerOptions{
|
||||
Name: "raft",
|
||||
Level: hclog.LevelFromString(cfg.LogLevel),
|
||||
Output: hclog.DefaultOutput,
|
||||
TimeFormat: "I0102 15:04:05.000000",
|
||||
})
|
||||
|
||||
rc := raft.DefaultConfig()
|
||||
rc.ProtocolVersion = 3
|
||||
rc.LocalID = raft.ServerID(cfg.ID)
|
||||
rc.Logger = hcl
|
||||
c.id = cfg.ID
|
||||
|
||||
pool := 3
|
||||
timeout := 10 * time.Second
|
||||
var transport *raft.NetworkTransport
|
||||
if cfg.TLS != nil {
|
||||
c.V(1).Info("setup", "transport", "tls")
|
||||
s, err := tls.NewStream(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
transport = raft.NewNetworkTransportWithLogger(s, pool, timeout, hcl)
|
||||
} else {
|
||||
c.V(1).Info("setup", "transport", "tcp")
|
||||
address, err := net.ResolveTCPAddr("tcp", cfg.Address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
transport, err = raft.NewTCPTransportWithLogger(cfg.Address, address, pool, timeout, hcl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Create Raft structures
|
||||
//snapshots := raft.NewInmemSnapshotStore()
|
||||
snapshots, err := raft.NewFileSnapshotStoreWithLogger(cfg.Dir, retainSnapshotCount, hcl)
|
||||
if err != nil {
|
||||
return fmt.Errorf("file snapshot store: %s", err)
|
||||
}
|
||||
|
||||
store := filepath.Join(cfg.Dir, "store.db")
|
||||
|
||||
//logStore := raft.NewInmemStore()
|
||||
bootstrap := true
|
||||
if _, err := os.Stat(store); err == nil {
|
||||
bootstrap = false
|
||||
}
|
||||
|
||||
stableStore, err := raftbbolt.NewStore(store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logStore := stableStore
|
||||
|
||||
// Cluster configuration
|
||||
configuration := raft.Configuration{}
|
||||
|
||||
// Add Local Peer
|
||||
configuration.Servers = append(configuration.Servers, raft.Server{
|
||||
ID: raft.ServerID(cfg.ID),
|
||||
Address: raft.ServerAddress(cfg.Address),
|
||||
})
|
||||
for _, p := range cfg.Peers {
|
||||
if cfg.Address != p.Address {
|
||||
configuration.Servers = append(configuration.Servers, raft.Server{
|
||||
ID: raft.ServerID(p.ID),
|
||||
Address: raft.ServerAddress(p.Address)})
|
||||
}
|
||||
}
|
||||
|
||||
if bootstrap {
|
||||
if err := raft.BootstrapCluster(rc, logStore, stableStore, snapshots, transport, configuration); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
c.r, err = raft.NewRaft(rc, (*fsm)(c.kvm), logStore, stableStore, snapshots, transport)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.kvm.r = c.r
|
||||
|
||||
t := time.NewTicker(time.Second)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
leading := false
|
||||
following := false
|
||||
for {
|
||||
if !leading && cfg.Address == string(c.r.Leader()) {
|
||||
leading = true
|
||||
go c.leader(ctx)
|
||||
} else if !following && !leading {
|
||||
following = true
|
||||
go c.follower(ctx)
|
||||
}
|
||||
|
||||
select {
|
||||
case <-t.C:
|
||||
case leader := <-c.r.LeaderCh():
|
||||
if leader {
|
||||
if following {
|
||||
cancel()
|
||||
following = false
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
}
|
||||
if !leading {
|
||||
leading = true
|
||||
go c.leader(ctx)
|
||||
}
|
||||
} else if c.r.State() == raft.Follower {
|
||||
if leading {
|
||||
cancel()
|
||||
leading = false
|
||||
ctx, cancel = context.WithCancel(context.Background())
|
||||
}
|
||||
if !following {
|
||||
following = true
|
||||
go c.follower(ctx)
|
||||
}
|
||||
}
|
||||
case <-c.stepdown:
|
||||
if leading {
|
||||
cancel()
|
||||
c.r.LeadershipTransfer().Error()
|
||||
}
|
||||
case <-c.stop:
|
||||
t.Stop()
|
||||
cancel()
|
||||
if leading {
|
||||
c.r.LeadershipTransfer().Error()
|
||||
}
|
||||
if c.callbacks.Cleanup != nil {
|
||||
ctx, _ := context.WithTimeout(context.Background(), time.Second*2)
|
||||
c.callbacks.Cleanup(ctx, c)
|
||||
}
|
||||
close(c.done)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cluster) leader(ctx context.Context) {
|
||||
defer func() {
|
||||
util.HandleCrash()
|
||||
}()
|
||||
c.callbacks.Leader(ctx, c)
|
||||
}
|
||||
|
||||
func (c *Cluster) follower(ctx context.Context) {
|
||||
defer func() {
|
||||
util.HandleCrash()
|
||||
}()
|
||||
c.callbacks.Follower(ctx, c)
|
||||
}
|
||||
|
||||
func (c *Cluster) Stepdown() {
|
||||
select {
|
||||
case c.stepdown <- struct{}{}:
|
||||
case <-time.After(time.Second * 2):
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cluster) Stop() {
|
||||
close(c.stop)
|
||||
<-c.done
|
||||
s := make(chan struct{})
|
||||
go func() {
|
||||
c.r.Shutdown().Error()
|
||||
close(s)
|
||||
}()
|
||||
select {
|
||||
case <-s:
|
||||
case <-time.After(time.Second * 5):
|
||||
}
|
||||
}
|
||||
63
pkg/raft/tls/stream.go
Normal file
63
pkg/raft/tls/stream.go
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
package tls
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"git.giftfish.de/ston1th/vipman/pkg/config"
|
||||
"github.com/hashicorp/raft"
|
||||
)
|
||||
|
||||
var (
|
||||
ciphers = []uint16{
|
||||
tls.TLS_CHACHA20_POLY1305_SHA256,
|
||||
}
|
||||
curves = []tls.CurveID{
|
||||
tls.X25519,
|
||||
}
|
||||
)
|
||||
|
||||
type stream struct {
|
||||
net.Listener
|
||||
insecure bool
|
||||
ca *x509.CertPool
|
||||
}
|
||||
|
||||
func NewStream(cfg *config.Raft) (s *stream, err error) {
|
||||
cert, err := tls.LoadX509KeyPair(cfg.TLS.Cert, cfg.TLS.Key)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ca, err := config.LoadCertPool(cfg.TLS.CA)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
l, err := tls.Listen("tcp", cfg.Address, &tls.Config{
|
||||
MinVersion: tls.VersionTLS13,
|
||||
CipherSuites: ciphers,
|
||||
CurvePreferences: curves,
|
||||
PreferServerCipherSuites: true,
|
||||
Certificates: []tls.Certificate{cert},
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s = &stream{l, cfg.TLS.Insecure, ca}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *stream) Dial(address raft.ServerAddress, timeout time.Duration) (net.Conn, error) {
|
||||
return tls.DialWithDialer(
|
||||
&net.Dialer{Timeout: timeout},
|
||||
"tcp", string(address),
|
||||
&tls.Config{
|
||||
MinVersion: tls.VersionTLS13,
|
||||
CipherSuites: ciphers,
|
||||
CurvePreferences: curves,
|
||||
InsecureSkipVerify: s.insecure,
|
||||
RootCAs: s.ca,
|
||||
},
|
||||
)
|
||||
}
|
||||
41
pkg/util/crash.go
Normal file
41
pkg/util/crash.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"runtime"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
var reallyCrash = true
|
||||
|
||||
func HandleCrash() {
|
||||
if r := recover(); r != nil {
|
||||
logPanic(r)
|
||||
if reallyCrash {
|
||||
panic(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// logPanic logs the caller tree when a panic occurs (except in the special case of http.ErrAbortHandler).
|
||||
func logPanic(r interface{}) {
|
||||
if r == http.ErrAbortHandler {
|
||||
// honor the http.ErrAbortHandler sentinel panic value:
|
||||
// ErrAbortHandler is a sentinel panic value to abort a handler.
|
||||
// While any panic from ServeHTTP aborts the response to the client,
|
||||
// panicking with ErrAbortHandler also suppresses logging of a stack trace to the server's error log.
|
||||
return
|
||||
}
|
||||
|
||||
// Same as stdlib http server code. Manually allocate stack trace buffer size
|
||||
// to prevent excessively large logs
|
||||
const size = 64 << 10
|
||||
stacktrace := make([]byte, size)
|
||||
stacktrace = stacktrace[:runtime.Stack(stacktrace, false)]
|
||||
if _, ok := r.(string); ok {
|
||||
klog.Errorf("Observed a panic: %s\n%s", r, stacktrace)
|
||||
} else {
|
||||
klog.Errorf("Observed a panic: %#v (%v)\n%s", r, r, stacktrace)
|
||||
}
|
||||
}
|
||||
10
pkg/vip/arp.go
Normal file
10
pkg/vip/arp.go
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// +build !linux
|
||||
|
||||
package vip
|
||||
|
||||
import "fmt"
|
||||
|
||||
// ARPSendGratuitous is only supported on Linux, so return an error
|
||||
func ARPSendGratuitous(cidr, iface string) error {
|
||||
return fmt.Errorf("Unsupported on this OS")
|
||||
}
|
||||
173
pkg/vip/arp_linux.go.bak
Normal file
173
pkg/vip/arp_linux.go.bak
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
// +build linux
|
||||
|
||||
// These syscalls are only supported on Linux, so this uses a build directive during compilation. Other OS's will use the arp_unsupported.go and receive an error
|
||||
|
||||
package vip
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
opARPRequest = 1
|
||||
opARPReply = 2
|
||||
hwLen = 6
|
||||
)
|
||||
|
||||
var (
|
||||
ethernetBroadcast = net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
|
||||
// arpRequest is used to flip between garp request or garp reply
|
||||
arpRequest = true
|
||||
)
|
||||
|
||||
func htons(p uint16) uint16 {
|
||||
var b [2]byte
|
||||
binary.BigEndian.PutUint16(b[:], p)
|
||||
return *(*uint16)(unsafe.Pointer(&b))
|
||||
}
|
||||
|
||||
// arpHeader specifies the header for an ARP message.
|
||||
type arpHeader struct {
|
||||
hardwareType uint16
|
||||
protocolType uint16
|
||||
hardwareAddressLength uint8
|
||||
protocolAddressLength uint8
|
||||
opcode uint16
|
||||
}
|
||||
|
||||
// arpMessage represents an ARP message.
|
||||
type arpMessage struct {
|
||||
arpHeader
|
||||
senderHardwareAddress []byte
|
||||
senderProtocolAddress []byte
|
||||
targetHardwareAddress []byte
|
||||
targetProtocolAddress []byte
|
||||
}
|
||||
|
||||
// bytes returns the wire representation of the ARP message.
|
||||
func (m *arpMessage) bytes() ([]byte, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
if err := binary.Write(buf, binary.BigEndian, m.arpHeader); err != nil {
|
||||
return nil, fmt.Errorf("binary write failed: %v", err)
|
||||
}
|
||||
buf.Write(m.senderHardwareAddress)
|
||||
buf.Write(m.senderProtocolAddress)
|
||||
buf.Write(m.targetHardwareAddress)
|
||||
buf.Write(m.targetProtocolAddress)
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
// gratuitousARP return a gARP request or gARP reply alternatively
|
||||
// because different devices may support either one of them
|
||||
func gratuitousARP(ip net.IP, mac net.HardwareAddr) (*arpMessage, error) {
|
||||
if ip.To4() == nil {
|
||||
return nil, fmt.Errorf("%q is not an IPv4 address", ip)
|
||||
}
|
||||
if len(mac) != hwLen {
|
||||
return nil, fmt.Errorf("%q is not an Ethernet MAC address", mac)
|
||||
}
|
||||
|
||||
m := &arpMessage{
|
||||
arpHeader: arpHeader{
|
||||
1, // Ethernet
|
||||
0x0800, // IPv4
|
||||
hwLen, // 48-bit MAC Address
|
||||
net.IPv4len, // 32-bit IPv4 Address
|
||||
opARPReply, // ARP Reply
|
||||
},
|
||||
}
|
||||
|
||||
// https://tools.ietf.org/html/rfc5944#section-4.6
|
||||
// In either case, the ARP Sender Hardware Address is
|
||||
// set to the link-layer address to which this cache entry should be
|
||||
// updated.
|
||||
m.senderHardwareAddress = mac
|
||||
|
||||
// When using an ARP Reply packet, the Target Hardware
|
||||
// Address is also set to the link-layer address to which this cache
|
||||
// entry should be updated (this field is not used in an ARP Request
|
||||
// packet).
|
||||
m.targetHardwareAddress = mac
|
||||
|
||||
// In either case, the ARP Sender Protocol Address and
|
||||
// ARP Target Protocol Address are both set to the IP address of the
|
||||
// cache entry to be updated,
|
||||
m.senderProtocolAddress = ip.To4()
|
||||
m.targetProtocolAddress = ip.To4()
|
||||
|
||||
// send arpRequest and arpReply alternatively
|
||||
arpRequest = !arpRequest
|
||||
if arpRequest {
|
||||
m.arpHeader.opcode = opARPRequest
|
||||
|
||||
// this field is not used in an ARP Request packet
|
||||
m.targetHardwareAddress = ethernetBroadcast
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// sendARP sends the given ARP message via the specified interface.
|
||||
func sendARP(iface *net.Interface, m *arpMessage) error {
|
||||
fd, err := syscall.Socket(syscall.AF_PACKET, syscall.SOCK_DGRAM, int(htons(syscall.ETH_P_ARP)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get raw socket: %v", err)
|
||||
}
|
||||
defer syscall.Close(fd)
|
||||
|
||||
if err := syscall.BindToDevice(fd, iface.Name); err != nil {
|
||||
return fmt.Errorf("failed to bind to device: %v", err)
|
||||
}
|
||||
|
||||
ll := syscall.SockaddrLinklayer{
|
||||
Protocol: htons(syscall.ETH_P_ARP),
|
||||
Ifindex: iface.Index,
|
||||
Pkttype: 0, // syscall.PACKET_HOST
|
||||
Hatype: m.hardwareType,
|
||||
Halen: m.hardwareAddressLength,
|
||||
}
|
||||
target := ethernetBroadcast
|
||||
for i := 0; i < len(target); i++ {
|
||||
ll.Addr[i] = target[i]
|
||||
}
|
||||
|
||||
b, err := m.bytes()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to convert ARP message: %v", err)
|
||||
}
|
||||
|
||||
if err := syscall.Bind(fd, &ll); err != nil {
|
||||
return fmt.Errorf("failed to bind: %v", err)
|
||||
}
|
||||
if err := syscall.Sendto(fd, b, 0, &ll); err != nil {
|
||||
return fmt.Errorf("failed to send: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ARPSendGratuitous sends a gratuitous ARP message via the specified interface.
|
||||
func ARPSendGratuitous(cidr, iface string) error {
|
||||
i, err := net.InterfaceByName(iface)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get interface %q: %v", iface, err)
|
||||
}
|
||||
ip, _, err := net.ParseCIDR(cidr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse cidr: %s", cidr)
|
||||
}
|
||||
|
||||
//log.Infof("Broadcasting ARP update for %s (%s) via %s", address, iface.HardwareAddr, iface.Name)
|
||||
m, err := gratuitousARP(ip, i.HardwareAddr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return sendARP(i, m)
|
||||
}
|
||||
38
pkg/vip/arp_linux2.go
Normal file
38
pkg/vip/arp_linux2.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package vip
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/mdlayher/arp"
|
||||
"github.com/mdlayher/ethernet"
|
||||
)
|
||||
|
||||
func sendARP(ip net.IP, iface *net.Interface) error {
|
||||
c, err := arp.Dial(iface)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, op := range []arp.Operation{arp.OperationRequest, arp.OperationReply} {
|
||||
pkt, err := arp.NewPacket(op, iface.HardwareAddr, ip, ethernet.Broadcast, ip)
|
||||
if err != nil {
|
||||
return fmt.Errorf("assembling %q gratuitous packet for %q: %s", op, ip, err)
|
||||
}
|
||||
if err = c.WriteTo(pkt, ethernet.Broadcast); err != nil {
|
||||
return fmt.Errorf("writing %q gratuitous packet for %q: %s", op, ip, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ARPSendGratuitous(cidr, iface string) error {
|
||||
i, err := net.InterfaceByName(iface)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get interface %q: %v", iface, err)
|
||||
}
|
||||
ip, _, err := net.ParseCIDR(cidr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to parse cidr: %s", cidr)
|
||||
}
|
||||
return sendARP(ip, i)
|
||||
}
|
||||
96
pkg/vip/vip.go
Normal file
96
pkg/vip/vip.go
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
package vip
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/vishvananda/netlink"
|
||||
"net"
|
||||
)
|
||||
|
||||
var ErrNoDefaultInterface = errors.New("no default interface found")
|
||||
|
||||
func DefaultInterface() (iface string, err error) {
|
||||
routes, err := netlink.RouteGet(net.IPv4bcast)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(routes) >= 1 {
|
||||
link, err := netlink.LinkByIndex(routes[0].LinkIndex)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return link.Attrs().Name, nil
|
||||
}
|
||||
err = ErrNoDefaultInterface
|
||||
return
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
iface string
|
||||
label string
|
||||
link netlink.Link
|
||||
}
|
||||
|
||||
func NewNetwork(iface string) (n *Network, err error) {
|
||||
return NewNetworkWithLabel(iface, "")
|
||||
}
|
||||
|
||||
func NewNetworkWithLabel(iface, label string) (n *Network, err error) {
|
||||
if iface == "" {
|
||||
iface, err = DefaultInterface()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
link, err := netlink.LinkByName(iface)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
n = &Network{iface, label, link}
|
||||
return
|
||||
}
|
||||
|
||||
func (n *Network) Interface() string {
|
||||
return n.iface
|
||||
}
|
||||
|
||||
func (n *Network) HasIP(a *netlink.Addr) bool {
|
||||
addrs, err := netlink.AddrList(n.link, 0)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, addr := range addrs {
|
||||
if addr.Equal(*a) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (n *Network) AddIP(cidr string) error {
|
||||
addr, err := netlink.ParseAddr(cidr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n.HasIP(addr) {
|
||||
return nil
|
||||
}
|
||||
if n.label != "" {
|
||||
addr.Label = n.iface + ":" + n.label
|
||||
}
|
||||
err = netlink.AddrReplace(n.link, addr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ARPSendGratuitous(cidr, n.iface)
|
||||
}
|
||||
|
||||
func (n *Network) DeleteIP(cidr string) error {
|
||||
addr, err := netlink.ParseAddr(cidr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !n.HasIP(addr) {
|
||||
return nil
|
||||
}
|
||||
return netlink.AddrDel(n.link, addr)
|
||||
}
|
||||
6
run_etcd.sh
Executable file
6
run_etcd.sh
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
cd data
|
||||
../vipman -config etcd.yaml &
|
||||
../vipman -config etcd.yaml &
|
||||
../vipman -config etcd.yaml
|
||||
7
run_raft.sh
Executable file
7
run_raft.sh
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
cd data
|
||||
rm -rf node*
|
||||
../vipman -config raft1.yaml &
|
||||
../vipman -config raft2.yaml &
|
||||
../vipman -config raft3.yaml
|
||||
Loading…
Add table
Add a link
Reference in a new issue