Skip to content

Commit

Permalink
feat: implement new discovery service
Browse files Browse the repository at this point in the history
This includes new in-memory core, new gRPC API, tests, etc.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
  • Loading branch information
smira committed Sep 23, 2021
1 parent 1a43970 commit 7174ec1
Show file tree
Hide file tree
Showing 38 changed files with 5,638 additions and 1,228 deletions.
4 changes: 2 additions & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2021-08-13T12:22:39Z by kres 907039b.
# Generated on 2021-09-22T21:32:59Z by kres 2a27963-dirty.

codecov:
require_ci_to_pass: false
Expand All @@ -9,7 +9,7 @@ coverage:
status:
project:
default:
target: 50%
target: 15%
threshold: 0.5%
base: auto
if_ci_failed: success
Expand Down
8 changes: 6 additions & 2 deletions .conform.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2021-08-13T12:22:39Z by kres 907039b.
# Generated on 2021-09-21T18:51:27Z by kres 7412de4-dirty.

---
policies:
- type: commit
spec:
dco: true
gpg: false
gpg:
required: true
identity:
gitHubOrganization: talos-systems
spellcheck:
locale: US
maximumOfOneCommit: true
Expand Down
5 changes: 3 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2021-08-13T12:32:42Z by kres 907039b.
# Generated on 2021-09-22T18:49:05Z by kres 2a27963-dirty.

**
!api
!cmd
!internal
!pkg
!cmd
!go.mod
!go.sum
!.golangci.yml
Expand Down
30 changes: 15 additions & 15 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2021-08-13T12:23:41Z by kres 907039b.
# Generated on 2021-09-21T13:33:04Z by kres 7412de4-dirty.

kind: pipeline
type: kubernetes
Expand Down Expand Up @@ -105,11 +105,11 @@ steps:
depends_on:
- unit-tests

- name: kubespan-manager
- name: discovery-service
pull: always
image: autonomy/build-container:latest
commands:
- make kubespan-manager
- make discovery-service
volumes:
- name: outer-docker-socket
path: /var/outer-run
Expand Down Expand Up @@ -139,11 +139,11 @@ steps:
depends_on:
- base

- name: image-kubespan-manager
- name: image-discovery-service
pull: always
image: autonomy/build-container:latest
commands:
- make image-kubespan-manager
- make image-discovery-service
volumes:
- name: outer-docker-socket
path: /var/outer-run
Expand All @@ -154,16 +154,16 @@ steps:
- name: ssh
path: /root/.ssh
depends_on:
- kubespan-manager
- discovery-service
- lint
- unit-tests

- name: push-kubespan-manager
- name: push-discovery-service
pull: always
image: autonomy/build-container:latest
commands:
- docker login ghcr.io --username "$${GHCR_USERNAME}" --password "$${GHCR_PASSWORD}"
- make image-kubespan-manager
- make image-discovery-service
environment:
GHCR_PASSWORD:
from_secret: ghcr_token
Expand All @@ -184,14 +184,14 @@ steps:
exclude:
- pull_request
depends_on:
- image-kubespan-manager
- image-discovery-service

- name: push-kubespan-manager-latest
- name: push-discovery-service-latest
pull: always
image: autonomy/build-container:latest
commands:
- docker login ghcr.io --username "$${GHCR_USERNAME}" --password "$${GHCR_PASSWORD}"
- make image-kubespan-manager TAG=latest
- make image-discovery-service TAG=latest
environment:
GHCR_PASSWORD:
from_secret: ghcr_token
Expand All @@ -214,7 +214,7 @@ steps:
exclude:
- pull_request
depends_on:
- push-kubespan-manager
- push-discovery-service

- name: release-notes
pull: always
Expand All @@ -236,8 +236,8 @@ steps:
depends_on:
- unit-tests
- coverage
- kubespan-manager
- image-kubespan-manager
- discovery-service
- image-discovery-service
- lint

- name: release
Expand Down Expand Up @@ -270,7 +270,7 @@ steps:

services:
- name: docker
image: docker:19.03-dind
image: docker:20.10-dind
entrypoint:
- dockerd
commands:
Expand Down
35 changes: 19 additions & 16 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2021-08-13T12:32:42Z by kres 907039b.

# Generated on 2021-09-21T13:11:46Z by kres 7412de4-dirty.

# options for analysis running
run:
Expand All @@ -22,7 +21,6 @@ output:
uniq-by-line: true
path-prefix: ""


# all available settings of specific linters
linters-settings:
dogsled:
Expand All @@ -38,7 +36,7 @@ linters-settings:
lines: 60
statements: 40
gci:
local-prefixes: github.com/talos-systems/kubespan-manager
local-prefixes: github.com/talos-systems/discovery-service
gocognit:
min-complexity: 30
nestif:
Expand All @@ -60,7 +58,7 @@ linters-settings:
gofmt:
simplify: true
goimports:
local-prefixes: github.com/talos-systems/kubespan-manager
local-prefixes: github.com/talos-systems/discovery-service
golint:
min-confidence: 0.8
gomnd:
Expand Down Expand Up @@ -116,23 +114,30 @@ linters-settings:

linters:
enable-all: true
disable-all: false
fast: false
disable:
- exhaustivestruct
- forbidigo
- funlen
- gas
- typecheck
- gochecknoglobals
- gochecknoinits
- funlen
- godox
- gomnd
- goerr113
- gomnd
- gomoddirectives
- nestif
- wrapcheck
- paralleltest
- exhaustivestruct
- forbidigo
disable-all: false
fast: false

- tagliatelle
- thelper
- typecheck
- wrapcheck
# abandoned linters for which golangci shows the warning that the repo is archived by the owner
- interfacer
- maligned
- golint
- scopelint

issues:
exclude: []
Expand All @@ -141,10 +146,8 @@ issues:
exclude-case-sensitive: false
max-issues-per-linter: 10
max-same-issues: 3

new: false

severity:
default-severity: error

case-sensitive: false
14 changes: 14 additions & 0 deletions .kres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
kind: golang.Protobuf
spec:
vtProtobufEnabled: true
specs:
- source: https://raw.githubusercontent.com/protocolbuffers/protobuf/master/src/google/protobuf/duration.proto
subdirectory: vendor/google
skipCompile: true
- source: api/v1alpha1/cluster.proto
subdirectory: v1alpha1/pb
---
kind: service.CodeCov
spec:
targetThreshold: 15
67 changes: 45 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2021-08-13T12:32:42Z by kres 907039b.
# Generated on 2021-09-22T18:49:05Z by kres 2a27963-dirty.

ARG TOOLCHAIN

# cleaned up specs and compiled versions
FROM scratch AS generate

FROM ghcr.io/talos-systems/ca-certificates:v0.3.0-12-g90722c3 AS image-ca-certificates

FROM ghcr.io/talos-systems/fhs:v0.3.0-12-g90722c3 AS image-fhs
Expand All @@ -22,6 +19,11 @@ COPY .markdownlint.json .
COPY ./README.md ./README.md
RUN markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules /node_modules/sentences-per-line/index.js .

# collects proto specs
FROM scratch AS proto-specs
ADD https://raw.githubusercontent.com/protocolbuffers/protobuf/master/src/google/protobuf/duration.proto /api/vendor/google/
ADD api/v1alpha1/cluster.proto /api/v1alpha1/pb/

# base toolchain image
FROM ${TOOLCHAIN} AS toolchain
RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev
Expand All @@ -31,12 +33,22 @@ FROM toolchain AS tools
ENV GO111MODULE on
ENV CGO_ENABLED 0
ENV GOPATH /go
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /bin v1.38.0
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b /bin v1.42.1
ARG GOFUMPT_VERSION
RUN cd $(mktemp -d) \
&& go mod init tmp \
&& go get mvdan.cc/gofumpt/gofumports@${GOFUMPT_VERSION} \
RUN go install mvdan.cc/gofumpt/gofumports@${GOFUMPT_VERSION} \
&& mv /go/bin/gofumports /bin/gofumports
ARG PROTOBUF_GO_VERSION
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v${PROTOBUF_GO_VERSION}
RUN mv /go/bin/protoc-gen-go /bin
ARG GRPC_GO_VERSION
RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v${GRPC_GO_VERSION}
RUN mv /go/bin/protoc-gen-go-grpc /bin
ARG GRPC_GATEWAY_VERSION
RUN go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION}
RUN mv /go/bin/protoc-gen-grpc-gateway /bin
ARG VTPROTOBUF_VERSION
RUN go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@${VTPROTOBUF_VERSION}
RUN mv /go/bin/protoc-gen-go-vtproto /bin

# tools and sources
FROM tools AS base
Expand All @@ -45,22 +57,23 @@ COPY ./go.mod .
COPY ./go.sum .
RUN --mount=type=cache,target=/go/pkg go mod download
RUN --mount=type=cache,target=/go/pkg go mod verify
COPY ./api ./api
COPY ./cmd ./cmd
COPY ./internal ./internal
COPY ./pkg ./pkg
COPY ./cmd ./cmd
RUN --mount=type=cache,target=/go/pkg go list -mod=readonly all >/dev/null

# builds kubespan-manager-linux-amd64
FROM base AS kubespan-manager-linux-amd64-build
COPY --from=generate / /
WORKDIR /src/cmd/kubespan-manager
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go build -ldflags "-s -w" -o /kubespan-manager-linux-amd64
# runs protobuf compiler
FROM tools AS proto-compile
COPY --from=proto-specs / /
RUN protoc -I/api --go_out=paths=source_relative:/api --go-grpc_out=paths=source_relative:/api --go-vtproto_out=paths=source_relative:/api --go-vtproto_opt=features=marshal+unmarshal+size /api/v1alpha1/pb/cluster.proto
RUN rm /api/v1alpha1/pb/cluster.proto

# runs gofumpt
FROM base AS lint-gofumpt
RUN find . -name '*.pb.go' | xargs -r rm
RUN find . -name '*.pb.gw.go' | xargs -r rm
RUN FILES="$(gofumports -l -local github.com/talos-systems/kubespan-manager .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'gofumports -w -local github.com/talos-systems/kubespan-manager .':\n${FILES}"; exit 1)
RUN FILES="$(gofumports -l -local github.com/talos-systems/discovery-service .)" && test -z "${FILES}" || (echo -e "Source code is not formatted with 'gofumports -w -local github.com/talos-systems/discovery-service .':\n${FILES}"; exit 1)

# runs golangci-lint
FROM base AS lint-golangci-lint
Expand All @@ -78,19 +91,29 @@ FROM base AS unit-tests-run
ARG TESTPKGS
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg --mount=type=cache,target=/tmp go test -v -covermode=atomic -coverprofile=coverage.txt -coverpkg=${TESTPKGS} -count 1 ${TESTPKGS}

FROM scratch AS kubespan-manager-linux-amd64
COPY --from=kubespan-manager-linux-amd64-build /kubespan-manager-linux-amd64 /kubespan-manager-linux-amd64
# cleaned up specs and compiled versions
FROM scratch AS generate
COPY --from=proto-compile /api/ /api/

FROM scratch AS unit-tests
COPY --from=unit-tests-run /src/coverage.txt /coverage.txt

FROM kubespan-manager-linux-${TARGETARCH} AS kubespan-manager
# builds discovery-service-linux-amd64
FROM base AS discovery-service-linux-amd64-build
COPY --from=generate / /
WORKDIR /src/cmd/discovery-service
RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go build -ldflags "-s -w" -o /discovery-service-linux-amd64

FROM scratch AS discovery-service-linux-amd64
COPY --from=discovery-service-linux-amd64-build /discovery-service-linux-amd64 /discovery-service-linux-amd64

FROM discovery-service-linux-${TARGETARCH} AS discovery-service

FROM scratch AS image-kubespan-manager
FROM scratch AS image-discovery-service
ARG TARGETARCH
COPY --from=kubespan-manager kubespan-manager-linux-${TARGETARCH} /kubespan-manager
COPY --from=discovery-service discovery-service-linux-${TARGETARCH} /discovery-service
COPY --from=image-fhs / /
COPY --from=image-ca-certificates / /
LABEL org.opencontainers.image.source https://github.com/talos-systems/wglan-manager
ENTRYPOINT ["/kubespan-manager"]
LABEL org.opencontainers.image.source https://github.com/talos-systems/discovery-service
ENTRYPOINT ["/discovery-service"]

0 comments on commit 7174ec1

Please sign in to comment.