Skip to content

Commit

Permalink
Feature: random assign scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho committed Oct 7, 2021
0 parents commit a005f7d
Show file tree
Hide file tree
Showing 31 changed files with 59,286 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/bin
3 changes: 3 additions & 0 deletions .gitmodules
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
22 changes: 22 additions & 0 deletions Dockerfile
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"]
31 changes: 31 additions & 0 deletions Makefile
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 added README.md
Empty file.
75 changes: 75 additions & 0 deletions config/config.go
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
}
30 changes: 30 additions & 0 deletions docker-compose.yml
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

5 changes: 5 additions & 0 deletions errors/errors.go
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")
52 changes: 52 additions & 0 deletions go.mod
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
)
Loading

0 comments on commit a005f7d

Please sign in to comment.