本文整理匯總了Golang中k8s/io/apimachinery/pkg/runtime.Scheme.AddFieldLabelConversionFunc方法的典型用法代碼示例。如果您正苦於以下問題:Golang Scheme.AddFieldLabelConversionFunc方法的具體用法?Golang Scheme.AddFieldLabelConversionFunc怎麽用?Golang Scheme.AddFieldLabelConversionFunc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/apimachinery/pkg/runtime.Scheme
的用法示例。
在下文中一共展示了Scheme.AddFieldLabelConversionFunc方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AddFieldLabelConversionsForNamespace
func AddFieldLabelConversionsForNamespace(scheme *runtime.Scheme) error {
return scheme.AddFieldLabelConversionFunc("v1", "Namespace",
func(label, value string) (string, string, error) {
switch label {
case "status.phase",
"metadata.name":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
})
}
示例2: addConversionFuncs
func addConversionFuncs(scheme *runtime.Scheme) error {
return scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.String(), "Cluster",
func(label, value string) (string, string, error) {
switch label {
case "metadata.name":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
},
)
}
示例3: AddFieldLabelConversionsForEvent
func AddFieldLabelConversionsForEvent(scheme *runtime.Scheme) error {
return scheme.AddFieldLabelConversionFunc("v1", "Event",
func(label, value string) (string, string, error) {
switch label {
case "involvedObject.kind",
"involvedObject.namespace",
"involvedObject.name",
"involvedObject.uid",
"involvedObject.apiVersion",
"involvedObject.resourceVersion",
"involvedObject.fieldPath",
"reason",
"source",
"type",
"metadata.namespace",
"metadata.name":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
})
}
示例4: addConversionFuncs
func addConversionFuncs(scheme *runtime.Scheme) error {
// Add non-generated conversion functions
err := scheme.AddConversionFuncs(
v1.Convert_v1_DeleteOptions_To_api_DeleteOptions,
v1.Convert_api_DeleteOptions_To_v1_DeleteOptions,
v1.Convert_v1_List_To_api_List,
v1.Convert_api_List_To_v1_List,
v1.Convert_v1_ListOptions_To_api_ListOptions,
v1.Convert_api_ListOptions_To_v1_ListOptions,
v1.Convert_v1_ObjectFieldSelector_To_api_ObjectFieldSelector,
v1.Convert_api_ObjectFieldSelector_To_v1_ObjectFieldSelector,
v1.Convert_v1_ObjectMeta_To_api_ObjectMeta,
v1.Convert_api_ObjectMeta_To_v1_ObjectMeta,
v1.Convert_v1_ObjectReference_To_api_ObjectReference,
v1.Convert_api_ObjectReference_To_v1_ObjectReference,
v1.Convert_v1_Secret_To_api_Secret,
v1.Convert_api_Secret_To_v1_Secret,
v1.Convert_v1_SecretList_To_api_SecretList,
v1.Convert_api_SecretList_To_v1_SecretList,
v1.Convert_v1_Service_To_api_Service,
v1.Convert_api_Service_To_v1_Service,
v1.Convert_v1_ServiceList_To_api_ServiceList,
v1.Convert_api_ServiceList_To_v1_ServiceList,
v1.Convert_v1_ServicePort_To_api_ServicePort,
v1.Convert_api_ServicePort_To_v1_ServicePort,
v1.Convert_v1_ServiceProxyOptions_To_api_ServiceProxyOptions,
v1.Convert_api_ServiceProxyOptions_To_v1_ServiceProxyOptions,
v1.Convert_v1_ServiceSpec_To_api_ServiceSpec,
v1.Convert_api_ServiceSpec_To_v1_ServiceSpec,
v1.Convert_v1_ServiceStatus_To_api_ServiceStatus,
v1.Convert_api_ServiceStatus_To_v1_ServiceStatus,
)
if err != nil {
return err
}
// Add field label conversions for kinds having selectable nothing but ObjectMeta fields.
for _, kind := range []string{
"Service",
} {
err = scheme.AddFieldLabelConversionFunc("v1", kind,
func(label, value string) (string, string, error) {
switch label {
case "metadata.namespace",
"metadata.name":
return label, value, nil
default:
return "", "", fmt.Errorf("field label %q not supported for %q", label, kind)
}
})
if err != nil {
return err
}
}
if err := v1.AddFieldLabelConversionsForEvent(scheme); err != nil {
return nil
}
if err := v1.AddFieldLabelConversionsForNamespace(scheme); err != nil {
return nil
}
if err := v1.AddFieldLabelConversionsForSecret(scheme); err != nil {
return nil
}
return nil
}
示例5: addConversionFuncs
func addConversionFuncs(scheme *runtime.Scheme) error {
// Add non-generated conversion functions
err := scheme.AddConversionFuncs(
Convert_api_Pod_To_v1_Pod,
Convert_api_PodSpec_To_v1_PodSpec,
Convert_api_ReplicationControllerSpec_To_v1_ReplicationControllerSpec,
Convert_api_ServiceSpec_To_v1_ServiceSpec,
Convert_v1_Pod_To_api_Pod,
Convert_v1_PodSpec_To_api_PodSpec,
Convert_v1_ReplicationControllerSpec_To_api_ReplicationControllerSpec,
Convert_v1_Secret_To_api_Secret,
Convert_v1_ServiceSpec_To_api_ServiceSpec,
Convert_v1_ResourceList_To_api_ResourceList,
Convert_v1_ReplicationController_to_extensions_ReplicaSet,
Convert_v1_ReplicationControllerSpec_to_extensions_ReplicaSetSpec,
Convert_v1_ReplicationControllerStatus_to_extensions_ReplicaSetStatus,
Convert_extensions_ReplicaSet_to_v1_ReplicationController,
Convert_extensions_ReplicaSetSpec_to_v1_ReplicationControllerSpec,
Convert_extensions_ReplicaSetStatus_to_v1_ReplicationControllerStatus,
)
if err != nil {
return err
}
// Add field label conversions for kinds having selectable nothing but ObjectMeta fields.
for _, k := range []string{
"Endpoints",
"ResourceQuota",
"PersistentVolumeClaim",
"Service",
"ServiceAccount",
"ConfigMap",
} {
kind := k // don't close over range variables
err = scheme.AddFieldLabelConversionFunc("v1", kind,
func(label, value string) (string, string, error) {
switch label {
case "metadata.namespace",
"metadata.name":
return label, value, nil
default:
return "", "", fmt.Errorf("field label %q not supported for %q", label, kind)
}
},
)
if err != nil {
return err
}
}
// Add field conversion funcs.
err = scheme.AddFieldLabelConversionFunc("v1", "Pod",
func(label, value string) (string, string, error) {
switch label {
case "metadata.annotations",
"metadata.labels",
"metadata.name",
"metadata.namespace",
"spec.nodeName",
"spec.restartPolicy",
"spec.serviceAccountName",
"status.phase",
"status.podIP":
return label, value, nil
// This is for backwards compatibility with old v1 clients which send spec.host
case "spec.host":
return "spec.nodeName", value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
},
)
if err != nil {
return err
}
err = scheme.AddFieldLabelConversionFunc("v1", "Node",
func(label, value string) (string, string, error) {
switch label {
case "metadata.name":
return label, value, nil
case "spec.unschedulable":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
},
)
if err != nil {
return err
}
err = scheme.AddFieldLabelConversionFunc("v1", "ReplicationController",
func(label, value string) (string, string, error) {
switch label {
case "metadata.name",
"metadata.namespace",
"status.replicas":
return label, value, nil
default:
return "", "", fmt.Errorf("field label not supported: %s", label)
}
//.........這裏部分代碼省略.........