mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
[master] updating to new signals package in wrangler (#4399)
* updating to new signals package in wrangler Signed-off-by: Luther Monson <luther.monson@gmail.com>
This commit is contained in:
parent
f1d6e9bc4b
commit
36c6634cce
3
go.mod
3
go.mod
@ -28,7 +28,6 @@ replace (
|
||||
github.com/opencontainers/runc => github.com/opencontainers/runc v1.0.2
|
||||
github.com/opencontainers/runtime-spec => github.com/opencontainers/runtime-spec v1.0.3-0.20210316141917-a8c4a9ee0f6b
|
||||
github.com/rancher/k3s/pkg/data => ./pkg/data
|
||||
github.com/rancher/wrangler => github.com/rancher/wrangler v0.8.5
|
||||
go.etcd.io/etcd/api/v3 => github.com/k3s-io/etcd/api/v3 v3.5.0-k3s2
|
||||
go.etcd.io/etcd/client/v3 => github.com/k3s-io/etcd/client/v3 v3.5.0-k3s2
|
||||
go.etcd.io/etcd/etcdutl/v3 => github.com/k3s-io/etcd/etcdutl/v3 v3.5.0-k3s2
|
||||
@ -110,7 +109,7 @@ require (
|
||||
github.com/rancher/lasso v0.0.0-20210616224652-fc3ebd901c08
|
||||
github.com/rancher/remotedialer v0.2.0
|
||||
github.com/rancher/wharfie v0.3.4
|
||||
github.com/rancher/wrangler v0.8.3
|
||||
github.com/rancher/wrangler v0.8.8
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/rootless-containers/rootlesskit v0.14.5
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
|
5
go.sum
5
go.sum
@ -871,8 +871,9 @@ github.com/rancher/remotedialer v0.2.0 h1:xD7t3K6JYwTdAsxmGtTHQMkEkFgKouQ1foLxVW
|
||||
github.com/rancher/remotedialer v0.2.0/go.mod h1:tkU8ZvrR5lRgaKWaX71nAy6daeqvPFx/lJEnbW7tXSI=
|
||||
github.com/rancher/wharfie v0.3.4 h1:wVqFW1cyRA20zY90Z56VrjG0lWg3oFmf/4ryr5Dkkis=
|
||||
github.com/rancher/wharfie v0.3.4/go.mod h1:cb8mSczpmw7ItbPF3K1W7crWuJLVdyV49sZZuaY4BS8=
|
||||
github.com/rancher/wrangler v0.8.5 h1:aHUVvJrOhD6CGrAELWKDpo1MBDC8vKtEQZvjMPnw2cs=
|
||||
github.com/rancher/wrangler v0.8.5/go.mod h1:dKEaHNB4izxmPUtpq1Hvr3z3Oh+9k5pCZyFO9sUhlaY=
|
||||
github.com/rancher/wrangler v0.8.3/go.mod h1:dKEaHNB4izxmPUtpq1Hvr3z3Oh+9k5pCZyFO9sUhlaY=
|
||||
github.com/rancher/wrangler v0.8.8 h1:3EEQmfUqZ/UG4hERHhihB+Q2F1s/W4CmfsPmXv17wS8=
|
||||
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/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
|
@ -86,7 +86,7 @@ func Run(ctx context.Context, cfg *config.Node) error {
|
||||
}
|
||||
|
||||
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.Stderr = stdErr
|
||||
cmd.Env = env
|
||||
|
@ -1,7 +1,6 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
@ -73,7 +72,7 @@ func Run(ctx *cli.Context) error {
|
||||
cfg.Debug = ctx.GlobalBool("debug")
|
||||
cfg.DataDir = dataDir
|
||||
|
||||
contextCtx := signals.SetupSignalHandler(context.Background())
|
||||
contextCtx := signals.SetupSignalContext()
|
||||
|
||||
return agent.Run(contextCtx, cfg)
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package etcdsnapshot
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -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.KubeConfigAdmin = filepath.Join(dataDir, "cred", "admin.kubeconfig")
|
||||
|
||||
ctx := signals.SetupSignalHandler(context.Background())
|
||||
ctx := signals.SetupSignalContext()
|
||||
e := etcd.NewETCD()
|
||||
e.SetControlConfig(&serverConfig.ControlConfig)
|
||||
|
||||
@ -132,7 +131,7 @@ func delete(app *cli.Context, cfg *cmds.Server) error {
|
||||
serverConfig.ControlConfig.DataDir = dataDir
|
||||
serverConfig.ControlConfig.Runtime.KubeConfigAdmin = filepath.Join(dataDir, "cred", "admin.kubeconfig")
|
||||
|
||||
ctx := signals.SetupSignalHandler(context.Background())
|
||||
ctx := signals.SetupSignalContext()
|
||||
e := etcd.NewETCD()
|
||||
e.SetControlConfig(&serverConfig.ControlConfig)
|
||||
|
||||
@ -162,7 +161,7 @@ func list(app *cli.Context, cfg *cmds.Server) error {
|
||||
|
||||
serverConfig.ControlConfig.DataDir = dataDir
|
||||
|
||||
ctx := signals.SetupSignalHandler(context.Background())
|
||||
ctx := signals.SetupSignalContext()
|
||||
e := etcd.NewETCD()
|
||||
e.SetControlConfig(&serverConfig.ControlConfig)
|
||||
|
||||
@ -203,7 +202,7 @@ func prune(app *cli.Context, cfg *cmds.Server) error {
|
||||
serverConfig.ControlConfig.DataDir = dataDir
|
||||
serverConfig.ControlConfig.EtcdSnapshotRetention = cfg.EtcdSnapshotRetention
|
||||
|
||||
ctx := signals.SetupSignalHandler(context.Background())
|
||||
ctx := signals.SetupSignalContext()
|
||||
e := etcd.NewETCD()
|
||||
e.SetControlConfig(&serverConfig.ControlConfig)
|
||||
|
||||
|
@ -408,7 +408,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
|
||||
|
||||
notifySocket := os.Getenv("NOTIFY_SOCKET")
|
||||
|
||||
ctx := signals.SetupSignalHandler(context.Background())
|
||||
ctx := signals.SetupSignalContext()
|
||||
|
||||
if err := server.StartServer(ctx, &serverConfig, cfg); err != nil {
|
||||
return err
|
||||
|
1
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_apply.go
generated
vendored
1
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_apply.go
generated
vendored
@ -30,6 +30,7 @@ const (
|
||||
LabelNamespace = "objectset.rio.cattle.io/owner-namespace"
|
||||
LabelHash = "objectset.rio.cattle.io/hash"
|
||||
LabelPrefix = "objectset.rio.cattle.io/"
|
||||
LabelPrune = "objectset.rio.cattle.io/prune"
|
||||
)
|
||||
|
||||
var (
|
||||
|
3
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_compare.go
generated
vendored
3
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_compare.go
generated
vendored
@ -207,8 +207,7 @@ func applyPatch(gvk schema.GroupVersionKind, reconciler Reconciler, patcher Patc
|
||||
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 {
|
||||
newObject, err := prepareObjectForCreate(gvk, newObject)
|
||||
if err != nil {
|
||||
|
14
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_process.go
generated
vendored
14
vendor/github.com/rancher/wrangler/pkg/apply/desiredset_process.go
generated
vendored
@ -382,6 +382,14 @@ func (o *desiredSet) list(namespaced bool, informer cache.SharedIndexInformer, c
|
||||
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) {
|
||||
for k := range newSet {
|
||||
if _, ok := existingSet[k]; ok {
|
||||
@ -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 {
|
||||
toDelete = append(toDelete, k)
|
||||
if shouldPrune(obj) {
|
||||
toDelete = append(toDelete, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
42
vendor/github.com/rancher/wrangler/pkg/signals/signal.go
generated
vendored
42
vendor/github.com/rancher/wrangler/pkg/signals/signal.go
generated
vendored
@ -1,12 +1,9 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@ -23,22 +20,47 @@ import (
|
||||
)
|
||||
|
||||
var onlyOneSignalHandler = make(chan struct{})
|
||||
var shutdownHandler chan os.Signal
|
||||
|
||||
// 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
|
||||
// is terminated with exit code 1.
|
||||
func SetupSignalHandler(parent context.Context) context.Context {
|
||||
close(onlyOneSignalHandler) // panics when called twice
|
||||
ctx, cancel := context.WithCancel(parent)
|
||||
// Only one of SetupSignalContext and SetupSignalHandler should be called, and only can
|
||||
// be called once.
|
||||
func SetupSignalHandler() <-chan struct{} {
|
||||
return SetupSignalContext().Done()
|
||||
}
|
||||
|
||||
c := make(chan os.Signal, 2)
|
||||
signal.Notify(c, shutdownSignals...)
|
||||
// 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
|
||||
|
||||
shutdownHandler = make(chan os.Signal, 2)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
signal.Notify(shutdownHandler, shutdownSignals...)
|
||||
go func() {
|
||||
<-c
|
||||
<-shutdownHandler
|
||||
cancel()
|
||||
<-c
|
||||
<-shutdownHandler
|
||||
os.Exit(1) // second signal. Exit directly.
|
||||
}()
|
||||
|
||||
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
|
||||
}
|
3
vendor/modules.txt
vendored
3
vendor/modules.txt
vendored
@ -996,7 +996,7 @@ github.com/rancher/remotedialer
|
||||
# github.com/rancher/wharfie v0.3.4
|
||||
## explicit
|
||||
github.com/rancher/wharfie/pkg/registries
|
||||
# github.com/rancher/wrangler v0.8.3 => github.com/rancher/wrangler v0.8.5
|
||||
# github.com/rancher/wrangler v0.8.8
|
||||
## explicit
|
||||
github.com/rancher/wrangler/pkg/apply
|
||||
github.com/rancher/wrangler/pkg/apply/injectors
|
||||
@ -3411,7 +3411,6 @@ sigs.k8s.io/yaml
|
||||
# github.com/opencontainers/runc => github.com/opencontainers/runc v1.0.2
|
||||
# github.com/opencontainers/runtime-spec => github.com/opencontainers/runtime-spec v1.0.3-0.20210316141917-a8c4a9ee0f6b
|
||||
# github.com/rancher/k3s/pkg/data => ./pkg/data
|
||||
# github.com/rancher/wrangler => github.com/rancher/wrangler v0.8.5
|
||||
# go.etcd.io/etcd/api/v3 => github.com/k3s-io/etcd/api/v3 v3.5.0-k3s2
|
||||
# go.etcd.io/etcd/client/v3 => github.com/k3s-io/etcd/client/v3 v3.5.0-k3s2
|
||||
# go.etcd.io/etcd/etcdutl/v3 => github.com/k3s-io/etcd/etcdutl/v3 v3.5.0-k3s2
|
||||
|
Loading…
Reference in New Issue
Block a user