Skip to content

Commit

Permalink
Convert custom health check into IR
Browse files Browse the repository at this point in the history
  • Loading branch information
sawsa307 committed Sep 19, 2024
1 parent 7803824 commit cb9abdf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pkg/i2gw/intermediate/provider_gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type GceHTTPRouteIR struct{}
type GceServiceIR struct {
SessionAffinity *SessionAffinityConfig
SecurityPolicy *SecurityPolicyConfig
HealthCheck *HealthCheckConfig
}
type SessionAffinityConfig struct {
AffinityType string
Expand All @@ -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.
Expand Down
29 changes: 28 additions & 1 deletion pkg/i2gw/providers/gce/extensions/input_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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,
Expand All @@ -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,
}
}
3 changes: 3 additions & 0 deletions pkg/i2gw/providers/gce/ir_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit cb9abdf

Please sign in to comment.