A Spring Boot service that compares two Kubernetes YAML files and produces: (1) a structured JSON diff (merged left/right lines + stats) and (2) a GitHub-like HTML snippet for visual review. Each successful comparison is logged as a DiffLog (filenames, SHA-256 hashes, counters, IP, timestamp). All JSON responses are wrapped in CustomResponse<T>.
- Client sends a multipart request with two files:
leftandright. Optionally pass a JSON partoptionswith{ "ignoreWhitespace": true|false }. - 2 sample files whose names are deployment-old.yaml and deployment-new.yaml are defined underneath files folder
- Service normalizes/decodes input, runs a line diff, builds a left/right-aligned merged view, computes stats (added / deleted / unchanged), and renders a GitHub-like HTML snippet.
-
Returns either:
200 OKJSON model (DiffResult) at/api/diff/compare200 OKHTML snippet at/api/diff/comparehtml
DiffLogvia AOP.
An aspect (@LoggableDiff) captures successful comparisons and stores: left/right filenames, SHA-256 (Base64URL) hashes, added/deleted/unchanged counts, requester IPv4, and createdAt.
400 Bad Request— Empty input side (left/right), invalid/too large files (≤ 2 MB)406 Not Acceptable— Client insists ontext/htmlbut only an error JSON is available500 Internal Server Error— Unexpected failures (e.g., crypto hashing)
Explore the API and schemas at: http://localhost:1928/swagger-ui/index.html (port configurable).
Endpoints Summary
| Method | URL | Description | Request Body | Headers/Path | Response | Status Codes |
|---|---|---|---|---|---|---|
| POST | /api/diff/compare |
Compare two YAML files and return JSON diff + stats |
Multipart:
|
Accept: application/json |
CustomResponse<DiffResultDto>DiffResultDto: lines[] (left/right line numbers + type + text), stats, html |
200, 400 |
| POST | /api/diff/comparehtml |
Compare two YAML files and return HTML snippet directly |
Multipart:
|
Accept: text/html |
HTML snippet (GitHub-like two-column diff) | 200, 400, 406 |
- Java 25
- Spring Boot 3.0
- Restful API
- Open Api (Swagger)
- Maven
- Junit5
- Mockito
- Integration Tests
- Mapstruct
- Docker
- Docker Compose
- CI/CD (Github Actions)
- Postman
- Prometheus
- Grafana
- Kubernetes
- JaCoCo (Test Report)
- AOP
- Sonarqube
Import postman collection under postman_collection folder
COMPARE_DB_IP=localhost
COMPARE_DB_PORT=3306
DATABASE_USERNAME={MY_SQL_DATABASE_USERNAME}
DATABASE_PASSWORD={MY_SQL_DATABASE_PASSWORD}
http://localhost:1928/swagger-ui/index.html
After the command named mvn clean install completes, the JaCoCo report will be available at:
target/site/jacoco/index.html
Navigate to the target/site/jacoco/ directory.
Open the index.html file in your browser to view the detailed coverage report.
To build and run the application with Maven, please follow the directions shown below;
$ git clone https://github.com/Rapter1990/kubernetesymlcompare.git
$ cd kubernetesymlcompare
$ mvn clean install
$ mvn spring-boot:runThe application can be built and run by the Docker engine. The Dockerfile has multistage build, so you do not need to build and run separately.
Please follow directions shown below in order to build and run the application with Docker Compose file;
$ cd kubernetesymlcompare
$ docker-compose up -dIf you change anything in the project and run it on Docker, you can also use this command shown below
$ cd kubernetesymlcompare
$ docker-compose up --buildTo monitor the application, you can use the following tools:
-
Prometheus:
Open in your browser at http://localhost:9090
Prometheus collects and stores application metrics. -
Grafana:
Open in your browser at http://localhost:3000
Grafana provides a dashboard for visualizing the metrics.
Default credentials:- Username:
admin - Password:
admin
- Username:
Define prometheus data source url, use this link shown below
http://prometheus:9090
To run the application, please follow the directions shown below;
- Start Minikube
$ minikube start- Open Minikube Dashboard
$ minikube dashboard- To deploy the application on Kubernetes, apply the Kubernetes configuration file underneath k8s folder
$ kubectl apply -f k8s- To open Prometheus, click tunnel url link provided by the command shown below to reach out Prometheus
minikube service prometheus-service- To open Grafana, click tunnel url link provided by the command shown below to reach out Prometheus
minikube service grafana-service- Define prometheus data source url, use this link shown below
http://prometheus-service.default.svc.cluster.local:9090
- Go to
localhost:9000for Docker and Go there throughminikube service sonarqubefor Kubernetes - Enter username and password as
admin - Change password
- Click
Create Local Project - Choose the baseline for this code for the project as
Use the global setting - Click
Locallyin Analyze Method - Define Token
- Click
Continue - Copy
sonar.host.urlandsonar.token(sonar.login) in thepropertiespart inpom.xml - Run
mvn sonar:sonarto show code analysis
https://hub.docker.com/repository/docker/noyandocker/kubernetesymlcompare/general
Click here to show the screenshots of project
Figure 1
Figure 2
Figure 3
Figure 4
Figure 5
Figure 6
Figure 7
Figure 8
Figure 9
Figure 10
Figure 11
Figure 12
Figure 13
Figure 14
Figure 15
Figure 16
Figure 17
Figure 18
Figure 19
Figure 20
Figure 21
Figure 22
Figure 23
Figure 24
Figure 25
Figure 26
Figure 27
Figure 28
Figure 29
Figure 30
Figure 31
Figure 32
Figure 33
Figure 34
