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

JsonSyntaxException related to status.conditions[0].lastTransitionTime #11

Open
dzhi-lyft opened this issue Dec 21, 2021 · 2 comments
Open

Comments

@dzhi-lyft
Copy link

dzhi-lyft commented Dec 21, 2021

Hit following error to parse getNamespacedCustomObject() result into KruiseAppsV1alpha1CloneSet (gson 2.8.9).

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at path $.status.conditions[0].lastTransitionTime

unfortunately I don't have the status.conditions[0].lastTransitionTime field as it does not normally exists in the cloneset object and we didn't save a copy when it happened (I will add an example if this happens again in the future). I wonder whether there is a possible mismatch between the expected and real format of the field. Or like to know if there is a better way to obtain KruiseAppsV1alpha1CloneSet from the returned obj.

    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    CustomObjectsApi customObjectsApi = new CustomObjectsApi(client);
    Object obj = customObjectsApi.getNamespacedCustomObject(
        "apps.kruise.io",                 // group
        "v1alpha1",                       // version
        K8sCommon.getNamespaceFromEnv(),  // namespace
        "clonesets",                      // plural
        cloneset                          // name
    );

    Gson gson = new JSON().getGson();
    KruiseAppsV1alpha1CloneSet v1cs = gson.fromJson(
        gson.toJsonTree(obj).getAsJsonObject(), KruiseAppsV1alpha1CloneSet.class);
@FillZpp
Copy link
Member

FillZpp commented Dec 22, 2021

@dzhi-lyft I wrote a test according your code and tried to get a cloneset in my test cluster. There is no error or exception.

The status of cloneset looks like this:

status:
  availableReplicas: 3
  collisionCount: 0
  currentRevision: demo-clone-d9cb8496d
  labelSelector: app=guestbook
  observedGeneration: 1
  readyReplicas: 3
  replicas: 3
  updateRevision: demo-clone-d9cb8496d
  updatedReadyReplicas: 3
  updatedReplicas: 3

I'm not sure what's the difference between yours?

@dzhi-lyft
Copy link
Author

dzhi-lyft commented Jan 4, 2022

@FillZpp I caught and logged one example below. I am not sure under what condition k8s include the "conditions" field and whether different versions of k8s returns different format. The "conditions" field only appears sometime in which case the parse will fail.

  "status": {
    "availableReplicas": 199.0,
    "collisionCount": 0.0,
    "conditions": [
      {
        "lastTransitionTime": "2022-01-04T18:09:54Z",
        "message": "The POST operation against Pod could not be completed at this time, please try again.",
        "status": "True",
        "type": "FailedScale"
      }
    ],
    "labelSelector": "app=nodemanager-894d7",
    "observedGeneration": 2329.0,
    "readyReplicas": 199.0,
    "replicas": 199.0,
    "updateRevision": "nodemanager-894d7-6b7579fb78",
    "updatedReadyReplicas": 199.0,
    "updatedReplicas": 199.0
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants