-
Notifications
You must be signed in to change notification settings - Fork 126
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
feat: First draft of a scheduler #19
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,107 @@ | ||
# Copyright 2020 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
ARCHS = amd64 arm64 | ||
COMMONENVVAR=GOOS=$(shell uname -s | tr A-Z a-z) | ||
BUILDENVVAR=CGO_ENABLED=0 | ||
|
||
LOCAL_REGISTRY=localhost:5000/scheduler-plugins | ||
LOCAL_IMAGE=kube-scheduler:latest | ||
LOCAL_CONTROLLER_IMAGE=controller:latest | ||
|
||
# RELEASE_REGISTRY is the container registry to push | ||
# into. | ||
RELEASE_REGISTRY?= | ||
RELEASE_VERSION?=$(shell date +%Y%m%d%s)-v0.24.3#$(shell git describe --tags --match "v*") | ||
RELEASE_IMAGE:=kube-scheduler:$(RELEASE_VERSION) | ||
RELEASE_CONTROLLER_IMAGE:=controller:$(RELEASE_VERSION) | ||
|
||
# VERSION is the scheduler's version | ||
# | ||
# The RELEASE_VERSION variable can have one of two formats: | ||
# v20201009-v0.18.800-46-g939c1c0 - automated build for a commit(not a tag) and also a local build | ||
# v20200521-v0.18.800 - automated build for a tag | ||
VERSION=$(shell echo $(RELEASE_VERSION) | awk -F - '{print $$2}') | ||
|
||
.PHONY: all | ||
all: build | ||
|
||
.PHONY: build | ||
build: build-scheduler | ||
|
||
.PHONY: build.amd64 | ||
build.amd64: build-controller.amd64 build-scheduler.amd64 | ||
|
||
.PHONY: build.arm64v8 | ||
build.arm64v8: build-controller.arm64v8 build-scheduler.arm64v8 | ||
|
||
.PHONY: build-controller | ||
build-controller: | ||
$(COMMONENVVAR) $(BUILDENVVAR) go build -ldflags '-w' -o bin/controller cmd/controller/controller.go | ||
|
||
.PHONY: build-controller.amd64 | ||
build-controller.amd64: | ||
$(COMMONENVVAR) $(BUILDENVVAR) GOARCH=amd64 go build -ldflags '-w' -o bin/controller cmd/controller/controller.go | ||
|
||
.PHONY: build-controller.arm64v8 | ||
build-controller.arm64v8: | ||
GOOS=linux $(BUILDENVVAR) GOARCH=arm64 go build -ldflags '-w' -o bin/controller cmd/controller/controller.go | ||
|
||
.PHONY: build-scheduler | ||
build-scheduler: | ||
$(COMMONENVVAR) $(BUILDENVVAR) go build -ldflags '-X k8s.io/component-base/version.gitVersion=$(VERSION) -w' -o bin/kube-scheduler cmd/scheduler/main.go | ||
|
||
.PHONY: build-scheduler.amd64 | ||
build-scheduler.amd64: | ||
$(COMMONENVVAR) $(BUILDENVVAR) GOARCH=amd64 go build -ldflags '-X k8s.io/component-base/version.gitVersion=$(VERSION) -w' -o bin/kube-scheduler cmd/scheduler/main.go | ||
#go build -ldflags '-X k8s.io/component-base/version.gitVersion=$(VERSION) -w' -o bin/kube-scheduler cmd/scheduler/main.go | ||
|
||
.PHONY: build-scheduler.arm64v8 | ||
build-scheduler.arm64v8: | ||
GOOS=linux $(BUILDENVVAR) GOARCH=arm64 go build -ldflags '-X k8s.io/component-base/version.gitVersion=$(VERSION) -w' -o bin/kube-scheduler cmd/scheduler/main.go | ||
|
||
.PHONY: local-image | ||
local-image: clean | ||
docker build -f ./build/scheduler/Dockerfile --build-arg ARCH="amd64" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(LOCAL_REGISTRY)/$(LOCAL_IMAGE) . | ||
#docker build -f ./build/controller/Dockerfile --build-arg ARCH="amd64" -t $(LOCAL_REGISTRY)/$(LOCAL_CONTROLLER_IMAGE) . | ||
|
||
.PHONY: release-image.amd64 | ||
release-image.amd64: clean | ||
docker build --no-cache -f ./build/scheduler/Dockerfile --build-arg ARCH="amd64" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-amd64 . | ||
#docker build -f ./build/controller/Dockerfile --build-arg ARCH="amd64" -t $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE)-amd64 . | ||
|
||
.PHONY: release-image.arm64v8 | ||
release-image.arm64v8: clean | ||
docker build --no-cache -f ./build/scheduler/Dockerfile --build-arg ARCH="arm64v8" --build-arg RELEASE_VERSION="$(RELEASE_VERSION)" -t $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-arm64 . | ||
#docker build -f ./build/controller/Dockerfile --build-arg ARCH="arm64v8" -t $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE)-arm64 . | ||
|
||
.PHONY: push-release-images | ||
push-release-images: release-image.amd64 release-image.arm64v8 | ||
#gcloud auth configure-docker | ||
for arch in $(ARCHS); do \ | ||
docker push $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-$${arch} ;\ | ||
#docker push $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE)-$${arch} ;\ | ||
done | ||
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(RELEASE_REGISTRY)/$(RELEASE_IMAGE) $(addprefix --amend $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-, $(ARCHS)) | ||
#DOCKER_CLI_EXPERIMENTAL=enabled docker manifest create $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE) $(addprefix --amend $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE)-, $(ARCHS)) | ||
for arch in $(ARCHS); do \ | ||
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest annotate --arch $${arch} $(RELEASE_REGISTRY)/$(RELEASE_IMAGE) $(RELEASE_REGISTRY)/$(RELEASE_IMAGE)-$${arch} ;\ | ||
#DOCKER_CLI_EXPERIMENTAL=enabled docker manifest annotate --arch $${arch} $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE) $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE)-$${arch} ;\ | ||
done | ||
DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push $(RELEASE_REGISTRY)/$(RELEASE_IMAGE) ;\ | ||
#DOCKER_CLI_EXPERIMENTAL=enabled docker manifest push $(RELEASE_REGISTRY)/$(RELEASE_CONTROLLER_IMAGE) ;\ | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf ./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,5 @@ | ||
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file | ||
# Ignore build and test binaries. | ||
bin/ | ||
testbin/ | ||
hack/tools/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,28 @@ | ||
# Copyright 2020 The Kubernetes Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
ARG ARCH | ||
FROM golang:1.18.0 | ||
|
||
WORKDIR /lfc-scheduler | ||
COPY . . | ||
ARG ARCH | ||
ARG RELEASE_VERSION | ||
RUN RELEASE_VERSION=${RELEASE_VERSION} make build-scheduler.$ARCH | ||
|
||
FROM $ARCH/alpine:3.16 | ||
|
||
COPY --from=0 /lfc-scheduler/bin/kube-scheduler /bin/kube-scheduler | ||
|
||
WORKDIR /bin | ||
CMD ["kube-scheduler"] |
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,37 @@ | ||
/* | ||
Copyright 2020 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/keptn-sandbox/lifecycle-controller/lfc-scheduler/pkg/klcpermit" | ||
"k8s.io/apimachinery/pkg/util/rand" | ||
"k8s.io/component-base/cli" | ||
"k8s.io/kubernetes/cmd/kube-scheduler/app" | ||
"os" | ||
"time" | ||
) | ||
|
||
func main() { | ||
|
||
rand.Seed(time.Now().UnixNano()) | ||
command := app.NewSchedulerCommand( | ||
app.WithPlugin(klcpermit.Name, klcpermit.New), | ||
) | ||
|
||
code := cli.Run(command) | ||
os.Exit(code) | ||
} |
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,204 @@ | ||
///* | ||
//Copyright 2020 The Kubernetes Authors. | ||
// | ||
//Licensed under the Apache License, Version 2.0 (the "License"); | ||
//you may not use this file except in compliance with the License. | ||
//You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
//Unless required by applicable law or agreed to in writing, software | ||
//distributed under the License is distributed on an "AS IS" BASIS, | ||
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
//See the License for the specific language governing permissions and | ||
//limitations under the License. | ||
//*/ | ||
// | ||
package main | ||
|
||
// | ||
//import ( | ||
// "context" | ||
// "fmt" | ||
// "io/ioutil" | ||
// "net" | ||
// "net/http" | ||
// "net/http/httptest" | ||
// "os" | ||
// "path/filepath" | ||
// "testing" | ||
// | ||
// "github.com/google/go-cmp/cmp" | ||
// "github.com/spf13/pflag" | ||
// | ||
// "k8s.io/kubernetes/cmd/kube-scheduler/app" | ||
// "k8s.io/kubernetes/cmd/kube-scheduler/app/options" | ||
// "k8s.io/kubernetes/pkg/scheduler/apis/config" | ||
// "k8s.io/kubernetes/pkg/scheduler/apis/config/testing/defaults" | ||
//) | ||
// | ||
//func TestSetup(t *testing.T) { | ||
// // temp dir | ||
// tmpDir, err := ioutil.TempDir("", "scheduler-options") | ||
// if err != nil { | ||
// t.Fatal(err) | ||
// } | ||
// defer os.RemoveAll(tmpDir) | ||
// | ||
// // https server | ||
// server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { | ||
// w.Header().Set("Content-Type", "application/json") | ||
// w.WriteHeader(200) | ||
// w.Write([]byte(`{"metadata": {"name": "test"}}`)) | ||
// })) | ||
// defer server.Close() | ||
// | ||
// configKubeconfig := filepath.Join(tmpDir, "config.kubeconfig") | ||
// if err := ioutil.WriteFile(configKubeconfig, []byte(fmt.Sprintf(` | ||
//apiVersion: v1 | ||
//kind: Config | ||
//clusters: | ||
//- cluster: | ||
// insecure-skip-tls-verify: true | ||
// server: %s | ||
// name: default | ||
//contexts: | ||
//- context: | ||
// cluster: default | ||
// user: default | ||
// name: default | ||
//current-context: default | ||
//users: | ||
//- name: default | ||
// user: | ||
// username: config | ||
//`, server.URL)), os.FileMode(0600)); err != nil { | ||
// t.Fatal(err) | ||
// } | ||
// | ||
// | ||
// // Coscheduling plugin config | ||
// coschedulingConfigFile := filepath.Join(tmpDir, "coscheduling.yaml") | ||
// if err := ioutil.WriteFile(coschedulingConfigFile, []byte(fmt.Sprintf(` | ||
//apiVersion: kubescheduler.config.k8s.io/v1beta3 | ||
//kind: KubeSchedulerConfiguration | ||
//clientConnection: | ||
// kubeconfig: "%s" | ||
//profiles: | ||
//- plugins: | ||
// multiPoint: | ||
// enabled: | ||
// - name: Coscheduling | ||
// queueSort: | ||
// disabled: | ||
// - name: PrioritySort | ||
// filter: | ||
// disabled: | ||
// - name: "*" | ||
// score: | ||
// disabled: | ||
// - name: "*" | ||
// preScore: | ||
// disabled: | ||
// - name: "*" | ||
// pluginConfig: | ||
// - name: Coscheduling | ||
// args: | ||
// permitWaitingTimeSeconds: 10 | ||
//`, configKubeconfig)), os.FileMode(0600)); err != nil { | ||
// t.Fatal(err) | ||
// } | ||
// | ||
// | ||
// testcases := []struct { | ||
// name string | ||
// flags []string | ||
// registryOptions []app.Option | ||
// wantPlugins map[string]*config.Plugins | ||
// }{ | ||
// { | ||
// name: "default config", | ||
// flags: []string{ | ||
// "--kubeconfig", configKubeconfig, | ||
// }, | ||
// wantPlugins: map[string]*config.Plugins{ | ||
// "default-scheduler": defaults.ExpandedPluginsV1beta3, | ||
// }, | ||
// }, | ||
// { | ||
// name: "single profile config - Coscheduling", | ||
// flags: []string{"--config", coschedulingConfigFile}, | ||
// registryOptions: []app.Option{app.WithPlugin(coscheduling.Name, coscheduling.New)}, | ||
// wantPlugins: map[string]*config.Plugins{ | ||
// "default-scheduler": { | ||
// MultiPoint: defaults.ExpandedPluginsV1beta3.MultiPoint, | ||
// QueueSort: config.PluginSet{Enabled: []config.Plugin{{Name: coscheduling.Name}}}, | ||
// Bind: defaults.ExpandedPluginsV1beta3.Bind, | ||
// PreFilter: config.PluginSet{ | ||
// Enabled: append(defaults.ExpandedPluginsV1beta3.PreFilter.Enabled, config.Plugin{Name: coscheduling.Name}), | ||
// }, | ||
// PostFilter: config.PluginSet{ | ||
// Enabled: append(defaults.ExpandedPluginsV1beta3.PostFilter.Enabled, config.Plugin{Name: coscheduling.Name}), | ||
// }, | ||
// Permit: config.PluginSet{ | ||
// Enabled: append(defaults.ExpandedPluginsV1beta3.Permit.Enabled, config.Plugin{Name: coscheduling.Name}), | ||
// }, | ||
// Reserve: config.PluginSet{ | ||
// Enabled: append(defaults.ExpandedPluginsV1beta3.Reserve.Enabled, config.Plugin{Name: coscheduling.Name}), | ||
// }, | ||
// PreBind: defaults.ExpandedPluginsV1beta3.PreBind, | ||
// PostBind: config.PluginSet{ | ||
// Enabled: append(defaults.ExpandedPluginsV1beta3.PostBind.Enabled, config.Plugin{Name: coscheduling.Name}), | ||
// }, | ||
// }, | ||
// }, | ||
// }, | ||
// // TODO: add a multi profile test. | ||
// // Ref: test "plugin config with multiple profiles" in | ||
// // https://github.com/kubernetes/kubernetes/blob/master/cmd/kube-scheduler/app/server_test.go | ||
// } | ||
// | ||
// makeListener := func(t *testing.T) net.Listener { | ||
// t.Helper() | ||
// l, err := net.Listen("tcp", ":0") | ||
// if err != nil { | ||
// t.Fatal(err) | ||
// } | ||
// return l | ||
// } | ||
// | ||
// for _, tc := range testcases { | ||
// t.Run(tc.name, func(t *testing.T) { | ||
// fs := pflag.NewFlagSet("test", pflag.PanicOnError) | ||
// opts := options.NewOptions() | ||
// | ||
// nfs := opts.Flags | ||
// for _, f := range nfs.FlagSets { | ||
// fs.AddFlagSet(f) | ||
// } | ||
// if err := fs.Parse(tc.flags); err != nil { | ||
// t.Fatal(err) | ||
// } | ||
// | ||
// // use listeners instead of static ports so parallel test runs don't conflict | ||
// opts.SecureServing.Listener = makeListener(t) | ||
// defer opts.SecureServing.Listener.Close() | ||
// | ||
// ctx, cancel := context.WithCancel(context.Background()) | ||
// defer cancel() | ||
// _, sched, err := app.Setup(ctx, opts, tc.registryOptions...) | ||
// if err != nil { | ||
// t.Fatal(err) | ||
// } | ||
// | ||
// gotPlugins := make(map[string]*config.Plugins) | ||
// for n, p := range sched.Profiles { | ||
// gotPlugins[n] = p.ListPlugins() | ||
// } | ||
// | ||
// if diff := cmp.Diff(tc.wantPlugins, gotPlugins); diff != "" { | ||
// t.Errorf("unexpected plugins diff (-want, +got): %s", diff) | ||
// } | ||
// }) | ||
// } | ||
//} |
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,9 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: metrics-reader | ||
rules: | ||
- nonResourceURLs: | ||
- "/metrics" | ||
verbs: | ||
- get |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would make sense to hook in an earlier stage? (https://kubernetes.io/docs/concepts/scheduling-eviction/scheduling-framework/)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my mind pre-deployment checks could take a while and it would not make sense to not discover in the meantime that there are other reasons for the pod not to be scheduled e.g. filters make it impossible to find a compatible node. We discussed having prechecks and scheduling steps in parallel up to resource allocation, but maybe also pre-Score could be an option, just I could not think of a reason why we would like to interfere with the node choice. What do you think could be another approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, think it makes sense to leave this in the permit-phase at the moment :-)