Skip to content

K8s RBAC issue on namespace scope #207

Closed

Description

@rohank07

Describe the bug

I am trying to run krr without cluster-admin permissions. This doesn't seem possible with the tool trying to get dameonsets, hpa, deployments, jobs etc. using on all namespaces on the cluster even though I am scoping it to a specific namespace. Looking to modify the source code to avoid calling all_namespaces_request function in init..py Looking for additional guidance if this is the way to go about this

Are you interested in contributing a fix for this?
Yes

Activity

  1. changed the title [-]K8s RBAC on namespace scope[/-] [+]K8s RBAC issue on namespace scope[/+] on Feb 9, 2024
  2. bondido commented on Feb 12, 2024

    @bondido

    Shouldn't it be possible to run krr not "touching" kubectl context in any way?
    If we have all data available with prometheus metrics, shouldn't it be enough to only get access to it?

    If no, then there should be info in the docs regarding minimal required RBAC privileges.

  3. aantn commented on Feb 13, 2024

    @aantn
    Contributor

    @bondido regarding not using kubectl at all, this would be a good improvement but its not possible today. KRR first discovers workloads in the cluster, then reaches out to Prometheus to fetch relevant metrics. This has some advantages, like enabling us to chunk requests to Prometheus and not fetch everything in a single large query. (There are performance implications for Prometheus itself.) Documenting this would be a good idea though. Please feel free to open a PR based on the code here.

    @rohank07 do you know which API call it is failing on? Is it possibly the HPA API? I think the others are namespaced.

  4. rohank07 commented on Feb 13, 2024

    @rohank07
    ContributorAuthor

    I've commented out https://github.com/robusta-dev/krr/blob/main/robusta_krr/core/integrations/kubernetes/__init__.py#L66
    and https://github.com/robusta-dev/krr/blob/main/robusta_krr/core/integrations/kubernetes/__init__.py#L134

    After commenting out those lines it fails on GET request calling self.list_namespaced_deployment_with_http_info
    Stack trace

    Error 403 listing Deployment in cluster <>: Forbidden                       __init__.py:198
                        Traceback (most recent call last):                                                                                     
                          File "/home/Code/krr/robusta_krr/core/integrations/kubernetes/__init__.py", line 185, in                      
                        _list_workflows                                                                                                        
                            ret_single = await task                                                                                            
                          File "/usr/lib/python3.10/asyncio/tasks.py", line 571, in _wait_for_one                                              
                            return f.result()  # May raise f.exception().                                                                      
                          File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run                                             
                            result = self.fn(*self.args, **self.kwargs)                                                                        
                          File "/home/Code/krr/robusta_krr/core/integrations/kubernetes/__init__.py", line 174, in                      
                        <lambda>                                                                                                               
                            lambda ns=namespace: namespaced_request(                                                                           
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/api/apps_v1_api.py", line                   
                        3345, in list_namespaced_deployment                                                                                    
                            return self.list_namespaced_deployment_with_http_info(namespace, **kwargs)  # noqa: E501                           
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/api/apps_v1_api.py", line                   
                        3460, in list_namespaced_deployment_with_http_info                                                                     
                            return self.api_client.call_api(                                                                                   
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/api_client.py", line 348, in                
                        call_api                                                                                                               
                            return self.__call_api(resource_path, method,                                                                      
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/api_client.py", line 180, in                
                        __call_api                                                                                                             
                            response_data = self.request(                                                                                      
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/api_client.py", line 373, in                
                        request                                                                                                                
                            return self.rest_client.GET(url,                                                                                   
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/rest.py", line 241, in GET                  
                            return self.request("GET", url,                                                                                    
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/rest.py", line 235, in                      
                        request                                                                                                                
                            raise ApiException(http_resp=r)                                                                                    
                        kubernetes.client.exceptions.ApiException: (403)                                                                       
                        Reason: Forbidden                                                                                                      
                        HTTP response headers: HTTPHeaderDict({'Audit-Id': '',                             
                        'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'X-Content-Type-Options':                    
                        'nosniff', 'X-Kubernetes-Pf-Flowschema-Uid': '',                                   
                        'X-Kubernetes-Pf-Prioritylevel-Uid': '', 'Date': 'Tue, 13 Feb 2024                 
                        14:26:01 GMT', 'Content-Length': '315'})                                                                               
                        HTTP response body:                                                                                                    
                        {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"deployments.apps is                     
                        forbidden: User \"<user>\" cannot list resource \"deployments\" in API group \"apps\" in                 
                        the namespace                                                                                                          
                        \"<namespace>\"","reason":"Forbidden","details":{"group":"apps","kind":"deployments"},"code":403}      
    
    

    403s are also thrown for dameonSet, job and statefulset. This works fine when I have cluster-admin privileges' on the cluster

  5. aantn commented on Feb 13, 2024

    @aantn
    Contributor

    Where it says "<namespace>", does it actually say that, or did you sanitize the logs?

  6. rohank07 commented on Feb 13, 2024

    @rohank07
    ContributorAuthor

    Yup, I sanitized the logs

  7. aantn commented on Feb 14, 2024

    @aantn
    Contributor

    This is strange. Does the equivalent kubectl get command work in the same shell, without cluster-admin?

    Is it possible you have multiple kubectl contexts and the wrong context is being picked up here?

  8. rohank07 commented on Feb 14, 2024

    @rohank07
    ContributorAuthor

    Turns out when I scope it to a specific namespace that I have access to (without cluster-admin)
    It throws me a 403 on services at the cluster scope.
    python3 krr.py simple -n test-namespace

     HTTP response body:                                                                                                    
                        {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"services is forbidden:                  
                        User \"<USER>\" cannot list resource \"services\" in API group \"\" at the cluster                       
                        scope","reason":"Forbidden","details":{"kind":"services"},"code":403} 
    

    If I run kubectl get svc -n <test-namespace> it retruns me a list of namespaces. I am on the correct kubectl context.

  9. rohank07 commented on Feb 14, 2024

    @rohank07
    ContributorAuthor

    It looks for all services in the cluster, even when you scope it to a particular namespace?
    stack trace:

    Traceback (most recent call last):                                                                                     
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 242, in run                                            
                            result = await self._collect_result()                                                                              
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 198, in _collect_result                                
                            scans = await asyncio.gather(*scans_tasks)                                                                         
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                          
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 132, in _calculate_object_recommendations              
                            prometheus_loader = self._get_prometheus_loader(object.cluster)                                                    
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 53, in _get_prometheus_loader                          
                            raise result                                                                                                       
                          File "/home/Code/krr/robusta_krr/core/runner.py", line 42, in _get_prometheus_loader                          
                            self._metrics_service_loaders[cluster] = PrometheusMetricsLoader(cluster=cluster)                                  
                          File "/home/Code/krr/robusta_krr/core/integrations/prometheus/loader.py", line 47, in __init__                
                            loader = self.get_metrics_service(api_client=self.api_client, cluster=cluster)                                     
                          File "/home/Code/krr/robusta_krr/core/integrations/prometheus/loader.py", line 62, in                         
                        get_metrics_service                                                                                                    
                            loader = metric_service_class(api_client=api_client, cluster=cluster, executor=self.executor)                      
                          File                                                                                                                 
                        "/home/Code/krr/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_servic              
                        e.py", line 71, in __init__                                                                                            
                            self.url = self.url or self.prometheus_discovery.find_metrics_url()                                                
                          File                                                                                                                 
                        "/home/Code/krr/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_servic              
                        e.py", line 34, in find_metrics_url                                                                                    
                            return super().find_url(                                                                                           
                          File "/home/Code/krr/robusta_krr/utils/service_discovery.py", line 74, in find_url                            
                            service_url = self.find_service_url(label_selector)                                                                
                          File "/home/Code/krr/robusta_krr/utils/service_discovery.py", line 30, in find_service_url                    
                            svc_list: V1ServiceList = v1.list_service_for_all_namespaces(label_selector=label_selector)                        
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/api/core_v1_api.py", line                   
                        18239, in list_service_for_all_namespaces                                                                              
                            return self.list_service_for_all_namespaces_with_http_info(**kwargs)  # noqa: E501                                 
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/api/core_v1_api.py", line                   
                        18346, in list_service_for_all_namespaces_with_http_info                                                               
                            return self.api_client.call_api(                                                                                   
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/api_client.py", line 348, in                
                        call_api                                                                                                               
                            return self.__call_api(resource_path, method,                                                                      
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/api_client.py", line 180, in                
                        __call_api                                                                                                             
                            response_data = self.request(                                                                                      
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/api_client.py", line 373, in                
                        request                                                                                                                
                            return self.rest_client.GET(url,                                                                                   
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/rest.py", line 241, in GET                  
                            return self.request("GET", url,                                                                                    
                          File "/home/.local/lib/python3.10/site-packages/kubernetes/client/rest.py", line 235, in request              
                            raise ApiException(http_resp=r)                                                                                    
                        kubernetes.client.exceptions.ApiException: (403)                                                                       
                        Reason: Forbidden                                                                                                      
                        HTTP response headers: HTTPHeaderDict({'Audit-Id': '',                             
                        'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'X-Content-Type-Options':                    
                        'nosniff', 'X-Kubernetes-Pf-Flowschema-Uid': '',                                   
                        'X-Kubernetes-Pf-Prioritylevel-Uid': '', 'Date': 'Wed, 14 Feb 2024                 
                        14:47:11 GMT', 'Content-Length': '269'})                                                                               
                        HTTP response body:                                                                                                    
                        {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"services is forbidden:                  
                        User \"<user>\" cannot list resource \"services\" in API group \"\" at the cluster                       
                        scope","reason":"Forbidden","details":{"kind":"services"},"code":403}
    
  10. rohank07 commented on Feb 14, 2024

    @rohank07
    ContributorAuthor
  11. aantn commented on Feb 18, 2024

    @aantn
    Contributor

    Thanks, looking into it.

  12. rohank07 commented on Feb 25, 2024

    @rohank07
    ContributorAuthor

    Any updates on this?

  13. aantn commented on Mar 2, 2024

    @aantn
    Contributor

    Sorry about the delay. Does #220 fix this for you?
    Note that:

    1. HPA detection is still broken on Improve support for limited permissions #220 (for now) but everything else should work
    2. You will have to explicitly specify Prometheus's url with -p as auto-detection requires cluster permissions to read all service accounts.
  14. rohank07 commented on Mar 3, 2024

    @rohank07
    ContributorAuthor

    When running python3 krr.py simple --as system:serviceaccount:<namespace>:krr-account -n <namespace> -p http://127.0.0.1:9090 I get the following for each pod in the namespace

            ERROR    Failed to load pods for Deployment <namespace>/<svcName>/<DeploymentName>: 'CustomPrometheusConnect' object has  loader.py:74
                        no attribute 'safe_custom_query'                                                                                                                       
                        Traceback (most recent call last):                                                                                                                     
                          File "/home/user/Code/krr/robusta_krr/core/integrations/prometheus/loader.py", line 72, in load_pods                                               
                            return await self.loader.load_pods(object, period)                                                                                                 
                          File "/home/user/Code/krr/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py", line 183, in                    
                        load_pods                                                                                                                                              
                            replicasets = await self.query(                                                                                                                    
                          File "/home/user/Code/krr/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py", line 111, in query              
                            return await loop.run_in_executor(self.executor, lambda: self.prometheus.safe_custom_query(query=query))                                           
                          File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run                                                                             
                            result = self.fn(*self.args, **self.kwargs)                                                                                                        
                          File "/home/user/Code/krr/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py", line 111, in                    
                        <lambda>                                                                                                                                               
                            return await loop.run_in_executor(self.executor, lambda: self.prometheus.safe_custom_query(query=query))                                           
                        AttributeError: 'CustomPrometheusConnect' object has no attribute 'safe_custom_query'             
     WARNING  Was not able to load any pods for Deployment <namespace>/<svc>/<deployment> from Prometheus.            runner.py:145
                                This could mean that Prometheus is missing some required metrics.                                                                              
                                Loaded pods from Kubernetes API instead.                                                                                                       
                                See more info at https://github.com/robusta-dev/krr#requirements                                                                               
               DEBUG    Gathering PercentileCPULoader metric for Deployment <namespace>/<svc>/<deployment>  prometheus_metrics_service.py:150
               ERROR    An unexpected error occurred                                                                                                              runner.py:248
                        Traceback (most recent call last):                                                                                                                     
                          File "/home/user/Code/krr/robusta_krr/core/runner.py", line 242, in run                                                                            
                            result = await self._collect_result()                                                                                                              
                          File "/home/user/Code/krr/robusta_krr/core/runner.py", line 198, in _collect_result                                                                
                            scans = await asyncio.gather(*scans_tasks)                                                                                                         
                          File "/home/user/Code/krr/robusta_krr/core/runner.py", line 168, in _gather_object_allocations                                                     
                            recommendation = await self._calculate_object_recommendations(k8s_object)                                                                          
                          File "/home/user/Code/krr/robusta_krr/core/runner.py", line 152, in _calculate_object_recommendations                                              
                            metrics = await prometheus_loader.gather_data(                                                                                                     
                          File "/home/user/Code/krr/robusta_krr/core/integrations/prometheus/loader.py", line 98, in gather_data                                             
                            return {                                                                                                                                           
                          File "/home/user/Code/krr/robusta_krr/core/integrations/prometheus/loader.py", line 99, in <dictcomp>                                              
                            MetricLoader.__name__: await self.loader.gather_data(object, MetricLoader, period, step)                                                           
                          File "/home/user/Code/krr/robusta_krr/core/integrations/prometheus/metrics_service/prometheus_metrics_service.py", line 153, in                    
                        gather_data                                                                                                                                            
                            data = await metric_loader.load_data(object, period, step)                                                                                         
                          File "/home/user/Code/krr/robusta_krr/core/integrations/prometheus/metrics/base.py", line 182, in load_data                                        
                            result = await self.query_prometheus(                                                                                                              
                          File "/home/user/Code/krr/robusta_krr/core/integrations/prometheus/metrics/base.py", line 148, in query_prometheus                                 
                            return await loop.run_in_executor(self.executor, lambda: self._query_prometheus_sync(data))                                                        
                          File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run                                                                             
                            result = self.fn(*self.args, **self.kwargs)                                                                                                        
                          File "/home/user/Code/krr/robusta_krr/core/integrations/prometheus/metrics/base.py", line 148, in <lambda>                                         
                            return await loop.run_in_executor(self.executor, lambda: self._query_prometheus_sync(data))                                                        
                          File "/home/user/Code/krr/robusta_krr/core/integrations/prometheus/metrics/base.py", line 129, in _query_prometheus_sync                           
                            response = self.prometheus.safe_custom_query(query=data.query)                                                                                     
                        AttributeError: 'CustomPrometheusConnect' object has no attribute 'safe_custom_query'
    
    
  15. aantn commented on Mar 4, 2024

    @aantn
    Contributor
  16. rohank07 commented on Mar 4, 2024

    @rohank07
    ContributorAuthor

    Thanks! It works now. Can the CLI get support for --as-group ?

    PR: #224

  17. aantn commented on Mar 5, 2024

    @aantn
    Contributor

    I've added support to the PR for reading HPA information with limited permissions. Please check and confirm that it works for you.

  18. rohank07 commented on Mar 5, 2024

    @rohank07
    ContributorAuthor

    This works for me without any issues with HPA. Thank you for all the help on this! Hope to have this merged into main really soon!
    Closing Issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions