Skip to content

Commit 97299d8

Browse files
committed
improve kcp import aliases
On-behalf-of: @SAP christoph.mewes@sap.com
1 parent 20c2f33 commit 97299d8

File tree

8 files changed

+49
-46
lines changed

8 files changed

+49
-46
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ linters:
7474
# Controller Runtime
7575
- pkg: sigs.k8s.io/controller-runtime/pkg/client
7676
alias: ctrlruntimeclient
77+
# kcp APIs
78+
- pkg: github.com/kcp-dev/sdk/apis/(\w+)/(v[\w\d]+)
79+
alias: kcp$1$2
7780
no-unaliased: true
7881
exclusions:
7982
generated: lax

cmd/api-syncagent/kcp.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
"github.com/kcp-dev/api-syncagent/internal/kcp"
2626

2727
"github.com/kcp-dev/logicalcluster/v3"
28-
kcpdevv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
29-
kcpdevcore "github.com/kcp-dev/sdk/apis/core"
30-
kcpdevcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1"
28+
kcpapisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
29+
kcpcore "github.com/kcp-dev/sdk/apis/core"
30+
kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1"
3131

3232
"k8s.io/apimachinery/pkg/fields"
3333
"k8s.io/apimachinery/pkg/runtime"
@@ -44,18 +44,18 @@ import (
4444
func setupEndpointKcpCluster(endpointSlice qualifiedAPIExportEndpointSlice) (cluster.Cluster, error) {
4545
scheme := runtime.NewScheme()
4646

47-
if err := kcpdevv1alpha1.AddToScheme(scheme); err != nil {
48-
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpdevv1alpha1.SchemeGroupVersion, err)
47+
if err := kcpapisv1alpha1.AddToScheme(scheme); err != nil {
48+
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpapisv1alpha1.SchemeGroupVersion, err)
4949
}
5050

51-
if err := kcpdevcorev1alpha1.AddToScheme(scheme); err != nil {
52-
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpdevcorev1alpha1.SchemeGroupVersion, err)
51+
if err := kcpcorev1alpha1.AddToScheme(scheme); err != nil {
52+
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpcorev1alpha1.SchemeGroupVersion, err)
5353
}
5454

5555
// RBAC in kcp might be very tight and might not allow to list/watch all objects;
5656
// restrict the cache's selectors accordingly so we can still make use of caching.
5757
byObject := map[ctrlruntimeclient.Object]cache.ByObject{
58-
&kcpdevv1alpha1.APIExportEndpointSlice{}: {
58+
&kcpapisv1alpha1.APIExportEndpointSlice{}: {
5959
Field: fields.SelectorFromSet(fields.Set{"metadata.name": endpointSlice.Name}),
6060
},
6161
}
@@ -74,18 +74,18 @@ func setupEndpointKcpCluster(endpointSlice qualifiedAPIExportEndpointSlice) (clu
7474
func setupManagedKcpCluster(apiExport qualifiedAPIExport) (cluster.Cluster, error) {
7575
scheme := runtime.NewScheme()
7676

77-
if err := kcpdevv1alpha1.AddToScheme(scheme); err != nil {
78-
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpdevv1alpha1.SchemeGroupVersion, err)
77+
if err := kcpapisv1alpha1.AddToScheme(scheme); err != nil {
78+
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpapisv1alpha1.SchemeGroupVersion, err)
7979
}
8080

81-
if err := kcpdevcorev1alpha1.AddToScheme(scheme); err != nil {
82-
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpdevcorev1alpha1.SchemeGroupVersion, err)
81+
if err := kcpcorev1alpha1.AddToScheme(scheme); err != nil {
82+
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpcorev1alpha1.SchemeGroupVersion, err)
8383
}
8484

8585
// RBAC in kcp might be very tight and might not allow to list/watch all objects;
8686
// restrict the cache's selectors accordingly so we can still make use of caching.
8787
byObject := map[ctrlruntimeclient.Object]cache.ByObject{
88-
&kcpdevv1alpha1.APIExport{}: {
88+
&kcpapisv1alpha1.APIExport{}: {
8989
Field: fields.SelectorFromSet(fields.Set{"metadata.name": apiExport.Name}),
9090
},
9191
}
@@ -106,12 +106,12 @@ type qualifiedCluster struct {
106106
}
107107

108108
type qualifiedAPIExport struct {
109-
*kcpdevv1alpha1.APIExport
109+
*kcpapisv1alpha1.APIExport
110110
qualifiedCluster
111111
}
112112

113113
type qualifiedAPIExportEndpointSlice struct {
114-
*kcpdevv1alpha1.APIExportEndpointSlice
114+
*kcpapisv1alpha1.APIExportEndpointSlice
115115
qualifiedCluster
116116
}
117117

@@ -129,11 +129,11 @@ type syncEndpoint struct {
129129
func resolveSyncEndpoint(ctx context.Context, initialRestConfig *rest.Config, endpointSliceRef string) (*syncEndpoint, error) {
130130
// construct temporary, uncached client
131131
scheme := runtime.NewScheme()
132-
if err := kcpdevcorev1alpha1.AddToScheme(scheme); err != nil {
133-
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpdevcorev1alpha1.SchemeGroupVersion, err)
132+
if err := kcpcorev1alpha1.AddToScheme(scheme); err != nil {
133+
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpcorev1alpha1.SchemeGroupVersion, err)
134134
}
135-
if err := kcpdevv1alpha1.AddToScheme(scheme); err != nil {
136-
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpdevv1alpha1.SchemeGroupVersion, err)
135+
if err := kcpapisv1alpha1.AddToScheme(scheme); err != nil {
136+
return nil, fmt.Errorf("failed to register scheme %s: %w", kcpapisv1alpha1.SchemeGroupVersion, err)
137137
}
138138

139139
clientOpts := ctrlruntimeclient.Options{Scheme: scheme}
@@ -175,7 +175,7 @@ func resolveSyncEndpoint(ctx context.Context, initialRestConfig *rest.Config, en
175175
}
176176

177177
func resolveAPIExportEndpointSlice(ctx context.Context, client ctrlruntimeclient.Client, ref string) (qualifiedAPIExportEndpointSlice, error) {
178-
endpointSlice := &kcpdevv1alpha1.APIExportEndpointSlice{}
178+
endpointSlice := &kcpapisv1alpha1.APIExportEndpointSlice{}
179179
key := types.NamespacedName{Name: ref}
180180
if err := client.Get(ctx, key, endpointSlice); err != nil {
181181
return qualifiedAPIExportEndpointSlice{}, fmt.Errorf("failed to get APIExportEndpointSlice %q: %w", ref, err)
@@ -196,7 +196,7 @@ func resolveAPIExportEndpointSlice(ctx context.Context, client ctrlruntimeclient
196196
}
197197

198198
func resolveAPIExport(ctx context.Context, client ctrlruntimeclient.Client, ref string) (qualifiedAPIExport, error) {
199-
apiExport := &kcpdevv1alpha1.APIExport{}
199+
apiExport := &kcpapisv1alpha1.APIExport{}
200200
key := types.NamespacedName{Name: ref}
201201
if err := client.Get(ctx, key, apiExport); err != nil {
202202
return qualifiedAPIExport{}, fmt.Errorf("failed to get APIExport %q: %w", ref, err)
@@ -217,13 +217,13 @@ func resolveAPIExport(ctx context.Context, client ctrlruntimeclient.Client, ref
217217
}
218218

219219
func resolveCurrentCluster(ctx context.Context, client ctrlruntimeclient.Client) (logicalcluster.Name, logicalcluster.Path, error) {
220-
lc := &kcpdevcorev1alpha1.LogicalCluster{}
220+
lc := &kcpcorev1alpha1.LogicalCluster{}
221221
if err := client.Get(ctx, types.NamespacedName{Name: kcp.IdentityClusterName}, lc); err != nil {
222222
return "", logicalcluster.None, fmt.Errorf("failed to resolve current workspace: %w", err)
223223
}
224224

225225
lcName := logicalcluster.From(lc)
226-
lcPath := logicalcluster.NewPath(lc.Annotations[kcpdevcore.LogicalClusterPathAnnotationKey])
226+
lcPath := logicalcluster.NewPath(lc.Annotations[kcpcore.LogicalClusterPathAnnotationKey])
227227

228228
return lcName, lcPath, nil
229229
}

internal/controller/apiexport/controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
syncagentv1alpha1 "github.com/kcp-dev/api-syncagent/sdk/apis/syncagent/v1alpha1"
3232

3333
"github.com/kcp-dev/logicalcluster/v3"
34-
kcpdevv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
34+
kcpapisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
3535

3636
"k8s.io/apimachinery/pkg/labels"
3737
"k8s.io/apimachinery/pkg/runtime/schema"
@@ -109,7 +109,7 @@ func Add(
109109
// Watch for changes to APIExport on the kcp side to start/restart the actual syncing controllers;
110110
// the cache is already restricted by a fieldSelector in the main.go to respect the RBC restrictions,
111111
// so there is no need here to add an additional filter.
112-
WatchesRawSource(source.Kind(kcpCluster.GetCache(), &kcpdevv1alpha1.APIExport{}, controllerutil.EnqueueConst[*kcpdevv1alpha1.APIExport]("dummy"))).
112+
WatchesRawSource(source.Kind(kcpCluster.GetCache(), &kcpapisv1alpha1.APIExport{}, controllerutil.EnqueueConst[*kcpapisv1alpha1.APIExport]("dummy"))).
113113
// Watch for changes to PublishedResources on the local service cluster
114114
Watches(&syncagentv1alpha1.PublishedResource{}, controllerutil.EnqueueConst[ctrlruntimeclient.Object]("dummy"), builder.WithPredicates(predicateutil.ByLabels(prFilter), hasARS)).
115115
Build(reconciler)
@@ -120,15 +120,15 @@ func Add(
120120
func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
121121
r.log.Debug("Processing")
122122

123-
apiExport := &kcpdevv1alpha1.APIExport{}
123+
apiExport := &kcpapisv1alpha1.APIExport{}
124124
if err := r.kcpClient.Get(ctx, types.NamespacedName{Name: r.apiExportName}, apiExport); err != nil {
125125
return reconcile.Result{}, ctrlruntimeclient.IgnoreNotFound(err)
126126
}
127127

128128
return reconcile.Result{}, r.reconcile(ctx, apiExport)
129129
}
130130

131-
func (r *Reconciler) reconcile(ctx context.Context, apiExport *kcpdevv1alpha1.APIExport) error {
131+
func (r *Reconciler) reconcile(ctx context.Context, apiExport *kcpapisv1alpha1.APIExport) error {
132132
// find all PublishedResources; we keep those that are not yet converted into ARS,
133133
// just to reduce the amount of re-reconciles when the agent processes a number of PRs in a row
134134
// and would constantly update the APIExport; instead we rely on kcp to handle the eventual

internal/controller/apiexport/reconciler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/kcp-dev/api-syncagent/internal/resources/reconciling"
2525
syncagentv1alpha1 "github.com/kcp-dev/api-syncagent/sdk/apis/syncagent/v1alpha1"
2626

27-
kcpdevv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
27+
kcpapisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
2828

2929
corev1 "k8s.io/api/core/v1"
3030
"k8s.io/apimachinery/pkg/runtime"
@@ -61,7 +61,7 @@ func (r *Reconciler) createAPIExportReconciler(
6161
recorder record.EventRecorder,
6262
) reconciling.NamedAPIExportReconcilerFactory {
6363
return func() (string, reconciling.APIExportReconciler) {
64-
return apiExportName, func(existing *kcpdevv1alpha1.APIExport) (*kcpdevv1alpha1.APIExport, error) {
64+
return apiExportName, func(existing *kcpapisv1alpha1.APIExport) (*kcpapisv1alpha1.APIExport, error) {
6565
if existing.Annotations == nil {
6666
existing.Annotations = map[string]string{}
6767
}
@@ -102,8 +102,8 @@ func (r *Reconciler) createAPIExportReconciler(
102102

103103
// add our missing claims
104104
for _, claimed := range claimsToAdd {
105-
existing.Spec.PermissionClaims = append(existing.Spec.PermissionClaims, kcpdevv1alpha1.PermissionClaim{
106-
GroupResource: kcpdevv1alpha1.GroupResource{
105+
existing.Spec.PermissionClaims = append(existing.Spec.PermissionClaims, kcpapisv1alpha1.PermissionClaim{
106+
GroupResource: kcpapisv1alpha1.GroupResource{
107107
Group: claimed.Group,
108108
Resource: claimed.Resource,
109109
},
@@ -121,7 +121,7 @@ func (r *Reconciler) createAPIExportReconciler(
121121
}
122122

123123
// prevent reconcile loops by ensuring a stable order
124-
slices.SortFunc(existing.Spec.PermissionClaims, func(a, b kcpdevv1alpha1.PermissionClaim) int {
124+
slices.SortFunc(existing.Spec.PermissionClaims, func(a, b kcpapisv1alpha1.PermissionClaim) int {
125125
if a.Group != b.Group {
126126
return strings.Compare(a.Group, b.Group)
127127
}

internal/controller/apiresourceschema/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
syncagentv1alpha1 "github.com/kcp-dev/api-syncagent/sdk/apis/syncagent/v1alpha1"
3131

3232
"github.com/kcp-dev/logicalcluster/v3"
33-
kcpdevv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
33+
kcpapisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
3434

3535
corev1 "k8s.io/api/core/v1"
3636
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -159,7 +159,7 @@ func (r *Reconciler) reconcile(ctx context.Context, log *zap.SugaredLogger, pubR
159159
arsName := kcp.GetAPIResourceSchemaName(projectedCRD)
160160

161161
// ensure ARS exists (don't try to reconcile it, it's basically entirely immutable)
162-
ars := &kcpdevv1alpha1.APIResourceSchema{}
162+
ars := &kcpapisv1alpha1.APIResourceSchema{}
163163
err = r.kcpClient.Get(ctx, types.NamespacedName{Name: arsName}, ars, &ctrlruntimeclient.GetOptions{})
164164

165165
if apierrors.IsNotFound(err) {

internal/controller/sync/controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
"github.com/kcp-dev/logicalcluster/v3"
3434
kcpcore "github.com/kcp-dev/sdk/apis/core"
35-
kcpdevcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1"
35+
kcpcorev1alpha1 "github.com/kcp-dev/sdk/apis/core/v1alpha1"
3636

3737
corev1 "k8s.io/api/core/v1"
3838
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -215,8 +215,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, request mcreconcile.Request)
215215
// if desired, fetch the workspace path as well (some downstream service providers might make use of it,
216216
// but since it requires an additional permission claim, it's optional)
217217
if r.pubRes.Spec.EnableWorkspacePaths {
218-
lc := &kcpdevcorev1alpha1.LogicalCluster{}
219-
if err := vwClient.Get(ctx, types.NamespacedName{Name: kcpdevcorev1alpha1.LogicalClusterName}, lc); err != nil {
218+
lc := &kcpcorev1alpha1.LogicalCluster{}
219+
if err := vwClient.Get(ctx, types.NamespacedName{Name: kcpcorev1alpha1.LogicalClusterName}, lc); err != nil {
220220
recorder.Event(remoteObj, corev1.EventTypeWarning, "ReconcilingError", "Failed to retrieve workspace path, cannot process object.")
221221
return reconcile.Result{}, fmt.Errorf("failed to retrieve remote logicalcluster: %w", err)
222222
}

internal/discovery/resource_prober.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222

23-
kcpdevv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
23+
kcpapisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
2424

2525
"k8s.io/apimachinery/pkg/runtime/schema"
2626
"k8s.io/apimachinery/pkg/types"
@@ -56,7 +56,7 @@ func (p *ResourceProber) HasGVK(ctx context.Context, gvk schema.GroupVersionKind
5656
}
5757

5858
func (p *ResourceProber) hasAPIThing(ctx context.Context, match matchFunc) (bool, error) {
59-
endpointSlice := &kcpdevv1alpha1.APIExportEndpointSlice{}
59+
endpointSlice := &kcpapisv1alpha1.APIExportEndpointSlice{}
6060
if err := p.client.Get(ctx, types.NamespacedName{Name: p.name}, endpointSlice); err != nil {
6161
return false, fmt.Errorf("failed to get APIExportEndpointSlice: %w", err)
6262
}

internal/kcp/apiresourceschema.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ import (
2222
"github.com/kcp-dev/api-syncagent/internal/crypto"
2323
syncagentv1alpha1 "github.com/kcp-dev/api-syncagent/sdk/apis/syncagent/v1alpha1"
2424

25-
kcpdevv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
25+
kcpapisv1alpha1 "github.com/kcp-dev/sdk/apis/apis/v1alpha1"
2626

2727
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
)
3030

31-
func CreateAPIResourceSchema(crd *apiextensionsv1.CustomResourceDefinition, name string, agentName string) (*kcpdevv1alpha1.APIResourceSchema, error) {
31+
func CreateAPIResourceSchema(crd *apiextensionsv1.CustomResourceDefinition, name string, agentName string) (*kcpapisv1alpha1.APIResourceSchema, error) {
3232
// prefix is irrelevant as the name is overridden later
33-
converted, err := kcpdevv1alpha1.CRDToAPIResourceSchema(crd, "irrelevant")
33+
converted, err := kcpapisv1alpha1.CRDToAPIResourceSchema(crd, "irrelevant")
3434
if err != nil {
3535
return nil, fmt.Errorf("failed to convert CRD: %w", err)
3636
}
3737

38-
ars := &kcpdevv1alpha1.APIResourceSchema{}
38+
ars := &kcpapisv1alpha1.APIResourceSchema{}
3939
ars.TypeMeta = metav1.TypeMeta{
40-
APIVersion: kcpdevv1alpha1.SchemeGroupVersion.String(),
40+
APIVersion: kcpapisv1alpha1.SchemeGroupVersion.String(),
4141
Kind: "APIResourceSchema",
4242
}
4343

@@ -55,9 +55,9 @@ func CreateAPIResourceSchema(crd *apiextensionsv1.CustomResourceDefinition, name
5555
ars.Spec.Versions = converted.Spec.Versions
5656

5757
if len(converted.Spec.Versions) > 1 {
58-
ars.Spec.Conversion = &kcpdevv1alpha1.CustomResourceConversion{
58+
ars.Spec.Conversion = &kcpapisv1alpha1.CustomResourceConversion{
5959
// as of kcp 0.27, there is no constant for this
60-
Strategy: kcpdevv1alpha1.ConversionStrategyType("None"),
60+
Strategy: kcpapisv1alpha1.ConversionStrategyType("None"),
6161
}
6262
}
6363

0 commit comments

Comments
 (0)