Skip to content

Commit db0166e

Browse files
committed
refactor to APIServiceExportTemplate
1 parent 09f9d4a commit db0166e

50 files changed

Lines changed: 778 additions & 1220 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ import (
3939

4040
kuberesources "github.com/kube-bind/kube-bind/backend/kubernetes/resources"
4141
"github.com/kube-bind/kube-bind/backend/options"
42-
catalogv1alpha1 "github.com/kube-bind/kube-bind/sdk/apis/catalog/v1alpha1"
4342
kubebindv1alpha1 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha1"
4443
kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2"
4544
)
@@ -89,9 +88,6 @@ func NewConfig(options *options.CompletedOptions) (*Config, error) {
8988
if err := kubebindv1alpha2.AddToScheme(scheme); err != nil {
9089
return nil, fmt.Errorf("error adding kubebind scheme: %w", err)
9190
}
92-
if err := catalogv1alpha1.AddToScheme(scheme); err != nil {
93-
return nil, fmt.Errorf("error adding catalog scheme: %w", err)
94-
}
9591

9692
config.Scheme = scheme
9793

backend/http/handler.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"github.com/kube-bind/kube-bind/backend/session"
4242
"github.com/kube-bind/kube-bind/backend/template"
4343
bindversion "github.com/kube-bind/kube-bind/pkg/version"
44-
catalogv1alpha1 "github.com/kube-bind/kube-bind/sdk/apis/catalog/v1alpha1"
4544
kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2"
4645
)
4746

@@ -417,7 +416,7 @@ func (h *handler) handleResources(w http.ResponseWriter, r *http.Request) {
417416

418417
func (h *handler) handleBind(w http.ResponseWriter, r *http.Request) {
419418
logger := getLogger(r)
420-
moduleName := r.URL.Query().Get("module")
419+
templateName := r.URL.Query().Get("template")
421420
providerCluster := mux.Vars(r)["cluster"]
422421

423422
prepareNoCache(w)
@@ -446,9 +445,9 @@ func (h *handler) handleBind(w http.ResponseWriter, r *http.Request) {
446445
}
447446

448447
// Module consist of many resources and permissionClaims. Read it and translate to
449-
module, err := h.kubeManager.GetModule(r.Context(), providerCluster, moduleName)
448+
template, err := h.kubeManager.GetTemplates(r.Context(), providerCluster, templateName)
450449
if err != nil {
451-
logger.Error(err, "failed to get module")
450+
logger.Error(err, "failed to get template")
452451
http.Error(w, "internal error", http.StatusInternalServerError)
453452
return
454453
}
@@ -459,12 +458,12 @@ func (h *handler) handleBind(w http.ResponseWriter, r *http.Request) {
459458
Kind: "APIServiceExportRequest",
460459
},
461460
ObjectMeta: kubebindv1alpha2.NameObjectMeta{
462-
Name: moduleName,
461+
Name: templateName,
463462
},
464463
Spec: kubebindv1alpha2.APIServiceExportRequestSpec{
465-
Resources: module.Spec.Resources,
466-
PermissionClaims: module.Spec.PermissionClaims,
467-
Namespaces: module.Spec.Namespaces,
464+
Resources: template.Spec.Resources,
465+
PermissionClaims: template.Spec.PermissionClaims,
466+
Namespaces: template.Spec.Namespaces,
468467
},
469468
}
470469

@@ -528,22 +527,22 @@ func mustRead(f func(name string) ([]byte, error), name string) string {
528527
// Flow is:
529528
// 1. List Collection and check what modules we are targeting
530529
// 2. Get modules from the backend cluster and consutruct shallow-bound schemas (no crd content).
531-
func (h *handler) listCollectionModules(ctx context.Context, cluster string) (*catalogv1alpha1.ModuleList, error) {
530+
func (h *handler) listCollectionModules(ctx context.Context, cluster string) (*kubebindv1alpha2.APIServiceExportTemplateList, error) {
532531
collections, err := h.kubeManager.ListCollections(ctx, cluster)
533532
if err != nil {
534533
return nil, fmt.Errorf("failed to list collections: %w", err)
535534
}
536535

537-
modules := &catalogv1alpha1.ModuleList{}
536+
templates := &kubebindv1alpha2.APIServiceExportTemplateList{}
538537
for _, collection := range collections.Items {
539-
for _, m := range collection.Spec.Modules {
540-
module, err := h.kubeManager.GetModule(ctx, cluster, m.Name)
538+
for _, t := range collection.Spec.Templates {
539+
template, err := h.kubeManager.GetTemplates(ctx, cluster, t.Name)
541540
if err != nil {
542-
return nil, fmt.Errorf("failed to get module %q: %w", m.Name, err)
541+
return nil, fmt.Errorf("failed to get template %q: %w", t.Name, err)
543542
}
544-
modules.Items = append(modules.Items, *module)
543+
templates.Items = append(templates.Items, *template)
545544
}
546545
}
547546

548-
return modules, nil
547+
return templates, nil
549548
}

backend/kubernetes/manager.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
mcmanager "sigs.k8s.io/multicluster-runtime/pkg/manager"
3434

3535
kuberesources "github.com/kube-bind/kube-bind/backend/kubernetes/resources"
36-
catalogv1alpha1 "github.com/kube-bind/kube-bind/sdk/apis/catalog/v1alpha1"
3736
kubebindv1alpha2 "github.com/kube-bind/kube-bind/sdk/apis/kubebind/v1alpha2"
3837
)
3938

@@ -166,14 +165,14 @@ func (m *Manager) ListCustomResourceDefinitions(ctx context.Context, cluster str
166165
return &crds, nil
167166
}
168167

169-
func (m *Manager) ListCollections(ctx context.Context, cluster string) (*catalogv1alpha1.CollectionList, error) {
168+
func (m *Manager) ListCollections(ctx context.Context, cluster string) (*kubebindv1alpha2.CollectionList, error) {
170169
cl, err := m.manager.GetCluster(ctx, cluster)
171170
if err != nil {
172171
return nil, err
173172
}
174173
c := cl.GetClient()
175174

176-
var collections catalogv1alpha1.CollectionList
175+
var collections kubebindv1alpha2.CollectionList
177176
err = c.List(ctx, &collections)
178177
if err != nil {
179178
return nil, err
@@ -182,20 +181,20 @@ func (m *Manager) ListCollections(ctx context.Context, cluster string) (*catalog
182181
return &collections, nil
183182
}
184183

185-
func (m *Manager) GetModule(ctx context.Context, cluster, name string) (*catalogv1alpha1.Module, error) {
184+
func (m *Manager) GetTemplates(ctx context.Context, cluster, name string) (*kubebindv1alpha2.APIServiceExportTemplate, error) {
186185
cl, err := m.manager.GetCluster(ctx, cluster)
187186
if err != nil {
188187
return nil, err
189188
}
190189
c := cl.GetClient()
191190

192-
var module catalogv1alpha1.Module
193-
err = c.Get(ctx, types.NamespacedName{Name: name}, &module)
191+
var template kubebindv1alpha2.APIServiceExportTemplate
192+
err = c.Get(ctx, types.NamespacedName{Name: name}, &template)
194193
if err != nil {
195194
return nil, err
196195
}
197196

198-
return &module, nil
197+
return &template, nil
199198
}
200199

201200
func (m *Manager) ListDynamicResources(ctx context.Context, cluster string, gvk schema.GroupVersionKind, selector labels.Selector) (*unstructured.UnstructuredList, error) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
apiVersion: catalog.kube-bind.io/v1alpha1
1+
apiVersion: kube-bind.io/v1alpha2
22
kind: Collection
33
metadata:
44
name: wildwest
55
namespace: default
66
spec:
77
description: "A collection of Wild West service definitions including Cowboys and Sheriffs for frontier management"
8-
modules:
8+
templates:
99
- name: cowboys
1010
- name: sheriffs

contrib/kcp/deploy/examples/module-cowboys.yaml renamed to contrib/kcp/deploy/examples/template-cowboys.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
apiVersion: catalog.kube-bind.io/v1alpha1
2-
kind: Module
1+
apiVersion: kube-bind.io/v1alpha2
2+
kind: APIServiceExportTemplate
33
metadata:
44
name: cowboys
55
spec:

contrib/kcp/deploy/examples/module-sheriffs.yaml renamed to contrib/kcp/deploy/examples/template-sheriffs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
apiVersion: catalog.kube-bind.io/v1alpha1
2-
kind: Module
1+
apiVersion: kube-bind.io/v1alpha2
2+
kind: APIServiceExportTemplate
33
metadata:
44
name: sheriffs
55
spec:

contrib/kcp/deploy/resources/apiexport-catalog.kube-bind.io.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.

contrib/kcp/deploy/resources/apiexport-kube-bind.io.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,14 @@ spec:
8787
schema: v250925-56669b8.clusterbindings.kube-bind.io
8888
storage:
8989
crd: {}
90+
- group: kube-bind.io
91+
name: apiserviceexporttemplates
92+
schema: v251020-d1ae972.apiserviceexporttemplates.kube-bind.io
93+
storage:
94+
crd: {}
95+
- group: kube-bind.io
96+
name: collections
97+
schema: v251020-d1ae972.collections.kube-bind.io
98+
storage:
99+
crd: {}
90100
status: {}

contrib/kcp/deploy/resources/apiresourceschema-modules.catalog.kube-bind.io.yaml renamed to contrib/kcp/deploy/resources/apiresourceschema-apiserviceexporttemplates.kube-bind.io.yaml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ apiVersion: apis.kcp.io/v1alpha1
22
kind: APIResourceSchema
33
metadata:
44
creationTimestamp: null
5-
name: v251017-d84f782.modules.catalog.kube-bind.io
5+
name: v251020-d1ae972.apiserviceexporttemplates.kube-bind.io
66
spec:
7-
group: catalog.kube-bind.io
7+
group: kube-bind.io
88
names:
99
categories:
1010
- kube-bind
11-
kind: Module
12-
listKind: ModuleList
13-
plural: modules
14-
singular: module
11+
kind: APIServiceExportTemplate
12+
listKind: APIServiceExportTemplateList
13+
plural: apiserviceexporttemplates
14+
singular: apiserviceexporttemplate
1515
scope: Cluster
1616
versions:
1717
- additionalPrinterColumns:
@@ -24,10 +24,10 @@ spec:
2424
- jsonPath: .metadata.creationTimestamp
2525
name: Age
2626
type: date
27-
name: v1alpha1
27+
name: v1alpha2
2828
schema:
29-
description: Module groups multiple CRDs with related resources (permissionClaims)
30-
as a Service definition.
29+
description: APIServiceExportTemplate groups multiple CRDs with related resources
30+
(permissionClaims) as a Service definition.
3131
properties:
3232
apiVersion:
3333
description: |-
@@ -47,11 +47,11 @@ spec:
4747
metadata:
4848
type: object
4949
spec:
50-
description: spec specifies the module.
50+
description: spec specifies the template.
5151
properties:
5252
namespaces:
5353
description: |-
54-
namespaces specifies the namespaces that should be bootstrapped as part of this module.
54+
namespaces specifies the namespaces that should be bootstrapped as part of this template.
5555
When objects originate from provider side, consumer does not always know the necessary details.
5656
This field allows provider to pre-heat the necessary namespaces on provider side by creating
5757
APIServiceNamespace objects attached to the APIServiceExport. More namespaces can be created later by the consumer.
@@ -67,7 +67,7 @@ spec:
6767
type: array
6868
permissionClaims:
6969
description: permissionClaims defines the permission claims required
70-
by this module.
70+
by this template.
7171
items:
7272
description: |-
7373
PermissionClaim selects objects of a GVR that a service provider may
@@ -167,9 +167,8 @@ spec:
167167
type: object
168168
type: array
169169
resources:
170-
description: resources defines the CRDs that are part of this module.
170+
description: resources defines the CRDs that are part of this template.
171171
items:
172-
description: APIServiceExportResource is a type alias for APIServiceExportRequestResource.
173172
properties:
174173
group:
175174
default: ""
@@ -205,17 +204,17 @@ spec:
205204
- enum:
206205
- Namespaced
207206
- Cluster
208-
description: scope defines the scope of the resources in this module.
207+
description: scope defines the scope of the resources in this template.
209208
type: string
210209
required:
211210
- resources
212211
- scope
213212
type: object
214213
status:
215-
description: status contains reconciliation information for the module.
214+
description: status contains reconciliation information for the template.
216215
properties:
217216
conditions:
218-
description: conditions is a list of conditions that apply to the Module.
217+
description: conditions is a list of conditions that apply to the APIServiceExportTemplate.
219218
items:
220219
description: Condition defines an observation of a object operational
221220
state.

contrib/kcp/deploy/resources/apiresourceschema-collections.catalog.kube-bind.io.yaml renamed to contrib/kcp/deploy/resources/apiresourceschema-collections.kube-bind.io.yaml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ apiVersion: apis.kcp.io/v1alpha1
22
kind: APIResourceSchema
33
metadata:
44
creationTimestamp: null
5-
name: v251016-4ed96ab.collections.catalog.kube-bind.io
5+
name: v251020-d1ae972.collections.kube-bind.io
66
spec:
7-
group: catalog.kube-bind.io
7+
group: kube-bind.io
88
names:
99
categories:
1010
- kube-bind
@@ -18,16 +18,16 @@ spec:
1818
- jsonPath: .spec.description
1919
name: Description
2020
type: string
21-
- jsonPath: .spec.modules[*]
22-
name: Modules
21+
- jsonPath: .spec.templates[*]
22+
name: Templates
2323
type: integer
2424
- jsonPath: .metadata.creationTimestamp
2525
name: Age
2626
type: date
27-
name: v1alpha1
27+
name: v1alpha2
2828
schema:
29-
description: Collection groups multiple Modules into a logical group. This functions
30-
as a folder in the UI.
29+
description: Collection groups multiple APIServiceExportTemplates into a logical
30+
group. This functions as a folder in the UI.
3131
properties:
3232
apiVersion:
3333
description: |-
@@ -52,22 +52,23 @@ spec:
5252
description:
5353
description: description is a human readable description of this collection.
5454
type: string
55-
modules:
56-
description: modules is a list of module references that are part of
57-
this collection.
55+
templates:
56+
description: templates is a list of template references that are part
57+
of this collection.
5858
items:
59-
description: ModuleReference references a Module by name.
59+
description: APIServiceExportTemplateReference references an APIServiceExportTemplate
60+
by name.
6061
properties:
6162
name:
62-
description: name is the name of the module.
63+
description: name is the name of the template.
6364
type: string
6465
required:
6566
- name
6667
type: object
6768
minItems: 1
6869
type: array
6970
required:
70-
- modules
71+
- templates
7172
type: object
7273
status:
7374
description: status contains reconciliation information for the collection.

0 commit comments

Comments
 (0)