I have deployed a CRD with limitRange as part of the spec:
limitRange:
properties:
limits: # array of 'limits' objects
items:
properties:
default: # property of limit
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: ResourceList is a set of (resource name, quantity)
pairs.
type: object
defaultRequest: # property of limit
additionalProperties:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: ResourceList is a set of (resource name, quantity)
pairs.
type: object
type: # property of limit
description: LimitType is a type of object that is limited.
It can be Pod, Container, PersistentVolumeClaim or a fully
qualified resource name.
type: string
type: object
type: array
type: object
I’m having trouble creating a CustomResource in my Java code using the fabric8 client with the above spec. This is my code right now, it’s creating the CustomResource but not with the limitRange object:
LimitRangeSpec.java
public class LimitRangeSpec {
private List<Limit> limits;
public LimitRangeSpec(List<Limit> limits) {
this.limits = limits;
}
}
Limit.java
public class Limit {
private DefaultLimit defaultLimit;
private DefaultRequest defaultRequest;
private String type;
public Limit(DefaultLimit defaultLimit, DefaultRequest defaultRequest, String type) {
this.defaultLimit = defaultLimit;
this.defaultRequest = defaultRequest;
this.type = type;
}
}
DefaultRequest.java / DefaultLimit.java (same)
public class DefaultRequest {
Map<String, Quantity> additionalProperties;
public DefaultRequest(Map<String, Quantity> additionalProperties) {
this.additionalProperties = additionalProperties;
}
public DefaultRequest() {
this.additionalProperties = new HashMap<>();
}
This is how i’m creating the CustomResource:
DefaultRequest defaultRequest = new DefaultRequest();
Map<String, Quantity> defaultRequestAdditionalProperties = new HashMap<>();
defaultRequestAdditionalProperties.put("cpu", new Quantity("500m"));
defaultRequestAdditionalProperties.put("memory", new Quantity("2Gi"));
defaultRequest.setAdditionalProperties(defaultRequestAdditionalProperties);
Limit limit = new Limit(defaultLimit, defaultRequest, "Container");
LimitRangeSpec limitRange = new LimitRangeSpec(List.of(limit));
namespaceOperatorSpec.setLimitRange(limitRange);
namespaceOperator.setSpec(namespaceOperatorSpec);
NamespaceOperatorTest createdNamespaceOperator =
nsOpClient.inNamespace("default").resource(namespaceOperator).create();
The CustomResource gets created but it doesn’t contain the LimitRange spec. Any idea on how I can get this to work? Thanks in advance