Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(import): missing versions when importing multi-version crd #387

Merged
merged 13 commits into from
Jul 21, 2022

Conversation

iliapolo
Copy link
Member

@iliapolo iliapolo commented Jul 12, 2022

For some reason, we were assuming a CRD can only contain a single version. We were extracting the first version from the versions property and operating solely on that.

This PR considers all versions in the CRD and appends the version to the FQN to avoid name collisions.
Note that for backwards compatibility, the first version remains un-sufixed.

So, for a CRD with kind MyCrd and versions ['v1alpha1', 'v1beta1'], we will get:

// for the first version - unsufixed
export class MyCrd extends ApiObject { ... };
export interface MyCrdProps { 
  readonly metadata?: ApiObjectMetadata;
  readonly spec?: MyCrdSpec;
};

// for the second version - sufixed
export class MyCrdV1Beta1 extends ApiObject { ... };
export interface MyCrdV1Beta1Props {
  readonly metadata?: ApiObjectMetadata;
  readonly spec?: MyCrdV1Beta1Spec;
}

Where we only used to have:

export class MyCrd extends ApiObject { ... };
export interface MyCrdProps { 
  readonly metadata?: ApiObjectMetadata;
  readonly spec?: MyCrdSpec;
};

Fixes #386

Signed-off-by: iliapolo <epolon@amazon.com>
Signed-off-by: iliapolo <epolon@amazon.com>
Signed-off-by: iliapolo <epolon@amazon.com>
Signed-off-by: iliapolo <epolon@amazon.com>
Signed-off-by: iliapolo <epolon@amazon.com>
Signed-off-by: iliapolo <epolon@amazon.com>
Signed-off-by: iliapolo <epolon@amazon.com>
Signed-off-by: iliapolo <epolon@amazon.com>
Signed-off-by: iliapolo <epolon@amazon.com>
@iliapolo iliapolo requested a review from a team July 12, 2022 19:09
@iliapolo iliapolo marked this pull request as ready for review July 12, 2022 19:09
@iliapolo iliapolo added the backport-to-1.x Backport a PR to the 1.x branch label Jul 20, 2022
@mergify mergify bot merged commit 74cb37e into 2.x Jul 21, 2022
@vinayak-kukreja vinayak-kukreja deleted the epolon/multi-version-crd branch July 21, 2022 00:00
cdk8s-automation pushed a commit that referenced this pull request Jul 21, 2022
For some reason, we were assuming a CRD can only contain a single version. We were extracting the first version from the `versions` property and operating solely on that.

This PR considers all versions in the CRD and appends the version to the FQN to avoid name collisions.
Note that for backwards compatibility, the first version remains un-sufixed.

So, for a CRD with kind `MyCrd` and versions `['v1alpha1', 'v1beta1']`, we will get:

```ts
// for the first version - unsufixed
export class MyCrd extends ApiObject { ... };
export interface MyCrdProps {
  readonly metadata?: ApiObjectMetadata;
  readonly spec?: MyCrdSpec;
};

// for the second version - sufixed
export class MyCrdV1Beta1 extends ApiObject { ... };
export interface MyCrdV1Beta1Props {
  readonly metadata?: ApiObjectMetadata;
  readonly spec?: MyCrdV1Beta1Spec;
}
```

Where we only used to have:

```ts
export class MyCrd extends ApiObject { ... };
export interface MyCrdProps {
  readonly metadata?: ApiObjectMetadata;
  readonly spec?: MyCrdSpec;
};
```

Fixes #386

(cherry picked from commit 74cb37e)
Signed-off-by: Eli Polonsky <epolon@amazon.com>
@cdk8s-automation
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
1.x

Questions ?

Please refer to the Backport tool documentation

mergify bot pushed a commit that referenced this pull request Jul 21, 2022
…#404)

# Backport

This will backport the following commits from `2.x` to `1.x`:
 - [fix(import): missing versions when importing multi-version crd (#387)](#387)



### Questions ?
Please refer to the [Backport tool documentation](https://github.com/sqren/backport)
mergify bot pushed a commit that referenced this pull request Jun 29, 2023
…different obejcts (#1042)

When a CRD has multiple objects that represent the same *kind* but for different versions, `cdk8s import` will fail with a vague "already exists" error.

For example:

```yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: tenants.capsule.clastix.io
spec:
  group: capsule.clastix.io
  names:
    kind: Tenant
    listKind: TenantList
    plural: tenants
    shortNames:
      - tnt
    singular: tenant
  scope: Cluster
  versions:
    - name: v1beta1
      schema:
        openAPIV3Schema: ...
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: tenants.capsule.clastix.io
spec:
  group: capsule.clastix.io
  names:
    kind: Tenant
    listKind: TenantList
    plural: tenants
    shortNames:
      - tnt
    singular: tenant
  scope: Cluster
  versions:
    - name: v1beta2
      schema:
        openAPIV3Schema: ...

```

Note that if the two versions are defined within the same object, import will succeed. 

For example:

```yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: tenants.capsule.clastix.io
spec:
  group: capsule.clastix.io
  names:
    kind: Tenant
    listKind: TenantList
    plural: tenants
    shortNames:
      - tnt
    singular: tenant
  scope: Cluster
  versions:
    - name: v1beta1
      schema:
        openAPIV3Schema: ...
    - name: v1beta2
      schema:
        openAPIV3Schema: ...
```

This is actually a followup to #387.
cdk8s-automation pushed a commit that referenced this pull request Jun 29, 2023
…different obejcts (#1042)

When a CRD has multiple objects that represent the same *kind* but for different versions, `cdk8s import` will fail with a vague "already exists" error.

For example:

```yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: tenants.capsule.clastix.io
spec:
  group: capsule.clastix.io
  names:
    kind: Tenant
    listKind: TenantList
    plural: tenants
    shortNames:
      - tnt
    singular: tenant
  scope: Cluster
  versions:
    - name: v1beta1
      schema:
        openAPIV3Schema: ...
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: tenants.capsule.clastix.io
spec:
  group: capsule.clastix.io
  names:
    kind: Tenant
    listKind: TenantList
    plural: tenants
    shortNames:
      - tnt
    singular: tenant
  scope: Cluster
  versions:
    - name: v1beta2
      schema:
        openAPIV3Schema: ...

```

Note that if the two versions are defined within the same object, import will succeed.

For example:

```yaml
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: tenants.capsule.clastix.io
spec:
  group: capsule.clastix.io
  names:
    kind: Tenant
    listKind: TenantList
    plural: tenants
    shortNames:
      - tnt
    singular: tenant
  scope: Cluster
  versions:
    - name: v1beta1
      schema:
        openAPIV3Schema: ...
    - name: v1beta2
      schema:
        openAPIV3Schema: ...
```

This is actually a followup to #387.

(cherry picked from commit 18e6eda)
Signed-off-by: Eli Polonsky <epolon@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-to-1.x Backport a PR to the 1.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not importing all versions of the CRDs when multiple versions are declared and defined
3 participants