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

Generate Api and Model classes from CRD results in missing IoK8sApimachineryPkgApisMetaV1DeleteOptionsV2 when run against kind 1.20 #1710

Closed
asavov opened this issue May 13, 2021 · 17 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@asavov
Copy link
Contributor

asavov commented May 13, 2021

Describe the bug

Using java-crd-cmd.sh script to generate Models and Apis from single CRD results in:

  1. referencing two missing classes by the InfraAlexComV1Api.
import com.alex.infra.models.IoK8sApimachineryPkgApisMetaV1DeleteOptionsV2;
import com.alex.infra.models.IoK8sApimachineryPkgApisMetaV1StatusV2;
  1. using IoK8sApimachineryPkgApisMetaV1ObjectMetaV2 (which is missing) instead of io.kubernetes.client.openapi.models.V1ObjectMeta

  2. not implements KubernetesObject by root CR (V1CloudAccount) object.

Here's the generate script:

generate() {
  git clone https://github.com/kubernetes-client/gen ${OPERATOR_PROJECT_TEMP_DIR}/models-generator || true

  cd $OPERATOR_PROJECT_TEMP_DIR/models-generator/openapi

  bash java-crd-cmd.sh \
   -n com.alex.infra \
   -p com.alex.infra \
   -o $OPERATOR_PROJECT_TEMP_DIR/models-generator-output \
   -g true < $OPERATOR_PROJECT_TEMP_DIR/models-generator-swagger
}

The full log from generation is : gen-models-output.txt

Client Version
12.0

Kubernetes Version
kind k8s from image: kindest/node:v1.20.2@sha256:8f7ea6e7642c0da54f04a7ee10431549c0257315b3a634f6ef2fecaaedb19bab
^^^ That's the problematic part.

Java Version
java -version
openjdk version "11.0.7" 2020-04-14 LTS
OpenJDK Runtime Environment Zulu11.39+16-SA (build 11.0.7+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.39+16-SA (build 11.0.7+10-LTS, mixed mode)

To Reproduce

This script is executed prior above generate script.

applyCrd() {
  echo "Apply CRDs: START"

  kubectl apply -f $CRD_1

  kubectl get --raw="/openapi/v2" > $OPERATOR_PROJECT_TEMP_DIR/models-generator-swagger

  while ! (grep -Fq '"CloudAccount"' $OPERATOR_PROJECT_TEMP_DIR/models-generator-swagger); do
    echo "Waiting for CloudAccount CRD to be applied..."
    sleep 1
    kubectl get --raw="/openapi/v2" > $OPERATOR_PROJECT_TEMP_DIR/models-generator-swagger
  done

  echo "Apply CRDs: END"
}

Server (please complete the following information):

  • OS: Mac
  • Environment: Local dev env

Additional context

This SAME script used to work. And the Api code generated referred:

import io.kubernetes.client.openapi.models.V1DeleteOptions;
import io.kubernetes.client.openapi.models.V1Status;

Seems that some recent change has introduced/replaced V1DeleteOptions and V1Status with

import com.alex.infra.models.IoK8sApimachineryPkgApisMetaV1DeleteOptionsV2;
import com.alex.infra.models.IoK8sApimachineryPkgApisMetaV1StatusV2;
@asavov
Copy link
Contributor Author

asavov commented May 13, 2021

Any idea what might be causing this or any workaround to apply?

@asavov
Copy link
Contributor Author

asavov commented May 13, 2021

Any idea what might be causing this or any workaround to apply?

Seems that using kindest/node:v1.19.7 (as opposite to kindest/node:v1.20.2) workaround the issue.

Still the issue is Why with 1.20 k8s version it's not working.

Is it possible to be some issue with def remove_model_prefixes(spec, crd_mode=False): and then conflict between DeleteOptions_V2 (which is available on 1.20 kind) and v1.DeleteOptions?

@brendandburns
Copy link
Contributor

The Swagger definitions for the APIs are downloaded from the Kubernetes API server. I suspect that the API object definitions changed between 1.19 and 1.20

@yue9944882
Copy link
Member

@asavov it seems that you're doing the code-generation in a deprecated approach. i'd suggest trying the latest doc according to https://github.com/kubernetes-client/java/blob/master/docs/generate-model-from-third-party-resources.md

@asavov
Copy link
Contributor Author

asavov commented May 14, 2021

The Swagger definitions for the APIs are downloaded from the Kubernetes API server. I suspect that the API object definitions changed between 1.19 and 1.20

Yes. with 1.20 it does not work. While with 1.19 and 1.18 it do work.

@asavov
Copy link
Contributor Author

asavov commented May 14, 2021

@asavov it seems that you're doing the code-generation in a deprecated approach. i'd suggest trying the latest doc according to https://github.com/kubernetes-client/java/blob/master/docs/generate-model-from-third-party-resources.md

I tried with

 docker run \
  --rm \
  -v "$CRD_1":"$CRD_1" \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v "$(pwd)":"$(pwd)" \
  -ti \
  --network host \
  ghcr.io/yue9944882/crd-model-gen:v1.0.3 \
  /generate.sh \
  -u $CRD_1 \
  -n com.alex.infra \
  -p com.alex.infra \
  -o "$(pwd)"

and it worked. And this is cause it uses internally kind 1.18

Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.18.2)

Still when run with 1.20 it fails.

I will change issue Name/Title.

@asavov asavov changed the title Generate api classes from crd results in missing IoK8sApimachineryPkgApisMetaV1DeleteOptionsV2 Generate Api and Model classes from CRD results in missing IoK8sApimachineryPkgApisMetaV1DeleteOptionsV2 when run against kind 1.20 May 14, 2021
@asavov
Copy link
Contributor Author

asavov commented May 18, 2021

Any feedback on this?

@wqq578
Copy link

wqq578 commented May 25, 2021

Report error every time

Existing cluster generation should be used

@wqq578
Copy link

wqq578 commented May 25, 2021

Describe the bug

Using java-crd-cmd.sh script to generate Models and Apis from single CRD results in:

  1. referencing two missing classes by the InfraAlexComV1Api.
import com.alex.infra.models.IoK8sApimachineryPkgApisMetaV1DeleteOptionsV2;
import com.alex.infra.models.IoK8sApimachineryPkgApisMetaV1StatusV2;
  1. using IoK8sApimachineryPkgApisMetaV1ObjectMetaV2 (which is missing) instead of io.kubernetes.client.openapi.models.V1ObjectMeta
  2. not implements KubernetesObject by root CR (V1CloudAccount) object.

Here's the generate script:

generate() {
  git clone https://github.com/kubernetes-client/gen ${OPERATOR_PROJECT_TEMP_DIR}/models-generator || true

  cd $OPERATOR_PROJECT_TEMP_DIR/models-generator/openapi

  bash java-crd-cmd.sh \
   -n com.alex.infra \
   -p com.alex.infra \
   -o $OPERATOR_PROJECT_TEMP_DIR/models-generator-output \
   -g true < $OPERATOR_PROJECT_TEMP_DIR/models-generator-swagger
}

The full log from generation is : gen-models-output.txt

Client Version
12.0

Kubernetes Version
kind k8s from image: kindest/node:v1.20.2@sha256:8f7ea6e7642c0da54f04a7ee10431549c0257315b3a634f6ef2fecaaedb19bab
^^^ That's the problematic part.

Java Version
java -version
openjdk version "11.0.7" 2020-04-14 LTS
OpenJDK Runtime Environment Zulu11.39+16-SA (build 11.0.7+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.39+16-SA (build 11.0.7+10-LTS, mixed mode)

To Reproduce

This script is executed prior above generate script.

applyCrd() {
  echo "Apply CRDs: START"

  kubectl apply -f $CRD_1

  kubectl get --raw="/openapi/v2" > $OPERATOR_PROJECT_TEMP_DIR/models-generator-swagger

  while ! (grep -Fq '"CloudAccount"' $OPERATOR_PROJECT_TEMP_DIR/models-generator-swagger); do
    echo "Waiting for CloudAccount CRD to be applied..."
    sleep 1
    kubectl get --raw="/openapi/v2" > $OPERATOR_PROJECT_TEMP_DIR/models-generator-swagger
  done

  echo "Apply CRDs: END"
}

Server (please complete the following information):

  • OS: Mac
  • Environment: Local dev env

Additional context

This SAME script used to work. And the Api code generated referred:

import io.kubernetes.client.openapi.models.V1DeleteOptions;
import io.kubernetes.client.openapi.models.V1Status;

Seems that some recent change has introduced/replaced V1DeleteOptions and V1Status with

import com.alex.infra.models.IoK8sApimachineryPkgApisMetaV1DeleteOptionsV2;
import com.alex.infra.models.IoK8sApimachineryPkgApisMetaV1StatusV2;

This image can't run. The parameters should be wrong. Do you have any details?

@yue9944882
Copy link
Member

hi @asavov i wasnt able to reproduce this after bumping the built-in kind version to 0.10.0 which provisions 1.20 k8s cluster internally. can you elaborate ur case why u need a newer k8s cluster to do the code-gen. i can publish a new one w/ the kind binary bumped if that works for u.

@asavov
Copy link
Contributor Author

asavov commented Jun 4, 2021

@yue9944882 Excuse my delayed response. Was on vacation.

On a brand new and fresh Mac (configured with latest bins)

>kind version
kind v0.10.0 go1.15.7 darwin/amd64
>kind create cluster (with config.yaml without image in order to use default)
Creating cluster "kind" ...
⢄⡱ Ensuring node image (kindest/node:v1.20.2) 🖼 

those 2 are still missing/invalid

import com.vmware.ccs.infra.models.IoK8sApimachineryPkgApisMetaV1DeleteOptionsV2;
import com.vmware.ccs.infra.models.IoK8sApimachineryPkgApisMetaV1StatusV2;

can you elaborate ur case why u need a newer k8s cluster to do the code-gen.

Working on a project using latest kind and kindest/node:v1.20.2, and needing k8s-models auto-generation.

How about to set up zoom?

Let me know if I can provide more details.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 2, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Oct 2, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link
Contributor

@k8s-triage-robot: Closing this issue.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@stefanbethke
Copy link

stefanbethke commented Feb 21, 2022

I'm running in to this very issue, on macOS, Docker Desktop:

$ kubectl version    
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.1", GitCommit:"86ec240af8cbd1b60bcc4c03c20da9b98005b92e", GitTreeState:"clean", BuildDate:"2021-12-16T11:33:37Z", GoVersion:"go1.17.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.5", GitCommit:"5c99e2ac2ff9a3c549d9ca665e7bc05a3e18f07e", GitTreeState:"clean", BuildDate:"2021-12-16T08:32:32Z", GoVersion:"go1.16.12", Compiler:"gc", Platform:"linux/amd64"}

The only reference I could google is to this issue, so I'm really stumped.

This is with the master version of gen.

@cheny1994
Copy link

This issue also occurs when using github action "CRD Java Model Generate"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

8 participants