@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "fmt"
2222 "io"
23+ "strings"
2324
2425 apierrors "k8s.io/apimachinery/pkg/api/errors"
2526 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -69,6 +70,7 @@ type pathAnnotationPlugin struct {
6970
7071var pathAnnotationResources = sets .New [string ](
7172 apisv1alpha2 .Resource ("apiexports" ).String (),
73+ apisv1alpha2 .Resource ("apibindings" ).String (),
7274 tenancyv1alpha1 .Resource ("workspacetypes" ).String (),
7375)
7476
@@ -105,6 +107,10 @@ func (p *pathAnnotationPlugin) Admit(ctx context.Context, a admission.Attributes
105107
106108 logicalCluster , err := p .getLogicalCluster (clusterName , corev1alpha1 .LogicalClusterName )
107109 if err != nil {
110+ // We skip gradually adding annotation for system bindings, if the logical cluster is not found during creation. This is racy during workspace bootstrap.
111+ if apierrors .IsNotFound (err ) && a .GetResource ().GroupResource () == apisv1alpha2 .Resource ("apibindings" ) && strings .Contains (a .GetName (), "kcp.io" ) {
112+ return nil
113+ }
108114 return admission .NewForbidden (a , fmt .Errorf ("cannot get this workspace: %w" , err ))
109115 }
110116 thisPath := logicalCluster .Annotations [core .LogicalClusterPathAnnotationKey ]
@@ -133,7 +139,12 @@ func (p *pathAnnotationPlugin) Validate(ctx context.Context, a admission.Attribu
133139 return nil
134140 }
135141
136- if a .GetResource ().GroupResource () == corev1alpha1 .Resource ("logicalclusters" ) {
142+ // We don't validate LogicalCluster resources themselves.
143+ // In addition, we skip validation for apibindings whose name contains "kcp.io" (system bindings),
144+ // as during bootstrap of the workspace its racy with creation of the LogicalCluster resource.
145+ // They will be eventually labeled, it will just takes a bit longer.
146+ if a .GetResource ().GroupResource () == corev1alpha1 .Resource ("logicalclusters" ) ||
147+ (a .GetResource ().GroupResource () == apisv1alpha2 .Resource ("apibindings" ) && strings .Contains (a .GetName (), "kcp.io" )) {
137148 return nil
138149 }
139150
0 commit comments