Skip to content

Commit bcfb633

Browse files
committed
Add path annotation to apibindings
Signed-off-by: Mangirdas Judeikis <[email protected]> On-behalf-of: @SAP [email protected]
1 parent fa4e118 commit bcfb633

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pkg/admission/pathannotation/pathannotation_admission.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type pathAnnotationPlugin struct {
6969

7070
var pathAnnotationResources = sets.New[string](
7171
apisv1alpha2.Resource("apiexports").String(),
72+
apisv1alpha2.Resource("apibindings").String(),
7273
tenancyv1alpha1.Resource("workspacetypes").String(),
7374
)
7475

@@ -105,6 +106,10 @@ func (p *pathAnnotationPlugin) Admit(ctx context.Context, a admission.Attributes
105106

106107
logicalCluster, err := p.getLogicalCluster(clusterName, corev1alpha1.LogicalClusterName)
107108
if err != nil {
109+
// We skip adding for system bindings if the logical cluster is not found during creation. This is racy during workspace bootstrap.
110+
if apierrors.IsNotFound(err) && a.GetResource().GroupResource() == apisv1alpha2.Resource("apibindings") {
111+
return nil
112+
}
108113
return admission.NewForbidden(a, fmt.Errorf("cannot get this workspace: %w", err))
109114
}
110115
thisPath := logicalCluster.Annotations[core.LogicalClusterPathAnnotationKey]
@@ -142,19 +147,25 @@ func (p *pathAnnotationPlugin) Validate(ctx context.Context, a admission.Attribu
142147
return fmt.Errorf("unexpected type %T", a.GetObject())
143148
}
144149

145-
value, found := u.GetAnnotations()[core.LogicalClusterPathAnnotationKey]
150+
annotations := u.GetAnnotations()
151+
value, found := annotations[core.LogicalClusterPathAnnotationKey]
146152
if pathAnnotationResources.Has(a.GetResource().GroupResource().String()) || found {
147153
logicalCluster, err := p.getLogicalCluster(clusterName, corev1alpha1.LogicalClusterName)
148154
if err != nil {
155+
// We skip adding for system bindings if the logical cluster is not found during creation. This is racy during workspace bootstrap.
156+
if apierrors.IsNotFound(err) && a.GetResource().GroupResource() == apisv1alpha2.Resource("apibindings") {
157+
return nil
158+
}
149159
return admission.NewForbidden(a, fmt.Errorf("cannot get this workspace: %w", err))
150160
}
151161
thisPath := logicalCluster.Annotations[core.LogicalClusterPathAnnotationKey]
152162
if thisPath == "" {
153163
thisPath = logicalcluster.From(logicalCluster).Path().String()
154164
}
155165

156-
if value != thisPath {
157-
return admission.NewForbidden(a, fmt.Errorf("annotation %q must match canonical path %q", core.LogicalClusterPathAnnotationKey, thisPath))
166+
// Only validate if annotation is explicitly set (found=true) and paths don't match
167+
if found && thisPath != "" && value != thisPath {
168+
return admission.NewForbidden(a, fmt.Errorf("annotation for %s, %q must match canonical path %q, but got %q", a.GetName(), core.LogicalClusterPathAnnotationKey, thisPath, value))
158169
}
159170
}
160171

0 commit comments

Comments
 (0)