i am currently discarding traefik ingress controller and writing the golang code.
i need help in understanding how to configure the ingress controller rules dynamically from grpc request and then forward to appropriate backend grpc server.
following is the existing code where grpc MethodName is hardcoded
var whitelistMethods = [...]string{`/auth.Auth/Authenticate`, `/xvm.xvmService/NewClientID`,`/xvm.xvmService/Authenticate`, `/xvm.xvmService/DeleteClientID`}
func gatewayDirector() proxy.StreamDirector {
return func(ctx context.Context, method string) (context.Context, *grpc.ClientConn, error) {
meta, ok := metadata.FromIncomingContext(ctx)
if !ok {
return ctx, nil, errInvalidMeta
}
var clientAddr string
if clientPeer, ok := peer.FromContext(ctx); ok {
addr, _, err := net.SplitHostPort(clientPeer.Addr.String())
if err != nil {
log.DErrorf("erred while parsing client address, error:%v", err)
} else {
clientAddr = addr
}
}
if isWhitelistMethod(method) {
log.Debugf("whitelist method:%v, forward to security service", method)
return ctx, securityClientConn, nil
}
var clientConn *grpc.ClientConn
// handle regular RPC methods and get the corresponding backend client
clientConn, err = handleRegularMethods(method, meta)
if err != nil {
return ctx, nil, err
}
return ctx, clientConn, nil
}
}
func isWhitelistMethod(method string) bool {
for _, m := range whitelistMethods {
if m == method {
return true
}
}
return false
}
instead of hardcoding var whitelistMethods need to dynamically configure custom ingress controller rules for gateway service.