Skip to content

Commit a4ef8e3

Browse files
committed
# This is a combination of 3 commits.
# This is the 1st commit message: Refactor service.go logic. Signed-off-by: agoins <alyssacgoins@gmail.com>
1 parent f8ab8a9 commit a4ef8e3

4 files changed

Lines changed: 39 additions & 5 deletions

File tree

backend/src/common/util/service.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"strings"
2323
"time"
2424

25+
"google.golang.org/grpc/connectivity"
2526
"google.golang.org/grpc/credentials"
2627
"google.golang.org/grpc/credentials/insecure"
2728

@@ -109,16 +110,33 @@ func GetRPCConnectionWithTimeout(address string, tlsCfg *tls.Config, timeout tim
109110
creds = credentials.NewTLS(tlsCfg)
110111
}
111112

112-
ctx, _ := context.WithDeadline(context.Background(), timeout)
113+
ctx, cancel := context.WithDeadline(context.Background(), timeout)
114+
defer cancel()
113115

114-
conn, err := grpc.DialContext(ctx, address, grpc.WithTransportCredentials(creds), grpc.WithBlock())
116+
conn, err := grpc.NewClient(
117+
address,
118+
grpc.WithTransportCredentials(creds),
119+
)
115120
if err != nil {
116121
return nil, errors.Wrapf(err, "Failed to create gRPC connection")
117122
}
123+
// Start connection attempts and wait until the connection is ready or the context deadline expires.
124+
conn.Connect()
125+
state := conn.GetState()
126+
for state != connectivity.Ready {
127+
if !conn.WaitForStateChange(ctx, state) {
128+
_ = conn.Close()
129+
if ctx.Err() != nil {
130+
return nil, errors.Wrapf(ctx.Err(), "Timed out waiting for gRPC connection")
131+
}
132+
return nil, errors.New("Failed to connect to gRPC server")
133+
}
134+
state = conn.GetState()
135+
}
118136
return conn, nil
119137
}
120138

121-
func GetRpcConnection(address string, tlsCfg *tls.Config) (*grpc.ClientConn, error) {
139+
func GetRPCConnection(address string, tlsCfg *tls.Config) (*grpc.ClientConn, error) {
122140
creds := insecure.NewCredentials()
123141
if tlsCfg != nil {
124142
creds = credentials.NewTLS(tlsCfg)
@@ -131,6 +149,9 @@ func GetRpcConnection(address string, tlsCfg *tls.Config) (*grpc.ClientConn, err
131149
if err != nil {
132150
return nil, errors.Wrapf(err, "Failed to create gRPC connection")
133151
}
152+
// NewClient does not support a blocking DialOption (grpc.WithBlock is deprecated and not applicable).
153+
// Start connection attempts immediately without blocking to preserve eager dialing semantics.
154+
conn.Connect()
134155
return conn, nil
135156
}
136157

backend/src/common/util/tls_config.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2025 The Kubeflow Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
// Package util provides utility functions.
216
package util
317

manifests/kustomize/env/cert-manager/base-tls-certs/kfp-api-cert.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ spec:
1313
- metadata-envoy-service
1414
- metadata-grpc-service
1515
- metadata-grpc-service.kubeflow
16-
- metadata-grpc-service.kubeflow.svc
1716
- localhost
1817
ipAddresses:
1918
# Necessary for running TLS-enabled cluster locally.

manifests/kustomize/env/cert-manager/platform-agnostic-standalone-tls/patches/ml-pipeline-apiserver-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
- name: METADATA_TLS_ENABLED
2222
value: "true"
2323
- name: METADATA_GRPC_SERVICE_SERVICE_HOST
24-
value: "metadata-grpc-service.kubeflow.svc"
24+
value: "metadata-grpc-service.kubeflow"
2525
- name: ML_PIPELINE_SERVICE_HOST
2626
value: "ml-pipeline.kubeflow.svc.cluster.local"
2727
readinessProbe:

0 commit comments

Comments
 (0)