@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"sync"
22
22
23
+ kerrors "k8s.io/apimachinery/pkg/util/errors"
23
24
"sigs.k8s.io/controller-runtime/pkg/cluster"
24
25
)
25
26
@@ -64,22 +65,33 @@ func (c *multiClusterController) Engage(clusterCtx context.Context, cl cluster.C
64
65
return nil
65
66
}
66
67
68
+ engaged := make ([]cluster.Aware , 0 , len (c .awares )+ 1 )
69
+ disengage := func () error {
70
+ var errs []error
71
+ for _ , aware := range engaged {
72
+ if err := aware .Disengage (clusterCtx , cl ); err != nil {
73
+ errs = append (errs , err )
74
+ }
75
+ }
76
+ return kerrors .NewAggregate (errs )
77
+ }
78
+
67
79
// pass through in case the controller itself is cluster aware
68
80
if ctrl , ok := c .Controller .(cluster.Aware ); ok {
69
81
if err := ctrl .Engage (clusterCtx , cl ); err != nil {
70
82
return err
71
83
}
84
+ engaged = append (engaged , ctrl )
72
85
}
73
86
74
87
// start watches on the cluster
75
88
if err := c .watcher .Watch (clusterCtx , cl ); err != nil {
76
- if ctrl , ok := c .Controller .(cluster.AwareRunnable ); ok {
77
- if err := ctrl .Disengage (clusterCtx , cl ); err != nil {
78
- return err
79
- }
89
+ if err := disengage (); err != nil {
90
+ return err
80
91
}
81
92
return err
82
93
}
94
+
83
95
c .clusters [cl .Name ()] = struct {}{}
84
96
85
97
return nil
@@ -96,11 +108,12 @@ func (c *multiClusterController) Disengage(ctx context.Context, cl cluster.Clust
96
108
delete (c .clusters , cl .Name ())
97
109
98
110
// pass through in case the controller itself is cluster aware
99
- if ctrl , ok := c .Controller .(cluster.AwareRunnable ); ok {
111
+ var errs []error
112
+ if ctrl , ok := c .Controller .(cluster.Aware ); ok {
100
113
if err := ctrl .Disengage (ctx , cl ); err != nil {
101
- return err
114
+ errs = append ( errs , err )
102
115
}
103
116
}
104
117
105
- return nil
118
+ return kerrors . NewAggregate ( errs )
106
119
}
0 commit comments