Giter VIP home page Giter VIP logo

podsetoperatorinjava's Introduction

PodSet Operator in Java Using Fabric8 Kubernetes Client

Build License Twitter

Note

This project is a demo project for blog for writing a simple Kubernetes operation in Java using Fabric8 Kubernetes Client. You can find full blog here: Writing a simple Kubernetes Operation in Java

This is a demo operator which implements a simple operator for a custom resource called PodSet which is somewhat equal to ReplicaSet. Here is what this resource looks like:

apiVersion: demo.fabric8.io/v1alpha1
kind: PodSet
metadata:
  name: example-podset
spec:
  replicas: 5

Each PodSet object would have 'x' number of replicas, so this operator just tries to maintain x number of replicas checking whether that number of pods are running in cluster or not.

How to Build

   mvn clean install

How to Run

   mvn exec:java -Dexec.mainClass=io.fabric8.podset.operator.PodSetOperatorMain

Make Sure that PodSet Custom Resource Definition is already applied onto the cluster. If not, just apply it using this command:

kubectl apply -f src/main/resources/crd.yaml

Once everything is set, you can see that operator creating pods in your cluster for PodSet resource: Demo Screenshot

Deploying onto Kubernetes(minikube) using Eclipse JKube

  • Make Sure that PodSet Custom Resource Definition is already applied onto the cluster. If not, just apply it using this command:
kubectl apply -f src/main/resources/crd.yaml
  • Make sure that you have given correct privileges to ServiceAccount that would be used by the Pod, it's default in our case. Otherwise you might get 403 from Kubernetes API server.
kubectl create clusterrolebinding default-pod --clusterrole cluster-admin --serviceaccount=default:default

# In case of some other namespace:
kubectl create clusterrolebinding default-pod --clusterrole cluster-admin --serviceaccount=<namespace>:default
  • Build Docker Image
mvn k8s:build

JKube Build Docker Image

  • Generate Kubernetes Manifests
mvn k8s:resource

JKube Generate Kubernetes Manifests

  • Apply generated Kubernetes Manifests onto Kubernetes
mvn k8s:apply

Once generated resources are applied, try creating one of PodSet objects in src/main/resources

kubectl apply -f src/main/resources/cr.yaml

JKube Apply Generated Kubernetes Manifests

podsetoperatorinjava's People

Contributors

rohankanojia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

podsetoperatorinjava's Issues

debugging dont work

Problem

The java application starts very well

/Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.1.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50592,suspend=y,server=n -javaagent:/Users/dabou/Library/Caches/IntelliJIdea2019.2/captureAgent/debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "/Users/dabou/Downloads/podsetoperatorinjava-master/target/classes:/Users/dabou/.m2/repository/io/fabric8/kubernetes-client/4.6.0/kubernetes-client-4.6.0.jar:/Users/dabou/.m2/repository/io/fabric8/kubernetes-model/4.6.0/kubernetes-model-4.6.0.jar:/Users/dabou/.m2/repository/io/fabric8/kubernetes-model-common/4.6.0/kubernetes-model-common-4.6.0.jar:/Users/dabou/.m2/repository/com/fasterxml/jackson/module/jackson-module-jaxb-annotations/2.9.9/jackson-module-jaxb-annotations-2.9.9.jar:/Users/dabou/.m2/repository/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar:/Users/dabou/.m2/repository/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar:/Users/dabou/.m2/repository/com/squareup/okhttp3/okhttp/3.12.0/okhttp-3.12.0.jar:/Users/dabou/.m2/repository/com/squareup/okio/okio/1.15.0/okio-1.15.0.jar:/Users/dabou/.m2/repository/com/squareup/okhttp3/logging-interceptor/3.12.0/logging-interceptor-3.12.0.jar:/Users/dabou/.m2/repository/org/slf4j/slf4j-api/1.7.26/slf4j-api-1.7.26.jar:/Users/dabou/.m2/repository/org/slf4j/jul-to-slf4j/1.7.26/jul-to-slf4j-1.7.26.jar:/Users/dabou/.m2/repository/com/fasterxml/jackson/dataformat/jackson-dataformat-yaml/2.9.9/jackson-dataformat-yaml-2.9.9.jar:/Users/dabou/.m2/repository/org/yaml/snakeyaml/1.23/snakeyaml-1.23.jar:/Users/dabou/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.9.9.3/jackson-databind-2.9.9.3.jar:/Users/dabou/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar:/Users/dabou/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.9.9/jackson-core-2.9.9.jar:/Users/dabou/.m2/repository/io/fabric8/zjsonpatch/0.3.0/zjsonpatch-0.3.0.jar:/Users/dabou/.m2/repository/com/github/mifmif/generex/1.0.2/generex-1.0.2.jar:/Users/dabou/.m2/repository/dk/brics/automaton/automaton/1.11-8/automaton-1.11-8.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar" io.fabric8.podset.operator.PodSetOperatorMain
Connected to the target VM, address: '127.0.0.1:50592', transport: 'socket'
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Oct 07, 2019 7:05:13 PM io.fabric8.podset.operator.controller.PodSetController run
INFO: Starting PodSet controller
Oct 07, 2019 7:05:14 PM io.fabric8.podset.operator.controller.PodSetController run
INFO: trying to fetch item from workqueue...
Oct 07, 2019 7:05:14 PM io.fabric8.podset.operator.controller.PodSetController run
INFO: Work Queue is empty

but if we want to debug, then break points is not called when a CR is deployed on ocp3.11
Screenshot 2019-10-07 19 10 05

and logs report such information

io.fabric8.podset.operator.controller.PodSetController$1.onAdd()
Oct 07, 2019 7:05:49 PM io.fabric8.podset.operator.controller.PodSetController enqueuePodSet
INFO: enqueuePodSet(example-podset)
Oct 07, 2019 7:05:49 PM io.fabric8.podset.operator.controller.PodSetController enqueuePodSet
INFO: Going to enqueue key scoped/example-podset
Oct 07, 2019 7:05:49 PM io.fabric8.podset.operator.controller.PodSetController enqueuePodSet
INFO: Adding item to workqueue
Oct 07, 2019 7:05:49 PM io.fabric8.podset.operator.controller.PodSetController run
INFO: Got scoped/example-podset
Oct 07, 2019 7:05:49 PM io.fabric8.podset.operator.controller.PodSetController run
SEVERE: PodSet example-podset in workqueue no longer exists

Question: Do we have to perform a specific step to debug a java operator (= connected to an informer queue) ?

Found a bug in the code in below code snippet

Comparing String with ==??
public void onUpdate(Pod oldPod, Pod newPod) { if (oldPod.getMetadata().getResourceVersion() == newPod.getMetadata().getResourceVersion()) { return; } handlePodObject(newPod);

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.