MemVerge / mmc.ai-setup

For AI platform setup
0 stars 1 forks source link

[source logging.sh] Returns "SyntaxError: invalid syntax" for 'source logging.sh' on line 3 #20

Open sscargal opened 1 week ago

sscargal commented 1 week ago

When executing mmcai-drain.sh, it calls mmcai_adjust_requests.py which fails with the following error:

$ ./mmcai-drain.sh 
error: at least one resource name must be specified since 'all' parameter is not set
--2024-09-23 20:04:16--  https://raw.githubusercontent.com/MemVerge/mmc.ai-setup/refs/heads/main/mmcai-drain.sh
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.110.133, 185.199.111.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1128 (1.1K) [text/plain]
Saving to: ‘mmcai_adjust_requests.py’

mmcai_adjust_requests.py                            100%[=================================================================================================================>]   1.10K  --.-KB/s    in 0s      

2024-09-23 20:04:16 (81.6 MB/s) - ‘mmcai_adjust_requests.py’ saved [1128/1128]

Requirement already satisfied: kubernetes in /opt/deepops/env/lib/python3.10/site-packages (31.0.0)
Requirement already satisfied: certifi>=14.05.14 in /opt/deepops/env/lib/python3.10/site-packages (from kubernetes) (2024.8.30)
Requirement already satisfied: six>=1.9.0 in /opt/deepops/env/lib/python3.10/site-packages (from kubernetes) (1.16.0)
Requirement already satisfied: python-dateutil>=2.5.3 in /opt/deepops/env/lib/python3.10/site-packages (from kubernetes) (2.9.0.post0)
Requirement already satisfied: pyyaml>=5.4.1 in /opt/deepops/env/lib/python3.10/site-packages (from kubernetes) (6.0.2)
Requirement already satisfied: google-auth>=1.0.1 in /opt/deepops/env/lib/python3.10/site-packages (from kubernetes) (2.35.0)
Requirement already satisfied: websocket-client!=0.40.0,!=0.41.*,!=0.42.*,>=0.32.0 in /opt/deepops/env/lib/python3.10/site-packages (from kubernetes) (1.8.0)
Requirement already satisfied: requests in /opt/deepops/env/lib/python3.10/site-packages (from kubernetes) (2.32.3)
Requirement already satisfied: requests-oauthlib in /opt/deepops/env/lib/python3.10/site-packages (from kubernetes) (2.0.0)
Requirement already satisfied: oauthlib>=3.2.2 in /opt/deepops/env/lib/python3.10/site-packages (from kubernetes) (3.2.2)
Requirement already satisfied: urllib3>=1.24.2 in /opt/deepops/env/lib/python3.10/site-packages (from kubernetes) (2.2.3)
Requirement already satisfied: durationpy>=0.7 in /opt/deepops/env/lib/python3.10/site-packages (from kubernetes) (0.7)
Requirement already satisfied: cachetools<6.0,>=2.0.0 in /opt/deepops/env/lib/python3.10/site-packages (from google-auth>=1.0.1->kubernetes) (5.5.0)
Requirement already satisfied: pyasn1-modules>=0.2.1 in /opt/deepops/env/lib/python3.10/site-packages (from google-auth>=1.0.1->kubernetes) (0.4.1)
Requirement already satisfied: rsa<5,>=3.1.4 in /opt/deepops/env/lib/python3.10/site-packages (from google-auth>=1.0.1->kubernetes) (4.9)
Requirement already satisfied: charset-normalizer<4,>=2 in /opt/deepops/env/lib/python3.10/site-packages (from requests->kubernetes) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /opt/deepops/env/lib/python3.10/site-packages (from requests->kubernetes) (3.10)
Requirement already satisfied: pyasn1<0.7.0,>=0.4.6 in /opt/deepops/env/lib/python3.10/site-packages (from pyasn1-modules>=0.2.1->google-auth>=1.0.1->kubernetes) (0.6.1)
  File "/home/mmai-admin/mmc.ai-setup/mmcai_adjust_requests.py", line 3
    source logging.sh
           ^^^^^^^
SyntaxError: invalid syntax
sscargal commented 1 week ago

We can fix this SyntaxError with:

source ./logging.sh

I see a bug caused by my previous commit.

wget -O mmcai_adjust_requests.py https://raw.githubusercontent.com/MemVerge/mmc.ai-setup/refs/heads/main/mmcai-drain.sh

Should be

wget -O mmcai_adjust_requests.py https://raw.githubusercontent.com/MemVerge/mmc.ai-setup/refs/heads/main/mmcai_adjust_requests.py
sscargal commented 1 week ago

I get a new error running mmcai-drain.sh:

  File "/home/mmai-admin/mmc.ai-setup/mmcai_adjust_requests.py", line 42
    'container': container.name
                 ^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

This is part of an object an is missing the comma:

pod_list.append({
    'namespace': pod.metadata.namespace,
    'name': pod.metadata.name,
    'labels': pod.metadata.labels,
    'cpu_request': cpu_request_m,
    'container': container.name,  # Add a comma here
    'owner': pod.metadata.owner_references[0]
})
sscargal commented 1 week ago

After fixing the previous issues, I got a new error:

Traceback (most recent call last):
  File "/home/mmai-admin/mmc.ai-setup/./mmcai_adjust_requests.py", line 194, in <module>
    main()
  File "/home/mmai-admin/mmc.ai-setup/./mmcai_adjust_requests.py", line 176, in main
    restart_deployment(pod['deployment'])
TypeError: restart_deployment() missing 2 required positional arguments: 'deployment' and 'namespace'

The restart_deployment() function requires three arguments, but only two are used:

def restart_deployment(v1_apps, deployment, namespace):

From the main function:

 # Restart the modified pods to apply the changes
    for pod in modified_pods:
        if 'deployment' in pod:
            restart_deployment(pod['deployment']). <<<<<<<<<
        else:
            restart_pod(pod['name'], pod['namespace'])

We need to call the function with the correct arguments:

restart_deployment(apps_v1, pod['deployment'], pod['namespace'])