Skip to content

Commit e21ffa3

Browse files
committed
handle unconventional cases in kubernetes schema
1 parent 5917c30 commit e21ffa3

File tree

3 files changed

+27
-37
lines changed

3 files changed

+27
-37
lines changed

docs/domains/k8s1.9.0.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ ObjectMeta is metadata that all persisted resources must have, which includes al
99

1010
| Name | Type | Description |
1111
| --- | --- | --- |
12-
| annotations | | Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata. They are not queryable and should be preserved when modifying objects. More info: http://kubernetes.io/docs/user-guide/annotations |
12+
| annotations | object | Annotations is an unstructured key value map stored with a resource that may be set by external tools to store and retrieve arbitrary metadata. They are not queryable and should be preserved when modifying objects. More info: http://kubernetes.io/docs/user-guide/annotations |
1313
| clusterName | string | The name of the cluster which the object belongs to. This is used to distinguish resources with same name and namespace in different clusters. This field is not set anywhere right now and apiserver is going to ignore it if set in create or update request. |
1414
| creationTimestamp | [Time](#time) | CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC.<br/><br/>Populated by the system. Read-only. Null for lists. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata |
15-
| deletionGracePeriodSeconds | | Number of seconds allowed for this object to gracefully terminate before it will be removed from the system. Only set when deletionTimestamp is also set. May only be shortened. Read-only. |
15+
| deletionGracePeriodSeconds | integer | Number of seconds allowed for this object to gracefully terminate before it will be removed from the system. Only set when deletionTimestamp is also set. May only be shortened. Read-only. |
1616
| deletionTimestamp | [Time](#time) | DeletionTimestamp is RFC 3339 date and time at which this resource will be deleted. This field is set by the server when a graceful deletion is requested by the user, and is not directly settable by a client. The resource is expected to be deleted (no longer visible from resource lists, and not reachable by name) after the time in this field, once the finalizers list is empty. As long as the finalizers list contains items, deletion is blocked. Once the deletionTimestamp is set, this value may not be unset or be set further into the future, although it may be shortened or the resource may be deleted prior to this time. For example, a user may request that a pod is deleted in 30 seconds. The Kubelet will react by sending a graceful termination signal to the containers in the pod. After that 30 seconds, the Kubelet will send a hard termination signal (SIGKILL) to the container and after cleanup, remove the pod from the API. In the presence of network partitions, this object may still exist after this timestamp, until an administrator or automated process can determine the resource is fully terminated. If not set, graceful deletion of the object has not been requested.<br/><br/>Populated by the system when a graceful deletion is requested. Read-only. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata |
1717
| finalizers | array of string | Must be empty before the object is deleted from the registry. Each entry is an identifier for the responsible component that will remove the entry from the list. If the deletionTimestamp of the object is non-nil, entries in this list can only be removed. |
1818
| generateName | string | GenerateName is an optional prefix, used by the server, to generate a unique name ONLY IF the Name field has not been provided. If this field is used, the name returned to the client will be different than the name passed. This value will also be combined with a unique suffix. The provided value has the same validation rules as the Name field, and may be truncated by the length of the suffix required to make the value unique on the server.<br/><br/>If this field is specified and the generated name exists, the server will NOT return a 409 - instead, it will either return 201 Created or 500 with Reason ServerTimeout indicating a unique name could not be found in the time allotted, and the client should retry (optionally after the time indicated in the Retry-After header).<br/><br/>Applied only if Name is not specified. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#idempotency |
19-
| generation | | A sequence number representing a specific generation of the desired state. Populated by the system. Read-only. |
19+
| generation | integer | A sequence number representing a specific generation of the desired state. Populated by the system. Read-only. |
2020
| initializers | [Initializers](#initializers) | An initializer is a controller which enforces some system invariant at object creation time. This field is a list of initializers that have not yet acted on this object. If nil or empty, this object has been completely initialized. Otherwise, the object is considered uninitialized and is hidden (in list/watch and get calls) from clients that haven't explicitly asked to observe uninitialized objects.<br/><br/>When an object is created, the system will populate this list with the current set of initializers. Only privileged users may set or modify this list. Once it is empty, it may not be modified further by any user. |
21-
| labels | | Map of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels |
21+
| labels | object | Map of string keys and values that can be used to organize and categorize (scope and select) objects. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels |
2222
| name | string | Name must be unique within a namespace. Is required when creating resources, although some resources may allow a client to request the generation of an appropriate name automatically. Name is primarily intended for creation idempotence and configuration definition. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names |
2323
| namespace | string | Namespace defines the space within each name must be unique. An empty namespace is equivalent to the "default" namespace, but "default" is the canonical representation. Not all objects are required to be scoped to a namespace - the value of this field for those objects will be empty.<br/><br/>Must be a DNS_LABEL. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/namespaces |
2424
| ownerReferences | array of [Owner Reference](#owner-reference) | List of objects depended by this object. If ALL objects in the list have been deleted, this object will be garbage collected. If this object is managed by a controller, then an entry in this list will point to this controller, with the controller field set to true. There cannot be more than one managing controller. |
@@ -54,7 +54,7 @@ SecurityContext holds security configuration that will be applied to a container
5454
| privileged | boolean | Run container in privileged mode. Processes in privileged containers are essentially equivalent to root on the host. Defaults to false. |
5555
| readOnlyRootFilesystem | boolean | Whether this container has a read-only root filesystem. Default is false. |
5656
| runAsNonRoot | boolean | Indicates that the container must run as a non-root user. If true, the Kubelet will validate the image at runtime to ensure that it does not run as UID 0 (root) and fail to start the container if it does. If unset or false, no such validation will be performed. May also be set in PodSecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. |
57-
| runAsUser | | The UID to run the entrypoint of the container process. Defaults to user specified in image metadata if unspecified. May also be set in PodSecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. |
57+
| runAsUser | integer | The UID to run the entrypoint of the container process. Defaults to user specified in image metadata if unspecified. May also be set in PodSecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. |
5858
| seLinuxOptions | [SE Linux Options](#se-linux-options) | The SELinux context to be applied to the container. If unspecified, the container runtime will allocate a random SELinux context for each container. May also be set in PodSecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. |
5959

6060
### Env Var
@@ -73,20 +73,20 @@ PodSecurityContext holds pod-level security attributes and common container sett
7373

7474
| Name | Type | Description |
7575
| --- | --- | --- |
76-
| fsGroup | | A special supplemental group that applies to all containers in a pod. Some volume types allow the Kubelet to change the ownership of that volume to be owned by the pod:<br/><br/>1. The owning GID will be the FSGroup 2. The setgid bit is set (new files created in the volume will be owned by FSGroup) 3. The permission bits are OR'd with rw-rw----<br/><br/>If unset, the Kubelet will not modify the ownership and permissions of any volume. |
76+
| fsGroup | integer | A special supplemental group that applies to all containers in a pod. Some volume types allow the Kubelet to change the ownership of that volume to be owned by the pod:<br/><br/>1. The owning GID will be the FSGroup 2. The setgid bit is set (new files created in the volume will be owned by FSGroup) 3. The permission bits are OR'd with rw-rw----<br/><br/>If unset, the Kubelet will not modify the ownership and permissions of any volume. |
7777
| runAsNonRoot | boolean | Indicates that the container must run as a non-root user. If true, the Kubelet will validate the image at runtime to ensure that it does not run as UID 0 (root) and fail to start the container if it does. If unset or false, no such validation will be performed. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence. |
78-
| runAsUser | | The UID to run the entrypoint of the container process. Defaults to user specified in image metadata if unspecified. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence for that container. |
78+
| runAsUser | integer | The UID to run the entrypoint of the container process. Defaults to user specified in image metadata if unspecified. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence for that container. |
7979
| seLinuxOptions | [SE Linux Options](#se-linux-options) | The SELinux context to be applied to all containers. If unspecified, the container runtime will allocate a random SELinux context for each container. May also be set in SecurityContext. If set in both SecurityContext and PodSecurityContext, the value specified in SecurityContext takes precedence for that container. |
80-
| supplementalGroups | array of | A list of groups applied to the first process run in each container, in addition to the container's primary GID. If unspecified, no groups will be added to any container. |
80+
| supplementalGroups | array of integer | A list of groups applied to the first process run in each container, in addition to the container's primary GID. If unspecified, no groups will be added to any container. |
8181

8282
### Resource Requirements
8383

8484
ResourceRequirements describes the compute resource requirements.
8585

8686
| Name | Type | Description |
8787
| --- | --- | --- |
88-
| limits | | Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/ |
89-
| requests | | Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/ |
88+
| limits | object | Limits describes the maximum amount of compute resources allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/ |
89+
| requests | object | Requests describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. More info: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/ |
9090

9191
### Volume Mount
9292

json-schema/src/main/java/oracle/kubernetes/json/YamlDocGenerator.java

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -150,24 +150,21 @@ String getString() {
150150
Type subType = getItems();
151151
return "array of " + subType.getString();
152152
default:
153-
return getReference();
153+
return Optional.ofNullable(getReference()).orElse(specifiedType);
154154
}
155155
}
156156

157+
@SuppressWarnings("unchecked")
157158
private Type getItems() {
158159
return new Type((Map<String, Object>) fieldMap.get("items"));
159160
}
160161

161162
private String getReference() {
162-
Reference reference = createReference(getReferenceString());
163-
return reference.getString();
163+
return createReference(getReferenceString()).getString();
164164
}
165165

166166
private String getReferenceString() {
167-
String reference = (String) fieldMap.get("$ref");
168-
if (reference != null) return reference;
169-
else if (fieldMap.get("items") == null) return null;
170-
else return (String) subMap(fieldMap, "items").get("$ref");
167+
return (String) fieldMap.get("$ref");
171168
}
172169
}
173170

@@ -207,23 +204,16 @@ String getLink() {
207204
private String getStructureName() {
208205
return toStructureName(typeName);
209206
}
210-
211-
abstract boolean isLocal();
212207
}
213208

214209
private class NullReference extends Reference {
215210
NullReference() {
216211
super(null);
217212
}
218213

219-
@Override
220-
boolean isLocal() {
221-
return false;
222-
}
223-
224214
@Override
225215
String getString() {
226-
return "";
216+
return null;
227217
}
228218
}
229219

@@ -241,15 +231,9 @@ private class LocalReference extends Reference {
241231
if (isReferenceType()) addReferenceIfNeeded(getTypeName());
242232
}
243233

244-
@Override
245-
boolean isLocal() {
246-
return true;
247-
}
248-
249234
@Override
250235
String getString() {
251-
if (isReferenceType()) return super.getString();
252-
else return getTypeName();
236+
return isReferenceType() ? super.getString() : getTypeName();
253237
}
254238

255239
private boolean isReferenceType() {
@@ -270,11 +254,6 @@ private String toK8sName(String ref) {
270254
return ref.substring(ref.lastIndexOf("/") + 1);
271255
}
272256

273-
@Override
274-
boolean isLocal() {
275-
return false;
276-
}
277-
278257
@Override
279258
String getLink() {
280259
return getKubernetesSchemaLink() + super.getLink();

json-schema/src/test/java/oracle/kubernetes/json/YamlDocGeneratorTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
package oracle.kubernetes.json;
66

7+
import static com.google.common.collect.ImmutableMap.of;
78
import static org.hamcrest.Matchers.containsString;
89
import static org.hamcrest.Matchers.equalTo;
910
import static org.hamcrest.Matchers.nullValue;
1011
import static org.hamcrest.junit.MatcherAssert.assertThat;
1112

13+
import com.google.common.collect.ImmutableMap;
1214
import java.io.IOException;
1315
import java.lang.reflect.Field;
1416
import java.util.HashMap;
@@ -48,6 +50,15 @@ private Map<String, Object> generateSchemaForField(Field field) {
4850
@Description("An annotated field")
4951
private Double annotatedDouble;
5052

53+
@Test
54+
public void whenSchemaHasUknownTypeAndNoReference_useAsSpecified() throws NoSuchFieldException {
55+
Map<String, Object> schema = ImmutableMap.of("anInt", of("type", "integer"));
56+
57+
String markdown = new YamlDocGenerator(schema).generateForProperty("anInt", schema);
58+
59+
assertThat(markdown, containsString(tableEntry("anInt", "integer", "")));
60+
}
61+
5162
@Test
5263
public void whenPropertyTypeIsDateTime_doNotGenerateReference() throws NoSuchFieldException {
5364
String markdown = generateForProperty(getClass().getDeclaredField("dateTime"));

0 commit comments

Comments
 (0)