MCPcopy
hub / github.com/cilium/cilium / NewWithFlags

Function NewWithFlags

hubble/cmd/common/conn/conn.go:126–156  ·  view source on GitHub ↗

NewWithFlags creates a new gRPC client connection, optionally port-forwarding to one of the hubble-relay pods, using flags to extract the required information.

(ctx context.Context, vp *viper.Viper)

Source from the content-addressed store, hash-verified

124// NewWithFlags creates a new gRPC client connection, optionally port-forwarding to one of the
125// hubble-relay pods, using flags to extract the required information.
126func NewWithFlags(ctx context.Context, vp *viper.Viper) (*grpc.ClientConn, error) {
127 server := vp.GetString(config.KeyServer)
128
129 if vp.GetBool(config.KeyPortForward) {
130 kubeContext := vp.GetString(config.KeyKubeContext)
131 kubeconfig := vp.GetString(config.KeyKubeconfig)
132 kubeNamespace := vp.GetString(config.KeyKubeNamespace)
133 localPort := vp.GetUint16(config.KeyPortForwardPort)
134
135 pf, err := newPortForwarder(kubeContext, kubeconfig)
136 if err != nil {
137 return nil, fmt.Errorf("failed to create k8s port forwader: %w", err)
138 }
139
140 // default to first port configured on the service when svcPort is set to 0
141 res, err := pf.PortForwardService(ctx, kubeNamespace, "hubble-relay", int32(localPort), 0)
142 if err != nil {
143 return nil, fmt.Errorf("failed to port forward: %w", err)
144 }
145
146 server = fmt.Sprintf("127.0.0.1:%d", res.ForwardedPort.Local)
147 logger.Logger.Debug("port-forward to hubble-relay pod running", logfields.Address, server)
148 }
149
150 conn, err := New(server)
151 if err != nil {
152 return nil, err
153 }
154
155 return conn, nil
156}
157
158func newPortForwarder(context, kubeconfig string) (*portforward.PortForwarder, error) {
159 restClientGetter := genericclioptions.ConfigFlags{

Callers 8

NewFunction · 0.92
newNodeCommandFunction · 0.92
newNamespacesCommandFunction · 0.92
newPeerCommandFunction · 0.92
newAgentEventsCommandFunction · 0.92
flows.goFile · 0.92
newDebugEventsCommandFunction · 0.92
NewFunction · 0.92

Calls 5

newPortForwarderFunction · 0.85
PortForwardServiceMethod · 0.80
NewFunction · 0.70
DebugMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…