// JobSelectableFields returns a field set that represents the object for matching purposes. func JobToSelectableFields(job *batch.Job) fields.Set { objectMetaFieldsSet := generic.ObjectMetaFieldsSet(job.ObjectMeta, true) specificFieldsSet := fields.Set{ "status.successful": strconv.Itoa(int(job.Status.Succeeded)), } return generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet) }
func getAttrs(obj runtime.Object) (objLabels labels.Set, objFields fields.Set, err error) { event, ok := obj.(*api.Event) if !ok { return nil, nil, errors.NewInternalError(fmt.Errorf("object is not of type event: %#v", obj)) } l := event.Labels if l == nil { l = labels.Set{} } objectMetaFieldsSet := generic.ObjectMetaFieldsSet(event.ObjectMeta, true) specificFieldsSet := fields.Set{ "involvedObject.kind": event.InvolvedObject.Kind, "involvedObject.namespace": event.InvolvedObject.Namespace, "involvedObject.name": event.InvolvedObject.Name, "involvedObject.uid": string(event.InvolvedObject.UID), "involvedObject.apiVersion": event.InvolvedObject.APIVersion, "involvedObject.resourceVersion": event.InvolvedObject.ResourceVersion, "involvedObject.fieldPath": event.InvolvedObject.FieldPath, "reason": event.Reason, "source": event.Source.Component, "type": event.Type, } return l, generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet), nil }
// ControllerToSelectableFields returns a field set that represents the object. func ControllerToSelectableFields(controller *api.ReplicationController) fields.Set { objectMetaFieldsSet := generic.ObjectMetaFieldsSet(controller.ObjectMeta, true) controllerSpecificFieldsSet := fields.Set{ "status.replicas": strconv.Itoa(int(controller.Status.Replicas)), } return generic.MergeFieldsSets(objectMetaFieldsSet, controllerSpecificFieldsSet) }
// NodeToSelectableFields returns a field set that represents the object. func NodeToSelectableFields(node *api.Node) fields.Set { objectMetaFieldsSet := generic.ObjectMetaFieldsSet(node.ObjectMeta, false) specificFieldsSet := fields.Set{ "spec.unschedulable": fmt.Sprint(node.Spec.Unschedulable), } return generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet) }
// SelectableFields returns a label set that can be used for filter selection func SelectableFields(obj *api.Secret) labels.Set { objectMetaFieldsSet := generic.ObjectMetaFieldsSet(obj.ObjectMeta, true) secretSpecificFieldsSet := fields.Set{ "type": string(obj.Type), } return labels.Set(generic.MergeFieldsSets(objectMetaFieldsSet, secretSpecificFieldsSet)) }
// PersistentVolumeToSelectableFields returns a label set that represents the object func PersistentVolumeToSelectableFields(persistentvolume *api.PersistentVolume) labels.Set { objectMetaFieldsSet := generic.ObjectMetaFieldsSet(persistentvolume.ObjectMeta, false) specificFieldsSet := fields.Set{ // This is a bug, but we need to support it for backward compatibility. "name": persistentvolume.Name, } return labels.Set(generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet)) }
// NamespaceToSelectableFields returns a label set that represents the object func NamespaceToSelectableFields(namespace *api.Namespace) labels.Set { objectMetaFieldsSet := generic.ObjectMetaFieldsSet(namespace.ObjectMeta, false) specificFieldsSet := fields.Set{ "status.phase": string(namespace.Status.Phase), // This is a bug, but we need to support it for backward compatibility. "name": namespace.Name, } return labels.Set(generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet)) }
func NewTestGenericStoreRegistry(t *testing.T) (*etcdtesting.EtcdTestServer, *Store) { podPrefix := "/pods" server := etcdtesting.NewEtcdTestClientServer(t) s := etcdstorage.NewEtcdStorage(server.Client, testapi.Default.StorageCodec(), etcdtest.PathPrefix(), false, etcdtest.DeserializationCacheSize) strategy := &testRESTStrategy{api.Scheme, api.SimpleNameGenerator, true, false, true} return server, &Store{ NewFunc: func() runtime.Object { return &api.Pod{} }, NewListFunc: func() runtime.Object { return &api.PodList{} }, QualifiedResource: api.Resource("pods"), CreateStrategy: strategy, UpdateStrategy: strategy, DeleteStrategy: strategy, KeyRootFunc: func(ctx api.Context) string { return podPrefix }, KeyFunc: func(ctx api.Context, id string) (string, error) { if _, ok := api.NamespaceFrom(ctx); !ok { return "", fmt.Errorf("namespace is required") } return path.Join(podPrefix, id), nil }, ObjectNameFunc: func(obj runtime.Object) (string, error) { return obj.(*api.Pod).Name, nil }, PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher { return &generic.SelectionPredicate{ Label: label, Field: field, GetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) { pod, ok := obj.(*api.Pod) if !ok { return nil, nil, fmt.Errorf("not a pod") } return labels.Set(pod.ObjectMeta.Labels), generic.ObjectMetaFieldsSet(pod.ObjectMeta, true), nil }, } }, Storage: s, } }
// IngressToSelectableFields returns a field set that represents the object. func IngressToSelectableFields(ingress *extensions.Ingress) fields.Set { return generic.ObjectMetaFieldsSet(ingress.ObjectMeta, true) }
// DeploymentToSelectableFields returns a field set that represents the object. func DeploymentToSelectableFields(deployment *extensions.Deployment) fields.Set { return generic.ObjectMetaFieldsSet(deployment.ObjectMeta, true) }
// PodSecurityPolicyToSelectableFields returns a label set that represents the object func PodSecurityPolicyToSelectableFields(obj *extensions.PodSecurityPolicy) fields.Set { return generic.ObjectMetaFieldsSet(obj.ObjectMeta, false) }
// PodDisruptionBudgetToSelectableFields returns a field set that represents the object. func PodDisruptionBudgetToSelectableFields(podDisruptionBudget *policy.PodDisruptionBudget) fields.Set { return generic.ObjectMetaFieldsSet(podDisruptionBudget.ObjectMeta, true) }
// NetworkPolicyToSelectableFields returns a field set that represents the object. func NetworkPolicyToSelectableFields(networkPolicy *extensions.NetworkPolicy) fields.Set { return generic.ObjectMetaFieldsSet(networkPolicy.ObjectMeta, true) }