microsoft / mindaro

Bridge to Kubernetes - for Visual Studio and Visual Studio Code
MIT License
307 stars 106 forks source link

Prep Connect -> Object Not Set error #178

Closed cotepatrice closed 3 years ago

cotepatrice commented 3 years ago

Describe the bug In Visual Studio 2019, Bridge To Kubernetes doesn't start anymore. I have a service in my local Docker Desktop cluster (default namespace). I tried to connect to it after setting all the right values in the configuration page (Kube Config Cluster: docker-desktop, Namespace: default, Service: , no routing isolation, application url : http://localhost:7778). When I try to launch the Bridge To Kubernetes debug, I get an "Object not set to an instance of an object" infamous error. It didn't prompt me for elevated permissions so that what seems to be the cause but I have no clue how to fix it. I looked at previous threads but can't seem to find a straight answer.

Logs bridge-mindarocli log :

 2021-05-27T17:09:47.5495584Z | MindaroCli | TRACE | Event: Command.Start <json>{"properties":{"arguments":"prep-connect --namespace default --output json","isRoutingEnabled":"false"},"metrics":null}</json>\nOperation context: <json>{"clientRequestId":null,"correlationId":"7179543c-75b5-4191-848a-1ca7666fa792:f25c9dd4eb4b","requestId":null,"userSubscriptionId":null,"startTime":"2021-05-27T17:09:47.1245737Z","userAgent":"LPK/2.1.20210515.1-887601f7 VisualStudio/16.9.31205.134","requestHttpMethod":null,"requestUri":null,"version":"1.0.20210421.2","requestHeaders":{},"loggingProperties":{"applicationName":"MindaroCli","deviceOperatingSystem":"Microsoft Windows 10.0.18363","framework":".NET Core 3.1.15","macAddressHash":"6b6cf3593ed53b629063e5628b1a44e5d48e28cc8c6bfd9a081816b3feb421e7","processId":27028,"targetEnvironment":"Production","commandId":"f25c9dd4eb4b"}}</json>
2021-05-27T17:09:47.7597267Z | MindaroCli | TRACE | Running Microsoft.BridgeToKubernetes.Exe.Commands.Connect.PrepConnectCommand...
2021-05-27T17:09:47.7654449Z | MindaroCli | TRACE | Initializing progress reporter...
2021-05-27T17:09:49.3358082Z | MindaroCli | ERROR | Dependency: Prep Connect <json>{"target":null,"success":false,"duration":null,"properties":{"requestId":"null","clientRequestId":"null","correlationRequestId":"null"}}</json>
2021-05-27T17:09:50.2650522Z | MindaroCli | ERROR | An unexpected error occurred: 'Object reference not set to an instance of an object.'\n
2021-05-27T17:09:50.2656239Z | MindaroCli | ERROR | To see our active issues or file a bug report, please visit https://aka.ms/bridge-to-k8s-report.\n
2021-05-27T17:09:50.2660561Z | MindaroCli | ERROR | For diagnostic information, see logs at 'C:\Users\li27tk\AppData\Local\Temp\Bridge To Kubernetes'.\n
2021-05-27T17:09:50.2801967Z | MindaroCli | ERROR | Logging handled exception: System.NullReferenceException: {"ClassName":"System.NullReferenceException","Message":"Object reference not set to an instance of an object.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)\r\n   at System.Collections.Generic.Dictionary`2.ContainsKey(TKey key)\r\n   at Microsoft.BridgeToKubernetes.Library.Connect.KubernetesRemoteEnvironmentManager.<>c__DisplayClass31_0.<_CollectServicesToRouteAsync>b__3(V1Endpoints e)\r\n   at System.Collections.Generic.IEnumerableExtensions.ExecuteForEach[T](IEnumerable`1 items, Action`1 action, CancellationToken cancellationToken)\r\n   at Microsoft.BridgeToKubernetes.Library.Connect.KubernetesRemoteEnvironmentManager.<>c__DisplayClass31_0.<<_CollectServicesToRouteAsync>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.BridgeToKubernetes.Library.Connect.KubernetesRemoteEnvironmentManager.GetReachableServicesAsync(String namespaceName, ILocalProcessConfig localProcessConfig, IProgress`1 progress, CancellationToken cancellationToken)\r\n   at Microsoft.BridgeToKubernetes.Library.ManagementClients.ConnectManagementClient.<>c__DisplayClass13_0.<<GetElevationRequestsAsync>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.BridgeToKubernetes.Library.ManagementClients.ManagementClientExceptionStrategy.RunWithHandlingAsync[T](Func`1 func, FailureConfig failureConfig)\r\n   at Microsoft.BridgeToKubernetes.Library.ManagementClients.ConnectManagementClient.GetElevationRequestsAsync(IProgress`1 progress, CancellationToken cancellationToken)\r\n   at Microsoft.BridgeToKubernetes.Exe.Commands.Connect.PrepConnectCommand.ExecuteAsync()\r\n   at Microsoft.BridgeToKubernetes.Exe.CliApp.RunCommandAsync(String[] args, CancellationToken cancellationToken)\r\n   at Microsoft.BridgeToKubernetes.Exe.CliApp.ExecuteAsync(String[] args, CancellationToken cancellationToken)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2147467261,"Source":"System.Private.CoreLib","WatsonBuckets":null}
2021-05-27T17:09:50.2821381Z | MindaroCli | TRACE | Event: Command.End <json>{"properties":{"arguments":"prep-connect --namespace default --output json","result":"Failed","failureReason":"Object reference not set to an instance of an object."},"metrics":{"duration":2834.0}}</json>

bridge-library log :

 2021-05-27T17:09:47.8003760Z | Library | TRACE | Pulling kubeconfig...\nOperation context: <json>{"clientRequestId":null,"correlationId":"7179543c-75b5-4191-848a-1ca7666fa792:f25c9dd4eb4b:e5b35568b0a8","requestId":null,"userSubscriptionId":null,"startTime":"2021-05-27T17:09:47.7324441Z","userAgent":"LPK/2.1.20210515.1-887601f7 VisualStudio/16.9.31205.134","requestHttpMethod":null,"requestUri":null,"version":"1.0.20210421.2","requestHeaders":{},"loggingProperties":{"applicationName":"Library","deviceOperatingSystem":"Microsoft Windows 10.0.18363","framework":".NET Core 3.1.15","macAddressHash":"6b6cf3593ed53b629063e5628b1a44e5d48e28cc8c6bfd9a081816b3feb421e7","processId":27028,"targetEnvironment":"Production"}}</json>
2021-05-27T17:09:48.0928658Z | Library | TRACE | Event: CloudProvider <json>{"properties":{"clusterFQDNDomain":"DockerInternal"},"metrics":null}</json>
2021-05-27T17:09:49.0238226Z | Library | TRACE | Dependency: Kubernetes <json>{"target":"ListServicesInNamespaceAsync","success":true,"duration":null,"properties":{}}</json>
2021-05-27T17:09:49.1908194Z | Library | TRACE | Dependency: Kubernetes <json>{"target":"ListPodsInNamespaceAsync","success":true,"duration":null,"properties":{}}</json>
2021-05-27T17:09:49.1990420Z | Library | TRACE | Detected headless service with selectors. Using selectors to look for endpoints...\nOperation context: <json>{"clientRequestId":null,"correlationId":"7179543c-75b5-4191-848a-1ca7666fa792:f25c9dd4eb4b:85a74103360a","requestId":null,"userSubscriptionId":null,"startTime":"2021-05-27T17:09:47.7324441Z","userAgent":"LPK/2.1.20210515.1-887601f7 VisualStudio/16.9.31205.134","requestHttpMethod":null,"requestUri":null,"version":"1.0.20210421.2","requestHeaders":{},"loggingProperties":{"applicationName":"Library","deviceOperatingSystem":"Microsoft Windows 10.0.18363","framework":".NET Core 3.1.15","macAddressHash":"6b6cf3593ed53b629063e5628b1a44e5d48e28cc8c6bfd9a081816b3feb421e7","processId":27028,"targetEnvironment":"Production","isRoutingEnabled":false}}</json>
2021-05-27T17:09:49.2209766Z | Library | TRACE | Detected headless service with selectors. Using selectors to look for endpoints...
2021-05-27T17:09:49.2419513Z | Library | TRACE | Dependency: Kubernetes <json>{"target":"ListEndpointsInNamespaceAsync","success":true,"duration":null,"properties":{}}</json>
2021-05-27T17:09:49.2419553Z | Library | TRACE | Dependency: Kubernetes <json>{"target":"ListEndpointsInNamespaceAsync","success":true,"duration":null,"properties":{}}</json>
2021-05-27T17:09:49.2496546Z | Library | TRACE | Found 1 endpoint(s) matching headless service 'mongodb-arbiter-headless'
2021-05-27T17:09:49.2496546Z | Library | TRACE | Found 1 endpoint(s) matching headless service 'mongodb-headless'
2021-05-27T17:09:49.2642212Z | Library | TRACE | Event: KubernetesRemoteEnvironmentManager-GetReachableServices <json>{"properties":{"result":"Failed"},"metrics":{"durationInMs":1072.0}}</json>
2021-05-27T17:09:49.2698142Z | Library | TRACE | Event: ConnectManagementClient-GetElevationRequests <json>{"properties":{"result":"Failed"},"metrics":{"durationInMs":1108.0}}</json>
2021-05-27T17:09:49.2712255Z | Library | ERROR | Failed to get elevation requests.
2021-05-27T17:09:49.3200540Z | Library | ERROR | Logging handled exception: System.NullReferenceException: {"ClassName":"System.NullReferenceException","Message":"Object reference not set to an instance of an object.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":"   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)\r\n   at System.Collections.Generic.Dictionary`2.ContainsKey(TKey key)\r\n   at Microsoft.BridgeToKubernetes.Library.Connect.KubernetesRemoteEnvironmentManager.<>c__DisplayClass31_0.<_CollectServicesToRouteAsync>b__3(V1Endpoints e)\r\n   at System.Collections.Generic.IEnumerableExtensions.ExecuteForEach[T](IEnumerable`1 items, Action`1 action, CancellationToken cancellationToken)\r\n   at Microsoft.BridgeToKubernetes.Library.Connect.KubernetesRemoteEnvironmentManager.<>c__DisplayClass31_0.<<_CollectServicesToRouteAsync>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.BridgeToKubernetes.Library.Connect.KubernetesRemoteEnvironmentManager.GetReachableServicesAsync(String namespaceName, ILocalProcessConfig localProcessConfig, IProgress`1 progress, CancellationToken cancellationToken)\r\n   at Microsoft.BridgeToKubernetes.Library.ManagementClients.ConnectManagementClient.<>c__DisplayClass13_0.<<GetElevationRequestsAsync>b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at Microsoft.BridgeToKubernetes.Library.ManagementClients.ManagementClientExceptionStrategy.RunWithHandlingAsync[T](Func`1 func, FailureConfig failureConfig)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2147467261,"Source":"System.Private.CoreLib","WatsonBuckets":null}

Environment Details Client used : Visual Studio 2019 Version 16.9.4

Client's version: Operating System: Windows 10 Enterprise build 18363

UPDATE I just noticed the known issue about the presence of headless services in the cluster that may impact connection. As a matter of fact, I do have 2 MongoDb headless services in the cluster (mongodb-headless and mongodb-arbiter-headless). Maybe that's the problem.

daniv-msft commented 3 years ago

Thanks @cotepatrice for logging this issue! Sorry for the disruption of your experience, null references are indeed pretty shameful. :( I just provided a bit more details in the other issue you mention, that corresponds to the same problem: https://github.com/microsoft/mindaro/issues/177#issuecomment-850708633

I'm going to close this issue as duplicate, but please feel free to reply there, or reopen this one if I missed something and that this is different.

daniv-msft commented 3 years ago

Closed as duplicate of https://github.com/microsoft/mindaro/issues/177