k8s-helper-cli 0.4.1__py3-none-any.whl → 0.4.3__py3-none-any.whl

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.
k8s_helper/__init__.py CHANGED
@@ -20,7 +20,7 @@ from .utils import (
20
20
  create_service_manifest
21
21
  )
22
22
 
23
- __version__ = "0.4.0"
23
+ __version__ = "0.4.3"
24
24
  __author__ = "Harshit Chatterjee"
25
25
  __email__ = "harshitchatterjee50@gmail.com"
26
26
 
k8s_helper/cli.py CHANGED
@@ -1400,6 +1400,14 @@ def setup_monitoring(
1400
1400
  if result['success']:
1401
1401
  console.print("✅ Monitoring stack deployed successfully!")
1402
1402
 
1403
+ # Show warning if Grafana configuration failed
1404
+ if result.get('warning'):
1405
+ console.print(f"⚠️ {result['warning']}")
1406
+ console.print("💡 You can manually configure Grafana by:")
1407
+ console.print(" 1. Accessing Grafana with admin/admin123")
1408
+ console.print(" 2. Adding Prometheus as a data source")
1409
+ console.print(f" 3. Use URL: http://prometheus-service.{result['namespace']}.svc.cluster.local:9090")
1410
+
1403
1411
  # Show deployment summary
1404
1412
  console.print(f"\n📋 Deployment Summary:")
1405
1413
  console.print(f"📍 Namespace: {result['namespace']}")
@@ -1412,6 +1420,12 @@ def setup_monitoring(
1412
1420
  if result['grafana']['deployed']:
1413
1421
  console.print("✅ Grafana: Deployed")
1414
1422
  console.print(f"🔑 Admin credentials: {result['grafana']['admin_user']}/{result['grafana']['admin_password']}")
1423
+
1424
+ # Show Grafana configuration status
1425
+ if result.get('grafana_configured', True):
1426
+ console.print("✅ Grafana: Automatically configured with Prometheus")
1427
+ else:
1428
+ console.print("⚠️ Grafana: Manual configuration required")
1415
1429
  else:
1416
1430
  console.print("❌ Grafana: Failed to deploy")
1417
1431
 
k8s_helper/core.py CHANGED
@@ -1724,8 +1724,11 @@ class K8sClient:
1724
1724
  # Configure Grafana data source and dashboard
1725
1725
  if self._configure_grafana(namespace, import_dashboard):
1726
1726
  result['success'] = True
1727
+ result['grafana_configured'] = True
1727
1728
  else:
1728
- result['error'] = "Failed to configure Grafana"
1729
+ result['success'] = True # Still successful even if config fails
1730
+ result['grafana_configured'] = False
1731
+ result['warning'] = "Grafana deployed but automatic configuration failed"
1729
1732
  else:
1730
1733
  result['error'] = "Monitoring deployments failed to become ready"
1731
1734
  else:
@@ -1964,15 +1967,33 @@ scrape_configs:
1964
1967
  raise e
1965
1968
 
1966
1969
  # ClusterRoleBinding
1967
- cluster_role_binding = client.V1ClusterRoleBinding(
1968
- metadata=client.V1ObjectMeta(name="prometheus"),
1969
- subjects=[
1970
- client.V1Subject(
1970
+ # Create subject with version compatibility
1971
+ try:
1972
+ # Try V1Subject first (older versions)
1973
+ subject = client.V1Subject(
1974
+ kind="ServiceAccount",
1975
+ name="prometheus",
1976
+ namespace=namespace
1977
+ )
1978
+ except AttributeError:
1979
+ # Try RbacV1Subject (newer versions)
1980
+ try:
1981
+ subject = client.RbacV1Subject(
1971
1982
  kind="ServiceAccount",
1972
1983
  name="prometheus",
1973
1984
  namespace=namespace
1974
1985
  )
1975
- ],
1986
+ except AttributeError:
1987
+ # Manual construction as fallback
1988
+ subject = {
1989
+ 'kind': 'ServiceAccount',
1990
+ 'name': 'prometheus',
1991
+ 'namespace': namespace
1992
+ }
1993
+
1994
+ cluster_role_binding = client.V1ClusterRoleBinding(
1995
+ metadata=client.V1ObjectMeta(name="prometheus"),
1996
+ subjects=[subject],
1976
1997
  role_ref=client.V1RoleRef(
1977
1998
  kind="ClusterRole",
1978
1999
  name="prometheus",
@@ -2106,9 +2127,6 @@ scrape_configs:
2106
2127
  def _configure_grafana(self, namespace: str, import_dashboard: bool = True) -> bool:
2107
2128
  """Configure Grafana with Prometheus data source and dashboard"""
2108
2129
  try:
2109
- # Wait a bit for Grafana to fully start
2110
- time.sleep(10)
2111
-
2112
2130
  import requests
2113
2131
  import json
2114
2132
 
@@ -2120,6 +2138,32 @@ scrape_configs:
2120
2138
 
2121
2139
  print(f"🔧 Configuring Grafana at {grafana_url}")
2122
2140
 
2141
+ # Wait for Grafana to be accessible with retry logic
2142
+ max_retries = 12 # 2 minutes total (12 * 10 seconds)
2143
+ retry_count = 0
2144
+ auth = ('admin', 'admin123')
2145
+
2146
+ while retry_count < max_retries:
2147
+ try:
2148
+ # Test connection to Grafana
2149
+ health_response = requests.get(
2150
+ f"{grafana_url}/api/health",
2151
+ auth=auth,
2152
+ timeout=10
2153
+ )
2154
+ if health_response.status_code == 200:
2155
+ print("✅ Grafana is accessible")
2156
+ break
2157
+ except Exception as e:
2158
+ retry_count += 1
2159
+ if retry_count < max_retries:
2160
+ print(f"⏳ Waiting for Grafana to be accessible... (attempt {retry_count}/{max_retries})")
2161
+ time.sleep(10)
2162
+ else:
2163
+ print(f"❌ Grafana not accessible after {max_retries} attempts")
2164
+ print("💡 You can manually add Prometheus as a data source in Grafana")
2165
+ return False
2166
+
2123
2167
  # Add Prometheus data source
2124
2168
  datasource_payload = {
2125
2169
  "name": "Prometheus",
@@ -2129,20 +2173,27 @@ scrape_configs:
2129
2173
  "isDefault": True
2130
2174
  }
2131
2175
 
2132
- auth = ('admin', 'admin123')
2133
-
2134
- # Add data source
2135
- response = requests.post(
2136
- f"{grafana_url}/api/datasources",
2137
- json=datasource_payload,
2138
- auth=auth,
2139
- timeout=30
2140
- )
2141
-
2142
- if response.status_code in [200, 409]: # Success or already exists
2143
- print("✅ Prometheus data source configured")
2144
- else:
2145
- print(f"⚠️ Warning: Could not add Prometheus data source: {response.text}")
2176
+ # Try to add data source with retry
2177
+ for attempt in range(3):
2178
+ try:
2179
+ response = requests.post(
2180
+ f"{grafana_url}/api/datasources",
2181
+ json=datasource_payload,
2182
+ auth=auth,
2183
+ timeout=30
2184
+ )
2185
+
2186
+ if response.status_code in [200, 409]: # Success or already exists
2187
+ print("✅ Prometheus data source configured")
2188
+ break
2189
+ else:
2190
+ print(f"⚠️ Attempt {attempt + 1}: Could not add Prometheus data source: {response.text}")
2191
+ if attempt < 2:
2192
+ time.sleep(5)
2193
+ except Exception as e:
2194
+ print(f"⚠️ Attempt {attempt + 1}: Error adding data source: {e}")
2195
+ if attempt < 2:
2196
+ time.sleep(5)
2146
2197
 
2147
2198
  # Import default dashboard if requested
2148
2199
  if import_dashboard:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: k8s-helper-cli
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Summary: A simplified Python wrapper for common Kubernetes operations
5
5
  Author-email: Harshit Chatterjee <harshitchatterjee50@gmail.com>
6
6
  License-Expression: MIT
@@ -0,0 +1,11 @@
1
+ k8s_helper/__init__.py,sha256=8xOzKrONciTYSjLyhDKR4cQs5wVVtW0UZll7TnsTpqQ,2666
2
+ k8s_helper/cli.py,sha256=g0hzBHaROOT0gbKN5xu5GeC-aqbIyXpl3U-xx7vNWEU,80259
3
+ k8s_helper/config.py,sha256=P7YdfyvCHprrNs2J9DRb3RrClylfTTh5hfTtDzLug0A,6867
4
+ k8s_helper/core.py,sha256=R0_EDqVGFWQCpu5YuWC4abLLWIqjFtpn6KHgGD_Wues,112490
5
+ k8s_helper/utils.py,sha256=wYgTd5ktyuI-EiVcfW7FrxA7MzXY5odrEKQgmMVdueY,9496
6
+ k8s_helper_cli-0.4.3.dist-info/licenses/LICENSE,sha256=tXPvVl3gLVc6e0qCEoLH9KjeA7z4JVL78UybpvGtBCw,1096
7
+ k8s_helper_cli-0.4.3.dist-info/METADATA,sha256=-uygNSjY9k0yhuw6KPwft5Uu-77b0GBGCPRURlt4PEM,30789
8
+ k8s_helper_cli-0.4.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ k8s_helper_cli-0.4.3.dist-info/entry_points.txt,sha256=IoCMWUZ6mn90LwzQzEy5YkWOwvogDdZ6ycqUWAzCFTQ,50
10
+ k8s_helper_cli-0.4.3.dist-info/top_level.txt,sha256=x9A1jflyer-z2cFnkqk5B42juoH2q0fy5hkT9upsTG8,11
11
+ k8s_helper_cli-0.4.3.dist-info/RECORD,,
@@ -1,11 +0,0 @@
1
- k8s_helper/__init__.py,sha256=XDUF1icyJlQZbTC8B1N4sI8nxUs9X9nJO2EOHzVVq4E,2666
2
- k8s_helper/cli.py,sha256=ngXnZ-6EaTm9hCViLPOLZya4HtFDsqpPbLYnOBEfQmA,79400
3
- k8s_helper/config.py,sha256=P7YdfyvCHprrNs2J9DRb3RrClylfTTh5hfTtDzLug0A,6867
4
- k8s_helper/core.py,sha256=g6PjbbOqfc9n6CbSJLmglxaDLYdLZltc1V2z0bxpAHk,109980
5
- k8s_helper/utils.py,sha256=wYgTd5ktyuI-EiVcfW7FrxA7MzXY5odrEKQgmMVdueY,9496
6
- k8s_helper_cli-0.4.1.dist-info/licenses/LICENSE,sha256=tXPvVl3gLVc6e0qCEoLH9KjeA7z4JVL78UybpvGtBCw,1096
7
- k8s_helper_cli-0.4.1.dist-info/METADATA,sha256=xwNsN6p-TUlQLnN-9HtMEu-Z5cnvlRIFt4F8SmfKzKM,30789
8
- k8s_helper_cli-0.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- k8s_helper_cli-0.4.1.dist-info/entry_points.txt,sha256=IoCMWUZ6mn90LwzQzEy5YkWOwvogDdZ6ycqUWAzCFTQ,50
10
- k8s_helper_cli-0.4.1.dist-info/top_level.txt,sha256=x9A1jflyer-z2cFnkqk5B42juoH2q0fy5hkT9upsTG8,11
11
- k8s_helper_cli-0.4.1.dist-info/RECORD,,