Skip to content

Add support for shortNames in generated CRDs #521

@pavansokkenagaraj

Description

@pavansokkenagaraj

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)
{{ if eq .CRD.Scope "Namespaced" }},shortNames={m{{ .CRD.Kind }}{{ else if eq .CRD.Scope "Cluster" }},shortNames={c{{ .CRD.Kind }}{{ end }}
// +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:

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

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

// 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions