1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 21:46:22 +01:00
Files
openshift-docs/modules/osdk-java-define-api.adoc
Andrew Taylor c61d8f0384 OSDOCS-2933 Java OSDK
peer review feedback

SME/QE review

final review feedback
2022-07-22 13:43:37 +00:00

70 lines
1.8 KiB
Plaintext

// Module included in the following assemblies:
//
// * operators/operator_sdk/java/osdk-java-tutorial.adoc
:_content-type: PROCEDURE
[id="osdk-java-define-api_{context}"]
= Defining the API
Define the API for the `Memcached` custom resource (CR).
.Procedure
* Edit the following files that were generated as part of the `create api` process:
.. Update the following attributes in the `MemcachedSpec.java` file to define the desired state of the `Memcached` CR:
+
[source,java]
----
public class MemcachedSpec {
private Integer size;
public Integer getSize() {
return size;
}
public void setSize(Integer size) {
this.size = size;
}
}
----
.. Update the following attributes in the `MemcachedStatus.java` file to define the observed state of the `Memcached` CR:
+
[NOTE]
====
The example below illustrates a Node status field. It is recommended that you use link:https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties[typical status properties] in practice.
====
+
[source,java]
----
import java.util.ArrayList;
import java.util.List;
public class MemcachedStatus {
// Add Status information here
// Nodes are the names of the memcached pods
private List<String> nodes;
public List<String> getNodes() {
if (nodes == null) {
nodes = new ArrayList<>();
}
return nodes;
}
public void setNodes(List<String> nodes) {
this.nodes = nodes;
}
}
----
.. Update the `Memcached.java` file to define the Schema for Memcached APIs that extends to both `MemcachedSpec.java` and `MemcachedStatus.java` files.
+
[source,java]
----
@Version("v1")
@Group("cache.example.com")
public class Memcached extends CustomResource<MemcachedSpec, MemcachedStatus> implements Namespaced {}
----