Skip to content

Commit d3a07c9

Browse files
committed
using default options if the grpc config not found
Signed-off-by: Wei Liu <liuweixa@redhat.com>
1 parent bff5c35 commit d3a07c9

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

pkg/cloudevents/server/grpc/options/options.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/spf13/pflag"
99
"gopkg.in/yaml.v2"
10+
"k8s.io/klog/v2"
1011
)
1112

1213
type GRPCServerOptions struct {
@@ -29,6 +30,11 @@ type GRPCServerOptions struct {
2930

3031
func LoadGRPCServerOptions(configPath string) (*GRPCServerOptions, error) {
3132
opts := NewGRPCServerOptions()
33+
if _, err := os.Stat(configPath); os.IsNotExist(err) {
34+
klog.Warningf("GRPC server config file %s does not exist. Using default options.", configPath)
35+
return opts, nil
36+
}
37+
3238
grpcServerConfig, err := os.ReadFile(configPath)
3339
if err != nil {
3440
return nil, err
@@ -43,6 +49,9 @@ func LoadGRPCServerOptions(configPath string) (*GRPCServerOptions, error) {
4349

4450
func NewGRPCServerOptions() *GRPCServerOptions {
4551
return &GRPCServerOptions{
52+
ClientCAFile: "/var/run/secrets/hub/grpc/ca/ca-bundle.crt",
53+
TLSCertFile: "/var/run/secrets/hub/grpc/serving-cert/tls.crt",
54+
TLSKeyFile: "/var/run/secrets/hub/grpc/serving-cert/tls.key",
4655
ServerBindPort: "8090",
4756
MaxConcurrentStreams: math.MaxUint32,
4857
MaxReceiveMessageSize: 1024 * 1024 * 4,
@@ -70,7 +79,7 @@ func (o *GRPCServerOptions) AddFlags(flags *pflag.FlagSet) {
7079
flags.BoolVar(&o.PermitPingWithoutStream, "permit-ping-without-stream", o.PermitPingWithoutStream, "Allow keepalive pings even when there are no active streams")
7180
flags.IntVar(&o.WriteBufferSize, "grpc-write-buffer-size", o.WriteBufferSize, "gPRC write buffer size")
7281
flags.IntVar(&o.ReadBufferSize, "grpc-read-buffer-size", o.ReadBufferSize, "gPRC read buffer size")
73-
flags.StringVar(&o.TLSCertFile, "grpc-tls-cert-file", "", "The path to the tls.crt file")
74-
flags.StringVar(&o.TLSKeyFile, "grpc-tls-key-file", "", "The path to the tls.key file")
75-
flags.StringVar(&o.ClientCAFile, "grpc-client-ca-file", "", "The path to the client ca file, must specify if using mtls authentication type")
82+
flags.StringVar(&o.TLSCertFile, "grpc-tls-cert-file", o.TLSCertFile, "The path to the tls.crt file")
83+
flags.StringVar(&o.TLSKeyFile, "grpc-tls-key-file", o.TLSKeyFile, "The path to the tls.key file")
84+
flags.StringVar(&o.ClientCAFile, "grpc-client-ca-file", o.ClientCAFile, "The path to the client ca file, must specify if using mtls authentication type")
7685
}

pkg/cloudevents/server/grpc/options/options_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ permit_ping_without_stream: true
7373
setup: func(t *testing.T) string {
7474
return filepath.Join(t.TempDir(), "non-existent-file.yaml")
7575
},
76-
expectedOpts: nil,
77-
expectErr: true,
76+
expectedOpts: defaultOpts,
77+
expectErr: false,
7878
},
7979
{
8080
name: "Invalid YAML content",
@@ -126,6 +126,9 @@ connection_timeout: 90s
126126
},
127127
expectedOpts: &GRPCServerOptions{
128128
ServerBindPort: "8888",
129+
ClientCAFile: "/var/run/secrets/hub/grpc/ca/ca-bundle.crt",
130+
TLSCertFile: "/var/run/secrets/hub/grpc/serving-cert/tls.crt",
131+
TLSKeyFile: "/var/run/secrets/hub/grpc/serving-cert/tls.key",
129132
MaxConcurrentStreams: defaultOpts.MaxConcurrentStreams,
130133
MaxReceiveMessageSize: defaultOpts.MaxReceiveMessageSize,
131134
MaxSendMessageSize: defaultOpts.MaxSendMessageSize,

0 commit comments

Comments
 (0)