Skip to content

Commit a44d8b5

Browse files
committed
Update clusters when their config changed
Signed-off-by: Nelo-T. Wallus <[email protected]>
1 parent 4f3a105 commit a44d8b5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

providers/file/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ replace sigs.k8s.io/multicluster-runtime => ../..
66

77
require (
88
github.com/go-logr/logr v1.4.3
9+
github.com/google/go-cmp v0.7.0
910
github.com/onsi/ginkgo/v2 v2.23.4
1011
github.com/onsi/gomega v1.38.0
1112
golang.org/x/sync v0.16.0
@@ -31,7 +32,6 @@ require (
3132
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
3233
github.com/gogo/protobuf v1.3.2 // indirect
3334
github.com/google/gnostic-models v0.6.9 // indirect
34-
github.com/google/go-cmp v0.7.0 // indirect
3535
github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect
3636
github.com/google/uuid v1.6.0 // indirect
3737
github.com/josharian/intern v1.0.0 // indirect

providers/file/provider.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"sync"
2727

2828
"github.com/go-logr/logr"
29+
"github.com/google/go-cmp/cmp"
2930
"gopkg.in/fsnotify.v1"
3031

3132
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -217,25 +218,34 @@ func (p *Provider) removeCluster(name string) {
217218
}
218219

219220
func (p *Provider) run(ctx context.Context, mgr mcmanager.Manager) error {
220-
currentClusters, err := p.loadClusters()
221+
loadedClusters, err := p.loadClusters()
221222
if err != nil {
222223
return fmt.Errorf("failed to load clusters: %w", err)
223224
}
224225
knownClusters := p.ClusterNames()
225226

226227
// add new clusters
227-
for name, cl := range currentClusters {
228+
for name, cl := range loadedClusters {
228229
if slices.Contains(knownClusters, name) {
230+
// update if the config has changed
231+
existingCluster, _ := p.Get(ctx, name)
232+
if !cmp.Equal(existingCluster.GetConfig(), cl.GetConfig()) {
233+
p.log.Info("updating cluster", "name", name)
234+
p.removeCluster(name)
235+
p.addCluster(ctx, mgr, name, cl)
236+
}
229237
continue
230238
}
239+
p.log.Info("adding cluster", "name", name)
231240
p.addCluster(ctx, mgr, name, cl)
232241
}
233242

234243
// delete clusters that are no longer present
235244
for _, name := range knownClusters {
236-
if _, ok := currentClusters[name]; ok {
245+
if _, ok := loadedClusters[name]; ok {
237246
continue
238247
}
248+
p.log.Info("removing cluster", "name", name)
239249
p.removeCluster(name)
240250
}
241251

0 commit comments

Comments
 (0)