Skip to content

Commit f54cdfa

Browse files
committed
handle isolation with resources
1 parent 7f727df commit f54cdfa

6 files changed

Lines changed: 29 additions & 11 deletions

File tree

backend/controllers/servicenamespace/servicenamespace_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ func NewAPIServiceNamespaceReconciler(
7575
informerScope: scope,
7676
isolation: isolation,
7777
reconciler: reconciler{
78-
scope: scope,
78+
scope: scope,
79+
isolation: isolation,
7980

8081
getNamespace: func(ctx context.Context, cache cache.Cache, name string) (*corev1.Namespace, error) {
8182
var ns corev1.Namespace

backend/controllers/servicenamespace/servicenamespace_reconcile.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import (
3939
)
4040

4141
type reconciler struct {
42-
scope kubebindv1alpha2.InformerScope
42+
scope kubebindv1alpha2.InformerScope
43+
isolation kubebindv1alpha2.Isolation
4344

4445
getNamespace func(ctx context.Context, cache cache.Cache, name string) (*corev1.Namespace, error)
4546
createNamespace func(ctx context.Context, client client.Client, ns *corev1.Namespace) error
@@ -52,11 +53,20 @@ type reconciler struct {
5253

5354
func (c *reconciler) reconcile(ctx context.Context, client client.Client, cache cache.Cache, sns *kubebindv1alpha2.APIServiceNamespace) error {
5455
var ns *corev1.Namespace
55-
nsName := sns.Namespace + "-" + sns.Name
56-
if sns.Status.Namespace != "" {
56+
var nsName string
57+
switch {
58+
case sns.Status.Namespace != "":
59+
// use existing namespace from status
5760
nsName = sns.Status.Namespace
58-
ns, _ = c.getNamespace(ctx, cache, nsName) // golint:errcheck
61+
case c.isolation == kubebindv1alpha2.IsolationNone:
62+
nsName = sns.Name
63+
case c.isolation == kubebindv1alpha2.IsolationNamespaced || c.isolation == kubebindv1alpha2.IsolationPrefixed:
64+
nsName = sns.Namespace + "-" + sns.Name
65+
default:
66+
return fmt.Errorf("unknown isolation strategy: %s", c.isolation)
5967
}
68+
ns, _ = c.getNamespace(ctx, cache, nsName)
69+
6070
if ns == nil {
6171
ns = &corev1.Namespace{
6272
ObjectMeta: metav1.ObjectMeta{

backend/options/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ func (options *Options) Complete() (*CompletedOptions, error) {
210210
options.Isolation = string(kubebindv1alpha2.IsolationNamespaced)
211211
case "none":
212212
options.Isolation = string(kubebindv1alpha2.IsolationNone)
213+
default:
214+
options.Isolation = string(kubebindv1alpha2.IsolationNone)
213215
}
214216

215217
if options.ExternalCAFile != "" && options.ExternalCA != nil {

docs/content/usage/api-concepts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ spec:
114114
consumer: consumer123
115115

116116
# How isolation is done at the provider side
117-
clusterScopedIsolation: Prefixed
117+
isolation: Prefixed
118118
# informerScope is the scope of the APIServiceExport. It can be either Cluster or Namespace.
119119
#
120120
# Cluster: The konnector has permission to watch all namespaces at once and cluster-scoped resources.

pkg/konnector/controllers/cluster/serviceexport/serviceexport_reconcile.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (r *reconciler) ensureControllers(ctx context.Context, namespace, name stri
144144
}
145145

146146
processedSchemas[name] = true // This is only schemas names (suffix)
147-
isClusterScoped = schema.Spec.Scope == apiextensionsv1.ClusterScoped || schema.Spec.InformerScope == kubebindv1alpha2.ClusterScope
147+
isClusterScoped = schema.Spec.InformerScope == kubebindv1alpha2.ClusterScope
148148
}
149149

150150
// Ensure controller for permission claims
@@ -267,16 +267,20 @@ func (r *reconciler) ensureControllerForSchema(ctx context.Context, export *kube
267267
return providerBindClient.KubeBindV1alpha2().APIServiceNamespaces(sn.Namespace).Create(ctx, sn, metav1.CreateOptions{})
268268
})
269269

270-
case export.Spec.ClusterScopedIsolation == kubebindv1alpha2.IsolationNone:
270+
case export.Spec.Isolation == kubebindv1alpha2.IsolationNone:
271+
logger.V(4).Info("Using None isolation strategy", "export", export.Name)
271272
isolationStrategy = isolation.NewNone(r.providerNamespace, providerNamespaceUID)
272273

273-
case export.Spec.ClusterScopedIsolation == kubebindv1alpha2.IsolationPrefixed:
274+
case export.Spec.Isolation == kubebindv1alpha2.IsolationPrefixed:
275+
logger.V(4).Info("Using Prefixed isolation strategy", "export", export.Name)
274276
isolationStrategy = isolation.NewPrefixed(r.providerNamespace, providerNamespaceUID)
275277

276-
case export.Spec.ClusterScopedIsolation == kubebindv1alpha2.IsolationNamespaced:
278+
case export.Spec.Isolation == kubebindv1alpha2.IsolationNamespaced:
279+
logger.V(4).Info("Using Namespaced isolation strategy", "export", export.Name)
277280
isolationStrategy = isolation.NewNamespaced(r.providerNamespace)
278281
default:
279282
// Default to None isolation strategy if no valid isolation strategy is specified
283+
logger.V(4).Info("Using default None isolation strategy", "export", export.Name)
280284
isolationStrategy = isolation.NewNone(r.providerNamespace, providerNamespaceUID)
281285
}
282286

@@ -343,7 +347,7 @@ func (r *reconciler) ensureControllersForPermissionClaims(
343347
ctx context.Context,
344348
export *kubebindv1alpha2.APIServiceExport,
345349
binding *kubebindv1alpha2.APIServiceBinding,
346-
isClusterScoped bool, // schema.Spec.Scope == apiextensionsv1.ClusterScoped || schema.Spec.InformerScope == kubebindv1alpha2.ClusterScope
350+
isClusterScoped bool, // schema.Spec.InformerScope == kubebindv1alpha2.ClusterScope
347351
) error {
348352
logger := klog.FromContext(ctx)
349353

pkg/konnector/controllers/cluster/serviceexport/spec/spec_reconcile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func (r *reconciler) reconcile(ctx context.Context, obj *unstructured.Unstructur
112112
}
113113

114114
logger.Info("Creating upstream object")
115+
logger.V(4).Info("Upstream object", "object", fmt.Sprintf("%s", upstream.Object))
115116
if _, err := r.createProviderObject(ctx, upstream); err != nil && !apierrors.IsAlreadyExists(err) {
116117
return err
117118
} else if apierrors.IsAlreadyExists(err) {

0 commit comments

Comments
 (0)