Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,11 @@ func (c *controller) process(ctx context.Context, key string) error {
continue
}

// CRD doesn't exist.
if b.CRDExpiry != nil && time.Now().After(b.CRDExpiry.Time) {
logger.V(4).Info("removing expired CRD binding of non-existing CRD", "crd", gr)
// CRD doesn't exist (anymore): release the lock immediately if it was
// held without an expiry (the CRD was deleted), or once an existing
// expiry has passed.
if b.CRDExpiry == nil || time.Now().After(b.CRDExpiry.Time) {
logger.V(4).Info("removing CRD binding of non-existing CRD", "crd", gr)
delete(rbs, gr)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func TestReconciler(t *testing.T) {
logicalCluster: &corev1alpha1.LogicalCluster{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
"internal.apis.kcp.io/resource-bindings": `{"as.group":{"n":"binding1"},"bs.group":{"n":"binding1"},"crd1s.group":{"c":true},"crd2s.group":{"c":true},"cs.group":{"n":"binding2"},"ds.group":{"n":"binding2"}}`,
}}},
crds: []*apiextensionsv1.CustomResourceDefinition{
withEstablished(newCRD("group", "crd1s")),
withEstablished(newCRD("group", "crd2s")),
},
apiBindings: []*apisv1alpha2.APIBinding{
&newAPIBinding().WithName("binding1").WithBoundResources("group", "as", "group", "bs").APIBinding,
},
Expand All @@ -115,6 +119,15 @@ func TestReconciler(t *testing.T) {
"internal.apis.kcp.io/resource-bindings": fmt.Sprintf(`{"crd1s.group":{"c":true},"crd3s.group":{"c":true,"e":%q}}`, notExpired),
}}},
},
"deleted CRD whose lock has no expiry is removed": {
logicalCluster: &corev1alpha1.LogicalCluster{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
"internal.apis.kcp.io/resource-bindings": `{"crd1s.group":{"c":true}}`,
}}},
crds: []*apiextensionsv1.CustomResourceDefinition{},
want: &corev1alpha1.LogicalCluster{ObjectMeta: metav1.ObjectMeta{Annotations: map[string]string{
"internal.apis.kcp.io/resource-bindings": `{}`,
}}},
},
}
for name, tt := range tests {
t.Run(name, func(t *testing.T) {
Expand Down