Unverified Commit 67d079ec authored by Luther Monson's avatar Luther Monson Committed by GitHub

[engine-1.21] updating to new signals package in wrangler (#4434)

* updating to new signals package in wrangler Signed-off-by: 's avatarLuther Monson <luther.monson@gmail.com>
parent 14cf9632
...@@ -2,7 +2,7 @@ TARGETS := $(shell ls scripts | grep -v \\.sh) ...@@ -2,7 +2,7 @@ TARGETS := $(shell ls scripts | grep -v \\.sh)
.dapper: .dapper:
@echo Downloading dapper @echo Downloading dapper
@curl -sL https://releases.rancher.com/dapper/v0.5.1/dapper-$$(uname -s)-$$(uname -m) > .dapper.tmp @curl -sL https://releases.rancher.com/dapper/v0.5.7/dapper-$$(uname -s)-$$(uname -m) > .dapper.tmp
@@chmod +x .dapper.tmp @@chmod +x .dapper.tmp
@./.dapper.tmp -v @./.dapper.tmp -v
@mv .dapper.tmp .dapper @mv .dapper.tmp .dapper
......
...@@ -108,7 +108,7 @@ require ( ...@@ -108,7 +108,7 @@ require (
github.com/rancher/lasso v0.0.0-20210616224652-fc3ebd901c08 github.com/rancher/lasso v0.0.0-20210616224652-fc3ebd901c08
github.com/rancher/remotedialer v0.2.0 github.com/rancher/remotedialer v0.2.0
github.com/rancher/wharfie v0.3.4 github.com/rancher/wharfie v0.3.4
github.com/rancher/wrangler v0.8.5 github.com/rancher/wrangler v0.8.8
github.com/robfig/cron/v3 v3.0.1 github.com/robfig/cron/v3 v3.0.1
github.com/rootless-containers/rootlesskit v0.14.0 github.com/rootless-containers/rootlesskit v0.14.0
github.com/sirupsen/logrus v1.8.1 github.com/sirupsen/logrus v1.8.1
......
...@@ -822,8 +822,8 @@ github.com/rancher/wharfie v0.3.4 h1:wVqFW1cyRA20zY90Z56VrjG0lWg3oFmf/4ryr5Dkkis ...@@ -822,8 +822,8 @@ github.com/rancher/wharfie v0.3.4 h1:wVqFW1cyRA20zY90Z56VrjG0lWg3oFmf/4ryr5Dkkis
github.com/rancher/wharfie v0.3.4/go.mod h1:cb8mSczpmw7ItbPF3K1W7crWuJLVdyV49sZZuaY4BS8= github.com/rancher/wharfie v0.3.4/go.mod h1:cb8mSczpmw7ItbPF3K1W7crWuJLVdyV49sZZuaY4BS8=
github.com/rancher/wrangler v0.4.0/go.mod h1:1cR91WLhZgkZ+U4fV9nVuXqKurWbgXcIReU4wnQvTN8= github.com/rancher/wrangler v0.4.0/go.mod h1:1cR91WLhZgkZ+U4fV9nVuXqKurWbgXcIReU4wnQvTN8=
github.com/rancher/wrangler v0.8.3/go.mod h1:dKEaHNB4izxmPUtpq1Hvr3z3Oh+9k5pCZyFO9sUhlaY= github.com/rancher/wrangler v0.8.3/go.mod h1:dKEaHNB4izxmPUtpq1Hvr3z3Oh+9k5pCZyFO9sUhlaY=
github.com/rancher/wrangler v0.8.5 h1:aHUVvJrOhD6CGrAELWKDpo1MBDC8vKtEQZvjMPnw2cs= github.com/rancher/wrangler v0.8.8 h1:3EEQmfUqZ/UG4hERHhihB+Q2F1s/W4CmfsPmXv17wS8=
github.com/rancher/wrangler v0.8.5/go.mod h1:dKEaHNB4izxmPUtpq1Hvr3z3Oh+9k5pCZyFO9sUhlaY= github.com/rancher/wrangler v0.8.8/go.mod h1:dKEaHNB4izxmPUtpq1Hvr3z3Oh+9k5pCZyFO9sUhlaY=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M= github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/robfig/cron v1.1.0 h1:jk4/Hud3TTdcrJgUOBgsqrZBarcxl6ADIjSC2iniwLY= github.com/robfig/cron v1.1.0 h1:jk4/Hud3TTdcrJgUOBgsqrZBarcxl6ADIjSC2iniwLY=
github.com/robfig/cron v1.1.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= github.com/robfig/cron v1.1.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
......
...@@ -86,7 +86,7 @@ func Run(ctx context.Context, cfg *config.Node) error { ...@@ -86,7 +86,7 @@ func Run(ctx context.Context, cfg *config.Node) error {
} }
logrus.Infof("Running containerd %s", config.ArgString(args[1:])) logrus.Infof("Running containerd %s", config.ArgString(args[1:]))
cmd := exec.Command(args[0], args[1:]...) cmd := exec.CommandContext(ctx, args[0], args[1:]...)
cmd.Stdout = stdOut cmd.Stdout = stdOut
cmd.Stderr = stdErr cmd.Stderr = stdErr
cmd.Env = env cmd.Env = env
......
package agent package agent
import ( import (
"context"
"fmt" "fmt"
"os" "os"
"runtime" "runtime"
...@@ -73,7 +72,7 @@ func Run(ctx *cli.Context) error { ...@@ -73,7 +72,7 @@ func Run(ctx *cli.Context) error {
cfg.Debug = ctx.GlobalBool("debug") cfg.Debug = ctx.GlobalBool("debug")
cfg.DataDir = dataDir cfg.DataDir = dataDir
contextCtx := signals.SetupSignalHandler(context.Background()) contextCtx := signals.SetupSignalContext()
return agent.Run(contextCtx, cfg) return agent.Run(contextCtx, cfg)
} }
package etcdsnapshot package etcdsnapshot
import ( import (
"context"
"errors" "errors"
"fmt" "fmt"
"os" "os"
...@@ -82,7 +81,7 @@ func run(app *cli.Context, cfg *cmds.Server) error { ...@@ -82,7 +81,7 @@ func run(app *cli.Context, cfg *cmds.Server) error {
serverConfig.ControlConfig.Runtime.ClientETCDKey = filepath.Join(dataDir, "tls", "etcd", "client.key") serverConfig.ControlConfig.Runtime.ClientETCDKey = filepath.Join(dataDir, "tls", "etcd", "client.key")
serverConfig.ControlConfig.Runtime.KubeConfigAdmin = filepath.Join(dataDir, "cred", "admin.kubeconfig") serverConfig.ControlConfig.Runtime.KubeConfigAdmin = filepath.Join(dataDir, "cred", "admin.kubeconfig")
ctx := signals.SetupSignalHandler(context.Background()) ctx := signals.SetupSignalContext()
e := etcd.NewETCD() e := etcd.NewETCD()
e.SetControlConfig(&serverConfig.ControlConfig) e.SetControlConfig(&serverConfig.ControlConfig)
...@@ -132,7 +131,7 @@ func delete(app *cli.Context, cfg *cmds.Server) error { ...@@ -132,7 +131,7 @@ func delete(app *cli.Context, cfg *cmds.Server) error {
serverConfig.ControlConfig.DataDir = dataDir serverConfig.ControlConfig.DataDir = dataDir
serverConfig.ControlConfig.Runtime.KubeConfigAdmin = filepath.Join(dataDir, "cred", "admin.kubeconfig") serverConfig.ControlConfig.Runtime.KubeConfigAdmin = filepath.Join(dataDir, "cred", "admin.kubeconfig")
ctx := signals.SetupSignalHandler(context.Background()) ctx := signals.SetupSignalContext()
e := etcd.NewETCD() e := etcd.NewETCD()
e.SetControlConfig(&serverConfig.ControlConfig) e.SetControlConfig(&serverConfig.ControlConfig)
...@@ -162,7 +161,7 @@ func list(app *cli.Context, cfg *cmds.Server) error { ...@@ -162,7 +161,7 @@ func list(app *cli.Context, cfg *cmds.Server) error {
serverConfig.ControlConfig.DataDir = dataDir serverConfig.ControlConfig.DataDir = dataDir
ctx := signals.SetupSignalHandler(context.Background()) ctx := signals.SetupSignalContext()
e := etcd.NewETCD() e := etcd.NewETCD()
e.SetControlConfig(&serverConfig.ControlConfig) e.SetControlConfig(&serverConfig.ControlConfig)
...@@ -203,7 +202,7 @@ func prune(app *cli.Context, cfg *cmds.Server) error { ...@@ -203,7 +202,7 @@ func prune(app *cli.Context, cfg *cmds.Server) error {
serverConfig.ControlConfig.DataDir = dataDir serverConfig.ControlConfig.DataDir = dataDir
serverConfig.ControlConfig.EtcdSnapshotRetention = cfg.EtcdSnapshotRetention serverConfig.ControlConfig.EtcdSnapshotRetention = cfg.EtcdSnapshotRetention
ctx := signals.SetupSignalHandler(context.Background()) ctx := signals.SetupSignalContext()
e := etcd.NewETCD() e := etcd.NewETCD()
e.SetControlConfig(&serverConfig.ControlConfig) e.SetControlConfig(&serverConfig.ControlConfig)
......
...@@ -397,7 +397,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont ...@@ -397,7 +397,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
notifySocket := os.Getenv("NOTIFY_SOCKET") notifySocket := os.Getenv("NOTIFY_SOCKET")
ctx := signals.SetupSignalHandler(context.Background()) ctx := signals.SetupSignalContext()
if err := server.StartServer(ctx, &serverConfig, cfg); err != nil { if err := server.StartServer(ctx, &serverConfig, cfg); err != nil {
return err return err
......
...@@ -30,6 +30,7 @@ const ( ...@@ -30,6 +30,7 @@ const (
LabelNamespace = "objectset.rio.cattle.io/owner-namespace" LabelNamespace = "objectset.rio.cattle.io/owner-namespace"
LabelHash = "objectset.rio.cattle.io/hash" LabelHash = "objectset.rio.cattle.io/hash"
LabelPrefix = "objectset.rio.cattle.io/" LabelPrefix = "objectset.rio.cattle.io/"
LabelPrune = "objectset.rio.cattle.io/prune"
) )
var ( var (
......
...@@ -207,8 +207,7 @@ func applyPatch(gvk schema.GroupVersionKind, reconciler Reconciler, patcher Patc ...@@ -207,8 +207,7 @@ func applyPatch(gvk schema.GroupVersionKind, reconciler Reconciler, patcher Patc
return false, nil return false, nil
} }
logrus.Debugf("DesiredSet - Patch %s %s/%s for %s -- [%s, %s, %s, %s]", gvk, oldMetadata.GetNamespace(), oldMetadata.GetName(), debugID, patch, original, modified, current) logrus.Debugf("DesiredSet - Patch %s %s/%s for %s -- [PATCH:%s, ORIGINAL:%s, MODIFIED:%s, CURRENT:%s]", gvk, oldMetadata.GetNamespace(), oldMetadata.GetName(), debugID, patch, original, modified, current)
if reconciler != nil { if reconciler != nil {
newObject, err := prepareObjectForCreate(gvk, newObject) newObject, err := prepareObjectForCreate(gvk, newObject)
if err != nil { if err != nil {
......
...@@ -382,6 +382,14 @@ func (o *desiredSet) list(namespaced bool, informer cache.SharedIndexInformer, c ...@@ -382,6 +382,14 @@ func (o *desiredSet) list(namespaced bool, informer cache.SharedIndexInformer, c
return objs, merr.NewErrors(errs...) return objs, merr.NewErrors(errs...)
} }
func shouldPrune(obj runtime.Object) bool {
meta, err := meta.Accessor(obj)
if err != nil {
return true
}
return meta.GetLabels()[LabelPrune] != "false"
}
func compareSets(existingSet, newSet map[objectset.ObjectKey]runtime.Object) (toCreate, toDelete, toUpdate []objectset.ObjectKey) { func compareSets(existingSet, newSet map[objectset.ObjectKey]runtime.Object) (toCreate, toDelete, toUpdate []objectset.ObjectKey) {
for k := range newSet { for k := range newSet {
if _, ok := existingSet[k]; ok { if _, ok := existingSet[k]; ok {
...@@ -391,9 +399,11 @@ func compareSets(existingSet, newSet map[objectset.ObjectKey]runtime.Object) (to ...@@ -391,9 +399,11 @@ func compareSets(existingSet, newSet map[objectset.ObjectKey]runtime.Object) (to
} }
} }
for k := range existingSet { for k, obj := range existingSet {
if _, ok := newSet[k]; !ok { if _, ok := newSet[k]; !ok {
toDelete = append(toDelete, k) if shouldPrune(obj) {
toDelete = append(toDelete, k)
}
} }
} }
......
/* /*
Copyright 2017 The Kubernetes Authors. Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
...@@ -23,22 +20,47 @@ import ( ...@@ -23,22 +20,47 @@ import (
) )
var onlyOneSignalHandler = make(chan struct{}) var onlyOneSignalHandler = make(chan struct{})
var shutdownHandler chan os.Signal
// SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned // SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned
// which is closed on one of these signals. If a second signal is caught, the program // which is closed on one of these signals. If a second signal is caught, the program
// is terminated with exit code 1. // is terminated with exit code 1.
func SetupSignalHandler(parent context.Context) context.Context { // Only one of SetupSignalContext and SetupSignalHandler should be called, and only can
// be called once.
func SetupSignalHandler() <-chan struct{} {
return SetupSignalContext().Done()
}
// SetupSignalContext is same as SetupSignalHandler, but a context.Context is returned.
// Only one of SetupSignalContext and SetupSignalHandler should be called, and only can
// be called once.
func SetupSignalContext() context.Context {
close(onlyOneSignalHandler) // panics when called twice close(onlyOneSignalHandler) // panics when called twice
ctx, cancel := context.WithCancel(parent)
c := make(chan os.Signal, 2) shutdownHandler = make(chan os.Signal, 2)
signal.Notify(c, shutdownSignals...)
ctx, cancel := context.WithCancel(context.Background())
signal.Notify(shutdownHandler, shutdownSignals...)
go func() { go func() {
<-c <-shutdownHandler
cancel() cancel()
<-c <-shutdownHandler
os.Exit(1) // second signal. Exit directly. os.Exit(1) // second signal. Exit directly.
}() }()
return ctx return ctx
} }
// RequestShutdown emulates a received event that is considered as shutdown signal (SIGTERM/SIGINT)
// This returns whether a handler was notified
func RequestShutdown() bool {
if shutdownHandler != nil {
select {
case shutdownHandler <- shutdownSignals[0]:
return true
default:
}
}
return false
}
\ No newline at end of file
...@@ -954,7 +954,7 @@ github.com/rancher/remotedialer ...@@ -954,7 +954,7 @@ github.com/rancher/remotedialer
# github.com/rancher/wharfie v0.3.4 # github.com/rancher/wharfie v0.3.4
## explicit ## explicit
github.com/rancher/wharfie/pkg/registries github.com/rancher/wharfie/pkg/registries
# github.com/rancher/wrangler v0.8.5 # github.com/rancher/wrangler v0.8.8
## explicit ## explicit
github.com/rancher/wrangler/pkg/apply github.com/rancher/wrangler/pkg/apply
github.com/rancher/wrangler/pkg/apply/injectors github.com/rancher/wrangler/pkg/apply/injectors
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment