Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate the internal kube-apiserver to kwok #333

Merged
merged 30 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f990efe
install: e2e-framework
sivchari Jan 30, 2024
6095ae6
poc: use kwok
sivchari Feb 6, 2024
6c347ec
simulator: specify etcd/api-server port
sivchari Feb 6, 2024
a02fc4f
disable: kube-scheduler
sivchari Feb 6, 2024
258f115
use: kubectl proxy
sivchari Feb 6, 2024
ba7cc8a
update: container settings
sivchari Feb 9, 2024
482ae82
update: module dependencies
sivchari Feb 9, 2024
2545f2c
update: simulator configuration
sivchari Feb 9, 2024
285cf1c
revert: Dockerfile
sivchari Feb 9, 2024
51cb468
remove: unnecessary config param
sivchari Feb 9, 2024
550bd4a
clean up kwok codes
sivchari Feb 9, 2024
0d78af3
fix: docker compose
sivchari Feb 9, 2024
272f5dc
simulator/docs: add KUBE_APISERVER_URL and caution about deprecating
sivchari Feb 9, 2024
12ad764
simulator/config: revert some configuration
sivchari Feb 9, 2024
95c562f
simulator: create `EtcdPrefix`
sivchari Feb 9, 2024
448ccb0
check whether kwok cluster is ready
sivchari Feb 9, 2024
91877da
change port from 8080 to 3131
sivchari Mar 10, 2024
01bdac2
follow up for integration
sivchari Mar 15, 2024
d569560
revert
sivchari Mar 15, 2024
d637020
Define the etcd prefix and use it
sivchari Mar 15, 2024
9bd672f
Use wait package to check whether cluster is ready
sivchari Mar 15, 2024
031d4c8
simlify README.md
sivchari Mar 15, 2024
0aca48b
docs: modify some sentences
sivchari Mar 15, 2024
ec64eb7
use PollUntil instead of Until
sivchari Mar 15, 2024
de0051b
fix errcheck
sivchari Mar 15, 2024
6c8130f
add more information to README.md
sivchari Mar 18, 2024
6a502ff
return nil even if an error is caused
sivchari Mar 18, 2024
89eef35
ignore KUBE_API_PORT and KUBE_API_HOST
sivchari Mar 18, 2024
f0faa06
add env for kubeapi-server to connect to cluster in KWOK
sivchari Mar 18, 2024
f73674a
revise documents
sivchari Mar 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ That's why we are developing a simulator for kube-scheduler
```shell
git clone git@github.com:kubernetes-sigs/kube-scheduler-simulator.git
cd kube-scheduler-simulator
# switch to the version you want to use.
git switch simulator/v0.1.1
# pull images from the registry and run up all components
make docker_up
# All things up!
Expand All @@ -41,12 +43,13 @@ We have several components:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update Getting started section like this otherwise people cannot run up the simulator correctly until a new release is cut.

## Getting started 

git clone git@github.com:kubernetes-sigs/kube-scheduler-simulator.git
cd kube-scheduler-simulator
# switch to the version you want to use.
git switch simulator/v0.1.1
# pull images from the registry and run up all components
make docker_up 
# All things up! 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'd revise it.

### Simulator

Simulator is kube-apiserver with some controllers + debuggable scheduler + the HTTP server which mainly for the web UI.
Simulator is composed of debuggable scheduler + the HTTP server which mainly for the web UI.

There are several ways to integrate your scheduler into the simulator.
See [integrate-your-scheduler.md](simulator/docs/integrate-your-scheduler.md).

You can create any resources by any ways (kubectl, k8s client library, or web UI described next).
Simulator runs with a fake cluster powered by [KWOK](/~https://github.com/kubernetes-sigs/kwok)
You can create any resources in KWOK cluster via any clients (e.g. kubectl, k8s client library, or web UI described next).
And when you create Pods,
Pods will be scheduled by the [debuggable scheduler](./simulator/docs/debuggable-scheduler.md),
and they'll get the annotations that explain how each Pod was evaluated by each scheduler plugin.
Expand Down
21 changes: 10 additions & 11 deletions docker-compose-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ services:
container_name: simulator-server
environment:
- PORT=1212
- KUBE_SCHEDULER_SIMULATOR_ETCD_URL=http://simulator-etcd:2379
- CORS_ALLOWED_ORIGIN_LIST=http://${SIMULATOR_EXTERNAL_IP:-localhost}:3000
sanposhiho marked this conversation as resolved.
Show resolved Hide resolved
- KUBE_API_HOST=0.0.0.0
- KUBE_API_PORT=3131
- KUBE_SCHEDULER_SIMULATOR_ETCD_URL=http://simulator-cluster:2379
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need an alias for KUBE_SCHEDULER_SIMULATOR_ETCD_URL, e.g. KUBE_ETCD_URL or ETCD_URL?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds simple and clear for me to define as ETCD_URL

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to worry about the env. The configuration thru env is deprecated and we'll remove them eventually. So, the current way of configuring is basically thru scheduler config file, which has EtcdURL instead of this messy long title.

- KUBE_APISERVER_URL=http://simulator-cluster:3131
ports:
- "1212:1212"
- "3131:3131"
restart: always
tty: true
networks:
Expand All @@ -27,17 +24,19 @@ services:
ports:
- "3000:3000"
tty: true
simulator-etcd:
image: quay.io/coreos/etcd:v3.4.26
container_name: simulator-etcd
simulator-cluster:
image: registry.k8s.io/kwok/cluster:v0.5.0-k8s.v1.29.0
container_name: simulator-cluster
restart: always
ports:
- "3131:3131"
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
- ./kwok.yaml:/root/.kwok/kwok.yaml
sanposhiho marked this conversation as resolved.
Show resolved Hide resolved
networks:
- simulator-internal-network
volumes:
simulator-etcd-data:
networks:
simulator-internal-network:
driver: bridge
volumes:
simulator-etcd-data:
21 changes: 10 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ services:
container_name: simulator-server
environment:
- PORT=1212
- KUBE_SCHEDULER_SIMULATOR_ETCD_URL=http://simulator-etcd:2379
- CORS_ALLOWED_ORIGIN_LIST=http://${SIMULATOR_EXTERNAL_IP:-localhost}:3000
sanposhiho marked this conversation as resolved.
Show resolved Hide resolved
- KUBE_API_HOST=0.0.0.0
- KUBE_API_PORT=3131
- KUBE_SCHEDULER_SIMULATOR_ETCD_URL=http://simulator-cluster:2379
- KUBE_APISERVER_URL=http://simulator-cluster:3131
ports:
- "1212:1212"
- "3131:3131"
restart: always
tty: true
networks:
Expand All @@ -27,17 +24,19 @@ services:
ports:
- "3000:3000"
tty: true
simulator-etcd:
image: quay.io/coreos/etcd:v3.4.26
container_name: simulator-etcd
simulator-cluster:
image: registry.k8s.io/kwok/cluster:v0.5.0-k8s.v1.29.0
container_name: simulator-cluster
restart: always
ports:
- "3131:3131"
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
- ./kwok.yaml:/root/.kwok/kwok.yaml
networks:
- simulator-internal-network
volumes:
simulator-etcd-data:
networks:
simulator-internal-network:
driver: bridge
volumes:
simulator-etcd-data:
12 changes: 12 additions & 0 deletions kwok.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: KwokctlConfiguration
apiVersion: config.kwok.x-k8s.io/v1alpha1
options:
kubeApiserverPort: 3131
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
kubeApiserverPort: 3131

etcdPort: 2379
etcdPrefix: /kube-scheduler-simulator
disableKubeScheduler: true
componentsPatches:
- name: kube-apiserver
extraArgs:
- key: cors-allowed-origins
value: ^*$
sanposhiho marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 4 additions & 8 deletions simulator/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ corsAllowedOriginList:
# cluster for importing resources to scheduler simulator.
kubeConfig: ""

# This is the host of kube-apiserver which the simulator
# starts internally. Its default value is 127.0.0.1.
kubeApiHost: "127.0.0.1"

# This is the port of kube-apiserver. Its default value is 3131.
kubeApiPort: 3131

# This is the url of kube-apiserver.
# This variable is used to connect to the user cluster's kube-apiserver.
kubeApiServerUrl: ""
sanposhiho marked this conversation as resolved.
Show resolved Hide resolved

# The path to a KubeSchedulerConfiguration file.
# If passed, the simulator will start the scheduler
Expand All @@ -45,4 +41,4 @@ externalImportEnabled: false

# This variable indicates whether an external scheduler
# is used.
externalSchedulerEnabled: false
externalSchedulerEnabled: false
27 changes: 11 additions & 16 deletions simulator/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ func NewConfig() (*Config, error) {
return nil, xerrors.Errorf("get frontend URL: %w", err)
}

apiurl := getKubeAPIServerURL()
apiurl, err := getKubeAPIServerURL()
if err != nil {
return nil, xerrors.Errorf("get kube API server URL: %w", err)
}

externalimportenabled := getExternalImportEnabled()
externalKubeClientCfg := &rest.Config{}
Expand Down Expand Up @@ -136,23 +139,15 @@ func getPort() (int, error) {
}

// getKubeAPIServerURL gets KubeAPIServerURL from environment variable first, if empty from the config file.
func getKubeAPIServerURL() string {
p := os.Getenv("KUBE_API_PORT")
if p == "" {
p = strconv.Itoa(configYaml.KubeAPIPort)
if p == "" {
p = "3131"
}
}

h := os.Getenv("KUBE_API_HOST")
if h == "" {
h = configYaml.KubeAPIHost
if h == "" {
h = "127.0.0.1"
Comment on lines -140 to -152
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we no longer need to keep these configurations actually. But, we cannot immediately remove them because it'd be a breaking change.

For now, please add a note on the document of config that they're old configuration and will be removed very soon.

func getKubeAPIServerURL() (string, error) {
url := os.Getenv("KUBE_APISERVER_URL")
if url == "" {
url = configYaml.KubeAPIServerURL
if url == "" {
return "", xerrors.Errorf("get KUBE_APISERVER_URL from config: %w", ErrEmptyConfig)
}
}
return h + ":" + p
return url, nil
}

// getExternalSchedulerEnabled gets ExternalSchedulerEnabled from environment variable first,
Expand Down
6 changes: 4 additions & 2 deletions simulator/config/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ type SimulatorConfiguration struct {
// server is started.
Port int `json:"port,omitempty"`

// This is the URL for etcd. The simulator runs kube-apiserver
// internally, and the kube-apiserver uses this etcd.
// This is the URL for etcd.
EtcdURL string `json:"etcdURL,omitempty"`

// This URL represents the URL once web UI is started.
Expand All @@ -41,6 +40,9 @@ type SimulatorConfiguration struct {
// cluster for importing resources to scheduler simulator.
KubeConfig string `json:"kubeConfig,omitempty"`

// This is the URL for kube-apiserver.
KubeAPIServerURL string `json:"kubeApiServerUrl,omitempty"`

// This is the host of kube-apiserver which the simulator
// starts internally. Its default value is 127.0.0.1.
KubeAPIHost string `json:"kubeApiHost,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion simulator/config/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion simulator/config/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion simulator/config/v1alpha1/zz_generated.defaults.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

145 changes: 0 additions & 145 deletions simulator/controller/controller.go

This file was deleted.

Loading