Skip to content

Commit 216ff38

Browse files
committed
Update providers and examples to use multicluster.ErrClusterNotFound
On-behalf-of: SAP <[email protected]> Signed-off-by: Marvin Beckers <[email protected]>
1 parent 3d04984 commit 216ff38

File tree

8 files changed

+21
-8
lines changed

8 files changed

+21
-8
lines changed

examples/cluster-api/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040

4141
mcbuilder "sigs.k8s.io/multicluster-runtime/pkg/builder"
4242
mcmanager "sigs.k8s.io/multicluster-runtime/pkg/manager"
43+
"sigs.k8s.io/multicluster-runtime/pkg/multicluster"
4344
mcreconcile "sigs.k8s.io/multicluster-runtime/pkg/reconcile"
4445
capi "sigs.k8s.io/multicluster-runtime/providers/cluster-api"
4546
)
@@ -103,6 +104,10 @@ func main() {
103104

104105
cl, err := mcMgr.GetCluster(ctx, req.ClusterName)
105106
if err != nil {
107+
if errors.Is(err, multicluster.ErrClusterNotFound) {
108+
log.Info("Cluster not found, might have been disengaged")
109+
return reconcile.Result{}, nil
110+
}
106111
return reconcile.Result{}, err
107112
}
108113

examples/kind/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535

3636
mcbuilder "sigs.k8s.io/multicluster-runtime/pkg/builder"
3737
mcmanager "sigs.k8s.io/multicluster-runtime/pkg/manager"
38+
"sigs.k8s.io/multicluster-runtime/pkg/multicluster"
3839
mcreconcile "sigs.k8s.io/multicluster-runtime/pkg/reconcile"
3940
"sigs.k8s.io/multicluster-runtime/providers/kind"
4041
)
@@ -61,7 +62,10 @@ func main() {
6162

6263
cl, err := mgr.GetCluster(ctx, req.ClusterName)
6364
if err != nil {
64-
return reconcile.Result{}, err
65+
if errors.Is(err, multicluster.ErrClusterNotFound) {
66+
log.Info("Cluster not found, might have been disengaged")
67+
return reconcile.Result{}, nil
68+
}
6569
}
6670

6771
cm := &corev1.ConfigMap{}

examples/namespace/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343

4444
mcbuilder "sigs.k8s.io/multicluster-runtime/pkg/builder"
4545
mcmanager "sigs.k8s.io/multicluster-runtime/pkg/manager"
46+
"sigs.k8s.io/multicluster-runtime/pkg/multicluster"
4647
mcreconcile "sigs.k8s.io/multicluster-runtime/pkg/reconcile"
4748
"sigs.k8s.io/multicluster-runtime/providers/namespace"
4849
)
@@ -127,6 +128,10 @@ func main() {
127128

128129
cl, err := mgr.GetCluster(ctx, req.ClusterName)
129130
if err != nil {
131+
if errors.Is(err, multicluster.ErrClusterNotFound) {
132+
log.Info("Cluster not found, might have been disengaged")
133+
return reconcile.Result{}, nil
134+
}
130135
return reconcile.Result{}, err
131136
}
132137

providers/cluster-api/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func (p *Provider) Get(_ context.Context, clusterName string) (cluster.Cluster,
123123
return cl, nil
124124
}
125125

126-
return nil, fmt.Errorf("cluster %s not found", clusterName)
126+
return nil, multicluster.ErrClusterNotFound
127127
}
128128

129129
// Run starts the provider and blocks.

providers/kind/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func (p *Provider) Get(ctx context.Context, clusterName string) (cluster.Cluster
7373
return cl, nil
7474
}
7575

76-
return nil, fmt.Errorf("cluster %s not found", clusterName)
76+
return nil, multicluster.ErrClusterNotFound
7777
}
7878

7979
// Run starts the provider and blocks.

providers/namespace/provider.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ func (p *Provider) Get(_ context.Context, clusterName string) (cluster.Cluster,
134134
if cl, ok := p.clusters[clusterName]; ok {
135135
return cl, nil
136136
}
137-
return nil, fmt.Errorf("cluster %s not found", clusterName)
137+
138+
return nil, multicluster.ErrClusterNotFound
138139
}
139140

140141
// IndexField indexes a field on all clusters.

providers/nop/provider.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package namespace
1818

1919
import (
2020
"context"
21-
"fmt"
2221

2322
"sigs.k8s.io/controller-runtime/pkg/client"
2423
"sigs.k8s.io/controller-runtime/pkg/cluster"
@@ -45,7 +44,7 @@ func (p *Provider) Run(ctx context.Context, _ mcmanager.Manager) error {
4544

4645
// Get returns an error for any cluster name.
4746
func (p *Provider) Get(_ context.Context, clusterName string) (cluster.Cluster, error) {
48-
return nil, fmt.Errorf("cluster %s not found", clusterName)
47+
return nil, multicluster.ErrClusterNotFound
4948
}
5049

5150
// IndexField does nothing.

providers/single/provider.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package namespace
1818

1919
import (
2020
"context"
21-
"fmt"
2221

2322
"sigs.k8s.io/controller-runtime/pkg/client"
2423
"sigs.k8s.io/controller-runtime/pkg/cluster"
@@ -55,7 +54,7 @@ func (p *Provider) Get(_ context.Context, clusterName string) (cluster.Cluster,
5554
if clusterName == p.name {
5655
return p.cl, nil
5756
}
58-
return nil, fmt.Errorf("cluster %s not found", clusterName)
57+
return nil, multicluster.ErrClusterNotFound
5958
}
6059

6160
// IndexField calls IndexField on the single cluster.

0 commit comments

Comments
 (0)