Skip to content

Commit 1e17495

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 1e17495

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

7071
var 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

Comments
 (0)