Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ func newDeployCommand() *deployCommand {
deployCommand.cmd.Flags().BoolVar(&deployCommand.args.ServiceOptions.TLSRedirect, "tls-redirect", true, "Redirect HTTP traffic to HTTPS")
deployCommand.cmd.Flags().StringVar(&deployCommand.args.ServiceOptions.CanonicalHost, "canonical-host", "", "Redirect all requests to this host (e.g., force root or www)")

deployCommand.cmd.Flags().DurationVar(&deployCommand.args.DeployTimeout, "deploy-timeout", server.DefaultDeployTimeout, "Maximum time to wait for the new target to become healthy")
deployCommand.cmd.Flags().DurationVar(&deployCommand.args.DrainTimeout, "drain-timeout", server.DefaultDrainTimeout, "Maximum time to allow existing connections to drain before removing old target")
deployCommand.cmd.Flags().DurationVar(&deployCommand.args.DeploymentOptions.DeployTimeout, "deploy-timeout", server.DefaultDeployTimeout, "Maximum time to wait for the new target to become healthy")
deployCommand.cmd.Flags().DurationVar(&deployCommand.args.DeploymentOptions.DrainTimeout, "drain-timeout", server.DefaultDrainTimeout, "Maximum time to allow existing connections to drain before removing old target")
deployCommand.cmd.Flags().BoolVar(&deployCommand.args.DeploymentOptions.Force, "force", false, "Skip health checks and force deployment")
deployCommand.cmd.Flags().DurationVar(&deployCommand.args.TargetOptions.HealthCheckConfig.Interval, "health-check-interval", server.DefaultHealthCheckInterval, "Interval between health checks")
deployCommand.cmd.Flags().DurationVar(&deployCommand.args.TargetOptions.HealthCheckConfig.Timeout, "health-check-timeout", server.DefaultHealthCheckTimeout, "Time each health check must complete in")
deployCommand.cmd.Flags().StringVar(&deployCommand.args.TargetOptions.HealthCheckConfig.Path, "health-check-path", server.DefaultHealthCheckPath, "Path to check for health")
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/rollout_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func newRolloutDeployCommand() *rolloutDeployCommand {

rolloutDeployCommand.cmd.Flags().StringSliceVar(&rolloutDeployCommand.args.TargetURLs, "target", []string{}, "Target host(s) to deploy")
rolloutDeployCommand.cmd.Flags().StringSliceVar(&rolloutDeployCommand.args.ReaderURLs, "read-target", []string{}, "Read-only target host(s) to deploy")
rolloutDeployCommand.cmd.Flags().DurationVar(&rolloutDeployCommand.args.DeployTimeout, "deploy-timeout", server.DefaultDeployTimeout, "Maximum time to wait for the new target to become healthy")
rolloutDeployCommand.cmd.Flags().DurationVar(&rolloutDeployCommand.args.DrainTimeout, "drain-timeout", server.DefaultDrainTimeout, "Maximum time to allow existing connections to drain before removing old target")
rolloutDeployCommand.cmd.Flags().DurationVar(&rolloutDeployCommand.args.DeploymentOptions.DeployTimeout, "deploy-timeout", server.DefaultDeployTimeout, "Maximum time to wait for the new target to become healthy")
rolloutDeployCommand.cmd.Flags().DurationVar(&rolloutDeployCommand.args.DeploymentOptions.DrainTimeout, "drain-timeout", server.DefaultDrainTimeout, "Maximum time to allow existing connections to drain before removing old target")

rolloutDeployCommand.cmd.MarkFlagRequired("target")

Expand Down
26 changes: 12 additions & 14 deletions internal/server/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ type CommandHandler struct {
}

type DeployArgs struct {
Service string
TargetURLs []string
ReaderURLs []string
DeployTimeout time.Duration
DrainTimeout time.Duration
ServiceOptions ServiceOptions
TargetOptions TargetOptions
Service string
TargetURLs []string
ReaderURLs []string
DeploymentOptions DeploymentOptions
ServiceOptions ServiceOptions
TargetOptions TargetOptions
}

type PauseArgs struct {
Expand All @@ -47,11 +46,10 @@ type RemoveArgs struct {
}

type RolloutDeployArgs struct {
Service string
TargetURLs []string
ReaderURLs []string
DeployTimeout time.Duration
DrainTimeout time.Duration
Service string
TargetURLs []string
ReaderURLs []string
DeploymentOptions DeploymentOptions
}

type RolloutSetArgs struct {
Expand Down Expand Up @@ -115,7 +113,7 @@ func (h *CommandHandler) Close() error {
}

func (h *CommandHandler) Deploy(args DeployArgs, reply *bool) error {
return h.router.DeployService(args.Service, args.TargetURLs, args.ReaderURLs, args.ServiceOptions, args.TargetOptions, args.DeployTimeout, args.DrainTimeout)
return h.router.DeployService(args.Service, args.TargetURLs, args.ReaderURLs, args.ServiceOptions, args.TargetOptions, args.DeploymentOptions)
}

func (h *CommandHandler) Pause(args PauseArgs, reply *bool) error {
Expand All @@ -141,7 +139,7 @@ func (h *CommandHandler) List(args bool, reply *ListResponse) error {
}

func (h *CommandHandler) RolloutDeploy(args RolloutDeployArgs, reply *bool) error {
return h.router.SetRolloutTargets(args.Service, args.TargetURLs, args.ReaderURLs, args.DeployTimeout, args.DrainTimeout)
return h.router.SetRolloutTargets(args.Service, args.TargetURLs, args.ReaderURLs, args.DeploymentOptions)
}

func (h *CommandHandler) RolloutSet(args RolloutSetArgs, reply *bool) error {
Expand Down
25 changes: 14 additions & 11 deletions internal/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
service.ServeHTTP(w, req)
}

func (r *Router) DeployService(name string, targetURLs, readerURLs []string, options ServiceOptions, targetOptions TargetOptions, deployTimeout time.Duration, drainTimeout time.Duration) error {
func (r *Router) DeployService(name string, targetURLs, readerURLs []string, options ServiceOptions, targetOptions TargetOptions, deploymentOptions DeploymentOptions) error {
options.Normalize()
slog.Info("Deploying", "service", name, "targets", targetURLs, "hosts", options.Hosts, "paths", options.PathPrefixes, "tls", options.TLSEnabled)

lb, err := r.createLoadBalancer(targetURLs, readerURLs, options, targetOptions, deployTimeout)
lb, err := r.createLoadBalancer(targetURLs, readerURLs, options, targetOptions, deploymentOptions)
if err != nil {
return err
}
Expand All @@ -123,22 +123,22 @@ func (r *Router) DeployService(name string, targetURLs, readerURLs []string, opt

if replaced != nil {
replaced.Dispose()
replaced.DrainAll(drainTimeout)
replaced.DrainAll(deploymentOptions.DrainTimeout)
}

slog.Info("Deployed", "service", name, "targets", targetURLs, "hosts", options.Hosts, "paths", options.PathPrefixes, "tls", options.TLSEnabled)
return nil
}

func (r *Router) SetRolloutTargets(name string, targetURLs, readerURLs []string, deployTimeout time.Duration, drainTimeout time.Duration) error {
func (r *Router) SetRolloutTargets(name string, targetURLs, readerURLs []string, deploymentOptions DeploymentOptions) error {
service := r.serviceForName(name)
if service == nil {
return ErrorServiceNotFound
}

slog.Info("Deploying for rollout", "service", name, "targets", targetURLs)

lb, err := r.createLoadBalancer(targetURLs, readerURLs, service.options, service.targetOptions, deployTimeout)
lb, err := r.createLoadBalancer(targetURLs, readerURLs, service.options, service.targetOptions, deploymentOptions)
if err != nil {
return err
}
Expand All @@ -152,7 +152,7 @@ func (r *Router) SetRolloutTargets(name string, targetURLs, readerURLs []string,

if replaced != nil {
replaced.Dispose()
replaced.DrainAll(drainTimeout)
replaced.DrainAll(deploymentOptions.DrainTimeout)
}

slog.Info("Deployed for rollout", "service", name, "targets", targetURLs)
Expand Down Expand Up @@ -297,17 +297,20 @@ func (r *Router) createOrUpdateService(name string, options ServiceOptions, targ
return service, err
}

func (r *Router) createLoadBalancer(targetURLs, readerURLs []string, options ServiceOptions, targetOptions TargetOptions, deployTimeout time.Duration) (*LoadBalancer, error) {
func (r *Router) createLoadBalancer(targetURLs, readerURLs []string, options ServiceOptions, targetOptions TargetOptions, deploymentOptions DeploymentOptions) (*LoadBalancer, error) {
tl, err := NewTargetList(targetURLs, readerURLs, targetOptions)
if err != nil {
return nil, err
}

lb := NewLoadBalancer(tl, options.WriterAffinityTimeout, options.ReadTargetsAcceptWebsockets)
err = lb.WaitUntilHealthy(deployTimeout)
if err != nil {
lb.Dispose()
return nil, err

if !deploymentOptions.Force {
err = lb.WaitUntilHealthy(deploymentOptions.DeployTimeout)
if err != nil {
lb.Dispose()
return nil, err
}
}

return lb, nil
Expand Down
Loading