pod_task: use annotations rather than labels for roles

Roles support in Kubernetes-Mesos was done using pod labels. This
commits moves this to pod annotations. Pod label yaml files don't
support '*' characters, furthermore roles are consumed by the scheduler
only and are not meant for querying/filtering.
This commit is contained in:
Sergiusz Urbaniak 2015-12-11 19:18:47 +01:00
parent 3680268c52
commit 1fd3bc087b
5 changed files with 8 additions and 29 deletions

View File

@ -34,4 +34,5 @@ const (
PortNameMappingKeyFormat = PortNameMappingKeyPrefix + "%s_%s"
ContainerPortKeyFormat = "k8s.mesosphere.io/containerPort_%s_%s_%d"
StaticPodFilenameKey = "k8s.mesosphere.io/staticPodFilename"
RolesKey = "k8s.mesosphere.io/roles"
)

View File

@ -1,22 +0,0 @@
/*
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 meta
// kubernetes api object labels
const (
RolesKey = "k8s.mesosphere.io/roles"
)

View File

@ -170,10 +170,10 @@ func (t *T) Has(f FlagType) (exists bool) {
}
// Roles returns the valid roles under which this pod task can be scheduled.
// If the pod has roles labels defined they are being used
// If the pod has roles annotations defined they are being used
// else default pod roles are being returned.
func (t *T) Roles() []string {
if r, ok := t.Pod.ObjectMeta.Labels[annotation.RolesKey]; ok {
func (t *T) Roles() (result []string) {
if r, ok := t.Pod.ObjectMeta.Annotations[annotation.RolesKey]; ok {
roles := strings.Split(r, ",")
for i, r := range roles {

View File

@ -56,7 +56,7 @@ func TestRoles(t *testing.T) {
assert := assert.New(t)
for i, tt := range []struct {
labels map[string]string
annotations map[string]string
frameworkRoles []string
want []string
}{
@ -105,7 +105,7 @@ func TestRoles(t *testing.T) {
},
} {
task := fakePodTask("test", tt.frameworkRoles, starRole)
task.Pod.ObjectMeta.Labels = tt.labels
task.Pod.ObjectMeta.Annotations = tt.annotations
assert.True(reflect.DeepEqual(task.Roles(), tt.want), "test #%d got %#v want %#v", i, task.Roles(), tt.want)
}
}

View File

@ -73,7 +73,7 @@ var _ = Describe("Mesos", func() {
fmt.Sprintf("number of static pods in namespace %s is %d", ns, numpods))
})
It("schedules pods labelled with roles on correct slaves", func() {
It("schedules pods annotated with roles on correct slaves", func() {
// launch a pod to find a node which can launch a pod. We intentionally do
// not just take the node list and choose the first of them. Depending on the
// cluster and the scheduler it might be that a "normal" pod cannot be
@ -86,7 +86,7 @@ var _ = Describe("Mesos", func() {
},
ObjectMeta: api.ObjectMeta{
Name: podName,
Labels: map[string]string{
Annotations: map[string]string{
"k8s.mesosphere.io/roles": "public",
},
},