Skip to content

Commit be46ed4

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 be46ed4

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

pkg/admission/apibinding/apibinding_interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type apiBinding interface {
3030
Validate() field.ErrorList
3131
ValidateUpdate(oldBinding apiBinding) field.ErrorList
3232
ToUnstructured() (map[string]interface{}, error)
33+
GetAnnotations() map[string]string
3334
}
3435

3536
type bindingReference interface {

pkg/admission/apibinding/apibinding_v1alpha1.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (b *apiBindingV1alpha1) SetLabels(labels map[string]string) {
5252
b.binding.Labels = labels
5353
}
5454

55+
func (b apiBindingV1alpha1) GetAnnotations() map[string]string {
56+
return b.binding.Annotations
57+
}
58+
5559
func (b *apiBindingV1alpha1) Validate() field.ErrorList {
5660
return apisv1alpha1.ValidateAPIBinding(b.binding)
5761
}

pkg/admission/apibinding/apibinding_v1alpha2.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ func (b *apiBindingV1alpha2) SetLabels(labels map[string]string) {
5252
b.binding.Labels = labels
5353
}
5454

55+
func (b apiBindingV1alpha2) GetAnnotations() map[string]string {
56+
return b.binding.Annotations
57+
}
58+
5559
func (b apiBindingV1alpha2) Validate() field.ErrorList {
5660
return apisv1alpha2.ValidateAPIBinding(b.binding)
5761
}

pkg/admission/pathannotation/pathannotation_admission.go

Lines changed: 9 additions & 0 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 annotation 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]
@@ -146,6 +151,10 @@ func (p *pathAnnotationPlugin) Validate(ctx context.Context, a admission.Attribu
146151
if pathAnnotationResources.Has(a.GetResource().GroupResource().String()) || found {
147152
logicalCluster, err := p.getLogicalCluster(clusterName, corev1alpha1.LogicalClusterName)
148153
if err != nil {
154+
// We skip adding annotation for system bindings if the logical cluster is not found during creation. This is racy during workspace bootstrap.
155+
if apierrors.IsNotFound(err) && a.GetResource().GroupResource() == apisv1alpha2.Resource("apibindings") {
156+
return nil
157+
}
149158
return admission.NewForbidden(a, fmt.Errorf("cannot get this workspace: %w", err))
150159
}
151160
thisPath := logicalCluster.Annotations[core.LogicalClusterPathAnnotationKey]

0 commit comments

Comments
 (0)