Skip to content
This repository was archived by the owner on Nov 10, 2018. It is now read-only.

Commit 89417ce

Browse files
committed
Initial open source commit.
0 parents  commit 89417ce

File tree

123 files changed

+7990
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+7990
-0
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/bin/
2+
/build/
3+
/cache/
4+
.terraform
5+
*~
6+
*.gpg
7+
*.tfplan
8+
*.tfstate
9+
*.tfstate.backup
10+
*.tgz
11+
/*.json
12+
/*.json.bak
13+
/.brew_home/
14+
TODO
15+
/.gopath
16+
/.DS_Store

CHANGELOG.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Substrate Changes
2+
3+
## v1.x (unreleased)
4+
5+
## v1.0.1
6+
7+
- Stop using our custom `terraform-provider-ubuntu` plugin, since Terraform can now provide this functionality natively.
8+
- Expose `node_exporter` http on director.
9+
- Bump up to Terraform 0.8.3
10+
- More version information from provisioning script and cli utils
11+
- Adapt to use `kubeadm` 1.6alpha line
12+
- Bump up to version 1.5.1 of Kubernetes
13+
14+
## v1.0.0
15+
16+
- Increase the number of worker instances from 2 to 4.
17+
- Fix a bug where the border Squid proxy wouldn't stay running after zone spinup.
18+
- Install and configure Prometheus `node_exporter` on each of our instances.
19+
- Add `quay.io` to our list of whitelisted container sources.
20+
21+
## v1.0.0-rc3 (2016-12-01)
22+
23+
- Fixed a bug where `journal-remote` logs collected on the border node were not being cleaned automatically. This led to the border node running out of disk over long periods of time. This is a bug in systemd/`journal-remote`, which we've worked around by cleaning up manually with a timer unit (aka cronjob).
24+
25+
## v1.0.0-rc2 (2016-11-29)
26+
27+
- Disabled log forwarding from `journald` (which is good about not using up the entire disk) to `syslog` (which is not). This avoids an issue where logs could fill the root volume and prevent Kubernetes from functioning properly on a node.
28+
- Lowered the logging verbosity of `kubelet` to reduce pressure on our logging system.
29+
30+
## v1.0.0-rc1 (2016-11-28)
31+
32+
- Our first v1.0.0 release candidate! We've made a ton of progress since our v0.0.x versions -- too much to reasonably list here. Suffice to say we built most of Substrate in the last year.
33+
34+
## v0.0.6
35+
36+
- Added a real CLI and a reworked build process.
37+
38+
## v0.0.5
39+
40+
- Begin work on new development flow, reintroduce `master` branch
41+
42+
## v0.0.4
43+
44+
- Remove proxy/squid setup
45+
- Move kubernetes master to a single instance etcd setup
46+
- Create a kubernetes worker ASG and launch configuration
47+
- Remove Route53 setup for now
48+
49+
## v0.0.3
50+
- Upgrade to Terraform 0.6.14.
51+
- Upgrade to Kubernetes 1.2
52+
53+
## v0.0.2
54+
- Made a test change to a naming thing to see if it gets picked up.
55+
56+
## v0.0.1
57+
- Initial version of substrate with versioning/CI set up.

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Copyright 2017 Simple Finance Technology Corp
2+
3+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4+
5+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6+
7+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8+
9+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Makefile

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
###############################################################################
2+
# set some flags to control Make's behavior
3+
###############################################################################
4+
5+
# disable all builtin suffix pattern rules
6+
.SUFFIXES:
7+
8+
# these rules should all run in parallel just fine
9+
MAKEFLAGS := "-j "
10+
11+
# run all the rule commands in Bash with "-o pipefail" so failing commands with
12+
# piped output still exit with the right status
13+
SHELL = /bin/bash -o pipefail
14+
15+
# define all our top level targets
16+
TARGETS := build build-release test fmt lint clean update-deps
17+
.PHONY: $(TARGETS)
18+
19+
# the default will be to build for the current host platform/arch (for easy development)
20+
.DEFAULT_GOAL := build
21+
22+
23+
###############################################################################
24+
# define some versioning logic (see "Versioning" in the README for details)
25+
###############################################################################
26+
27+
# full Git commit hash of the revision we're building
28+
SUBSTRATE_COMMIT := $(shell git rev-parse HEAD)
29+
30+
# append -dirty to the commit hash if the working directory has been modified
31+
SUBSTRATE_COMMIT := $(SUBSTRATE_COMMIT)$(shell git status | grep -q 'added to commit' && echo -dirty)
32+
33+
# current version as tagged in ./VERSION
34+
SUBSTRATE_VERSION := $(shell cat VERSION)
35+
36+
# if the current branch/tag == VERSION, we must be doing a final release build,
37+
# otherwise we're doing a "snapshot" build.
38+
ifneq ($(SUBSTRATE_VERSION),$(shell git describe --tags))
39+
SUBSTRATE_VERSION := $(SUBSTRATE_VERSION)-snapshot
40+
endif
41+
42+
43+
###############################################################################
44+
# set up some cross-compilation variables
45+
###############################################################################
46+
47+
# detect the host OS/arch (where this make is running)
48+
export HOST_TARGET ?= $(shell uname -s | tr A-Z a-z)-$(subst x86_64,amd64,$(shell uname -m))
49+
50+
# target platform/architectures for when we want to build a full release
51+
export RELEASE_TARGETS ?= linux-amd64 darwin-amd64
52+
53+
# define some helpers to extract just the platform or architecture from our target,
54+
# assuming the target is the pattern stem (%) value
55+
export PLATFORM = $(word 1, $(subst -, ,$*))
56+
export ARCH = $(word 2, $(subst -, ,$*))
57+
58+
59+
###############################################################################
60+
# define some additional top level variables
61+
###############################################################################
62+
63+
# what version of Terraform we're bundling
64+
export TERRAFORM_VERSION := 0.8.3
65+
66+
# this is a directory we'll cache downloaded files in by default, we
67+
# can override this to point at $HOME/... in Jenkins to keep cached files
68+
# between builds
69+
export CACHE_DIR ?= $(CURDIR)/cache
70+
71+
# this is the directory we'll use to store all intermediate build products
72+
export BUILD_DIR := $(CURDIR)/build
73+
74+
# this is the directory we'll use for the final output binaries
75+
export BIN_DIR := $(CURDIR)/bin
76+
77+
# we're going to do all builds inside an isolated GOPATH under BUILD_DIR
78+
export GOPATH := $(BUILD_DIR)/gopath
79+
80+
# define a separate GOPATH only for tools that we need during the build
81+
export TOOLS_GOPATH := $(CACHE_DIR)/tools-$(HOST_TARGET)
82+
83+
84+
###############################################################################
85+
# define top level targets (ones you might type on the command line)
86+
###############################################################################
87+
88+
# build (default target) compiles substrate for the current host platform
89+
# and copy to ./bin/substrate for convenience
90+
build: bin/substrate
91+
bin/substrate: $(BIN_DIR)/substrate-$(HOST_TARGET)-$(SUBSTRATE_VERSION)
92+
@cp -v $< $@ && touch $@
93+
94+
# build-release compiles substrate for all supported target platforms
95+
build-release: $(patsubst %,$(BIN_DIR)/substrate-%-$(SUBSTRATE_VERSION),$(RELEASE_TARGETS))
96+
97+
# clean should essentially revert back to a clean checkout
98+
# it should always run before any other top level targs
99+
clean:
100+
rm -rf $(BIN_DIR) $(BUILD_DIR)
101+
102+
# fmt and lint are broken out into their own Makefile
103+
fmt lint: $(BUILD_DIR)/$(HOST_TARGET)/terraform
104+
@$(MAKE) -C util $@ TERRAFORM=$< SOURCE_DIR=$(CURDIR) GOPATH=$(TOOLS_GOPATH) | sed -e 's/^/[$@] /'
105+
106+
# test only runs linters and checks that things compile for now
107+
test: lint build-release
108+
@echo WARNING: Substrate only has lint checks for now, not any real tests!
109+
110+
111+
###############################################################################
112+
# define rules to set up the Go build environment (isolated GOPATH)
113+
###############################################################################
114+
115+
# directory of the substrate directory within GOPATH
116+
SUBSTRATE_PKG_DIR := $(GOPATH)/src/github.com/SimpleFinance/substrate
117+
118+
# copied_go_sources returns a list of all the the .go source files, translated
119+
# into their destination path under the GOPATH
120+
copied_go_sources = $(patsubst %, $(SUBSTRATE_PKG_DIR)/%, $(shell find $1 -type f -name '*.go'))
121+
# copy our source files into the right place within the GOPATH package directory on demand
122+
$(SUBSTRATE_PKG_DIR)/%: %
123+
@mkdir -p $(@D)
124+
@cp $< $@
125+
.PRECIOUS: $(SUBSTRATE_PKG_DIR)/%
126+
127+
# GO_DEPS is a marker file so we can set up the Go environment when we need it
128+
# it needs to be updated whenever our Glide-specified dependencies change
129+
GO_DEPS := $(SUBSTRATE_PKG_DIR)/vendor/installed
130+
$(GO_DEPS): glide.yaml glide.lock
131+
@(go version | grep -q "go version") || (echo "You don't seem to have a valid Go toolchain, maybe GOROOT isn't set?"; exit 1)
132+
@mkdir -p $(@D)
133+
@cp glide.yaml glide.lock $(SUBSTRATE_PKG_DIR)
134+
cd $(SUBSTRATE_PKG_DIR) && glide --no-color install 2>&1 | sed -e 's/^/[glide] /'
135+
@touch $@
136+
137+
# update-deps updates the glide.lock file with the latest updates to glide.yaml
138+
# and any new package versions (subject to version constraints in glide.yaml)
139+
update-deps: $(GO_DEPS)
140+
cd $(SUBSTRATE_PKG_DIR) && glide --no-color update
141+
cp $(SUBSTRATE_PKG_DIR)/glide.lock glide.lock
142+
143+
144+
###############################################################################
145+
# install tools we need to do the build itself
146+
###############################################################################
147+
148+
# go-bindata is a tool for bundling binary assets into a .go source file
149+
GOBINDATA := $(TOOLS_GOPATH)/bin/go-bindata
150+
$(GOBINDATA):
151+
GOPATH=$(TOOLS_GOPATH) go get -u github.com/jteeuwen/go-bindata/...
152+
@touch $@
153+
154+
155+
###############################################################################
156+
# define rules to build our custom Terraform provider plugins
157+
###############################################################################
158+
159+
# our custom terraform providers
160+
CUSTOM_PROVIDERS := \
161+
terraform-provider-bakery \
162+
terraform-provider-tarball
163+
164+
# messy macro-laden loop which defines the build rules for all the custom providers
165+
CUSTOM_TERRAFORM_BINARIES:=
166+
define build_provider
167+
CUSTOM_TERRAFORM_BINARIES += $(BUILD_DIR)/%/$(1)
168+
$$(BUILD_DIR)/%/$(1): $$(GO_DEPS) $$(call copied_go_sources, providers/$(1))
169+
GOOS=$$(PLATFORM) GOARCH=$$(ARCH) go build -o $$@ github.com/SimpleFinance/substrate/providers/$(1)
170+
@touch $$@
171+
endef
172+
$(foreach p, $(CUSTOM_PROVIDERS),$(eval $(call build_provider,$(p))))
173+
.PRECIOUS: $(CUSTOM_TERRAFORM_BINARIES)
174+
175+
176+
###############################################################################
177+
# define rules to download and extract the builtin Terraform providers we need
178+
###############################################################################
179+
180+
#the builtin terraform binaries on which we depend
181+
BUILTIN_PROVIDERS := terraform
182+
183+
# download the Terraform release zip for a particular platform/arch
184+
CACHED_TERRAFORM_ZIP := $(CACHE_DIR)/terraform-$(TERRAFORM_VERSION)-%.zip
185+
.PRECIOUS: $(CACHED_TERRAFORM_ZIP) # don't delete the cached zip between builds
186+
$(CACHED_TERRAFORM_ZIP):
187+
@mkdir -p $(@D)
188+
curl -s -o $@ https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION)/terraform_$(TERRAFORM_VERSION)_$(PLATFORM)_$(ARCH).zip
189+
@touch $@
190+
191+
TERRAFORM_ZIP := $(BUILD_DIR)/%/terraform-$(TERRAFORM_VERSION).zip
192+
.PRECIOUS: $(TERRAFORM_ZIP)
193+
$(TERRAFORM_ZIP): $(CACHED_TERRAFORM_ZIP)
194+
@mkdir -p $(@D)
195+
@cp $< $@
196+
197+
# extract the builtin terraform binaries we want into $BUILD_DIR/$TARGET/
198+
BUILTIN_TERRAFORM_BINARIES := $(BUILD_DIR)/%/terraform
199+
200+
$(BUILD_DIR)/%/terraform: $(TERRAFORM_ZIP)
201+
@mkdir -p $(@D)
202+
unzip -p $< $(notdir $@) > $@
203+
@chmod +x $@ && touch $@
204+
.PRECIOUS: $(BUILTIN_TERRAFORM_BINARIES)
205+
206+
###############################################################################
207+
# define rules to bundle the (platform/arch specifc) binaries into a .go file
208+
###############################################################################
209+
210+
# define a rule to bundle all our custom and builtin binaries into a .go source file
211+
CLI_BUNDLE_BINARIES := $(SUBSTRATE_PKG_DIR)/cmd/substrate/assets/binaries/data-%.go
212+
$(CLI_BUNDLE_BINARIES): $(CUSTOM_TERRAFORM_BINARIES) $(BUILTIN_TERRAFORM_BINARIES) | $(GOBINDATA)
213+
$(GOBINDATA) \
214+
-pkg binaries \
215+
-nomemcopy \
216+
-nocompress \
217+
-tags "$(PLATFORM),$(ARCH)" \
218+
-prefix $(BUILD_DIR)/$(PLATFORM)-$(ARCH)/ \
219+
-o $@ \
220+
$^
221+
@touch $@
222+
.PRECIOUS: $(CLI_BUNDLE_BINARIES)
223+
224+
225+
###############################################################################
226+
# define rules to bundle the zone configuration (./zone) into a .go file
227+
###############################################################################
228+
229+
# generate a bundle of the ./zone directory containing all our configuration files
230+
CLI_BUNDLE_ZONE_CONFIG := $(SUBSTRATE_PKG_DIR)/cmd/substrate/assets/zoneconfig/data.go
231+
$(CLI_BUNDLE_ZONE_CONFIG): $(shell find ./zone -not -iname "*~" -type f) | $(GOBINDATA)
232+
$(GOBINDATA) \
233+
-pkg zoneconfig \
234+
-nomemcopy \
235+
-nocompress \
236+
-o $@ \
237+
$^
238+
@touch $@
239+
.PRECIOUS: $(CLI_BUNDLE_ZONE_CONFIG)
240+
241+
242+
###############################################################################
243+
# define the rule for building the final CLI binary from everything above
244+
###############################################################################
245+
246+
# build the final `substrate` CLI binary for a particular target
247+
$(BIN_DIR)/substrate-%-$(SUBSTRATE_VERSION): $(CLI_BUNDLE_BINARIES) $(CLI_BUNDLE_ZONE_CONFIG) $(call copied_go_sources, cmd)
248+
@mkdir -p $(@D)
249+
GOOS=$(PLATFORM) GOARCH=$(ARCH) go build \
250+
-o $@ \
251+
-tags "$(PLATFORM),$(ARCH)" \
252+
-ldflags "-X main.version=$(SUBSTRATE_VERSION) -X main.commit=$(SUBSTRATE_COMMIT)" \
253+
github.com/SimpleFinance/substrate/cmd/substrate
254+
@touch $@

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Substrate
2+
3+
This is an opinionated tool for managing Kubernetes clusters. It is no longer under active development at Simple, but we're sharing it as-is. It should probably not be used directly. See [@asynchio's giant spreadsheet](https://docs.google.com/spreadsheets/d/1LxSqBzjOxfGx3cmtZ4EbB_BGCxT_wlxW_xgHVVa23es/edit#gid=0) for some alternatives.
4+
5+
For more information, see the `./docs` directory:
6+
7+
- [`docs/developing.md`](docs/developing.md) describes the basics of hacking on Substrate.
8+
9+
- [`docs/design.md`](docs/design.md) documents the overall design and terminology.
10+
11+
- [`docs/mechanics.md`](docs/mechanics.md) describes how the bootstrap process works to create a zone.
12+
13+
## Versioning
14+
15+
- Substrate uses [SemVer](http://semver.org/).
16+
- Major versions live in long-lived branches named like `v1.x`, `v2.x`, etc...
17+
- We may maintain more than one major version of Substrate. This allows us to
18+
make major backwards-incompatible changes while still shipping bug fixes to
19+
older versions. For example, versions `v1.0.1` and `v2.0.1` might be
20+
released at the same time to fix the same bug across multiple major
21+
versions.

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v1.0.2

0 commit comments

Comments
 (0)