@@ -6,12 +6,8 @@ package main
6
6
import (
7
7
"context"
8
8
"flag"
9
- "github.com/go-logr/logr"
10
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
9
clientset "k8s.io/client-go/kubernetes"
12
10
"k8s.io/client-go/rest"
13
- "k8s.io/client-go/tools/leaderelection"
14
- "k8s.io/client-go/tools/leaderelection/resourcelock"
15
11
"k8s.io/klog/v2"
16
12
"os"
17
13
logf "sigs.k8s.io/controller-runtime/pkg/log"
@@ -22,54 +18,6 @@ import (
22
18
// Version of kapp-controller is set via ldflags at build-time from the most recent git tag; see hack/build.sh
23
19
var Version = "develop"
24
20
25
- var (
26
- client * clientset.Clientset
27
- )
28
-
29
- func getNewLock (lockname , podname , namespace string ) * resourcelock.LeaseLock {
30
- return & resourcelock.LeaseLock {
31
- LeaseMeta : metav1.ObjectMeta {
32
- Name : lockname ,
33
- Namespace : namespace ,
34
- },
35
- Client : client .CoordinationV1 (),
36
- LockConfig : resourcelock.ResourceLockConfig {
37
- Identity : podname ,
38
- },
39
- }
40
- }
41
-
42
- func runLeaderElection (ctx context.Context , lock * resourcelock.LeaseLock , podname string , ctrlOpts Options , log logr.Logger ) {
43
- // Start the leader election for running kapp-controller
44
- log .Info ("Waiting for leader election" )
45
- leaderelection .RunOrDie (ctx , leaderelection.LeaderElectionConfig {
46
- Lock : lock ,
47
- ReleaseOnCancel : true ,
48
- LeaseDuration : 15 * time .Second ,
49
- RenewDeadline : 10 * time .Second ,
50
- RetryPeriod : 2 * time .Second ,
51
- Callbacks : leaderelection.LeaderCallbacks {
52
- OnStartedLeading : func (c context.Context ) {
53
- err := Run (ctrlOpts , log .WithName ("controller" ))
54
- if err != nil {
55
- klog .Errorf ("Error while running as leader: %v" , err )
56
- }
57
- },
58
- OnStoppedLeading : func () {
59
- klog .Fatalf ("no longer the leader, staying inactive." )
60
- os .Exit (0 )
61
- },
62
- OnNewLeader : func (identity string ) {
63
- //Notify when a new leader is elected
64
- if identity == podname {
65
- return
66
- }
67
- klog .InfoS ("new leader elected" , "id" , identity )
68
- },
69
- },
70
- })
71
- }
72
-
73
21
func main () {
74
22
ctrlOpts := Options {}
75
23
var sidecarexec bool
0 commit comments