Created
December 3, 2025 15:45
-
-
Save rssnyder/5313f905457fc112a4b50e6ce6196802 to your computer and use it in GitHub Desktop.
find duplicate k8s/ccm connectors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from doctest import master | |
| from os import getenv | |
| from json import dumps | |
| from requests import post | |
| def get_connectors(type: str, page: int = 0, size: int = 10): | |
| resp = post( | |
| "https://app.harness.io/gateway/ng/api/connectors/listV2", | |
| params={ | |
| "routingId": getenv("HARNESS_ACCOUNT_ID"), | |
| "onlyFavorites": "false", | |
| "pageIndex": page, | |
| "pageSize": size, | |
| "accountIdentifier": getenv("HARNESS_ACCOUNT_ID"), | |
| }, | |
| headers={"x-api-key": getenv("HARNESS_PLATFORM_API_KEY")}, | |
| json={"types": [type], "filterType": "Connector"}, | |
| ) | |
| resp.raise_for_status() | |
| data = resp.json() | |
| connectors = data["data"]["content"] | |
| if data["data"]["pageIndex"] < data["data"]["totalPages"] - 1: | |
| connectors.extend(get_connectors(type, page + 1, size)) | |
| return connectors | |
| def find_duplicate_elements(my_list): | |
| seen = set() | |
| duplicates = set() | |
| for item in my_list: | |
| if item in seen: | |
| duplicates.add(item) | |
| else: | |
| seen.add(item) | |
| return list(duplicates) | |
| if __name__ == "__main__": | |
| connectors = get_connectors("K8sCluster", size=100) | |
| masterUrlConnectors = [ | |
| x | |
| for x in connectors | |
| if x["connector"]["spec"]["credential"]["type"] == "ManualConfig" | |
| ] | |
| urls = [ | |
| x["connector"]["spec"]["credential"]["spec"]["masterUrl"] | |
| for x in masterUrlConnectors | |
| ] | |
| dups = find_duplicate_elements(urls) | |
| ccmConns = get_connectors("CEK8sCluster", size=100) | |
| for dup in dups: | |
| dupConns = [ | |
| x["connector"]["identifier"] | |
| for x in masterUrlConnectors | |
| if x["connector"]["spec"]["credential"]["spec"]["masterUrl"] == dup | |
| ] | |
| dupCcmConn = [] | |
| for conn in dupConns: | |
| dupCcmConn.extend( | |
| [ | |
| x["connector"]["identifier"] | |
| for x in ccmConns | |
| if x["connector"]["spec"]["connectorRef"] == conn | |
| ] | |
| ) | |
| print("Duplicate K8s: " + str(dupConns)) | |
| print("Matching CCM: " + str(dupCcmConn)) | |
| if len(dupCcmConn) > 1: | |
| print("!! MULTIPLE CCM CONNECTORS FOUND FOR THIS CLUSTER") | |
| print() | |
| print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment