@@ -29,6 +29,7 @@ import (
29
29
"k8s.io/apimachinery/pkg/util/sets"
30
30
"k8s.io/apimachinery/pkg/util/validation"
31
31
"k8s.io/apimachinery/pkg/util/validation/field"
32
+ "k8s.io/klog/v2"
32
33
ctrl "sigs.k8s.io/controller-runtime"
33
34
"sigs.k8s.io/controller-runtime/pkg/client"
34
35
"sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -40,6 +41,7 @@ import (
40
41
"sigs.k8s.io/cluster-api/internal/topology/check"
41
42
topologynames "sigs.k8s.io/cluster-api/internal/topology/names"
42
43
"sigs.k8s.io/cluster-api/internal/topology/variables"
44
+ clog "sigs.k8s.io/cluster-api/util/log"
43
45
)
44
46
45
47
func (webhook * ClusterClass ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
@@ -137,9 +139,11 @@ func (webhook *ClusterClass) ValidateDelete(ctx context.Context, obj runtime.Obj
137
139
}
138
140
139
141
if len (clusters ) > 0 {
140
- // TODO(killianmuldoon): Improve error here to include the names of some clusters using the clusterClass.
142
+ clustersList := clog .ListToString (clusters , func (cluster clusterv1.Cluster ) string {
143
+ return klog .KObj (& cluster ).String ()
144
+ }, 3 )
141
145
return nil , apierrors .NewForbidden (clusterv1 .GroupVersion .WithResource ("ClusterClass" ).GroupResource (), clusterClass .Name ,
142
- fmt .Errorf ("ClusterClass cannot be deleted because it is used by %d Cluster(s)" , len ( clusters ) ))
146
+ fmt .Errorf ("ClusterClass cannot be deleted because it is used by Cluster(s): %s " , clustersList ))
143
147
}
144
148
return nil , nil
145
149
}
0 commit comments