All Projects → java-operator-sdk → Java Operator Sdk

java-operator-sdk / Java Operator Sdk

Licence: apache-2.0
Java SDK for building Kubernetes Operators

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Java Operator Sdk

Kudo
Kubernetes Universal Declarative Operator (KUDO)
Stars: ✭ 849 (+356.45%)
Mutual labels:  hacktoberfest, kubernetes-operator
Percona Xtradb Cluster Operator
A Kubernetes Operator for Percona XtraDB Cluster
Stars: ✭ 230 (+23.66%)
Mutual labels:  hacktoberfest, kubernetes-operator
Opentelemetry Operator
Kubernetes Operator for OpenTelemetry Collector
Stars: ✭ 104 (-44.09%)
Mutual labels:  hacktoberfest, kubernetes-operator
Securecodebox
secureCodeBox (SCB) - continuous secure delivery out of the box
Stars: ✭ 279 (+50%)
Mutual labels:  hacktoberfest, kubernetes-operator
Operators
Collection of Kubernetes Operators built with KUDO.
Stars: ✭ 175 (-5.91%)
Mutual labels:  hacktoberfest, kubernetes-operator
Petergate
Easy to use and read action and content based authorizations.
Stars: ✭ 188 (+1.08%)
Mutual labels:  hacktoberfest
Comit Rs
Reference implementation of COMIT, an open protocol facilitating trustless cross-blockchain applications.
Stars: ✭ 190 (+2.15%)
Mutual labels:  hacktoberfest
Red Discordbot
A multi-function Discord bot
Stars: ✭ 2,855 (+1434.95%)
Mutual labels:  hacktoberfest
Nimlsp
Language Server Protocol implementation for Nim
Stars: ✭ 186 (+0%)
Mutual labels:  hacktoberfest
Treestyletab
Tree Style Tab, Show tabs like a tree.
Stars: ✭ 2,438 (+1210.75%)
Mutual labels:  hacktoberfest
Css Declaration Sorter
Sort CSS declarations fast and automatically in a certain order.
Stars: ✭ 188 (+1.08%)
Mutual labels:  hacktoberfest
Programmers Community
This repository contains various solution of a problem in Ruby, C, C++, Python and Java.
Stars: ✭ 189 (+1.61%)
Mutual labels:  hacktoberfest
Pyresample
Geospatial image resampling in Python
Stars: ✭ 188 (+1.08%)
Mutual labels:  hacktoberfest
Matterpoll
Create polls and surveys directly within Mattermost
Stars: ✭ 189 (+1.61%)
Mutual labels:  hacktoberfest
Readability
Readability is Elixir library for extracting and curating articles.
Stars: ✭ 188 (+1.08%)
Mutual labels:  hacktoberfest
Dinosaurs
Hack Club dinosaur mascots.
Stars: ✭ 189 (+1.61%)
Mutual labels:  hacktoberfest
Files
File browser designed for elementary OS
Stars: ✭ 187 (+0.54%)
Mutual labels:  hacktoberfest
Awesome Devsecops
Curating the best DevSecOps resources and tooling.
Stars: ✭ 188 (+1.08%)
Mutual labels:  hacktoberfest
Laravel Datatables Html
Laravel DataTables HTML Builder Plugin
Stars: ✭ 188 (+1.08%)
Mutual labels:  hacktoberfest
Androrat
A Simple android remote administration tool using sockets. It uses java on the client side and python on the server side
Stars: ✭ 187 (+0.54%)
Mutual labels:  hacktoberfest

java-operator-sdk

Java CI with Maven Discord

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
  • Automatic registration of Custom Resource watches
  • Retry action on failure
  • Smart event scheduling (only handle the 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. In case you are interested how to handle more complex scenarios take a look on event sources.

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
  • 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.

⚠️ 1.7.0 Upgrade The 1.7.0 upgrade comes with big changes due to the update to the 5.0.0 version of the fabric8 Kubernetes client. While this should improve the user experience quite nicely, there are a couple of things to be aware of when upgrading from a previous version as detailed below.

Overview of the 1.8.0 changes

Overview of the 1.7.0 changes
  • Doneable classes have been removed along with all the involved complexity
  • Controller annotation has been simplified: the crdName field has been removed as that value is computed from the associated custom resource implementation
  • Custom Resource implementation classes now need to be annotated with Group and Version annotations so that they can be identified properly. Optionally, they can also be annotated with Kind (if the name of the implementation class doesn't match the desired kind) and Plural if the plural version cannot be automatically computed (or the default computed version doesn't match your expectations).
  • The CustomResource class that needs to be extended is now parameterized with spec and status types, so you can have an empty default implementation that does what you'd expect. If you don't need a status, using Void for the associated type should work.
  • Custom Resources that are namespace-scoped need to implement the Namespaced interface so that the client can generate the proper URLs. This means, in particular, that CustomResource implementations that do not implement Namespaced are considered cluster-scoped. As a consequence, the isClusterScoped method/field has been removed from the appropriate classes (Controller annotation, in particular) as this is now inferred from the CustomResource type associated with your Controller.

Many of these changes might not be immediately apparent but will result in 404 errors when connecting to the cluster. Please check that the Custom Resource implementations are properly annotated and that the value corresponds to your CRD manifest. If the namespace appear to be missing in your request URL, don't forget that namespace-scoped Custom Resources need to implement the Namescaped interface.

Usage

We have several sample Operators under the samples directory:

  • pure-java: 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.
  • spring-boot-plain/auto-config: Samples showing integration with Spring Boot.
  • quarkus: Minimal application showing automatic configuration / injection of Operator / Controllers.

And there are more samples in the standalone samples repo:

  • webserver: Simple example creating an NGINX webserver from a Custom Resource containing HTML code.
  • mysql-schema: Operator managing schemas in a MySQL database.
  • tomcat: Operator with two controllers, managing Tomcat instances and Webapps for these.

Add dependency to your project with Maven:

<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>

Or alternatively with Gradle, which also requires declaring the SDK as an annotation processor to generate the mappings between controllers and custom resource classes:

dependencies {
    implementation "io.javaoperatorsdk:operator-framework:${javaOperatorVersion}"
    annotationProcessor "io.javaoperatorsdk:operator-framework:${javaOperatorVersion}"
}

Once you've added the dependency, define a main method initializing the Operator and registering a controller.

public class Runner {

   public static void main(String[] args) {
       Operator operator = new Operator(new DefaultKubernetesClient(),
           DefaultConfigurationService.instance());
       operator.register(new WebServerController());
   }
}

The Controller implements the business logic and describes all the classes needed to handle the CRD.

@Controller
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

@Group("sample.javaoperatorsdk")
@Version("v1")
public class WebServer extends CustomResource<WebServerSpec, WebServerStatus> implements Namespaced {}

public class WebServerSpec {

    private String html;

    public String getHtml() {
        return html;
    }

    public void setHtml(String html) {
        this.html = html;
    }
}

Deactivating CustomResource implementations validation

The operator will, by default, query the deployed CRDs to check that the CustomResource implementations match what is known to the cluster. This requires an additional query to the cluster and, sometimes, elevated privileges for the operator to be able to read the CRDs from the cluster. This validation is mostly meant to help users new to operator development get started and avoid common mistakes. Advanced users or production deployments might want to skip this step. This is done by setting the CHECK_CRD_ENV_KEY environment variable to false. Quarkus users can also add quarkus.operator-sdk.check-crd-and-validate-local-model=false to their application.properties for the same purpose. Spring Boot users can set the property javaoperatorsdk.check-crd-and-validate-local-model to false.

Automatic generation of CRDs

To automatically generate CRD manifests from your annotated Custom Resource classes, you only need to add the following dependencies to your project:

<dependency>
  <groupId>io.fabric8</groupId>
  <artifactId>crd-generator</artifactId>
  <scope>compile</scope>
</dependency>
<!-- This dependency will not be needed anymore in a future release of the kubernetes-client -->
<dependency>
  <groupId>io.fabric8</groupId>
  <artifactId>kubernetes-model-common</artifactId>
</dependency>

The CRD will be generated in target/classes/META-INF/fabric8 (or in target/test-classes/META-INF/fabric8, if you use the test scope) with the CRD name suffixed by the generated spec version. For example, a CR using the java-operator-sdk.io group with a mycrs plural form will result in 2 files:

  • mycrs.java-operator-sdk.io-v1.yml
  • mycrs.java-operator-sdk.io-v1beta1.yml

Quarkus

A Quarkus extension is also provided to ease the development of Quarkus-based operators.

Add this dependency to your project:

<dependency>
  <groupId>io.quarkiverse.operatorsdk</groupId>
  <artifactId>quarkus-operator-sdk</artifactId>
  <version>{see https://search.maven.org/search?q=a:quarkus-operator-sdk for latest version}</version>
</dependency>

Create an Application, Quarkus will automatically create and inject a KubernetesClient (or OpenShiftClient), Operator, ConfigurationService and ResourceController instances that your application can use. Below, you can see the minimal code you need to write to get your operator and controllers up and running:

@QuarkusMain
public class QuarkusOperator implements QuarkusApplication {

  @Inject Operator operator;

  public static void main(String... args) {
    Quarkus.run(QuarkusOperator.class, args);
  }

  @Override
  public int run(String... args) throws Exception {
    operator.start();
    Quarkus.waitForExit();
    return 0;
  }
}

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>operator-framework-spring-boot-starter</artifactId>
 <version>{see https://search.maven.org/search?q=a:operator-framework-spring-boot-starter for latest version}</version>
</dependency>

Create an Application

@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

Spring Boot test support

Adding the following dependency would let you mock the operator for the tests where loading the spring container is necessary, but it doesn't need real access to a Kubernetes cluster.

<dependency>
 <groupId>io.javaoperatorsdk</groupId>
 <artifactId>operator-framework-spring-boot-starter-test</artifactId>
 <version>{see https://search.maven.org/search?q=a:operator-framework-spring-boot-starter for latest version}</version>
</dependency>

Mock the operator:

@SpringBootTest
@EnableMockOperator
public class SpringBootStarterSampleApplicationTest {

  @Test
  void contextLoads() {}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].