Compare commits
42 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a398ce82f7 | ||
|
e814b37839 | ||
|
cb4d9e81a4 | ||
|
b87a4628e6 | ||
|
b22fdd5ac9 | ||
|
6939fc2ddc | ||
|
e3117269cb | ||
|
3bb3a683a4 | ||
|
e1033c979e | ||
|
9a4d24826f | ||
|
7bed1307e1 | ||
|
47b536532d | ||
|
7df5cf761e | ||
|
799c02865c | ||
|
9f38792d43 | ||
|
7e4fa423e4 | ||
|
c3f17bd07b | ||
|
85a473d972 | ||
|
aea5ca5252 | ||
|
4e84180ad5 | ||
|
0f1717bf26 | ||
|
6a9aa60a8d | ||
|
7cacb2e127 | ||
|
1f688dcdca | ||
|
f6d8190e8f | ||
|
3263816cf5 | ||
|
96e1cb5a7a | ||
|
cf556d2a81 | ||
|
62bda8e6cc | ||
|
0d1d1f77be | ||
|
a7e21747fa | ||
|
26b54534d6 | ||
|
8201d75115 | ||
|
1d024af4c1 | ||
|
09c690cbe7 | ||
|
49adf19081 | ||
|
46b046c82e | ||
|
e01a1f70c3 | ||
|
2e4ea503b0 | ||
|
c7aef5fdf2 | ||
|
c4605160c5 | ||
|
054de85da2 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
*.swp
|
*.swp
|
||||||
bin/
|
bin/
|
||||||
|
coverage/
|
||||||
pkg/
|
pkg/
|
||||||
|
87
CONTRIBUTING.md
Normal file
87
CONTRIBUTING.md
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
# How to Contribute
|
||||||
|
|
||||||
|
CoreOS projects are [Apache 2.0 licensed](LICENSE) and accept contributions via
|
||||||
|
GitHub pull requests. This document outlines some of the conventions on
|
||||||
|
development workflow, commit message formatting, contact points and other
|
||||||
|
resources to make it easier to get your contribution accepted.
|
||||||
|
|
||||||
|
# Certificate of Origin
|
||||||
|
|
||||||
|
By contributing to this project you agree to the Developer Certificate of
|
||||||
|
Origin (DCO). This document was created by the Linux Kernel community and is a
|
||||||
|
simple statement that you, as a contributor, have the legal right to make the
|
||||||
|
contribution. See the [DCO](DCO) file for details.
|
||||||
|
|
||||||
|
# Email and Chat
|
||||||
|
|
||||||
|
The project currently uses the general CoreOS email list and IRC channel:
|
||||||
|
- Email: [coreos-dev](https://groups.google.com/forum/#!forum/coreos-dev)
|
||||||
|
- IRC: #[coreos](irc://irc.freenode.org:6667/#coreos) IRC channel on freenode.org
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
- Fork the repository on GitHub
|
||||||
|
- Read the [README](README.md) for build and test instructions
|
||||||
|
- Play with the project, submit bugs, submit patches!
|
||||||
|
|
||||||
|
## Contribution Flow
|
||||||
|
|
||||||
|
This is a rough outline of what a contributor's workflow looks like:
|
||||||
|
|
||||||
|
- Create a topic branch from where you want to base your work (usually master).
|
||||||
|
- Make commits of logical units.
|
||||||
|
- Make sure your commit messages are in the proper format (see below).
|
||||||
|
- Push your changes to a topic branch in your fork of the repository.
|
||||||
|
- Make sure the tests pass, and add any new tests as appropriate.
|
||||||
|
- Submit a pull request to the original repository.
|
||||||
|
|
||||||
|
Thanks for your contributions!
|
||||||
|
|
||||||
|
### Format of the Commit Message
|
||||||
|
|
||||||
|
We follow a rough convention for commit messages borrowed from AngularJS. This
|
||||||
|
is an example of a commit:
|
||||||
|
|
||||||
|
```
|
||||||
|
feat(scripts/test-cluster): add a cluster test command
|
||||||
|
|
||||||
|
this uses tmux to setup a test cluster that you can easily kill and
|
||||||
|
start for debugging.
|
||||||
|
```
|
||||||
|
|
||||||
|
The format can be described more formally as follows:
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>(<scope>): <subject>
|
||||||
|
<BLANK LINE>
|
||||||
|
<body>
|
||||||
|
<BLANK LINE>
|
||||||
|
<footer>
|
||||||
|
```
|
||||||
|
|
||||||
|
The first line is the subject and should be no longer than 70 characters, the
|
||||||
|
second line is always blank, and other lines should be wrapped at 80 characters.
|
||||||
|
This allows the message to be easier to read on GitHub as well as in various
|
||||||
|
git tools.
|
||||||
|
|
||||||
|
#### Subject Line
|
||||||
|
|
||||||
|
The subject line contains a succinct description of the change.
|
||||||
|
|
||||||
|
#### Allowed `<type>`s
|
||||||
|
- *feat* (feature)
|
||||||
|
- *fix* (bug fix)
|
||||||
|
- *docs* (documentation)
|
||||||
|
- *style* (formatting, missing semi colons, …)
|
||||||
|
- *refactor*
|
||||||
|
- *test* (when adding missing tests)
|
||||||
|
- *chore* (maintain)
|
||||||
|
|
||||||
|
#### Allowed `<scope>`s
|
||||||
|
|
||||||
|
Scopes can anything specifying the place of the commit change in the code base -
|
||||||
|
for example, "api", "store", etc.
|
||||||
|
|
||||||
|
|
||||||
|
For more details on the commit format, see the [AngularJS commit style
|
||||||
|
guide](https://docs.google.com/a/coreos.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#).
|
36
DCO
Normal file
36
DCO
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
Developer Certificate of Origin
|
||||||
|
Version 1.1
|
||||||
|
|
||||||
|
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
|
||||||
|
660 York Street, Suite 102,
|
||||||
|
San Francisco, CA 94110 USA
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies of this
|
||||||
|
license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
|
||||||
|
Developer's Certificate of Origin 1.1
|
||||||
|
|
||||||
|
By making a contribution to this project, I certify that:
|
||||||
|
|
||||||
|
(a) The contribution was created in whole or in part by me and I
|
||||||
|
have the right to submit it under the open source license
|
||||||
|
indicated in the file; or
|
||||||
|
|
||||||
|
(b) The contribution is based upon previous work that, to the best
|
||||||
|
of my knowledge, is covered under an appropriate open source
|
||||||
|
license and I have the right under that license to submit that
|
||||||
|
work with modifications, whether created in whole or in part
|
||||||
|
by me, under the same open source license (unless I am
|
||||||
|
permitted to submit under a different license), as indicated
|
||||||
|
in the file; or
|
||||||
|
|
||||||
|
(c) The contribution was provided directly to me by some other
|
||||||
|
person who certified (a), (b) or (c) and I have not modified
|
||||||
|
it.
|
||||||
|
|
||||||
|
(d) I understand and agree that this project and the contribution
|
||||||
|
are public and that a record of the contribution (including all
|
||||||
|
personal information I submit with it, including my sign-off) is
|
||||||
|
maintained indefinitely and may be redistributed consistent with
|
||||||
|
this project or the open source license(s) involved.
|
37
Documentation/cloud-config-oem.md
Normal file
37
Documentation/cloud-config-oem.md
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
## OEM configuration
|
||||||
|
|
||||||
|
The `coreos.oem.*` parameters follow the [os-release spec][os-release], but have been repurposed as a way for coreos-cloudinit to know about the OEM partition on this machine. Customizing this section is only needed when generating a new OEM of CoreOS from the SDK. The fields include:
|
||||||
|
|
||||||
|
- **id**: Lowercase string identifying the OEM
|
||||||
|
- **name**: Human-friendly string representing the OEM
|
||||||
|
- **version-id**: Lowercase string identifying the version of the OEM
|
||||||
|
- **home-url**: Link to the homepage of the provider or OEM
|
||||||
|
- **bug-report-url**: Link to a place to file bug reports about this OEM
|
||||||
|
|
||||||
|
coreos-cloudinit renders these fields to `/etc/oem-release`.
|
||||||
|
If no **id** field is provided, coreos-cloudinit will ignore this section.
|
||||||
|
|
||||||
|
For example, the following cloud-config document...
|
||||||
|
|
||||||
|
```
|
||||||
|
#cloud-config
|
||||||
|
coreos:
|
||||||
|
oem:
|
||||||
|
id: rackspace
|
||||||
|
name: Rackspace Cloud Servers
|
||||||
|
version-id: 168.0.0
|
||||||
|
home-url: https://www.rackspace.com/cloud/servers/
|
||||||
|
bug-report-url: https://github.com/coreos/coreos-overlay
|
||||||
|
```
|
||||||
|
|
||||||
|
...would be rendered to the following `/etc/oem-release`:
|
||||||
|
|
||||||
|
```
|
||||||
|
ID=rackspace
|
||||||
|
NAME="Rackspace Cloud Servers"
|
||||||
|
VERSION_ID=168.0.0
|
||||||
|
HOME_URL="https://www.rackspace.com/cloud/servers/"
|
||||||
|
BUG_REPORT_URL="https://github.com/coreos/coreos-overlay"
|
||||||
|
```
|
||||||
|
|
||||||
|
[os-release]: http://www.freedesktop.org/software/systemd/man/os-release.html
|
@@ -70,44 +70,23 @@ Note that hyphens in the coreos.etcd.* keys are mapped to underscores.
|
|||||||
|
|
||||||
[etcd-config]: https://github.com/coreos/etcd/blob/master/Documentation/configuration.md
|
[etcd-config]: https://github.com/coreos/etcd/blob/master/Documentation/configuration.md
|
||||||
|
|
||||||
#### oem
|
#### update
|
||||||
|
|
||||||
The `coreos.oem.*` parameters follow the [os-release spec][os-release], but have been repurposed as a way for coreos-cloudinit to know about the OEM partition on this machine:
|
The `coreos.update.*` parameters manipulate settings related to how CoreOS instances are updated.
|
||||||
|
|
||||||
- **id**: Lowercase string identifying the OEM
|
- **reboot-strategy**: One of "reboot", "etcd-lock", "best-effort" or "off" for controlling when reboots are issued after an update is performed.
|
||||||
- **name**: Human-friendly string representing the OEM
|
- _reboot_: Reboot immediately after an update is applied.
|
||||||
- **version-id**: Lowercase string identifying the version of the OEM
|
- _etcd-lock_: Reboot after first taking a distributed lock in etcd, this guarantees that only one host will reboot concurrently and that the cluster will remain available during the update.
|
||||||
- **home-url**: Link to the homepage of the provider or OEM
|
- _best-effort_ - If etcd is running, "etcd-lock", otherwise simply "reboot".
|
||||||
- **bug-report-url**: Link to a place to file bug reports about this OEM
|
- _off_ - Disable rebooting after updates are applied (not recommended).
|
||||||
|
|
||||||
coreos-cloudinit renders these fields to `/etc/oem-release`.
|
|
||||||
If no **id** field is provided, coreos-cloudinit will ignore this section.
|
|
||||||
|
|
||||||
For example, the following cloud-config document...
|
|
||||||
|
|
||||||
```
|
```
|
||||||
#cloud-config
|
#cloud-config
|
||||||
coreos:
|
coreos:
|
||||||
oem:
|
update:
|
||||||
id: rackspace
|
reboot-strategy: etcd-lock
|
||||||
name: Rackspace Cloud Servers
|
|
||||||
version-id: 168.0.0
|
|
||||||
home-url: https://www.rackspace.com/cloud/servers/
|
|
||||||
bug-report-url: https://github.com/coreos/coreos-overlay
|
|
||||||
```
|
```
|
||||||
|
|
||||||
...would be rendered to the following `/etc/oem-release`:
|
|
||||||
|
|
||||||
```
|
|
||||||
ID=rackspace
|
|
||||||
NAME="Rackspace Cloud Servers"
|
|
||||||
VERSION_ID=168.0.0
|
|
||||||
HOME_URL="https://www.rackspace.com/cloud/servers/"
|
|
||||||
BUG_REPORT_URL="https://github.com/coreos/coreos-overlay"
|
|
||||||
```
|
|
||||||
|
|
||||||
[os-release]: http://www.freedesktop.org/software/systemd/man/os-release.html
|
|
||||||
|
|
||||||
#### units
|
#### units
|
||||||
|
|
||||||
The `coreos.units.*` parameters define a list of arbitrary systemd units to start. Each item is an object with the following fields:
|
The `coreos.units.*` parameters define a list of arbitrary systemd units to start. Each item is an object with the following fields:
|
||||||
@@ -130,6 +109,7 @@ Write a unit to disk, automatically starting it.
|
|||||||
coreos:
|
coreos:
|
||||||
units:
|
units:
|
||||||
- name: docker-redis.service
|
- name: docker-redis.service
|
||||||
|
command: start
|
||||||
content: |
|
content: |
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Redis container
|
Description=Redis container
|
||||||
@@ -292,6 +272,16 @@ The `write-file` parameter defines a list of files to create on the local filesy
|
|||||||
Explicitly not implemented is the **encoding** attribute.
|
Explicitly not implemented is the **encoding** attribute.
|
||||||
The **content** field must represent exactly what should be written to disk.
|
The **content** field must represent exactly what should be written to disk.
|
||||||
|
|
||||||
|
```
|
||||||
|
#cloud-config
|
||||||
|
write_files:
|
||||||
|
- path: /etc/fleet/fleet.conf
|
||||||
|
permissions: 0644
|
||||||
|
content: |
|
||||||
|
verbosity=1
|
||||||
|
metadata="region=us-west,type=ssd"
|
||||||
|
```
|
||||||
|
|
||||||
### manage_etc_hosts
|
### manage_etc_hosts
|
||||||
|
|
||||||
The `manage_etc_hosts` parameter configures the contents of the `/etc/hosts` file, which is used for local name resolution.
|
The `manage_etc_hosts` parameter configures the contents of the `/etc/hosts` file, which is used for local name resolution.
|
||||||
|
202
LICENSE
Normal file
202
LICENSE
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright {yyyy} {name of copyright owner}
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
|
5
NOTICE
Normal file
5
NOTICE
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
CoreOS Project
|
||||||
|
Copyright 2014 CoreOS, Inc
|
||||||
|
|
||||||
|
This product includes software developed at CoreOS, Inc.
|
||||||
|
(http://www.coreos.com/).
|
5
build
5
build
@@ -1,6 +1,9 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
ORG_PATH="github.com/coreos"
|
||||||
|
REPO_PATH="${ORG_PATH}/coreos-cloudinit"
|
||||||
|
|
||||||
export GOBIN=${PWD}/bin
|
export GOBIN=${PWD}/bin
|
||||||
export GOPATH=${PWD}
|
export GOPATH=${PWD}
|
||||||
|
|
||||||
go build -o bin/coreos-cloudinit github.com/coreos/coreos-cloudinit
|
go build -o bin/coreos-cloudinit ${REPO_PATH}
|
||||||
|
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/coreos/coreos-cloudinit/system"
|
"github.com/coreos/coreos-cloudinit/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
const version = "0.5.0"
|
const version = "0.6.1"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var printVersion bool
|
var printVersion bool
|
||||||
@@ -42,11 +42,6 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if file != "" && url != "" && !useProcCmdline {
|
|
||||||
fmt.Println("Provide one of --from-file, --from-url or --from-proc-cmdline")
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ds datasource.Datasource
|
var ds datasource.Datasource
|
||||||
if file != "" {
|
if file != "" {
|
||||||
ds = datasource.NewLocalFile(file)
|
ds = datasource.NewLocalFile(file)
|
||||||
@@ -112,4 +107,3 @@ func main() {
|
|||||||
log.Fatalf("Failed resolving user-data: %v", err)
|
log.Fatalf("Failed resolving user-data: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
27
cover
Executable file
27
cover
Executable file
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
#
|
||||||
|
# Generate coverage HTML for a package
|
||||||
|
# e.g. PKG=./initialize ./cover
|
||||||
|
#
|
||||||
|
|
||||||
|
if [ -z "$PKG" ]; then
|
||||||
|
echo "cover only works with a single package, sorry"
|
||||||
|
exit 255
|
||||||
|
fi
|
||||||
|
|
||||||
|
COVEROUT="coverage"
|
||||||
|
|
||||||
|
if ! [ -d "$COVEROUT" ]; then
|
||||||
|
mkdir "$COVEROUT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# strip out slashes and dots
|
||||||
|
COVERPKG=${PKG//\//}
|
||||||
|
COVERPKG=${COVERPKG//./}
|
||||||
|
|
||||||
|
# generate arg for "go test"
|
||||||
|
export COVER="-coverprofile ${COVEROUT}/${COVERPKG}.out"
|
||||||
|
|
||||||
|
source ./test
|
||||||
|
|
||||||
|
go tool cover -html=${COVEROUT}/${COVERPKG}.out
|
@@ -13,9 +13,10 @@ import (
|
|||||||
type CloudConfig struct {
|
type CloudConfig struct {
|
||||||
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
|
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys"`
|
||||||
Coreos struct {
|
Coreos struct {
|
||||||
Etcd EtcdEnvironment
|
Etcd EtcdEnvironment
|
||||||
Units []system.Unit
|
Update map[string]string
|
||||||
OEM OEMRelease
|
Units []system.Unit
|
||||||
|
OEM OEMRelease
|
||||||
}
|
}
|
||||||
WriteFiles []system.File `yaml:"write_files"`
|
WriteFiles []system.File `yaml:"write_files"`
|
||||||
Hostname string
|
Hostname string
|
||||||
@@ -128,6 +129,13 @@ func Apply(cfg CloudConfig, env *Environment) error {
|
|||||||
log.Printf("Wrote etcd config file to filesystem")
|
log.Printf("Wrote etcd config file to filesystem")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s, ok := cfg.Coreos.Update["reboot-strategy"]; ok {
|
||||||
|
if err := WriteLocksmithConfig(s, env.Root()); err != nil {
|
||||||
|
log.Fatalf("Failed to write locksmith config to filesystem: %v", err)
|
||||||
|
}
|
||||||
|
log.Printf("Wrote locksmith config file to filesystem")
|
||||||
|
}
|
||||||
|
|
||||||
if len(cfg.Coreos.Units) > 0 {
|
if len(cfg.Coreos.Units) > 0 {
|
||||||
commands := make(map[string]string, 0)
|
commands := make(map[string]string, 0)
|
||||||
for _, unit := range cfg.Coreos.Units {
|
for _, unit := range cfg.Coreos.Units {
|
||||||
@@ -161,6 +169,10 @@ func Apply(cfg CloudConfig, env *Environment) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := system.DaemonReload(); err != nil {
|
||||||
|
log.Fatalf("Failed systemd daemon-reload: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
for unit, command := range commands {
|
for unit, command := range commands {
|
||||||
log.Printf("Calling unit command '%s %s'", command, unit)
|
log.Printf("Calling unit command '%s %s'", command, unit)
|
||||||
res, err := system.RunUnitCommand(command, unit)
|
res, err := system.RunUnitCommand(command, unit)
|
||||||
|
@@ -32,6 +32,8 @@ func TestCloudConfig(t *testing.T) {
|
|||||||
coreos:
|
coreos:
|
||||||
etcd:
|
etcd:
|
||||||
discovery: "https://discovery.etcd.io/827c73219eeb2fa5530027c37bf18877"
|
discovery: "https://discovery.etcd.io/827c73219eeb2fa5530027c37bf18877"
|
||||||
|
update:
|
||||||
|
reboot-strategy: reboot
|
||||||
units:
|
units:
|
||||||
- name: 50-eth0.network
|
- name: 50-eth0.network
|
||||||
runtime: yes
|
runtime: yes
|
||||||
@@ -129,6 +131,9 @@ Address=10.209.171.177/19
|
|||||||
if cfg.Hostname != "trontastic" {
|
if cfg.Hostname != "trontastic" {
|
||||||
t.Errorf("Failed to parse hostname")
|
t.Errorf("Failed to parse hostname")
|
||||||
}
|
}
|
||||||
|
if cfg.Coreos.Update["reboot-strategy"] != "reboot" {
|
||||||
|
t.Errorf("Failed to parse locksmith strategy")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assert that our interface conversion doesn't panic
|
// Assert that our interface conversion doesn't panic
|
||||||
|
@@ -5,7 +5,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"syscall"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -60,15 +59,15 @@ Environment="ETCD_PEER_BIND_ADDR=127.0.0.1:7002"
|
|||||||
|
|
||||||
func TestEtcdEnvironmentWrittenToDisk(t *testing.T) {
|
func TestEtcdEnvironmentWrittenToDisk(t *testing.T) {
|
||||||
ec := EtcdEnvironment{
|
ec := EtcdEnvironment{
|
||||||
"name": "node001",
|
"name": "node001",
|
||||||
"discovery": "http://disco.example.com/foobar",
|
"discovery": "http://disco.example.com/foobar",
|
||||||
"peer-bind-addr": "127.0.0.1:7002",
|
"peer-bind-addr": "127.0.0.1:7002",
|
||||||
}
|
}
|
||||||
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
|
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create tempdir: %v", err)
|
t.Fatalf("Unable to create tempdir: %v", err)
|
||||||
}
|
}
|
||||||
defer syscall.Rmdir(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
if err := WriteEtcdEnvironment(ec, dir); err != nil {
|
if err := WriteEtcdEnvironment(ec, dir); err != nil {
|
||||||
t.Fatalf("Processing of EtcdEnvironment failed: %v", err)
|
t.Fatalf("Processing of EtcdEnvironment failed: %v", err)
|
||||||
@@ -106,7 +105,7 @@ func TestEtcdEnvironmentWrittenToDiskDefaultToMachineID(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create tempdir: %v", err)
|
t.Fatalf("Unable to create tempdir: %v", err)
|
||||||
}
|
}
|
||||||
defer syscall.Rmdir(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
os.Mkdir(path.Join(dir, "etc"), os.FileMode(0755))
|
os.Mkdir(path.Join(dir, "etc"), os.FileMode(0755))
|
||||||
err = ioutil.WriteFile(path.Join(dir, "etc", "machine-id"), []byte("node007"), os.FileMode(0444))
|
err = ioutil.WriteFile(path.Join(dir, "etc", "machine-id"), []byte("node007"), os.FileMode(0444))
|
||||||
@@ -134,6 +133,6 @@ Environment="ETCD_NAME=node007"
|
|||||||
}
|
}
|
||||||
|
|
||||||
func rmdir(path string) error {
|
func rmdir(path string) error {
|
||||||
cmd := exec.Command("rm", "-rf", path)
|
cmd := exec.Command("rm", "-rf", path)
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
85
initialize/locksmith.go
Normal file
85
initialize/locksmith.go
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
package initialize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/coreos/coreos-cloudinit/system"
|
||||||
|
)
|
||||||
|
|
||||||
|
const locksmithUnit = "locksmithd.service"
|
||||||
|
|
||||||
|
// addStrategy creates an `/etc/coreos/update.conf` file with the requested
|
||||||
|
// strategy via rewriting the file on disk or by starting from
|
||||||
|
// `/usr/share/coreos/update.conf`.
|
||||||
|
func addStrategy(strategy string, root string) error {
|
||||||
|
etcUpdate := path.Join(root, "etc", "coreos", "update.conf")
|
||||||
|
usrUpdate := path.Join(root, "usr", "share", "coreos", "update.conf")
|
||||||
|
|
||||||
|
// Ensure /etc/coreos/ exists before attempting to write a file in it
|
||||||
|
os.MkdirAll(path.Join(root, "etc", "coreos"), 0755)
|
||||||
|
|
||||||
|
tmp, err := ioutil.TempFile(path.Join(root, "etc", "coreos"), ".update.conf")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = tmp.Chmod(0644)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
conf, err := os.Open(etcUpdate)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
conf, err = os.Open(usrUpdate)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(conf)
|
||||||
|
|
||||||
|
sawStrat := false
|
||||||
|
stratLine := "REBOOT_STRATEGY="+strategy
|
||||||
|
for scanner.Scan() {
|
||||||
|
line := scanner.Text()
|
||||||
|
if strings.HasPrefix(line, "REBOOT_STRATEGY=") {
|
||||||
|
line = stratLine
|
||||||
|
sawStrat = true
|
||||||
|
}
|
||||||
|
fmt.Fprintln(tmp, line)
|
||||||
|
if err := scanner.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !sawStrat {
|
||||||
|
fmt.Fprintln(tmp, stratLine)
|
||||||
|
}
|
||||||
|
|
||||||
|
return os.Rename(tmp.Name(), etcUpdate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteLocksmithConfig updates the `update.conf` file with a REBOOT_STRATEGY for locksmith.
|
||||||
|
func WriteLocksmithConfig(strategy string, root string) error {
|
||||||
|
cmd := "restart"
|
||||||
|
if strategy == "off" {
|
||||||
|
err := system.MaskUnit(locksmithUnit, root)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
cmd = "stop"
|
||||||
|
} else {
|
||||||
|
return addStrategy(strategy, root)
|
||||||
|
}
|
||||||
|
if err := system.DaemonReload(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err := system.RunUnitCommand(cmd, locksmithUnit); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
91
initialize/locksmith_test.go
Normal file
91
initialize/locksmith_test.go
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package initialize
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
base = `SERVER=https://example.com
|
||||||
|
GROUP=thegroupc`
|
||||||
|
|
||||||
|
configured = base + `
|
||||||
|
REBOOT_STRATEGY=awesome
|
||||||
|
`
|
||||||
|
|
||||||
|
expected = base + `
|
||||||
|
REBOOT_STRATEGY=etcd-lock
|
||||||
|
`
|
||||||
|
)
|
||||||
|
|
||||||
|
func setupFixtures(dir string) {
|
||||||
|
os.MkdirAll(path.Join(dir, "usr", "share", "coreos"), 0755)
|
||||||
|
os.MkdirAll(path.Join(dir, "run", "systemd", "system"), 0755)
|
||||||
|
|
||||||
|
ioutil.WriteFile(path.Join(dir, "usr", "share", "coreos", "update.conf"), []byte(base), 0644)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLocksmithEnvironmentWrittenToDisk(t *testing.T) {
|
||||||
|
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to create tempdir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
setupFixtures(dir)
|
||||||
|
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
if i == 1 {
|
||||||
|
err = ioutil.WriteFile(path.Join(dir, "etc", "coreos", "update.conf"), []byte(configured), 0644)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := WriteLocksmithConfig("etcd-lock", dir); err != nil {
|
||||||
|
t.Fatalf("Processing of LocksmithEnvironment failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath := path.Join(dir, "etc", "coreos", "update.conf")
|
||||||
|
|
||||||
|
fi, err := os.Stat(fullPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to stat file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if fi.Mode() != os.FileMode(0644) {
|
||||||
|
t.Errorf("File has incorrect mode: %v", fi.Mode())
|
||||||
|
}
|
||||||
|
|
||||||
|
contents, err := ioutil.ReadFile(fullPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to read expected file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if string(contents) != expected {
|
||||||
|
t.Fatalf("File has incorrect contents, got %v, wanted %v", string(contents), expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func TestLocksmithEnvironmentMasked(t *testing.T) {
|
||||||
|
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to create tempdir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
setupFixtures(dir)
|
||||||
|
|
||||||
|
if err := WriteLocksmithConfig("off", dir); err != nil {
|
||||||
|
t.Fatalf("Processing of LocksmithEnvironment failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath := path.Join(dir, "etc", "systemd", "system", "locksmithd.service")
|
||||||
|
target, err := os.Readlink(fullPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to read link %v", err)
|
||||||
|
}
|
||||||
|
if target != "/dev/null" {
|
||||||
|
t.Fatalf("Locksmith not masked, unit target %v", target)
|
||||||
|
}
|
||||||
|
}
|
@@ -4,7 +4,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"syscall"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,7 +19,7 @@ func TestOEMReleaseWrittenToDisk(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create tempdir: %v", err)
|
t.Fatalf("Unable to create tempdir: %v", err)
|
||||||
}
|
}
|
||||||
defer syscall.Rmdir(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
if err := WriteOEMRelease(&oem, dir); err != nil {
|
if err := WriteOEMRelease(&oem, dir); err != nil {
|
||||||
t.Fatalf("Processing of EtcdEnvironment failed: %v", err)
|
t.Fatalf("Processing of EtcdEnvironment failed: %v", err)
|
||||||
|
@@ -29,3 +29,21 @@ func TestParseHeaderCRLF(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseConfigCRLF(t *testing.T) {
|
||||||
|
contents := "#cloud-config\r\nhostname: foo\r\nssh_authorized_keys:\r\n - foobar\r\n"
|
||||||
|
ud, err := ParseUserData(contents)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Failed parsing config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg := ud.(CloudConfig)
|
||||||
|
|
||||||
|
if cfg.Hostname != "foo" {
|
||||||
|
t.Error("Failed parsing hostname from config")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(cfg.SSHAuthorizedKeys) != 1 {
|
||||||
|
t.Error("Parsed incorrect number of SSH keys")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -11,10 +11,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type File struct {
|
type File struct {
|
||||||
Encoding string
|
Encoding string
|
||||||
Content string
|
Content string
|
||||||
Owner string
|
Owner string
|
||||||
Path string
|
Path string
|
||||||
RawFilePermissions string `yaml:"permissions"`
|
RawFilePermissions string `yaml:"permissions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,6 @@ func (f *File) Permissions() (os.FileMode, error) {
|
|||||||
return os.FileMode(perm), nil
|
return os.FileMode(perm), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func WriteFile(f *File) error {
|
func WriteFile(f *File) error {
|
||||||
if f.Encoding != "" {
|
if f.Encoding != "" {
|
||||||
return fmt.Errorf("Unable to write file with encoding %s", f.Encoding)
|
return fmt.Errorf("Unable to write file with encoding %s", f.Encoding)
|
||||||
|
@@ -65,8 +65,8 @@ func PlaceUnit(u *Unit, dst string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
file := File{
|
file := File{
|
||||||
Path: dst,
|
Path: dst,
|
||||||
Content: u.Content,
|
Content: u.Content,
|
||||||
RawFilePermissions: "0644",
|
RawFilePermissions: "0644",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,3 +165,11 @@ func MachineID(root string) string {
|
|||||||
|
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MaskUnit(unit string, root string) error {
|
||||||
|
masked := path.Join(root, "etc", "systemd", "system", unit)
|
||||||
|
if err := os.MkdirAll(path.Dir(masked), os.FileMode(0755)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return os.Symlink("/dev/null", masked)
|
||||||
|
}
|
||||||
|
@@ -4,15 +4,14 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"syscall"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPlaceNetworkUnit(t *testing.T) {
|
func TestPlaceNetworkUnit(t *testing.T) {
|
||||||
u := Unit{
|
u := Unit{
|
||||||
Name: "50-eth0.network",
|
Name: "50-eth0.network",
|
||||||
Runtime: true,
|
Runtime: true,
|
||||||
Content: `[Match]
|
Content: `[Match]
|
||||||
Name=eth47
|
Name=eth47
|
||||||
|
|
||||||
[Network]
|
[Network]
|
||||||
@@ -24,7 +23,7 @@ Address=10.209.171.177/19
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create tempdir: %v", err)
|
t.Fatalf("Unable to create tempdir: %v", err)
|
||||||
}
|
}
|
||||||
defer syscall.Rmdir(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
dst := UnitDestination(&u, dir)
|
dst := UnitDestination(&u, dir)
|
||||||
expectDst := path.Join(dir, "run", "systemd", "network", "50-eth0.network")
|
expectDst := path.Join(dir, "run", "systemd", "network", "50-eth0.network")
|
||||||
@@ -63,9 +62,9 @@ Address=10.209.171.177/19
|
|||||||
|
|
||||||
func TestPlaceMountUnit(t *testing.T) {
|
func TestPlaceMountUnit(t *testing.T) {
|
||||||
u := Unit{
|
u := Unit{
|
||||||
Name: "media-state.mount",
|
Name: "media-state.mount",
|
||||||
Runtime: false,
|
Runtime: false,
|
||||||
Content: `[Mount]
|
Content: `[Mount]
|
||||||
What=/dev/sdb1
|
What=/dev/sdb1
|
||||||
Where=/media/state
|
Where=/media/state
|
||||||
`,
|
`,
|
||||||
@@ -75,7 +74,7 @@ Where=/media/state
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create tempdir: %v", err)
|
t.Fatalf("Unable to create tempdir: %v", err)
|
||||||
}
|
}
|
||||||
defer syscall.Rmdir(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
dst := UnitDestination(&u, dir)
|
dst := UnitDestination(&u, dir)
|
||||||
expectDst := path.Join(dir, "etc", "systemd", "system", "media-state.mount")
|
expectDst := path.Join(dir, "etc", "systemd", "system", "media-state.mount")
|
||||||
@@ -115,7 +114,7 @@ func TestMachineID(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to create tempdir: %v", err)
|
t.Fatalf("Unable to create tempdir: %v", err)
|
||||||
}
|
}
|
||||||
defer syscall.Rmdir(dir)
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
os.Mkdir(path.Join(dir, "etc"), os.FileMode(0755))
|
os.Mkdir(path.Join(dir, "etc"), os.FileMode(0755))
|
||||||
ioutil.WriteFile(path.Join(dir, "etc", "machine-id"), []byte("node007\n"), os.FileMode(0444))
|
ioutil.WriteFile(path.Join(dir, "etc", "machine-id"), []byte("node007\n"), os.FileMode(0444))
|
||||||
@@ -124,3 +123,22 @@ func TestMachineID(t *testing.T) {
|
|||||||
t.Fatalf("File has incorrect contents")
|
t.Fatalf("File has incorrect contents")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func TestMaskUnit(t *testing.T) {
|
||||||
|
dir, err := ioutil.TempDir(os.TempDir(), "coreos-cloudinit-")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to create tempdir: %v", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
if err := MaskUnit("foo.service", dir); err != nil {
|
||||||
|
t.Fatalf("Unable to mask unit: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath := path.Join(dir, "etc", "systemd", "system", "foo.service")
|
||||||
|
target, err := os.Readlink(fullPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unable to read link", err)
|
||||||
|
}
|
||||||
|
if target != "/dev/null" {
|
||||||
|
t.Fatalf("unit not masked, got unit target", target)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -53,7 +53,7 @@ func CreateUser(u *User) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if u.PrimaryGroup != "" {
|
if u.PrimaryGroup != "" {
|
||||||
args = append(args, "--primary-group", u.PrimaryGroup)
|
args = append(args, "--gid", u.PrimaryGroup)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(u.Groups) > 0 {
|
if len(u.Groups) > 0 {
|
||||||
|
39
test
39
test
@@ -1,10 +1,37 @@
|
|||||||
#!/bin/bash -e
|
#!/bin/bash -e
|
||||||
|
#
|
||||||
|
# Run all coreos-cloudinit tests
|
||||||
|
# ./test
|
||||||
|
# ./test -v
|
||||||
|
#
|
||||||
|
# Run tests for one package
|
||||||
|
# PKG=initialize ./test
|
||||||
|
#
|
||||||
|
|
||||||
echo "Building bin/coreos-cloudinit"
|
# Invoke ./cover for HTML output
|
||||||
. build
|
COVER=${COVER:-"-cover"}
|
||||||
|
|
||||||
|
source ./build
|
||||||
|
|
||||||
|
declare -a TESTPKGS=(initialize system datasource)
|
||||||
|
|
||||||
|
if [ -z "$PKG" ]; then
|
||||||
|
GOFMTPATH="$TESTPKGS coreos-cloudinit.go"
|
||||||
|
# prepend repo path to each package
|
||||||
|
TESTPKGS=${TESTPKGS[@]/#/${REPO_PATH}/}
|
||||||
|
else
|
||||||
|
GOFMTPATH="$TESTPKGS"
|
||||||
|
# strip out slashes and dots from PKG=./foo/
|
||||||
|
TESTPKGS=${PKG//\//}
|
||||||
|
TESTPKGS=${TESTPKGS//./}
|
||||||
|
TESTPKGS=${TESTPKGS/#/${REPO_PATH}/}
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Running tests..."
|
echo "Running tests..."
|
||||||
for pkg in "./initialize ./system ./datasource"; do
|
go test -i ${TESTPKGS}
|
||||||
go test -i $pkg
|
go test ${COVER} $@ ${TESTPKGS}
|
||||||
go test -v $pkg
|
|
||||||
done
|
echo "Checking gofmt..."
|
||||||
|
fmtRes=$(gofmt -l $GOFMTPATH)
|
||||||
|
|
||||||
|
echo "Success"
|
||||||
|
12
units/user-cloudinit-proc-cmdline.service
Normal file
12
units/user-cloudinit-proc-cmdline.service
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Load cloud-config from url defined in /proc/cmdline
|
||||||
|
Requires=coreos-setup-environment.service
|
||||||
|
After=coreos-setup-environment.service
|
||||||
|
Before=user-config.target
|
||||||
|
ConditionKernelCommandLine=cloud-config-url
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=yes
|
||||||
|
EnvironmentFile=-/etc/environment
|
||||||
|
ExecStart=/usr/bin/coreos-cloudinit --from-proc-cmdline
|
@@ -0,0 +1,24 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Load cloud-config from %f
|
||||||
|
Requires=coreos-setup-environment.service
|
||||||
|
After=coreos-setup-environment.service
|
||||||
|
Before=user-config.target
|
||||||
|
ConditionFileNotEmpty=%f
|
||||||
|
|
||||||
|
# HACK: work around ordering between config drive and ec2 metadata It is
|
||||||
|
# possible for OpenStack style systems to provide both the metadata service
|
||||||
|
# and config drive, to prevent the two from stomping on eachother force
|
||||||
|
# this to run after OEM and after metadata (if it exsts). I'm doing this
|
||||||
|
# here instead of in the ec2 service because the ec2 unit is not written
|
||||||
|
# to disk until the OEM cloud config is evaluated and I want to make sure
|
||||||
|
# systemd knows about the ordering as early as possible.
|
||||||
|
# coreos-cloudinit could implement a simple lock but that cannot be used
|
||||||
|
# until after the systemd dbus calls are made non-blocking.
|
||||||
|
After=system-cloudinit@usr-share-oem-cloud\x2dconfig.yml.service
|
||||||
|
After=ec2-cloudinit.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
RemainAfterExit=yes
|
||||||
|
EnvironmentFile=-/etc/environment
|
||||||
|
ExecStart=/usr/bin/coreos-cloudinit --from-file=%f
|
@@ -6,3 +6,6 @@ After=system-config.target
|
|||||||
# Load user_data placed by coreos-install
|
# Load user_data placed by coreos-install
|
||||||
Requires=user-cloudinit@var-lib-coreos\x2dinstall-user_data.service
|
Requires=user-cloudinit@var-lib-coreos\x2dinstall-user_data.service
|
||||||
After=user-cloudinit@var-lib-coreos\x2dinstall-user_data.service
|
After=user-cloudinit@var-lib-coreos\x2dinstall-user_data.service
|
||||||
|
|
||||||
|
Requires=user-cloudinit-proc-cmdline.service
|
||||||
|
After=user-cloudinit-proc-cmdline.service
|
||||||
|
Reference in New Issue
Block a user