openimsdk/open-im-server · error
failed to get service %s: %v
Error message
failed to get service %s: %v
What it means
getServicePort looks up the Service object to find the gRPC port. If the API server Get fails (service missing, RBAC, API unreachable) it wraps the error with the service name. Without the port, endpoints cannot be dialed.
Source
Thrown at pkg/common/discovery/kubernetes/kubernetes.go:221
func (k *KubernetesConnManager) Register(serviceName, host string, port int, opts ...grpc.DialOption) error {
return nil
}
func (k *KubernetesConnManager) UnRegister() error {
return nil
}
func (k *KubernetesConnManager) GetUserIdHashGatewayHost(ctx context.Context, userId string) (string, error) {
return "", nil
}
func (k *KubernetesConnManager) getServicePort(serviceName string) (int32, error) {
var svcPort int32
svc, err := k.clientset.CoreV1().Services(k.namespace).Get(context.Background(), serviceName, metav1.GetOptions{})
if err != nil {
fmt.Print("namespace:", k.namespace)
return 0, fmt.Errorf("failed to get service %s: %v", serviceName, err)
}
if len(svc.Spec.Ports) == 0 {
return 0, fmt.Errorf("service %s has no ports defined", serviceName)
}
for _, port := range svc.Spec.Ports {
// fmt.Println(serviceName, " Now Get Port:", port.Port)
if port.Port != 10001 {
svcPort = port.Port
break
}
}
return svcPort, nil
}
// watchEndpoints listens for changes in Pod resources.View on GitHub (pinned to 175a7bb067)
Solutions
- Confirm the Service exists: kubectl get svc <serviceName> -n <namespace>.
- Check RBAC allows get on services for the pod's ServiceAccount.
- Verify k.namespace matches the deployment namespace.
- If this fires transiently during rollout, retry GetConns after the service becomes ready.
Example fix
// before
svc, err := k.clientset.CoreV1().Services(k.namespace).Get(ctx, serviceName, metav1.GetOptions{})
// after
svc, err := k.clientset.CoreV1().Services(k.namespace).Get(ctx, serviceName, metav1.GetOptions{})
if err != nil {
return 0, fmt.Errorf("namespace=%q service=%q: %w", k.namespace, serviceName, err)
} Defensive patterns
Strategy: try-catch
Validate before calling
_, err := clientset.CoreV1().Services(ns).Get(ctx, svcName, metav1.GetOptions{})
if err != nil { /* service missing or RBAC denied */ } Try / catch
port, err := mgr.GetConn(ctx, serviceName)
if err != nil {
if apierrors.IsNotFound(errors.Unwrap(err)) {
log.Fatalf("service %s/%s not found", ns, serviceName)
}
} Prevention
- Apply Service manifests before starting RPC clients
- Grant get on services in RBAC for the ServiceAccount
- Keep service name and namespace in a single config source to avoid typos
When it happens
Trigger: clientset.CoreV1().Services(namespace).Get(ctx, serviceName, ...) returns an error inside getServicePort, called from initializeConns and GetConn.
Common situations: Service not created in the configured namespace; ServiceAccount missing get/services RBAC; typo in service name; connecting before the service manifest is applied.
Related errors
- failed to create in-cluster config: %v
- failed to get endpoints for service %s: %v
- failed to initialize connections for service %s: %v
- failed to create clientset: %v
- failed to dial endpoint %s: %v
AI-assisted analysis of openimsdk/open-im-server@175a7bb067 (2026-09-04).
Data as JSON: /api/errors/c4e2487e8e98ee87.
Report an issue: GitHub.