Closed liboyue23 closed 4 years ago
Can you move forward to at least version 6.0.1
in your pom.xml? That's the latest released library.
It looks to me like the Quantity serializer isn't properly registered in GSON for serialization.
Please move to the 6.0.1
and if that doesn't fix things, please include the code for how you are creating your Client.
Thanks!
"resources": {
"limits": {
"memory": {
"number": 8589934592,
"format": "BINARY_SI"
},
"cpu": {
"number": 4,
"format": "DECIMAL_SI"
}
},
"requests": {
"memory": {
"number": 8589934592,
"format": "BINARY_SI"
},
"cpu": {
"number": 4,
"format": "DECIMAL_SI"
}
}
}
the quantities are not correctly serialized.. and it's suggesting that you're not using the provided GSON codec from ApiClient..
"resources": { "limits": { "memory": { "number": 8589934592, "format": "BINARY_SI" }, "cpu": { "number": 4, "format": "DECIMAL_SI" } }, "requests": { "memory": { "number": 8589934592, "format": "BINARY_SI" }, "cpu": { "number": 4, "format": "DECIMAL_SI" } } }
the quantities are not correctly serialized.. and it's suggesting that you're not using the provided GSON codec from ApiClient..
I use the same code, to run in minikube v1.1.1, it works and the print json is:
"resources": {
"limits": {
"memory": "2Gi",
"cpu": "1"
},
"requests": {
"memory": "2Gi",
"cpu": "1"
}
}
here is my code:
public String createInst(){
V1Pod body = new V1Pod();
body.setApiVersion("v1");
body.setKind("Pod");
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(dockerName);
Map<String, String> labelMap = Maps.newHashMap();
labelMap.put(ANTI_AFFINITY_KEY, dockerName);
meta.setLabels(labelMap);
String namespace = getDefaultNamespace();
logger.info("namespace is : " + namespace);
meta.setNamespace(namespace);
body.setMetadata(meta);
V1PodSpec spec = new V1PodSpec();
V1Container container = new V1Container();
container.setName("drds-server");
container.setImage(rq.getImageId());
container.setImagePullPolicy("Always");
container.setEnv(buildEnv(rq.getInstanceType(), String.valueOf(rq.isSslEnable())));
container.setResources(buildResource(rq.getInstanceType()));
container.setLivenessProbe(buildLivenessProbe());
container.setReadinessProbe(buildReadinessProbe());
List<V1Container> list = Lists.newArrayList();
list.add(container);
spec.setContainers(list);
spec.setRestartPolicy("Always");
spec.setAffinity(buildAffinity(rq.getAffinityId()));
body.setSpec(spec);
System.out.println(body.toString());
V1Pod result = api.createNamespacedPod(getDefaultNamespace(), body, "false", null, null);
}
private V1ResourceRequirements buildResource(String spec) {
Map<String, String> parseSpec = parseSpec(spec);
String mem = parseSpec.get("mem");
String cpu = parseSpec.get("cpu");
V1ResourceRequirements resourceRequirements = new V1ResourceRequirements();
Long m = Integer.valueOf(mem) * 1024L;
Quantity memoryQuantity = new QuantityFormatter().parse(String.valueOf(m) + "Mi");
Quantity cpuQuantity = new QuantityFormatter().parse(cpu);
resourceRequirements.putLimitsItem("memory", memoryQuantity);
resourceRequirements.putLimitsItem("cpu", cpuQuantity);
resourceRequirements.putRequestsItem("memory", memoryQuantity);
resourceRequirements.putRequestsItem("cpu", cpuQuantity);
return resourceRequirements;
}
private Map<String, String> parseSpec(String spec) {
Map<String, String> map = Maps.newHashMap();
char[] charArray = spec.toCharArray();
StringBuilder cpuSb = new StringBuilder();
StringBuilder memSb = new StringBuilder();
boolean isCpu = true;
for (int i = 0; i < charArray.length; i++) {
if (charArray[i] != 'c' && isCpu) {
cpuSb.append(charArray[i]);
} else if (charArray[i] == 'c') {
isCpu = false;
} else if (charArray[i] != 'g' && !isCpu) {
memSb.append(charArray[i]);
} else if (charArray[i] == 'g') {
break;
}
}
String cpu = cpuSb.toString();
String mem = memSb.toString();
map.put("cpu", cpu);
map.put("mem", mem);
return map;
}
but use in kubernetes 1.12.6 version, the print json is:
"resources": {
"limits": {
"memory": {
"number": 8589934592,
"format": "BINARY_SI"
},
"cpu": {
"number": 4,
"format": "DECIMAL_SI"
}
},
"requests": {
"memory": {
"number": 8589934592,
"format": "BINARY_SI"
},
"cpu": {
"number": 4,
"format": "DECIMAL_SI"
}
}
}
why ?
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten
.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle rotten
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen
.
Mark the issue as fresh with /remove-lifecycle rotten
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /close
@fejta-bot: Closing this issue.
I use the sdk to create pod, here is the dependency:
and here is the error
the print json is:
What's wrong with my code?