crossplane / crossplane/upjet

Add support for shortNames in generated CRDs

Open
#521 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
481
Forks
131
Avg merge
2d 1h
Merged PRs (30d)
11

Description

### What problem are you facing?

Currently, upjet only supports CRD Kind Names (like `"amis.ec2.aws.m.upbound.io"`, `"amis.ec2.aws.upbound.io"`) which get added as CRD categories. However, there's no way to define kubectl shortNames for individual resources.

This becomes particularly problematic in v2 where both cluster-scoped and namespaced CRs can have the same resource names (e.g., both `amis` resources exist in different API groups).
**Having short aliases would significantly improve the user experience when working with kubectl.**

For example, it would be very helpful to define short names like:
- `mAmi` for namespaced Project CRs
- `ami` /`cAmi` for cluster-scoped Project CRs
- `mCluster` for namespaced Cluster CRs
- `cCluster`/`Cluster` for cluster-scoped Cluster CRs

### How could Upjet help solve your problem?

### Option 1: Smart auto-generation
Automatically generate shortNames based on scope and resource type:
- Namespaced resources: `m{{ .CRD.Kind }}` (e.g., `mAmi`, `mCluster`)
- Cluster-scoped resources: `c{{ .CRD.Kind }}` (e.g., `mAmi`, `cCluster`)

```go
{{ if eq .CRD.Scope "Namespaced" }},shortNames={m{{ .CRD.Kind }}{{ else if eq .CRD.Scope "Cluster" }},shortNames={c{{ .CRD.Kind }}{{ end }}
```

```go
// +kubebuilder:resource:scope={{ .CRD.Scope }},categories={crossplane,managed,{{ .Provider.ShortName }}{{ if .CRD.Path }},path={{ .CRD.Path }}{{ end }}{{ if eq .CRD.Scope "Namespaced" }},shortNames={m{{ .CRD.Kind }}{{ else if eq .CRD.Scope "Cluster" }},shortNames={c{{ .CRD.Kind }}{{ end }}

```

### Option 2: Add ShortName field to Resource struct
Add a `ShortName` field to the `config.Resource` struct that gets passed through to the CRD generation:

```go
type Resource struct {
// ... existing fields ...
ShortName string // kubectl shortName for this resource
}
```

Update the CRD template to support shortNames in the kubebuilder resource marker:

```go
// Current template:
// +kubebuilder:resource:scope={{ .CRD.Scope }},categories={crossplane,managed,{{ .Provider.ShortName }}}{{ if .CRD.Path }},path={{ .CRD.Path }}{{ end }}

// Proposed template:
// +kubebuilder:resource:scope={{ .CRD.Scope }},categories={crossplane,managed,{{ .Provider.ShortName }}}{{ if .CRD.ShortName }},shortNames={{{ .CRD.ShortName }}}{{ end }}{{ if .CRD.Path }},path={{ .CRD.Path }}{{ end }}
```

## Use Cases

1. **Improved kubectl experience**: Users can use `kubectl get mAmi` instead of `kubectl get amis.ec2.aws.m.upbound.io -n namespace`
2. **Scope disambiguation**: Clear distinction between cluster and namespaced resources with same names
3. **Better UX**: Reduce typing and improve resource identification

Contributor guide

Open the contributing guide

Research direction

Locate the config.Resource definition and the CRD generation template, then trace how resource metadata reaches the generated kubebuilder marker. Decide how short names should be configured or derived for namespaced and cluster-scoped resources, and inspect the generation tests before adding coverage. Done means generated CRDs expose the intended kubectl shortNames without breaking existing categories or paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.