chore: change Route crd structure
This commit is contained in:
@@ -100,8 +100,8 @@ func createUpdateDeployment(r GatewayReconciler, ctx context.Context, req ctrl.R
|
||||
},
|
||||
},
|
||||
ReadinessProbe: &corev1.Probe{
|
||||
InitialDelaySeconds: 20,
|
||||
PeriodSeconds: 20,
|
||||
InitialDelaySeconds: 15,
|
||||
PeriodSeconds: 10,
|
||||
ProbeHandler: corev1.ProbeHandler{
|
||||
HTTPGet: &corev1.HTTPGetAction{
|
||||
Path: "/readyz",
|
||||
|
||||
@@ -2,6 +2,7 @@ package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/jinzhu/copier"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
@@ -20,8 +21,10 @@ func gatewayConfig(r GatewayReconciler, ctx context.Context, req ctrl.Request, g
|
||||
logger := log.FromContext(ctx)
|
||||
gomaConfig := &GatewayConfig{}
|
||||
gomaConfig.Version = GatewayConfigVersion
|
||||
gomaConfig.Gateway = mapToGateway(gateway.Spec)
|
||||
|
||||
err := copier.Copy(&gomaConfig.Gateway, &gateway.Spec.Server)
|
||||
if err != nil {
|
||||
logger.Error(err, "failed to copy gateway spec")
|
||||
}
|
||||
// attach cert files
|
||||
if len(gateway.Spec.Server.TlsSecretName) != 0 {
|
||||
gomaConfig.Gateway.SSLKeyFile = TLSKeyFile
|
||||
@@ -44,12 +47,16 @@ func gatewayConfig(r GatewayReconciler, ctx context.Context, req ctrl.Request, g
|
||||
for _, route := range routes.Items {
|
||||
logger.Info("Found Route", "Name", route.Name)
|
||||
if route.Spec.Gateway == gateway.Name {
|
||||
gomaConfig.Gateway.Routes = append(gomaConfig.Gateway.Routes, route.Spec.Routes...)
|
||||
for _, rt := range route.Spec.Routes {
|
||||
middlewareNames = append(middlewareNames, rt.Middlewares...)
|
||||
|
||||
logger.Info("Found Route", "Name", route.Name)
|
||||
rt := Route{}
|
||||
err := copier.Copy(&rt, &route.Spec)
|
||||
if err != nil {
|
||||
logger.Error(err, "Failed to deep copy Route", "Name", route.Name)
|
||||
return *gomaConfig
|
||||
}
|
||||
|
||||
rt.Name = route.Name
|
||||
gomaConfig.Gateway.Routes = append(gomaConfig.Gateway.Routes, rt)
|
||||
middlewareNames = append(middlewareNames, rt.Middlewares...)
|
||||
}
|
||||
}
|
||||
for _, mid := range middlewares.Items {
|
||||
@@ -66,7 +73,10 @@ func updateGatewayConfig(r RouteReconciler, ctx context.Context, req ctrl.Reques
|
||||
logger := log.FromContext(ctx)
|
||||
gomaConfig := &GatewayConfig{}
|
||||
gomaConfig.Version = GatewayConfigVersion
|
||||
gomaConfig.Gateway = mapToGateway(gateway.Spec)
|
||||
err := copier.Copy(&gomaConfig.Gateway, &gateway.Spec.Server)
|
||||
if err != nil {
|
||||
logger.Error(err, "failed to copy gateway spec")
|
||||
}
|
||||
// attach cert files
|
||||
if len(gateway.Spec.Server.TlsSecretName) != 0 {
|
||||
gomaConfig.Gateway.SSLKeyFile = TLSKeyFile
|
||||
@@ -88,12 +98,15 @@ func updateGatewayConfig(r RouteReconciler, ctx context.Context, req ctrl.Reques
|
||||
for _, route := range routes.Items {
|
||||
logger.Info("Found Route", "Name", route.Name)
|
||||
if route.Spec.Gateway == gateway.Name {
|
||||
gomaConfig.Gateway.Routes = append(gomaConfig.Gateway.Routes, route.Spec.Routes...)
|
||||
for _, rt := range route.Spec.Routes {
|
||||
middlewareNames = append(middlewareNames, rt.Middlewares...)
|
||||
|
||||
rt := Route{}
|
||||
err := copier.Copy(&rt, &route.Spec)
|
||||
if err != nil {
|
||||
logger.Error(err, "Failed to deep copy Route", "Name", route.Name)
|
||||
return false, err
|
||||
}
|
||||
|
||||
rt.Name = route.Name
|
||||
gomaConfig.Gateway.Routes = append(gomaConfig.Gateway.Routes, rt)
|
||||
middlewareNames = append(middlewareNames, rt.Middlewares...)
|
||||
}
|
||||
}
|
||||
for _, mid := range middlewares.Items {
|
||||
|
||||
@@ -77,15 +77,11 @@ var _ = Describe("Route Controller", func() {
|
||||
},
|
||||
Spec: gomaprojv1beta1.RouteSpec{
|
||||
Gateway: resourceName,
|
||||
Routes: []gomaprojv1beta1.RouteConfig{
|
||||
{
|
||||
Path: "/",
|
||||
Name: resourceName,
|
||||
Rewrite: "/",
|
||||
Destination: "https://example.com",
|
||||
Methods: []string{"GET", "POST"},
|
||||
},
|
||||
},
|
||||
|
||||
Path: "/",
|
||||
Rewrite: "/",
|
||||
Destination: "https://example.com",
|
||||
Methods: []string{"GET", "POST"},
|
||||
},
|
||||
}
|
||||
Expect(k8sClient.Create(ctx, resource)).To(Succeed())
|
||||
|
||||
@@ -28,10 +28,38 @@ type Gateway struct {
|
||||
DisableKeepAlive bool `yaml:"disableKeepAlive"`
|
||||
EnableMetrics bool `yaml:"enableMetrics"`
|
||||
// InterceptErrors holds the status codes to intercept the error from backend
|
||||
InterceptErrors []int `yaml:"interceptErrors,omitempty"`
|
||||
Routes []gomaprojv1beta1.RouteConfig `json:"routes,omitempty" yaml:"routes,omitempty"`
|
||||
InterceptErrors []int `yaml:"interceptErrors,omitempty"`
|
||||
Routes []Route `json:"routes,omitempty" yaml:"routes,omitempty"`
|
||||
}
|
||||
type Route struct {
|
||||
// Path defines route path
|
||||
Path string `json:"path" yaml:"path"`
|
||||
// Name defines route name
|
||||
Name string `json:"name" yaml:"name"`
|
||||
// Hosts Domains/hosts based request routing
|
||||
Hosts []string `json:"hosts,omitempty" yaml:"hosts"`
|
||||
// Rewrite rewrites route path to desired path
|
||||
Rewrite string `json:"rewrite,omitempty" yaml:"rewrite"`
|
||||
// Methods allowed method
|
||||
Methods []string `json:"methods,omitempty" yaml:"methods"`
|
||||
// Destination Defines backend URL
|
||||
Destination string `json:"destination,omitempty" yaml:"destination"`
|
||||
Backends []string `json:"backends,omitempty" yaml:"backends"`
|
||||
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty" yaml:"insecureSkipVerify"`
|
||||
// HealthCheck Defines the backend is health
|
||||
HealthCheck gomaprojv1beta1.RouteHealthCheck `json:"healthCheck,omitempty" yaml:"healthCheck,omitempty"`
|
||||
// Cors contains the route cors headers
|
||||
Cors gomaprojv1beta1.Cors `json:"cors,omitempty" yaml:"cors"`
|
||||
RateLimit int `json:"rateLimit,omitempty" yaml:"rateLimit"`
|
||||
// DisableHostFording Disable host forwarding.
|
||||
DisableHostFording bool `json:"disableHostFording,omitempty" yaml:"disableHostFording"`
|
||||
// InterceptErrors intercepts backend errors based on the status codes
|
||||
InterceptErrors []int `json:"interceptErrors,omitempty" yaml:"interceptErrors"`
|
||||
// BlockCommonExploits enable, disable block common exploits
|
||||
BlockCommonExploits bool `json:"blockCommonExploits,omitempty" yaml:"blockCommonExploits"`
|
||||
// Middlewares Defines route middleware
|
||||
Middlewares []string `json:"middlewares,omitempty" yaml:"middlewares"`
|
||||
}
|
||||
|
||||
type Redis struct {
|
||||
// Addr redis hostname and port number :
|
||||
Addr string `yaml:"addr"`
|
||||
|
||||
@@ -1,22 +1 @@
|
||||
package controller
|
||||
|
||||
import gomaprojv1beta1 "github.com/jkaninda/goma-operator/api/v1beta1"
|
||||
|
||||
func mapToGateway(g gomaprojv1beta1.GatewaySpec) Gateway {
|
||||
return Gateway{
|
||||
SSLKeyFile: "",
|
||||
SSLCertFile: "",
|
||||
Redis: g.Server.Redis,
|
||||
WriteTimeout: g.Server.WriteTimeout,
|
||||
ReadTimeout: g.Server.ReadTimeout,
|
||||
IdleTimeout: g.Server.IdleTimeout,
|
||||
LogLevel: g.Server.LogLevel,
|
||||
Cors: g.Server.Cors,
|
||||
DisableHealthCheckStatus: g.Server.DisableHealthCheckStatus,
|
||||
DisableRouteHealthCheckError: g.Server.DisableHealthCheckStatus,
|
||||
DisableKeepAlive: g.Server.DisableKeepAlive,
|
||||
InterceptErrors: g.Server.InterceptErrors,
|
||||
EnableMetrics: g.Server.EnableMetrics,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user