generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
138 changed files
with
77,163 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
web/* | ||
submodules/kubernetes/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "submodules/kubernetes"] | ||
path = submodules/kubernetes | ||
url = [email protected]:kubernetes/kubernetes.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
linters-settings: | ||
gci: | ||
local-prefixes: github.com/kubernetes-sigs/kube-scheduler-simulator | ||
gocritic: | ||
disabled-checks: | ||
- appendAssign | ||
|
||
linters: | ||
disable-all: true | ||
enable: | ||
- unused | ||
- govet | ||
- staticcheck | ||
- typecheck | ||
- varcheck | ||
- errcheck | ||
- gosimple | ||
- asciicheck | ||
- bodyclose | ||
- cyclop | ||
- dogsled | ||
- durationcheck | ||
- errorlint | ||
- exportloopref | ||
- forcetypeassert | ||
- funlen | ||
- gci | ||
- gochecknoinits | ||
- gocognit | ||
- gocritic | ||
- gocyclo | ||
- godot | ||
- goerr113 | ||
- gofmt | ||
- gofumpt | ||
- gosec | ||
- ifshort | ||
- makezero | ||
- nakedret | ||
- nestif | ||
- nilerr | ||
- nolintlint | ||
- paralleltest | ||
- predeclared | ||
- revive | ||
- rowserrcheck | ||
- sqlclosecheck | ||
- thelper | ||
- unconvert | ||
- unparam | ||
- wastedassign | ||
|
||
issues: | ||
exclude-rules: | ||
- path: _test\.go | ||
linters: | ||
- funlen | ||
- goerr113 | ||
- errcheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM golang:1.16.6 AS build-env | ||
|
||
ENV GOOS=linux | ||
ENV GOARCH=amd64 | ||
ENV CGO_ENABLED=0 | ||
ENV GO111MODULE=on | ||
|
||
WORKDIR /go/src/simulator-server | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
RUN go build -v -o ./bin/simulator simulator.go | ||
|
||
FROM alpine:3.14.0 | ||
|
||
COPY --from=build-env /go/src/simulator-server/bin/simulator /simulator | ||
RUN chmod a+x /simulator | ||
|
||
EXPOSE 1212 | ||
CMD ["/simulator"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
.PHONY: tools | ||
tools: | ||
cd ./tools; \ | ||
cat tools.go | grep "_" | awk -F'"' '{print $$2}' | xargs -tI % go install % | ||
|
||
.PHONY: generate | ||
generate: | ||
go generate ./... | ||
|
||
.PHONY: lint | ||
lint: | ||
golangci-lint run ./... | ||
|
||
.PHONY: format | ||
format: | ||
golangci-lint run --fix ./... | ||
|
||
.PHONY: test | ||
test: | ||
go test ./... | ||
|
||
.PHONY: build | ||
build: | ||
go build -o ./bin/simulator ./simulator.go | ||
|
||
.PHONY: start | ||
serve: build | ||
./hack/start_simulator.sh | ||
|
||
# re-generate openapi file for running api-server | ||
.PHONY: openapi | ||
openapi: | ||
./hack/openapi.sh | ||
|
||
.PHONY: docker_build | ||
docker_build: docker_build_server docker_build_front | ||
|
||
.PHONY: docker_build_server | ||
docker_build_server: | ||
docker build -t simulator-server . | ||
|
||
.PHONY: docker_build_front | ||
docker_build_front: | ||
docker build -t simulator-frontend ./web/ | ||
|
||
.PHONY: docker_up | ||
docker_up: | ||
docker-compose up -d | ||
|
||
.PHONY: docker_build_and_up | ||
docker_build_and_up: docker_build docker_up | ||
|
||
.PHONY: docker_down | ||
docker_down: | ||
docker-compose down |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
"os" | ||
"strconv" | ||
|
||
"golang.org/x/xerrors" | ||
) | ||
|
||
// ErrEmptyEnv represents the required environment variable don't exist. | ||
var ErrEmptyEnv = errors.New("env is needed, but empty") | ||
|
||
// Config is configuration for simulator. | ||
type Config struct { | ||
Port int | ||
EtcdURL string | ||
FrontendURL string | ||
} | ||
|
||
// NewConfig gets some settings from environment variables. | ||
func NewConfig() (*Config, error) { | ||
port, err := getPort() | ||
if err != nil { | ||
return nil, xerrors.Errorf("get port: %w", err) | ||
} | ||
|
||
etcdurl, err := getEtcdURL() | ||
if err != nil { | ||
return nil, xerrors.Errorf("get etcd URL: %w", err) | ||
} | ||
|
||
frontendurl, err := getFrontendURL() | ||
if err != nil { | ||
return nil, xerrors.Errorf("get frontend URL: %w", err) | ||
} | ||
|
||
return &Config{ | ||
Port: port, | ||
EtcdURL: etcdurl, | ||
FrontendURL: frontendurl, | ||
}, nil | ||
} | ||
|
||
// getPort gets Port from the environment variable named PORT. | ||
func getPort() (int, error) { | ||
p := os.Getenv("PORT") | ||
if p == "" { | ||
return 0, xerrors.Errorf("get PORT from env: %w", ErrEmptyEnv) | ||
} | ||
|
||
port, err := strconv.Atoi(p) | ||
if err != nil { | ||
return 0, xerrors.Errorf("convert PORT of string to int: %w", err) | ||
} | ||
return port, nil | ||
} | ||
|
||
func getEtcdURL() (string, error) { | ||
e := os.Getenv("KUBE_SCHEDULER_SIMULATOR_ETCD_URL") | ||
if e == "" { | ||
return "", xerrors.Errorf("get KUBE_SCHEDULER_SIMULATOR_ETCD_URL from env: %w", ErrEmptyEnv) | ||
} | ||
|
||
return e, nil | ||
} | ||
|
||
func getFrontendURL() (string, error) { | ||
e := os.Getenv("FRONTEND_URL") | ||
if e == "" { | ||
return "", xerrors.Errorf("get FRONTEND_URL from env: %w", ErrEmptyEnv) | ||
} | ||
|
||
return e, nil | ||
} |
Oops, something went wrong.