@@ -29,6 +29,7 @@ import (
2929 "k8s.io/apimachinery/pkg/util/sets"
3030 "k8s.io/apimachinery/pkg/util/validation"
3131 "k8s.io/apimachinery/pkg/util/validation/field"
32+ "k8s.io/klog/v2"
3233 ctrl "sigs.k8s.io/controller-runtime"
3334 "sigs.k8s.io/controller-runtime/pkg/client"
3435 "sigs.k8s.io/controller-runtime/pkg/webhook"
@@ -40,6 +41,7 @@ import (
4041 "sigs.k8s.io/cluster-api/internal/topology/check"
4142 topologynames "sigs.k8s.io/cluster-api/internal/topology/names"
4243 "sigs.k8s.io/cluster-api/internal/topology/variables"
44+ clog "sigs.k8s.io/cluster-api/util/log"
4345)
4446
4547func (webhook * ClusterClass ) SetupWebhookWithManager (mgr ctrl.Manager ) error {
@@ -137,9 +139,11 @@ func (webhook *ClusterClass) ValidateDelete(ctx context.Context, obj runtime.Obj
137139 }
138140
139141 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 )
141145 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 ))
143147 }
144148 return nil , nil
145149}
0 commit comments