diff --git a/pkg/i2gw/intermediate/provider_gce.go b/pkg/i2gw/intermediate/provider_gce.go index d37aec68..911eceb8 100644 --- a/pkg/i2gw/intermediate/provider_gce.go +++ b/pkg/i2gw/intermediate/provider_gce.go @@ -23,6 +23,7 @@ type GceHTTPRouteIR struct{} type GceServiceIR struct { SessionAffinity *SessionAffinityConfig SecurityPolicy *SecurityPolicyConfig + HealthCheck *HealthCheckConfig } type SessionAffinityConfig struct { AffinityType string @@ -31,6 +32,15 @@ type SessionAffinityConfig struct { type SecurityPolicyConfig struct { Name string } +type HealthCheckConfig struct { + CheckIntervalSec *int64 + TimeoutSec *int64 + HealthyThreshold *int64 + UnhealthyThreshold *int64 + Type *string + Port *int64 + RequestPath *string +} func mergeGceGatewayIR(current, existing *GceGatewayIR) *GceGatewayIR { // If either GceGatewayIR is nil, return the other one as the merged result. diff --git a/pkg/i2gw/providers/gce/extensions/input_extensions.go b/pkg/i2gw/providers/gce/extensions/input_extensions.go index 762bf7c1..a1fcfde9 100644 --- a/pkg/i2gw/providers/gce/extensions/input_extensions.go +++ b/pkg/i2gw/providers/gce/extensions/input_extensions.go @@ -29,7 +29,11 @@ func ValidateBeConfig(beConfig *backendconfigv1.BackendConfig) error { return err } } - + if beConfig.Spec.HealthCheck != nil { + if err := validateHealthCheck(beConfig); err != nil { + return err + } + } return nil } @@ -40,6 +44,17 @@ func validateSessionAffinity(beConfig *backendconfigv1.BackendConfig) error { return nil } +func validateHealthCheck(beConfig *backendconfigv1.BackendConfig) error { + hcType := beConfig.Spec.HealthCheck.Type + if hcType == nil { + return fmt.Errorf("HealthCheck Protocol type is not specified") + } + if *hcType != "HTTP" && *hcType != "HTTPS" && *hcType != "HTTP2" { + return fmt.Errorf("Protocol %q is not valid, must be one of [HTTP,HTTPS,HTTP2]", *hcType) + } + return nil +} + func BuildIRSessionAffinityConfig(beConfig *backendconfigv1.BackendConfig) *intermediate.SessionAffinityConfig { return &intermediate.SessionAffinityConfig{ AffinityType: beConfig.Spec.SessionAffinity.AffinityType, @@ -52,3 +67,15 @@ func BuildIRSecurityPolicyConfig(beConfig *backendconfigv1.BackendConfig) *inter Name: beConfig.Spec.SecurityPolicy.Name, } } + +func BuildIRHealthCheckConfig(beConfig *backendconfigv1.BackendConfig) *intermediate.HealthCheckConfig { + return &intermediate.HealthCheckConfig{ + CheckIntervalSec: beConfig.Spec.HealthCheck.CheckIntervalSec, + TimeoutSec: beConfig.Spec.HealthCheck.TimeoutSec, + HealthyThreshold: beConfig.Spec.HealthCheck.HealthyThreshold, + UnhealthyThreshold: beConfig.Spec.HealthCheck.UnhealthyThreshold, + Type: beConfig.Spec.HealthCheck.Type, + Port: beConfig.Spec.HealthCheck.Port, + RequestPath: beConfig.Spec.HealthCheck.RequestPath, + } +} diff --git a/pkg/i2gw/providers/gce/ir_converter.go b/pkg/i2gw/providers/gce/ir_converter.go index e0f11066..b9e4b37e 100644 --- a/pkg/i2gw/providers/gce/ir_converter.go +++ b/pkg/i2gw/providers/gce/ir_converter.go @@ -204,6 +204,9 @@ func beConfigToGceServiceIR(beConfig *backendconfigv1.BackendConfig) intermediat if beConfig.Spec.SecurityPolicy != nil { gceServiceIR.SecurityPolicy = extensions.BuildIRSecurityPolicyConfig(beConfig) } + if beConfig.Spec.HealthCheck != nil { + gceServiceIR.HealthCheck = extensions.BuildIRHealthCheckConfig(beConfig) + } return gceServiceIR }