-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a005f7d
Showing
31 changed files
with
59,286 additions
and
0 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 @@ | ||
/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,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,31 @@ | ||
.PHONY: test | ||
test: | ||
go test ./... | ||
|
||
.PHONY: build | ||
build: | ||
go build -o ./bin/sched ./sched.go | ||
|
||
.PHONY: start | ||
start: 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 -t minisched . | ||
|
||
.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 |
Empty file.
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 | ||
} |
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,30 @@ | ||
version: "3.7" | ||
services: | ||
simulator-server: | ||
image: simulator-server | ||
container_name: simulator-server | ||
environment: | ||
- PORT=1212 | ||
- KUBE_SCHEDULER_SIMULATOR_ETCD_URL=http://simulator-etcd:2379 | ||
- FRONTEND_URL=http://localhost:3000 | ||
ports: | ||
- "1212:1212" | ||
restart: always | ||
tty: true | ||
networks: | ||
- simulator-internal-network | ||
simulator-etcd: | ||
image: quay.io/coreos/etcd:v3.4.0 | ||
container_name: simulator-etcd | ||
restart: always | ||
volumes: | ||
- simulator-etcd-data:/var/lib/etcd | ||
command: etcd --advertise-client-urls http://simulator-etcd:2379 --data-dir /var/lib/etcd --listen-client-urls http://0.0.0.0:2379 --initial-cluster-state new --initial-cluster-token tkn | ||
networks: | ||
- simulator-internal-network | ||
volumes: | ||
simulator-etcd-data: | ||
networks: | ||
simulator-internal-network: | ||
driver: bridge | ||
|
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,5 @@ | ||
package errors | ||
|
||
import "errors" | ||
|
||
var ErrNotFound = errors.New("resource not found") |
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,52 @@ | ||
module github.com/sanposhiho/mini-kube-scheduler | ||
|
||
go 1.16 | ||
|
||
replace ( | ||
google.golang.org/grpc => google.golang.org/grpc v1.38.0 | ||
k8s.io/api => k8s.io/api v0.22.0 | ||
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.22.0 | ||
k8s.io/apimachinery => k8s.io/apimachinery v0.22.0 | ||
k8s.io/apiserver => k8s.io/apiserver v0.22.0 | ||
k8s.io/cli-runtime => k8s.io/cli-runtime v0.22.0 | ||
k8s.io/client-go => k8s.io/client-go v0.22.0 | ||
k8s.io/cloud-provider => k8s.io/cloud-provider v0.22.0 | ||
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.22.0 | ||
k8s.io/code-generator => k8s.io/code-generator v0.22.0 | ||
k8s.io/component-base => k8s.io/component-base v0.22.0 | ||
k8s.io/component-helpers => k8s.io/component-helpers v0.22.0 | ||
k8s.io/controller-manager => k8s.io/controller-manager v0.22.0 | ||
k8s.io/cri-api => k8s.io/cri-api v0.22.0 | ||
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.22.0 | ||
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.22.0 | ||
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.22.0 | ||
k8s.io/kube-proxy => k8s.io/kube-proxy v0.22.0 | ||
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.22.0 | ||
k8s.io/kubectl => k8s.io/kubectl v0.22.0 | ||
k8s.io/kubelet => k8s.io/kubelet v0.22.0 | ||
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.22.0 | ||
k8s.io/metrics => k8s.io/metrics v0.22.0 | ||
k8s.io/mount-utils => k8s.io/mount-utils v0.22.0 | ||
k8s.io/pod-security-admission => k8s.io/pod-security-admission v0.22.0 | ||
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.22.0 | ||
) | ||
|
||
require ( | ||
github.com/golang/mock v1.4.4 | ||
github.com/golangci/golangci-lint v1.41.1 | ||
github.com/google/uuid v1.1.2 | ||
github.com/labstack/echo/v4 v4.5.0 | ||
github.com/labstack/gommon v0.3.0 | ||
github.com/stretchr/testify v1.7.0 | ||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 | ||
k8s.io/api v1.22.0 | ||
k8s.io/apiextensions-apiserver v0.0.0 | ||
k8s.io/apimachinery v1.22.0 | ||
k8s.io/apiserver v1.22.0 | ||
k8s.io/client-go v1.22.0 | ||
k8s.io/component-base v0.22.0 | ||
k8s.io/klog/v2 v2.9.0 | ||
k8s.io/kube-openapi v0.0.0-20210421082810-95288971da7e | ||
k8s.io/kube-scheduler v1.22.0 | ||
k8s.io/kubernetes v1.22.0 | ||
) |
Oops, something went wrong.