awslabs.eks-mcp-server 0.1.8__tar.gz → 0.1.10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/PKG-INFO +13 -7
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/README.md +12 -6
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/__init__.py +1 -1
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/k8s_apis.py +19 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/pyproject.toml +1 -1
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_k8s_apis.py +164 -15
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/uv.lock +625 -625
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/.gitignore +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/.python-version +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/CHANGELOG.md +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/Dockerfile +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/LICENSE +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/NOTICE +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/__init__.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/aws_helper.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/cloudwatch_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/cloudwatch_metrics_guidance_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/consts.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/data/eks_cloudwatch_metrics_guidance.json +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/eks_kb_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/eks_stack_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/iam_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/k8s_client_cache.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/k8s_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/logging_helper.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/models.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/scripts/update_eks_cloudwatch_metrics_guidance.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/server.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/templates/eks-templates/eks-with-vpc.yaml +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/templates/k8s-templates/deployment.yaml +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/templates/k8s-templates/service.yaml +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/docker-healthcheck.sh +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_aws_helper.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_cloudwatch_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_cloudwatch_metrics_guidance_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_eks_kb_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_eks_stack_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_iam_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_init.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_k8s_client_cache.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_k8s_handler.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_logging_helper.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_main.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_models.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/tests/test_server.py +0 -0
- {awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/uv-requirements.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: awslabs.eks-mcp-server
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.10
|
|
4
4
|
Summary: An AWS Labs Model Context Protocol (MCP) server for EKS
|
|
5
5
|
Project-URL: homepage, https://awslabs.github.io/mcp/
|
|
6
6
|
Project-URL: docs, https://awslabs.github.io/mcp/servers/eks-mcp-server/
|
|
@@ -128,7 +128,7 @@ This quickstart guide walks you through the steps to configure the Amazon EKS MC
|
|
|
128
128
|
|
|
129
129
|
| Cursor | VS Code |
|
|
130
130
|
|:------:|:-------:|
|
|
131
|
-
| [](https://cursor.com/install-mcp?name=awslabs.eks-mcp-server&config=eyJhdXRvQXBwcm92ZSI6W10sImRpc2FibGVkIjpmYWxzZSwiY29tbWFuZCI6InV2eCBhd3NsYWJzLmVrcy1tY3Atc2VydmVyQGxhdGVzdCAtLWFsbG93LXdyaXRlIC0tYWxsb3ctc2Vuc2l0aXZlLWRhdGEtYWNjZXNzIiwiZW52Ijp7IkZBU1RNQ1BfTE9HX0xFVkVMIjoiRVJST1IifSwidHJhbnNwb3J0VHlwZSI6InN0ZGlvIn0%3D) | [](https://insiders.vscode.dev/redirect/mcp/install?name=EKS%20MCP%20Server&config=%7B%22autoApprove%22%3A%5B%5D%2C%22disabled%22%3Afalse%2C%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22awslabs.eks-mcp-server%40latest%22%2C%22--allow-write%22%2C%22--allow-sensitive-data-access%22%5D%2C%22env%22%3A%7B%22FASTMCP_LOG_LEVEL%22%3A%22ERROR%22%7D%2C%22transportType%22%3A%22stdio%22%7D) |
|
|
131
|
+
| [](https://cursor.com/en/install-mcp?name=awslabs.eks-mcp-server&config=eyJhdXRvQXBwcm92ZSI6W10sImRpc2FibGVkIjpmYWxzZSwiY29tbWFuZCI6InV2eCBhd3NsYWJzLmVrcy1tY3Atc2VydmVyQGxhdGVzdCAtLWFsbG93LXdyaXRlIC0tYWxsb3ctc2Vuc2l0aXZlLWRhdGEtYWNjZXNzIiwiZW52Ijp7IkZBU1RNQ1BfTE9HX0xFVkVMIjoiRVJST1IifSwidHJhbnNwb3J0VHlwZSI6InN0ZGlvIn0%3D) | [](https://insiders.vscode.dev/redirect/mcp/install?name=EKS%20MCP%20Server&config=%7B%22autoApprove%22%3A%5B%5D%2C%22disabled%22%3Afalse%2C%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22awslabs.eks-mcp-server%40latest%22%2C%22--allow-write%22%2C%22--allow-sensitive-data-access%22%5D%2C%22env%22%3A%7B%22FASTMCP_LOG_LEVEL%22%3A%22ERROR%22%7D%2C%22transportType%22%3A%22stdio%22%7D) |
|
|
132
132
|
|
|
133
133
|
**Set up the Amazon Q Developer CLI**
|
|
134
134
|
|
|
@@ -272,7 +272,9 @@ The `env` field in the MCP server definition allows you to configure environment
|
|
|
272
272
|
"env": {
|
|
273
273
|
"FASTMCP_LOG_LEVEL": "ERROR",
|
|
274
274
|
"AWS_PROFILE": "my-profile",
|
|
275
|
-
"AWS_REGION": "us-west-2"
|
|
275
|
+
"AWS_REGION": "us-west-2",
|
|
276
|
+
"HTTP_PROXY": "http://proxy.example.com:8080",
|
|
277
|
+
"HTTPS_PROXY": "https://proxy.example.com:8080"
|
|
276
278
|
}
|
|
277
279
|
}
|
|
278
280
|
}
|
|
@@ -301,6 +303,14 @@ Specifies the AWS region where EKS clusters are managed, which will be used for
|
|
|
301
303
|
* Default: None (If not set, uses default AWS region).
|
|
302
304
|
* Example: `"AWS_REGION": "us-west-2"`
|
|
303
305
|
|
|
306
|
+
#### `HTTP_PROXY` / `HTTPS_PROXY` (optional)
|
|
307
|
+
|
|
308
|
+
Configures proxy settings for HTTP and HTTPS connections. These environment variables are used when the EKS MCP server needs to make outbound connections to the K8s API server through a proxy or firewall.
|
|
309
|
+
|
|
310
|
+
* Default: None (Direct connections are used if not set).
|
|
311
|
+
* Example: `"HTTP_PROXY": "http://proxy.example.com:8080"`, `"HTTPS_PROXY": "https://proxy.example.com:8080"`
|
|
312
|
+
* Note: Both variables can be set to the same proxy server if it handles both HTTP and HTTPS traffic.
|
|
313
|
+
|
|
304
314
|
## Tools
|
|
305
315
|
|
|
306
316
|
The following tools are provided by the EKS MCP server for managing Amazon EKS clusters and Kubernetes resources. Each tool performs a specific action that can be invoked to automate common tasks in your EKS clusters and Kubernetes workloads.
|
|
@@ -688,7 +698,3 @@ In accordance with security best practices, we recommend the following:
|
|
|
688
698
|
* **Log Level**: Increase the log level to DEBUG for more detailed logs.
|
|
689
699
|
|
|
690
700
|
For general EKS issues, consult the [Amazon EKS documentation](https://docs.aws.amazon.com/eks/).
|
|
691
|
-
|
|
692
|
-
## Version
|
|
693
|
-
|
|
694
|
-
Current MCP server version: 0.1.0
|
|
@@ -94,7 +94,7 @@ This quickstart guide walks you through the steps to configure the Amazon EKS MC
|
|
|
94
94
|
|
|
95
95
|
| Cursor | VS Code |
|
|
96
96
|
|:------:|:-------:|
|
|
97
|
-
| [](https://cursor.com/install-mcp?name=awslabs.eks-mcp-server&config=eyJhdXRvQXBwcm92ZSI6W10sImRpc2FibGVkIjpmYWxzZSwiY29tbWFuZCI6InV2eCBhd3NsYWJzLmVrcy1tY3Atc2VydmVyQGxhdGVzdCAtLWFsbG93LXdyaXRlIC0tYWxsb3ctc2Vuc2l0aXZlLWRhdGEtYWNjZXNzIiwiZW52Ijp7IkZBU1RNQ1BfTE9HX0xFVkVMIjoiRVJST1IifSwidHJhbnNwb3J0VHlwZSI6InN0ZGlvIn0%3D) | [](https://insiders.vscode.dev/redirect/mcp/install?name=EKS%20MCP%20Server&config=%7B%22autoApprove%22%3A%5B%5D%2C%22disabled%22%3Afalse%2C%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22awslabs.eks-mcp-server%40latest%22%2C%22--allow-write%22%2C%22--allow-sensitive-data-access%22%5D%2C%22env%22%3A%7B%22FASTMCP_LOG_LEVEL%22%3A%22ERROR%22%7D%2C%22transportType%22%3A%22stdio%22%7D) |
|
|
97
|
+
| [](https://cursor.com/en/install-mcp?name=awslabs.eks-mcp-server&config=eyJhdXRvQXBwcm92ZSI6W10sImRpc2FibGVkIjpmYWxzZSwiY29tbWFuZCI6InV2eCBhd3NsYWJzLmVrcy1tY3Atc2VydmVyQGxhdGVzdCAtLWFsbG93LXdyaXRlIC0tYWxsb3ctc2Vuc2l0aXZlLWRhdGEtYWNjZXNzIiwiZW52Ijp7IkZBU1RNQ1BfTE9HX0xFVkVMIjoiRVJST1IifSwidHJhbnNwb3J0VHlwZSI6InN0ZGlvIn0%3D) | [](https://insiders.vscode.dev/redirect/mcp/install?name=EKS%20MCP%20Server&config=%7B%22autoApprove%22%3A%5B%5D%2C%22disabled%22%3Afalse%2C%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22awslabs.eks-mcp-server%40latest%22%2C%22--allow-write%22%2C%22--allow-sensitive-data-access%22%5D%2C%22env%22%3A%7B%22FASTMCP_LOG_LEVEL%22%3A%22ERROR%22%7D%2C%22transportType%22%3A%22stdio%22%7D) |
|
|
98
98
|
|
|
99
99
|
**Set up the Amazon Q Developer CLI**
|
|
100
100
|
|
|
@@ -238,7 +238,9 @@ The `env` field in the MCP server definition allows you to configure environment
|
|
|
238
238
|
"env": {
|
|
239
239
|
"FASTMCP_LOG_LEVEL": "ERROR",
|
|
240
240
|
"AWS_PROFILE": "my-profile",
|
|
241
|
-
"AWS_REGION": "us-west-2"
|
|
241
|
+
"AWS_REGION": "us-west-2",
|
|
242
|
+
"HTTP_PROXY": "http://proxy.example.com:8080",
|
|
243
|
+
"HTTPS_PROXY": "https://proxy.example.com:8080"
|
|
242
244
|
}
|
|
243
245
|
}
|
|
244
246
|
}
|
|
@@ -267,6 +269,14 @@ Specifies the AWS region where EKS clusters are managed, which will be used for
|
|
|
267
269
|
* Default: None (If not set, uses default AWS region).
|
|
268
270
|
* Example: `"AWS_REGION": "us-west-2"`
|
|
269
271
|
|
|
272
|
+
#### `HTTP_PROXY` / `HTTPS_PROXY` (optional)
|
|
273
|
+
|
|
274
|
+
Configures proxy settings for HTTP and HTTPS connections. These environment variables are used when the EKS MCP server needs to make outbound connections to the K8s API server through a proxy or firewall.
|
|
275
|
+
|
|
276
|
+
* Default: None (Direct connections are used if not set).
|
|
277
|
+
* Example: `"HTTP_PROXY": "http://proxy.example.com:8080"`, `"HTTPS_PROXY": "https://proxy.example.com:8080"`
|
|
278
|
+
* Note: Both variables can be set to the same proxy server if it handles both HTTP and HTTPS traffic.
|
|
279
|
+
|
|
270
280
|
## Tools
|
|
271
281
|
|
|
272
282
|
The following tools are provided by the EKS MCP server for managing Amazon EKS clusters and Kubernetes resources. Each tool performs a specific action that can be invoked to automate common tasks in your EKS clusters and Kubernetes workloads.
|
|
@@ -654,7 +664,3 @@ In accordance with security best practices, we recommend the following:
|
|
|
654
664
|
* **Log Level**: Increase the log level to DEBUG for more detailed logs.
|
|
655
665
|
|
|
656
666
|
For general EKS issues, consult the [Amazon EKS documentation](https://docs.aws.amazon.com/eks/).
|
|
657
|
-
|
|
658
|
-
## Version
|
|
659
|
-
|
|
660
|
-
Current MCP server version: 0.1.0
|
{awslabs_eks_mcp_server-0.1.8 → awslabs_eks_mcp_server-0.1.10}/awslabs/eks_mcp_server/k8s_apis.py
RENAMED
|
@@ -73,6 +73,9 @@ class K8sApis:
|
|
|
73
73
|
os.unlink(self._ca_cert_file_path)
|
|
74
74
|
raise e
|
|
75
75
|
|
|
76
|
+
# Configure HTTP proxy settings if environment variables are present
|
|
77
|
+
self._configure_proxy_settings(configuration)
|
|
78
|
+
|
|
76
79
|
# Create base API client
|
|
77
80
|
self.api_client = client.ApiClient(configuration)
|
|
78
81
|
|
|
@@ -86,6 +89,22 @@ class K8sApis:
|
|
|
86
89
|
logger.error('kubernetes package not installed')
|
|
87
90
|
raise
|
|
88
91
|
|
|
92
|
+
def _configure_proxy_settings(self, config):
|
|
93
|
+
"""Configure proxy settings for Kubernetes client from environment variables."""
|
|
94
|
+
# Get proxy URL (HTTPS proxy takes precedence over HTTP proxy)
|
|
95
|
+
proxy_url = (
|
|
96
|
+
os.environ.get('HTTPS_PROXY')
|
|
97
|
+
or os.environ.get('https_proxy')
|
|
98
|
+
or os.environ.get('HTTP_PROXY')
|
|
99
|
+
or os.environ.get('http_proxy')
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
if not proxy_url:
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
logger.debug(f'Configuring proxy: {proxy_url}')
|
|
106
|
+
config.proxy = proxy_url
|
|
107
|
+
|
|
89
108
|
def _patch_resource(
|
|
90
109
|
self,
|
|
91
110
|
resource,
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"""Tests for the K8sApis class."""
|
|
16
16
|
|
|
17
17
|
import base64
|
|
18
|
+
import os
|
|
18
19
|
import pytest
|
|
19
20
|
from awslabs.eks_mcp_server.k8s_apis import K8sApis
|
|
20
21
|
from awslabs.eks_mcp_server.models import Operation
|
|
@@ -42,7 +43,7 @@ def mock_kubernetes_client():
|
|
|
42
43
|
@pytest.fixture
|
|
43
44
|
def k8s_apis(mock_kubernetes_client):
|
|
44
45
|
"""Create a K8sApis instance with mocked Kubernetes client."""
|
|
45
|
-
|
|
46
|
+
_, _, mock_api_client = mock_kubernetes_client
|
|
46
47
|
|
|
47
48
|
# Mock the dynamic client
|
|
48
49
|
mock_dynamic_client = MagicMock()
|
|
@@ -100,7 +101,7 @@ class TestK8sApisInitialization:
|
|
|
100
101
|
|
|
101
102
|
def test_init_with_ca_data(self, mock_kubernetes_client):
|
|
102
103
|
"""Test initialization with CA data."""
|
|
103
|
-
|
|
104
|
+
_, mock_config, _ = mock_kubernetes_client
|
|
104
105
|
|
|
105
106
|
# Mock tempfile and file operations with context manager support
|
|
106
107
|
mock_temp_file = MagicMock()
|
|
@@ -241,7 +242,7 @@ class TestK8sApisOperations:
|
|
|
241
242
|
# Verify the dynamic client was used correctly
|
|
242
243
|
mock_resources.get.assert_called_once_with(api_version='v1', kind='Pod')
|
|
243
244
|
mock_resource.create.assert_called_once()
|
|
244
|
-
|
|
245
|
+
_, kwargs = mock_resource.create.call_args
|
|
245
246
|
assert kwargs['body']['kind'] == 'Pod'
|
|
246
247
|
assert kwargs['body']['apiVersion'] == 'v1'
|
|
247
248
|
assert kwargs['body']['metadata']['name'] == 'test-pod'
|
|
@@ -279,7 +280,7 @@ class TestK8sApisOperations:
|
|
|
279
280
|
# Verify the dynamic client was used correctly
|
|
280
281
|
mock_resources.get.assert_called_once_with(api_version='v1', kind='Pod')
|
|
281
282
|
mock_resource.replace.assert_called_once()
|
|
282
|
-
|
|
283
|
+
_, kwargs = mock_resource.replace.call_args
|
|
283
284
|
assert kwargs['body']['kind'] == 'Pod'
|
|
284
285
|
assert kwargs['body']['apiVersion'] == 'v1'
|
|
285
286
|
assert kwargs['body']['metadata']['name'] == 'test-pod'
|
|
@@ -303,7 +304,7 @@ class TestK8sApisOperations:
|
|
|
303
304
|
# Verify the dynamic client was used correctly
|
|
304
305
|
mock_resources.get.assert_called_once_with(api_version='v1', kind='Pod')
|
|
305
306
|
mock_resource.patch.assert_called_once()
|
|
306
|
-
|
|
307
|
+
_, kwargs = mock_resource.patch.call_args
|
|
307
308
|
assert kwargs['body']['kind'] == 'Pod'
|
|
308
309
|
assert kwargs['body']['apiVersion'] == 'v1'
|
|
309
310
|
assert kwargs['body']['metadata']['labels']['app'] == 'test'
|
|
@@ -362,7 +363,7 @@ class TestK8sApisOperations:
|
|
|
362
363
|
assert kwargs1['content_type'] == 'application/strategic-merge-patch+json'
|
|
363
364
|
|
|
364
365
|
# Check second call (merge patch fallback)
|
|
365
|
-
|
|
366
|
+
_, kwargs2 = mock_resource.patch.call_args_list[1]
|
|
366
367
|
assert kwargs2['name'] == 'test-pod'
|
|
367
368
|
assert kwargs2['namespace'] == 'default'
|
|
368
369
|
assert kwargs2['body']['kind'] == 'Pod'
|
|
@@ -383,7 +384,7 @@ class TestK8sApisOperations:
|
|
|
383
384
|
|
|
384
385
|
# Verify patch was called with strategic merge patch
|
|
385
386
|
mock_resource.patch.assert_called_once()
|
|
386
|
-
|
|
387
|
+
_, kwargs = mock_resource.patch.call_args
|
|
387
388
|
assert kwargs['body'] == body
|
|
388
389
|
assert kwargs['name'] == name
|
|
389
390
|
assert kwargs['namespace'] == namespace
|
|
@@ -408,7 +409,7 @@ class TestK8sApisOperations:
|
|
|
408
409
|
|
|
409
410
|
# Verify patch was called once with strategic merge patch
|
|
410
411
|
mock_resource.patch.assert_called_once()
|
|
411
|
-
|
|
412
|
+
_, kwargs = mock_resource.patch.call_args
|
|
412
413
|
assert kwargs['content_type'] == 'application/strategic-merge-patch+json'
|
|
413
414
|
|
|
414
415
|
def test_manage_resource_validation(self, k8s_apis):
|
|
@@ -462,7 +463,7 @@ class TestK8sApisOperations:
|
|
|
462
463
|
# Verify the dynamic client was used correctly
|
|
463
464
|
mock_resources.get.assert_called_once_with(api_version='v1', kind='Pod')
|
|
464
465
|
mock_resource.get.assert_called_once()
|
|
465
|
-
|
|
466
|
+
_, kwargs = mock_resource.get.call_args
|
|
466
467
|
assert kwargs['namespace'] == 'default'
|
|
467
468
|
assert kwargs['label_selector'] == 'app=test'
|
|
468
469
|
assert kwargs['field_selector'] == 'status.phase=Running'
|
|
@@ -481,7 +482,7 @@ class TestK8sApisOperations:
|
|
|
481
482
|
# Verify the dynamic client was used correctly
|
|
482
483
|
mock_resources.get.assert_called_once_with(api_version='v1', kind='Pod')
|
|
483
484
|
mock_resource.get.assert_called_once()
|
|
484
|
-
|
|
485
|
+
_, kwargs = mock_resource.get.call_args
|
|
485
486
|
assert 'namespace' not in kwargs
|
|
486
487
|
|
|
487
488
|
def test_list_resources_with_additional_kwargs(self, k8s_apis):
|
|
@@ -504,7 +505,7 @@ class TestK8sApisOperations:
|
|
|
504
505
|
# Verify the dynamic client was used correctly
|
|
505
506
|
mock_resources.get.assert_called_once_with(api_version='v1', kind='Pod')
|
|
506
507
|
mock_resource.get.assert_called_once()
|
|
507
|
-
|
|
508
|
+
_, kwargs = mock_resource.get.call_args
|
|
508
509
|
assert kwargs['namespace'] == 'default'
|
|
509
510
|
assert kwargs['limit'] == 100
|
|
510
511
|
assert kwargs['timeout_seconds'] == 30
|
|
@@ -1033,7 +1034,7 @@ class TestK8sApisOperations:
|
|
|
1033
1034
|
k8s_apis._patch_resource = MagicMock()
|
|
1034
1035
|
|
|
1035
1036
|
# Call the method with force=False
|
|
1036
|
-
|
|
1037
|
+
_, created_count, updated_count = k8s_apis.apply_from_yaml(yaml_objects, force=False)
|
|
1037
1038
|
|
|
1038
1039
|
# Verify results - should create new resources, not update existing ones
|
|
1039
1040
|
assert created_count == 1
|
|
@@ -1069,7 +1070,7 @@ class TestK8sApisOperations:
|
|
|
1069
1070
|
resource_mock.get.side_effect = Exception('Not found')
|
|
1070
1071
|
|
|
1071
1072
|
# Call the method
|
|
1072
|
-
|
|
1073
|
+
_, created_count, updated_count = k8s_apis.apply_from_yaml(yaml_objects)
|
|
1073
1074
|
|
|
1074
1075
|
# Verify results
|
|
1075
1076
|
assert created_count == 1
|
|
@@ -1167,7 +1168,7 @@ class TestK8sApisOperations:
|
|
|
1167
1168
|
resource_mock.get.side_effect = Exception('Not found')
|
|
1168
1169
|
|
|
1169
1170
|
# Call the method with additional kwargs
|
|
1170
|
-
|
|
1171
|
+
_, created_count, updated_count = k8s_apis.apply_from_yaml(
|
|
1171
1172
|
yaml_objects, dry_run='All', field_manager='test-manager'
|
|
1172
1173
|
)
|
|
1173
1174
|
|
|
@@ -1177,7 +1178,7 @@ class TestK8sApisOperations:
|
|
|
1177
1178
|
assert resource_mock.create.call_count == 1
|
|
1178
1179
|
|
|
1179
1180
|
# Verify create was called with correct parameters including additional kwargs
|
|
1180
|
-
|
|
1181
|
+
_, kwargs = resource_mock.create.call_args
|
|
1181
1182
|
assert kwargs['body']['kind'] == 'Deployment'
|
|
1182
1183
|
assert kwargs['dry_run'] == 'All'
|
|
1183
1184
|
assert kwargs['field_manager'] == 'test-manager'
|
|
@@ -1281,3 +1282,151 @@ class TestK8sApisOperations:
|
|
|
1281
1282
|
mock_core_api.get_api_versions.assert_called_once()
|
|
1282
1283
|
# ApisApi should not be called since CoreApi failed
|
|
1283
1284
|
mock_client.ApisApi.assert_not_called()
|
|
1285
|
+
|
|
1286
|
+
|
|
1287
|
+
class TestK8sProxySupport:
|
|
1288
|
+
"""Test proxy configuration for Kubernetes client."""
|
|
1289
|
+
|
|
1290
|
+
@pytest.fixture
|
|
1291
|
+
def mock_k8s_modules(self):
|
|
1292
|
+
"""Mock kubernetes modules."""
|
|
1293
|
+
with (
|
|
1294
|
+
patch('kubernetes.client') as mock_client,
|
|
1295
|
+
patch('kubernetes.dynamic') as mock_dynamic,
|
|
1296
|
+
):
|
|
1297
|
+
# Create mock configuration
|
|
1298
|
+
mock_config = MagicMock()
|
|
1299
|
+
mock_client.Configuration.return_value = mock_config
|
|
1300
|
+
|
|
1301
|
+
# Create mock API client
|
|
1302
|
+
mock_api_client = MagicMock()
|
|
1303
|
+
mock_client.ApiClient.return_value = mock_api_client
|
|
1304
|
+
|
|
1305
|
+
# Create mock dynamic client
|
|
1306
|
+
mock_dynamic_client = MagicMock()
|
|
1307
|
+
mock_dynamic.DynamicClient.return_value = mock_dynamic_client
|
|
1308
|
+
|
|
1309
|
+
yield {
|
|
1310
|
+
'config': mock_config,
|
|
1311
|
+
'api_client': mock_api_client,
|
|
1312
|
+
'dynamic_client': mock_dynamic_client,
|
|
1313
|
+
'client_module': mock_client,
|
|
1314
|
+
'dynamic_module': mock_dynamic,
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
def test_proxy_configuration_with_https_proxy(self, mock_k8s_modules):
|
|
1318
|
+
"""Test that HTTPS proxy settings are correctly configured."""
|
|
1319
|
+
# Set up environment variables
|
|
1320
|
+
test_env = {
|
|
1321
|
+
'HTTPS_PROXY': 'http://proxy.example.com:8080',
|
|
1322
|
+
'HTTP_PROXY': 'http://proxy.example.com:8080',
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
with patch.dict(os.environ, test_env, clear=False):
|
|
1326
|
+
# Create test data
|
|
1327
|
+
endpoint = 'https://test-cluster.eks.amazonaws.com'
|
|
1328
|
+
token = 'test-token'
|
|
1329
|
+
ca_data = base64.b64encode(b'test-ca-cert').decode()
|
|
1330
|
+
|
|
1331
|
+
# Create K8sApis instance
|
|
1332
|
+
K8sApis(endpoint, token, ca_data)
|
|
1333
|
+
|
|
1334
|
+
# Verify proxy was configured
|
|
1335
|
+
mock_config = mock_k8s_modules['config']
|
|
1336
|
+
assert mock_config.proxy == 'http://proxy.example.com:8080'
|
|
1337
|
+
|
|
1338
|
+
def test_proxy_configuration_http_fallback(self, mock_k8s_modules):
|
|
1339
|
+
"""Test that HTTP proxy is used when HTTPS proxy is not available."""
|
|
1340
|
+
# Set up environment variables with only HTTP proxy
|
|
1341
|
+
test_env = {
|
|
1342
|
+
'HTTP_PROXY': 'http://proxy.example.com:9090',
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
with patch.dict(os.environ, test_env, clear=False):
|
|
1346
|
+
# Create test data
|
|
1347
|
+
endpoint = 'https://test-cluster.eks.amazonaws.com'
|
|
1348
|
+
token = 'test-token'
|
|
1349
|
+
ca_data = base64.b64encode(b'test-ca-cert').decode()
|
|
1350
|
+
|
|
1351
|
+
# Create K8sApis instance
|
|
1352
|
+
K8sApis(endpoint, token, ca_data)
|
|
1353
|
+
|
|
1354
|
+
# Verify HTTP proxy was configured
|
|
1355
|
+
mock_config = mock_k8s_modules['config']
|
|
1356
|
+
assert mock_config.proxy == 'http://proxy.example.com:9090'
|
|
1357
|
+
|
|
1358
|
+
def test_proxy_configuration_lowercase_env_vars(self, mock_k8s_modules):
|
|
1359
|
+
"""Test that lowercase proxy environment variables are supported."""
|
|
1360
|
+
# Set up environment variables with lowercase names
|
|
1361
|
+
test_env = {
|
|
1362
|
+
'https_proxy': 'http://proxy.example.com:8080',
|
|
1363
|
+
'http_proxy': 'http://proxy.example.com:8080',
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
with patch.dict(os.environ, test_env, clear=False):
|
|
1367
|
+
# Create test data
|
|
1368
|
+
endpoint = 'https://test-cluster.eks.amazonaws.com'
|
|
1369
|
+
token = 'test-token'
|
|
1370
|
+
ca_data = base64.b64encode(b'test-ca-cert').decode()
|
|
1371
|
+
|
|
1372
|
+
# Create K8sApis instance
|
|
1373
|
+
K8sApis(endpoint, token, ca_data)
|
|
1374
|
+
|
|
1375
|
+
# Verify proxy was configured
|
|
1376
|
+
mock_config = mock_k8s_modules['config']
|
|
1377
|
+
assert mock_config.proxy == 'http://proxy.example.com:8080'
|
|
1378
|
+
|
|
1379
|
+
def test_no_proxy_configuration_when_env_vars_absent(self, mock_k8s_modules):
|
|
1380
|
+
"""Test that no proxy is configured when environment variables are not set."""
|
|
1381
|
+
# Ensure proxy environment variables are not set by removing them
|
|
1382
|
+
proxy_vars = ['HTTP_PROXY', 'HTTPS_PROXY', 'http_proxy', 'https_proxy']
|
|
1383
|
+
|
|
1384
|
+
# Save original values and remove them
|
|
1385
|
+
original_values = {}
|
|
1386
|
+
for var in proxy_vars:
|
|
1387
|
+
original_values[var] = os.environ.get(var)
|
|
1388
|
+
if var in os.environ:
|
|
1389
|
+
del os.environ[var]
|
|
1390
|
+
|
|
1391
|
+
try:
|
|
1392
|
+
# Create test data
|
|
1393
|
+
endpoint = 'https://test-cluster.eks.amazonaws.com'
|
|
1394
|
+
token = 'test-token'
|
|
1395
|
+
ca_data = base64.b64encode(b'test-ca-cert').decode()
|
|
1396
|
+
|
|
1397
|
+
# Create K8sApis instance
|
|
1398
|
+
k8s_apis = K8sApis(endpoint, token, ca_data)
|
|
1399
|
+
|
|
1400
|
+
# Verify no proxy was configured - with no proxy env vars,
|
|
1401
|
+
# the proxy attribute should remain as the default MagicMock
|
|
1402
|
+
mock_k8s_modules['config']
|
|
1403
|
+
# Since we can't easily check if proxy was set with MagicMock,
|
|
1404
|
+
# we just verify the instance was created successfully
|
|
1405
|
+
assert k8s_apis is not None
|
|
1406
|
+
|
|
1407
|
+
finally:
|
|
1408
|
+
# Restore original values
|
|
1409
|
+
for var, value in original_values.items():
|
|
1410
|
+
if value is not None:
|
|
1411
|
+
os.environ[var] = value
|
|
1412
|
+
|
|
1413
|
+
def test_proxy_configuration_with_mixed_case_env_vars(self, mock_k8s_modules):
|
|
1414
|
+
"""Test that uppercase proxy variables take precedence over lowercase."""
|
|
1415
|
+
# Set up environment variables with both cases
|
|
1416
|
+
test_env = {
|
|
1417
|
+
'HTTPS_PROXY': 'http://uppercase-proxy.example.com:8080',
|
|
1418
|
+
'https_proxy': 'http://lowercase-proxy.example.com:8080',
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
with patch.dict(os.environ, test_env, clear=False):
|
|
1422
|
+
# Create test data
|
|
1423
|
+
endpoint = 'https://test-cluster.eks.amazonaws.com'
|
|
1424
|
+
token = 'test-token'
|
|
1425
|
+
ca_data = base64.b64encode(b'test-ca-cert').decode()
|
|
1426
|
+
|
|
1427
|
+
# Create K8sApis instance
|
|
1428
|
+
K8sApis(endpoint, token, ca_data)
|
|
1429
|
+
|
|
1430
|
+
# Verify uppercase proxy was used
|
|
1431
|
+
mock_config = mock_k8s_modules['config']
|
|
1432
|
+
assert mock_config.proxy == 'http://uppercase-proxy.example.com:8080'
|