In my case ,i want use java api to create kongingress ,find a lot of things , i got k8s provide crd module to get&create crd.
I use CustomObjectsApi.listClusterCustomObject get kongingress config ,but when i use CustomObjectsApi.createClusterCustomObject api, k8s return 404 not found ;
Is my code wrong or is need setting some config
get kongingress code :
CustomObjectsApi apiInstance = new CustomObjectsApi();
String group = “configuration.konghq.com”;
String version = “v1”;
String plural = “kongingresses”;
String pretty = “ture”;
String fieldSelector = “metadata.namespace=” + buId;
try {
Object result = apiInstance.listClusterCustomObject(group, version, plural, null,
null, fieldSelector, null, null,
null, null, null);
String listCluster = JSONObject.toJSONString(result);
log.error(listCluster);
JSONObject jsonObject = JSONObject.parseObject(listCluster);
if (null == jsonObject.getJSONArray(“items”) || jsonObject.getJSONArray(“items”).isEmpty()) {
return false;
} else {
return true;
}
} catch (Exception e) {
log.error(“Get KongIngress error,” + buId, e);
throw new RuntimeException(“Get KongIngress error,” + buId, e);
}
return message:
{“apiVersion”:“configuration.konghq.com/v1",“items”:[],“kind”:“KongIngressList”,“metadata”:{“continue”:"",“resourceVersion”:“694409337”,“selfLink”:"/apis/configuration.konghq.com/v1/kongingresses”}}
create kongingress code :
CustomObjectsApi apiInstance = new CustomObjectsApi();
String group = “configuration.konghq.com”;
String version = “v1”;
String plural = “kongingresses”;
Object createRs = apiInstance.createClusterCustomObject(group, version, plural, ingressYaml, null, null,
null);
ingressYaml like:
apiVersion: configuration.konghq.com/v1
kind: KongIngress
metadata:
name: https-only
namespace: testbu001
route:
protocols:
- https
https_redirect_status_code: 302
error message:
io.kubernetes.client.openapi.ApiException: Not Found
at io.kubernetes.client.openapi.ApiClient.handleResponse(ApiClient.java:971)
at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:883)
at io.kubernetes.client.openapi.apis.CustomObjectsApi.createClusterCustomObjectWithHttpInfo(CustomObjectsApi.java:263)
at io.kubernetes.client.openapi.apis.CustomObjectsApi.createClusterCustomObject(CustomObjectsApi.java:218)