| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Build Kubernetes Operators in Java without hassle. Inspired by operator-sdk.
| S.No. | Contents |
|---|---|
| 1. | Features |
| 2. | Why build your own Operator? |
| 3. | Roadmap |
| 4. | Join us on Discord! |
| 5. | User Guide |
| 6. | Usage |
| 7. | Spring Boot |
Check out this blog post about the non-trivial yet common problems needs to be solved for every operator.
You can (will) find detailed documentation here. Note that these docs are currently in progress.
We have several sample Operators under the samples directory:
Add dependency to your project:
<dependency>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>operator-framework</artifactId>
<version>{see https://search.maven.org/search?q=a:operator-framework for latest version}</version>
</dependency>Main method initializing the Operator and registering a controller..
public class Runner {
public static void main(String[] args) {
Operator operator = new Operator(new DefaultKubernetesClient());
operator.registerController(new WebServerController());
}
}The Controller implements the business logic and describes all the classes needed to handle the CRD.
@Controller(customResourceClass = WebServer.class,
crdName = "webservers.sample.javaoperatorsdk")
public class WebServerController implements ResourceController<WebServer> {
@Override
public boolean deleteResource(CustomService resource, Context<WebServer> context) {
// ... your logic ...
return true;
}
// Return the changed resource, so it gets updated. See javadoc for details.
@Override
public UpdateControl<CustomService> createOrUpdateResource(CustomService resource, Context<WebServer> context) {
// ... your logic ...
return UpdateControl.updateStatusSubResource(resource);
}
}A sample custom resource POJO representation
public class WebServer extends CustomResource {
private WebServerSpec spec;
private WebServerStatus status;
public WebServerSpec getSpec() {
return spec;
}
public void setSpec(WebServerSpec spec) {
this.spec = spec;
}
public WebServerStatus getStatus() {
return status;
}
public void setStatus(WebServerStatus status) {
this.status = status;
}
}
public class WebServerSpec {
private String html;
public String getHtml() {
return html;
}
public void setHtml(String html) {
this.html = html;
}
}You can also let Spring Boot wire your application together and automatically register the controllers.
Add this dependency to your project:
<dependency>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>spring-boot-operator-framework-starter</artifactId>
<version>{see https://search.maven.org/search?q=a:spring-boot-operator-framework-starter for latest version}</version>
</dependency>Create an Application
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}| Back | FazBrowse Home | New Git URL |