Code Monkey home page Code Monkey logo

java-operator-sdk's Introduction

java-operator-sdk

Java CI with Maven

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

Features

  • Framework for handling Kubernetes API events
  • Registering Custom Resource watches
  • Retry action on failure
  • Smart event scheduling (only handle latest event for the same resource)

Check out this blog post about the non-trivial yet common problems needed to be solved for every operator.

Why build your own Operator?

  • Infrastructure automation using the power and flexibility of Java. See blog post.
  • Provisioning of complex applications - avoiding Helm chart hell
  • Integration with Cloud services - e.g. Secret stores
  • Safer deployment of applications - only expose cluster to users by Custom Resources

Roadmap

  • Testing of the framework and all samples while running on a real cluster.
  • Generate a project skeleton
  • Generate Java classes from CRD defintion (and/or the other way around)
  • Integrate with Quarkus (including native image build)
  • Integrate with OLM (Operator Lifecycle Manager)

Join us on Discord!

Discord Invite Link

User Guide

You can (will) find detailed documentation here. Note that these docs are currently in progress.

Usage

We have several sample Operators under the samples directory:

  • basic: Minimal Operator implementation which only parses the Custom Resource and prints to stdout. Implemented with and without Spring Boot support. The two samples share the common module.
  • webserver: More realistic example creating an nginx webserver from a Custom Resource containing html code.
  • mysql-schema: Operator managing schemas in a MySQL database
  • spring-boot-plain/auto-config: Samples showing integration with Spring Boot.

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(crdName = "webservers.sample.javaoperatorsdk")
public class WebServerController implements ResourceController<WebServer> {

    @Override
    public DeleteControl deleteResource(CustomService resource, Context<WebServer> context) {
        // ... your logic ...
        return DeleteControl.DEFAULT_DELETE;
    }
    
    // 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;
    }
}

Spring Boot

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);
    }
}

java-operator-sdk's People

Contributors

csviri avatar adam-sandor avatar dependabot[bot] avatar charlottemach avatar gauravbisht005 avatar actions-user avatar kirek007 avatar s-soroosh avatar sullis avatar mvegter avatar metacosm avatar amouat avatar didier-durand avatar cs-marek-ruszczyk avatar mureinik avatar synox avatar mcwienczek avatar sushant-varanasi avatar trishitapingolia avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.