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

Commit a3a038a

Browse files
committed
[WIP] v1.0.0
1 parent 15cd873 commit a3a038a

Some content is hidden

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

72 files changed

+3680
-3890
lines changed

.drone.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ steps:
2222
event:
2323
- push
2424

25-
- name: manager-testing
25+
- name: e2e
2626
image: golang:1.14
2727
volumes:
2828
- name: gocache
2929
path: /go
3030
commands:
31-
- go test -v ./pkg/manager -test.long
31+
- make test-e2e
3232
when:
3333
branch:
3434
- master

.goreleaser.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ builds:
2626
- all=-trimpath={{.Env.GOPATH}}
2727
ldflags:
2828
- -s -w
29-
- -X "github.com/criticalstack/e2d/pkg/buildinfo.Date={{.Date}}"
30-
- -X "github.com/criticalstack/e2d/pkg/buildinfo.GitSHA={{.ShortCommit}}"
31-
- -X "github.com/criticalstack/e2d/pkg/buildinfo.Version={{.Tag}}"
29+
- -X "github.com/criticalstack/e2d/internal/buildinfo.Date={{.Date}}"
30+
- -X "github.com/criticalstack/e2d/internal/buildinfo.GitSHA={{.ShortCommit}}"
31+
- -X "github.com/criticalstack/e2d/internal/buildinfo.Version={{.Tag}}"
3232
archives:
3333
- replacements:
3434
darwin: Darwin
@@ -55,7 +55,7 @@ nfpms:
5555
- /etc/systemd/system/e2d.service.d
5656
- /var/lib/etcd
5757
files:
58-
deploy/e2d.service: /etc/systemd/system/e2d.service
58+
build/e2d.service: /etc/systemd/system/e2d.service
5959
checksum:
6060
name_template: 'checksums.txt'
6161
snapshot:

Makefile

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1-
# If you update this file, please follow
2-
# https://suva.sh/posts/well-documented-makefiles
3-
41
.DEFAULT_GOAL:=help
52

6-
ifeq ($(GOPROXY),)
7-
export GOPROXY = direct
8-
endif
9-
10-
# Directories.
11-
TOOLS_DIR := hack/tools
3+
BIN_DIR ?= bin
4+
TOOLS_DIR := hack/tools
125
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
13-
BIN_DIR := bin
14-
15-
# Binaries.
166
GOLANGCI_LINT := $(TOOLS_BIN_DIR)/golangci-lint
177

18-
# Golang build env
19-
LDFLAGS := -s -w
20-
218
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD | sed 's/\///g')
229
GIT_COMMIT = $(shell git rev-parse HEAD)
2310
GIT_SHA = $(shell git rev-parse --short HEAD)
@@ -28,29 +15,36 @@ ifneq ($(GIT_TAG),)
2815
VERSION = $(GIT_TAG)
2916
endif
3017

31-
LDFLAGS += -X "github.com/criticalstack/e2d/pkg/buildinfo.Date=$(shell date -u +'%Y-%m-%dT%TZ')"
32-
LDFLAGS += -X "github.com/criticalstack/e2d/pkg/buildinfo.GitSHA=$(GIT_SHA)"
33-
LDFLAGS += -X "github.com/criticalstack/e2d/pkg/buildinfo.Version=$(VERSION)"
18+
LDFLAGS := -s -w
19+
LDFLAGS += -X "github.com/criticalstack/e2d/internal/buildinfo.Date=$(shell date -u +'%Y-%m-%dT%TZ')"
20+
LDFLAGS += -X "github.com/criticalstack/e2d/internal/buildinfo.GitSHA=$(GIT_SHA)"
21+
LDFLAGS += -X "github.com/criticalstack/e2d/internal/buildinfo.Version=$(VERSION)"
3422
GOFLAGS = -gcflags "all=-trimpath=$(PWD)" -asmflags "all=-trimpath=$(PWD)"
3523

3624
GO_BUILD_ENV_VARS := GO111MODULE=on CGO_ENABLED=0
3725

38-
.PHONY: build test test-manager clean
26+
##@ Building
3927

40-
build: clean ## Build the e2d golang binary
28+
.PHONY: e2d
29+
30+
e2d: ## Build the e2d golang binary
4131
$(GO_BUILD_ENV_VARS) go build -o bin/e2d $(GOFLAGS) -ldflags '$(LDFLAGS)' ./cmd/e2d
4232

43-
test: ## Run all tests
44-
go test ./...
33+
.PHONY: update-codegen
34+
update-codegen: ## Update generated code (slow)
35+
@echo "Updating generated code files ..."
36+
@echo " *** This can be slow and does not need to run every build ***"
37+
@hack/tools/update-codegen.sh
4538

46-
test-manager: ## Test the manager package
47-
go test ./pkg/manager -test.long
39+
##@ Testing
4840

49-
clean: ## Cleanup the project folders
50-
@rm -rf ./bin/*
51-
@rm -rf hack/tools/bin
41+
.PHONY: test test-e2e lint lint-full
42+
43+
test: ## Run all tests
44+
@go test $(shell go list ./... | grep -v e2e)
5245

53-
.PHONY: lint
46+
test-e2e: ## Run e2e tests
47+
@go test ./e2e -parallel=16 -count=1
5448

5549
lint: $(GOLANGCI_LINT) ## Lint codebase
5650
$(GOLANGCI_LINT) run -v
@@ -60,15 +54,20 @@ lint-full: $(GOLANGCI_LINT) ## Run slower linters to detect possible issues
6054

6155
##@ Helpers
6256

63-
.PHONY: help
57+
.PHONY: help clean
6458

6559
$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod # Build golangci-lint from tools folder.
6660
cd $(TOOLS_DIR); go build -tags=tools -o $(BIN_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
6761

62+
clean: ## Cleanup the project folders
63+
@rm -rf ./bin/*
64+
@rm -rf hack/tools/bin
65+
6866
help: ## Display this help
69-
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
67+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
7068

7169

70+
# TODO: move to hack/tools
7271
generate:
7372
protoc -I pkg/manager/e2dpb \
7473
-I vendor/ \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# e2d
22

3-
[![GoDoc](https://godoc.org/github.com/criticalstack/e2d?status.svg)](https://godoc.org/github.com/criticalstack/e2d)
3+
[![PkgGoDev](https://pkg.go.dev/badge/github.com/criticalstack/e2d)](https://pkg.go.dev/github.com/criticalstack/e2d)
44
[![Build Status](https://cloud.drone.io/api/badges/criticalstack/e2d/status.svg)](https://cloud.drone.io/criticalstack/e2d)
55

66
e2d is a command-line tool for deploying and managing etcd clusters, both in the cloud or on bare-metal. It also includes [e2db](https://github.com/criticalstack/e2d/tree/master/pkg/e2db), an ORM-like abstraction for working with etcd.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
Description=e2d
33

44
[Service]
5-
ExecStart=/usr/local/bin/e2d run
5+
Environment="E2D_CONFIG_ARGS=--config=/etc/e2d.yaml"
6+
ExecStart=/usr/local/bin/e2d run $E2D_CONFIG_ARGS
67
EnvironmentFile=-/etc/e2d.conf
78
Restart=on-failure
89
RestartSec=30

cmd/e2d/app/certs/certs.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package certs
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
certsgenerate "github.com/criticalstack/e2d/cmd/e2d/app/certs/generate"
7+
certsinit "github.com/criticalstack/e2d/cmd/e2d/app/certs/init"
8+
)
9+
10+
func NewCommand() *cobra.Command {
11+
cmd := &cobra.Command{
12+
Use: "certs",
13+
Short: "manage e2d certs",
14+
}
15+
cmd.AddCommand(
16+
certsinit.NewCommand(),
17+
certsgenerate.NewCommand(),
18+
)
19+
return cmd
20+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package generate
2+
3+
import (
4+
"path/filepath"
5+
"strings"
6+
7+
"github.com/spf13/cobra"
8+
9+
"github.com/criticalstack/e2d/pkg/log"
10+
"github.com/criticalstack/e2d/pkg/manager"
11+
)
12+
13+
var opts struct {
14+
CertDir string
15+
AltNames string
16+
}
17+
18+
func NewCommand() *cobra.Command {
19+
cmd := &cobra.Command{
20+
Use: "generate [flags] [arg]\n\nValidArgs:\n all, server, peer, client",
21+
Short: "generate certificates/private keys",
22+
Aliases: []string{"gen"},
23+
Args: cobra.ExactValidArgs(1),
24+
ValidArgs: []string{
25+
"all",
26+
"server",
27+
"peer",
28+
"client",
29+
},
30+
SilenceErrors: true,
31+
RunE: func(cmd *cobra.Command, args []string) error {
32+
var names []string
33+
if opts.AltNames != "" {
34+
names = strings.Split(opts.AltNames, ",")
35+
}
36+
ca, err := manager.LoadCertificateAuthority(filepath.Join(opts.CertDir, "ca.crt"), filepath.Join(opts.CertDir, "ca.key"), names...)
37+
if err != nil {
38+
return err
39+
}
40+
switch args[0] {
41+
case "all":
42+
if err := ca.WriteAll(); err != nil {
43+
return err
44+
}
45+
log.Info("generated all certificates successfully.")
46+
return nil
47+
case "server":
48+
if err := ca.WriteServerCertAndKey(); err != nil {
49+
return err
50+
}
51+
log.Info("generated server certificates successfully.")
52+
return nil
53+
case "peer":
54+
if err := ca.WritePeerCertAndKey(); err != nil {
55+
return err
56+
}
57+
log.Info("generated peer certificates successfully.")
58+
return nil
59+
case "client":
60+
if err := ca.WriteClientCertAndKey(); err != nil {
61+
return err
62+
}
63+
log.Info("generated client certificates successfully.")
64+
return nil
65+
}
66+
return nil
67+
},
68+
}
69+
70+
cmd.Flags().StringVar(&opts.CertDir, "cert-dir", "", "")
71+
cmd.Flags().StringVar(&opts.AltNames, "alt-names", "", "")
72+
return cmd
73+
}

cmd/e2d/app/certs/init/init.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package init
2+
3+
import (
4+
"os"
5+
6+
"github.com/spf13/cobra"
7+
8+
"github.com/criticalstack/e2d/pkg/manager"
9+
)
10+
11+
var opts struct {
12+
CertDir string
13+
}
14+
15+
func NewCommand() *cobra.Command {
16+
cmd := &cobra.Command{
17+
Use: "init",
18+
Short: "initialize a new CA",
19+
Args: cobra.NoArgs,
20+
SilenceErrors: true,
21+
SilenceUsage: true,
22+
RunE: func(cmd *cobra.Command, args []string) error {
23+
if err := os.MkdirAll(opts.CertDir, 0755); err != nil && !os.IsExist(err) {
24+
return err
25+
}
26+
return manager.WriteNewCA(opts.CertDir)
27+
},
28+
}
29+
30+
cmd.Flags().StringVar(&opts.CertDir, "cert-dir", "", "")
31+
return cmd
32+
}

cmd/e2d/app/completion.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)