(labels_str: str)
| 57 | |
| 58 | |
| 59 | def parse_node_labels_string(labels_str: str) -> Dict[str, str]: |
| 60 | labels = {} |
| 61 | |
| 62 | # Remove surrounding quotes if they exist |
| 63 | if len(labels_str) > 1 and labels_str.startswith('"') and labels_str.endswith('"'): |
| 64 | labels_str = labels_str[1:-1] |
| 65 | |
| 66 | if labels_str == "": |
| 67 | return labels |
| 68 | |
| 69 | # Labels argument should consist of a string of key=value pairs |
| 70 | # separated by commas. Labels follow Kubernetes label syntax. |
| 71 | label_pairs = labels_str.split(",") |
| 72 | for pair in label_pairs: |
| 73 | # Split each pair by `=` |
| 74 | key_value = pair.split("=") |
| 75 | if len(key_value) != 2: |
| 76 | raise ValueError("Label string is not a key-value pair.") |
| 77 | key = key_value[0].strip() |
| 78 | value = key_value[1].strip() |
| 79 | labels[key] = value |
| 80 | |
| 81 | # Validate parsed node labels follow expected Kubernetes label syntax |
| 82 | validate_node_label_syntax(labels) |
| 83 | |
| 84 | return labels |
| 85 | |
| 86 | |
| 87 | def parse_node_labels_from_yaml_file(path: str) -> Dict[str, str]: |
searching dependent graphs…