Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay pod deletion to handle deregistraton delay #1775

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ rules:
- get
- list
- watch
- patch
- delete
- apiGroups:
- ""
resources:
Expand Down
18 changes: 18 additions & 0 deletions config/webhook/manifests.v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ metadata:
creationTimestamp: null
name: webhook
webhooks:
- clientConfig:
caBundle: Cg==
service:
name: webhook-service
namespace: system
path: /validate-v1-pod
failurePolicy: Ignore
name: vpod.elbv2.k8s.aws
rules:
- apiGroups:
- ""
apiVersions:
- v1
operations:
- DELETE
resources:
- pods
sideEffects: NoneOnDryRun
- clientConfig:
caBundle: Cg==
service:
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"sigs.k8s.io/aws-load-balancer-controller/pkg/aws"
"sigs.k8s.io/aws-load-balancer-controller/pkg/aws/throttle"
"sigs.k8s.io/aws-load-balancer-controller/pkg/config"
"sigs.k8s.io/aws-load-balancer-controller/pkg/gracefuldrain"
"sigs.k8s.io/aws-load-balancer-controller/pkg/inject"
"sigs.k8s.io/aws-load-balancer-controller/pkg/k8s"
"sigs.k8s.io/aws-load-balancer-controller/pkg/networking"
Expand Down Expand Up @@ -143,6 +144,14 @@ func main() {
elbv2webhook.NewTargetGroupBindingValidator(ctrl.Log).SetupWithManager(mgr)
//+kubebuilder:scaffold:builder

podGracefulDrain := gracefuldrain.NewPodGracefulDrain(controllerCFG.PodGracefulDrainConfig, mgr.GetClient(),
ctrl.Log.WithName("pod-graceful-drain"))
if err := mgr.Add(podGracefulDrain); err != nil {
setupLog.Error(err, "Unable to add pod-graceful-drain")
os.Exit(1)
}
corewebhook.NewPodValidator(podGracefulDrain, ctrl.Log).SetupWithManager(mgr)

stopChan := ctrl.SetupSignalHandler()
go func() {
setupLog.Info("starting podInfo repo")
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/controller_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/pflag"
"sigs.k8s.io/aws-load-balancer-controller/pkg/aws"
"sigs.k8s.io/aws-load-balancer-controller/pkg/gracefuldrain"
"sigs.k8s.io/aws-load-balancer-controller/pkg/inject"
)

Expand Down Expand Up @@ -33,6 +34,8 @@ type ControllerConfig struct {
IngressConfig IngressConfig
// Configurations for Addons feature
AddonsConfig AddonsConfig
// Configurations for Pod graaceful drain
PodGracefulDrainConfig gracefuldrain.Config

// Default AWS Tags that will be applied to all AWS resources managed by this controller.
DefaultTags map[string]string
Expand Down Expand Up @@ -61,12 +64,16 @@ func (cfg *ControllerConfig) BindFlags(fs *pflag.FlagSet) {
cfg.PodWebhookConfig.BindFlags(fs)
cfg.IngressConfig.BindFlags(fs)
cfg.AddonsConfig.BindFlags(fs)
cfg.PodGracefulDrainConfig.BindFlags(fs)
}

// Validate the controller configuration
func (cfg *ControllerConfig) Validate() error {
if len(cfg.ClusterName) == 0 {
return errors.New("kubernetes cluster name must be specified")
}
if cfg.PodGracefulDrainConfig.PodGracefulDrainDelay < 0 {
return errors.New("pod-graceful-drain-delay cannot be negative")
}
return nil
}
19 changes: 19 additions & 0 deletions pkg/gracefuldrain/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package gracefuldrain

import (
"github.com/spf13/pflag"
"time"
)

const (
flagPodGracefulDrainDelay = "pod-graceful-drain-delay"
)

type Config struct {
PodGracefulDrainDelay time.Duration
}

func (cfg *Config) BindFlags(fs *pflag.FlagSet) {
fs.DurationVar(&cfg.PodGracefulDrainDelay, flagPodGracefulDrainDelay, time.Duration(0),
`Deregistering pod's deletions are delayed while draining`)
}
Loading