func Convert_v1beta1_ScaleStatus_To_extensions_ScaleStatus(in *ScaleStatus, out *extensions.ScaleStatus, s conversion.Scope) error { out.Replicas = in.Replicas // Normally when 2 fields map to the same internal value we favor the old field, since // old clients can't be expected to know about new fields but clients that know about the // new field can be expected to know about the old field (though that's not quite true, due // to kubectl apply). However, these fields are readonly, so any non-nil value should work. if in.TargetSelector != "" { labelSelector, err := metav1.ParseToLabelSelector(in.TargetSelector) if err != nil { out.Selector = nil return fmt.Errorf("failed to parse target selector: %v", err) } out.Selector = labelSelector } else if in.Selector != nil { out.Selector = new(metav1.LabelSelector) selector := make(map[string]string) for key, val := range in.Selector { selector[key] = val } out.Selector.MatchLabels = selector } else { out.Selector = nil } return nil }
// StructuredGenerate outputs a pod disruption budget object using the configured fields. func (s *PodDisruptionBudgetV1Generator) StructuredGenerate() (runtime.Object, error) { if err := s.validate(); err != nil { return nil, err } selector, err := metav1.ParseToLabelSelector(s.Selector) if err != nil { return nil, err } return &policy.PodDisruptionBudget{ ObjectMeta: metav1.ObjectMeta{ Name: s.Name, }, Spec: policy.PodDisruptionBudgetSpec{ MinAvailable: intstr.Parse(s.MinAvailable), Selector: selector, }, }, nil }
// getResourcesAndSelector retrieves resources and the selector expression from the given args (assuming selectors the last arg) func getResourcesAndSelector(args []string) (resources []string, selector *metav1.LabelSelector, err error) { if len(args) == 0 { return []string{}, nil, nil } resources = args[:len(args)-1] selector, err = metav1.ParseToLabelSelector(args[len(args)-1]) return resources, selector, err }