Revert "Revert "Adding converter functions to convert field label selectors to internal version before matching""

This reverts commit 5f35a67002.
This commit is contained in:
Daniel Smith
2015-03-02 15:00:09 -08:00
parent 32523f8a52
commit c4822dc060
13 changed files with 225 additions and 57 deletions

View File

@@ -1291,4 +1291,26 @@ func init() {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
// Add field conversion funcs.
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta1", "pods",
func(label, value string) (string, string, error) {
switch label {
case "name":
return "name", value, nil
case "DesiredState.Host":
return "Status.Host", value, nil
case "DesiredState.Status":
podStatus := PodStatus(value)
var internalValue newer.PodPhase
newer.Scheme.Convert(&podStatus, &internalValue)
return "Status.Phase", string(internalValue), nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
})
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
}

View File

@@ -1206,4 +1206,26 @@ func init() {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
// Add field conversion funcs.
err = newer.Scheme.AddFieldLabelConversionFunc("v1beta2", "pods",
func(label, value string) (string, string, error) {
switch label {
case "name":
return "name", value, nil
case "DesiredState.Host":
return "Status.Host", value, nil
case "DesiredState.Status":
podStatus := PodStatus(value)
var internalValue newer.PodPhase
newer.Scheme.Convert(&podStatus, &internalValue)
return "Status.Phase", string(internalValue), nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
})
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
}

View File

@@ -0,0 +1,44 @@
/*
Copyright 2014 Google Inc. 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 v1beta3
import (
"fmt"
newer "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
func init() {
// Add field conversion funcs.
err := newer.Scheme.AddFieldLabelConversionFunc("v1beta3", "pods",
func(label, value string) (string, string, error) {
switch label {
case "name":
fallthrough
case "Status.Phase":
fallthrough
case "Status.Host":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
})
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
panic(err)
}
}