func getPodsPrefix(controllerName string) string { // use the dash (if the name isn't too long) to make the pod name a bit prettier prefix := fmt.Sprintf("%s-", controllerName) if len(validation.ValidatePodName(prefix, true)) != 0 { prefix = controllerName } return prefix }
func getReplicaPrefix(controllerName string) string { // use the dash (if the name isn't too long) to make the pod name a bit prettier prefix := fmt.Sprintf("%s-", controllerName) if ok, _ := validation.ValidatePodName(prefix, true); !ok { prefix = controllerName } return prefix }
func parseDestination(destination string) (string, string, error) { parts := strings.SplitN(destination, ":", 2) if len(parts) < 2 || len(parts[0]) == 0 || len(parts[1]) == 0 { return "", "", fmt.Errorf("invalid destination %s: must be of the form PODNAME:DESTINATION_DIR", destination) } valid, msg := kvalidation.ValidatePodName(parts[0], false) if !valid { return "", "", fmt.Errorf("invalid pod name %s: %s", parts[0], msg) } return parts[0], parts[1], nil }
func PodMetricsUrl(namespace string, name string) (string, error) { errs := validation.ValidateNamespaceName(namespace, false) if len(errs) > 0 { message := fmt.Sprintf("invalid namespace: %s - %v", namespace, errs) return "", errors.New(message) } if len(name) > 0 { errs = validation.ValidatePodName(name, false) if len(errs) > 0 { message := fmt.Sprintf("invalid pod name: %s - %v", name, errs) return "", errors.New(message) } } return fmt.Sprintf("%s/namespaces/%s/pods/%s", MetricsRoot, namespace, name), nil }
// parsePathSpec parses a string argument into a pathSpec object func parsePathSpec(path string) (*pathSpec, error) { parts := strings.SplitN(path, ":", 2) if len(parts) == 1 || (isWindows() && len(parts[0]) == 1) { return &pathSpec{ Path: path, }, nil } if reasons := kvalidation.ValidatePodName(parts[0], false); len(reasons) != 0 { return nil, fmt.Errorf("invalid pod name %s: %s", parts[0], strings.Join(reasons, ", ")) } return &pathSpec{ PodName: parts[0], Path: parts[1], }, nil }
// parsePathSpec parses a string argument into a pathSpec object func parsePathSpec(path string) (*pathSpec, error) { parts := strings.SplitN(path, ":", 2) if len(parts) == 1 || (isWindows() && len(parts[0]) == 1) { return &pathSpec{ Path: path, }, nil } valid, msg := kvalidation.ValidatePodName(parts[0], false) if !valid { return nil, fmt.Errorf("invalid pod name %s: %s", parts[0], msg) } return &pathSpec{ PodName: parts[0], Path: parts[1], }, nil }