
This commit includes the fundamental components of the Kubernetes Mesos integration: * Kubernetes-Mesos scheduler * Kubernetes-Mesos executor * Supporting libs Dependencies and upstream changes are included in a separate commit for easy review. After this initial upstream, there'll be two PRs following. * km (hypercube) and k8sm-controller-manager #9265 * Static pods support #9077 Fixes applied: - Precise metrics subsystems definitions - mesosphere/kubernetes-mesos#331 - https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion_r31875232 - https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion_r31875240 - Improve comments and add clarifications - Fixes https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion-diff-31875208 - Fixes https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion-diff-31875226 - Fixes https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion-diff-31875227 - Fixes https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion-diff-31875228 - Fixes https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion-diff-31875239 - Fixes https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion-diff-31875243 - Fixes https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion-diff-31875234 - Fixes https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion-diff-31875256 - Fixes https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion-diff-31875255 - Fixes https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion-diff-31875251 - Clarify which Schedule function is actually called - Fixes https://github.com/GoogleCloudPlatform/kubernetes/pull/8882#discussion-diff-31875246
154 lines
3.5 KiB
Go
154 lines
3.5 KiB
Go
/*
|
|
Copyright 2015 The Kubernetes Authors All rights reserved.
|
|
|
|
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 podtask
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
|
mesos "github.com/mesos/mesos-go/mesosproto"
|
|
mutil "github.com/mesos/mesos-go/mesosutil"
|
|
)
|
|
|
|
const (
|
|
t_min_cpu = 128
|
|
t_min_mem = 128
|
|
)
|
|
|
|
func fakePodTask(id string) (*T, error) {
|
|
return New(api.NewDefaultContext(), "", api.Pod{
|
|
ObjectMeta: api.ObjectMeta{
|
|
Name: id,
|
|
Namespace: api.NamespaceDefault,
|
|
},
|
|
}, &mesos.ExecutorInfo{})
|
|
}
|
|
|
|
func TestEmptyOffer(t *testing.T) {
|
|
t.Parallel()
|
|
task, err := fakePodTask("foo")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if ok := task.AcceptOffer(nil); ok {
|
|
t.Fatalf("accepted nil offer")
|
|
}
|
|
if ok := task.AcceptOffer(&mesos.Offer{}); ok {
|
|
t.Fatalf("accepted empty offer")
|
|
}
|
|
}
|
|
|
|
func TestNoPortsInPodOrOffer(t *testing.T) {
|
|
t.Parallel()
|
|
task, err := fakePodTask("foo")
|
|
if err != nil || task == nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
offer := &mesos.Offer{
|
|
Resources: []*mesos.Resource{
|
|
mutil.NewScalarResource("cpus", 0.001),
|
|
mutil.NewScalarResource("mem", 0.001),
|
|
},
|
|
}
|
|
if ok := task.AcceptOffer(offer); ok {
|
|
t.Fatalf("accepted offer %v:", offer)
|
|
}
|
|
|
|
offer = &mesos.Offer{
|
|
Resources: []*mesos.Resource{
|
|
mutil.NewScalarResource("cpus", t_min_cpu),
|
|
mutil.NewScalarResource("mem", t_min_mem),
|
|
},
|
|
}
|
|
if ok := task.AcceptOffer(offer); !ok {
|
|
t.Fatalf("did not accepted offer %v:", offer)
|
|
}
|
|
}
|
|
|
|
func TestAcceptOfferPorts(t *testing.T) {
|
|
t.Parallel()
|
|
task, _ := fakePodTask("foo")
|
|
pod := &task.Pod
|
|
|
|
offer := &mesos.Offer{
|
|
Resources: []*mesos.Resource{
|
|
mutil.NewScalarResource("cpus", t_min_cpu),
|
|
mutil.NewScalarResource("mem", t_min_mem),
|
|
rangeResource("ports", []uint64{1, 1}),
|
|
},
|
|
}
|
|
if ok := task.AcceptOffer(offer); !ok {
|
|
t.Fatalf("did not accepted offer %v:", offer)
|
|
}
|
|
|
|
pod.Spec = api.PodSpec{
|
|
Containers: []api.Container{{
|
|
Ports: []api.ContainerPort{{
|
|
HostPort: 123,
|
|
}},
|
|
}},
|
|
}
|
|
if ok := task.AcceptOffer(offer); ok {
|
|
t.Fatalf("accepted offer %v:", offer)
|
|
}
|
|
|
|
pod.Spec.Containers[0].Ports[0].HostPort = 1
|
|
if ok := task.AcceptOffer(offer); !ok {
|
|
t.Fatalf("did not accepted offer %v:", offer)
|
|
}
|
|
|
|
pod.Spec.Containers[0].Ports[0].HostPort = 0
|
|
if ok := task.AcceptOffer(offer); !ok {
|
|
t.Fatalf("did not accepted offer %v:", offer)
|
|
}
|
|
|
|
offer.Resources = []*mesos.Resource{
|
|
mutil.NewScalarResource("cpus", t_min_cpu),
|
|
mutil.NewScalarResource("mem", t_min_mem),
|
|
}
|
|
if ok := task.AcceptOffer(offer); ok {
|
|
t.Fatalf("accepted offer %v:", offer)
|
|
}
|
|
|
|
pod.Spec.Containers[0].Ports[0].HostPort = 1
|
|
if ok := task.AcceptOffer(offer); ok {
|
|
t.Fatalf("accepted offer %v:", offer)
|
|
}
|
|
}
|
|
|
|
func TestGeneratePodName(t *testing.T) {
|
|
p := &api.Pod{
|
|
ObjectMeta: api.ObjectMeta{
|
|
Name: "foo",
|
|
Namespace: "bar",
|
|
},
|
|
}
|
|
name := generateTaskName(p)
|
|
expected := "foo.bar.pods"
|
|
if name != expected {
|
|
t.Fatalf("expected %q instead of %q", expected, name)
|
|
}
|
|
|
|
p.Namespace = ""
|
|
name = generateTaskName(p)
|
|
expected = "foo.default.pods"
|
|
if name != expected {
|
|
t.Fatalf("expected %q instead of %q", expected, name)
|
|
}
|
|
}
|