Skip to content

Commit

Permalink
Initial commit after moving files from the old repository
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeetraina committed Sep 20, 2024
0 parents commit e5a00dd
Show file tree
Hide file tree
Showing 35 changed files with 29,785 additions and 0 deletions.
82 changes: 82 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
FROM golang:1.21-alpine AS builder
ENV CGO_ENABLED=0
WORKDIR /vm
COPY vm/go.* .
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go mod download
COPY vm/. .
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go build -trimpath -ldflags="-s -w" -o bin/service

FROM --platform=$BUILDPLATFORM node:21.6-alpine3.18 AS client-builder
WORKDIR /client
# cache packages in layer
COPY client/package.json /client/package.json
COPY client/package-lock.json /client/package-lock.json
RUN --mount=type=cache,target=/usr/src/app/.npm \
npm set cache /usr/src/app/.npm && \
npm ci
# install
COPY client /client
RUN npm run build

# Final stage with KRS-Extension installation
FROM python:3.12.5-alpine
LABEL org.opencontainers.image.title="Krs - Chat with the Kubernetes Cluster" \
org.opencontainers.image.description="A GenAI-powered Kubetools Recommender System for Kubernetes clusters." \
org.opencontainers.image.vendor="Kubetools" \
com.docker.desktop.extension.api.version="0.3.4" \
com.docker.extension.screenshots="" \
com.docker.desktop.extension.icon="https://github.com/user-attachments/assets/a24f03df-ef85-44c4-a489-ba5c9b0e9352" \
com.docker.extension.detailed-description="" \
com.docker.extension.publisher-url="" \
com.docker.extension.additional-urls="" \
com.docker.extension.categories="" \
com.docker.extension.changelog=""

# Install required dependencies including curl
RUN apk add --update --no-cache curl git openssh-client ncurses bash ttyd tini sudo bash-completion docker-cli

# Clone the KRS repository
# Use the --break-system-packages option to bypass the externally managed environment errors
RUN git clone https://github.com/kubetoolsca/krs.git /krs \
&& cd /krs \
&& pip install . --break-system-packages \
&& chmod +x /usr/local/bin/krs \
&& chmod +x . \
&& chown -R 1000:1000 /krs
# Verify the command is working
RUN krs --help

# Install Kubectl in multiple environments.
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl \
&& chmod +x ./kubectl && mv ./kubectl /usr/local/bin/kubectl \
&& mkdir -p /linux \
&& cp /usr/local/bin/kubectl /linux/

RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/darwin/amd64/kubectl" \
&& mkdir -p /darwin \
&& chmod +x ./kubectl && mv ./kubectl /darwin/

RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/windows/amd64/kubectl.exe" \
&& mkdir -p /windows \
&& chmod +x ./kubectl.exe && mv ./kubectl.exe /windows/

# Copy the compiled backend binary from the Go builder stage
COPY --from=builder /vm/bin/service /
COPY kubetools.svg metadata.json docker-compose.yml /

# Copy frontend files from client-builder stage
COPY --from=client-builder /client/dist /ui

# Copy the script to automate the krs health command to the container
COPY automateKrsHealth.sh /sbin/
RUN chmod +x /sbin/automateKrsHealth.sh

# Expose port for ttyd (for interactive terminal)
EXPOSE 57681

# Start ttyd and the service
CMD ["ttyd", "-W","-p", "7681", "sh", "/sbin/automateKrsHealth.sh"]
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
IMAGE?=dminhph/krs-extension
TAG?=latest

BUILDER=buildx-multi-arch

INFO_COLOR = \033[0;36m
NO_COLOR = \033[m

build-extension: ## Build service image to be deployed as a desktop extension
docker build --rm --tag=$(IMAGE):$(TAG) .

install-extension: build-extension ## Install the extension
docker extension install $(IMAGE):$(TAG)

update-extension: build-extension ## Update the extension
docker extension update $(IMAGE):$(TAG)

debug-extension: build-extension## Debug extension
docker extension dev debug $(IMAGE):$(TAG)

reset-extension: ## Turn off debug mode
docker extension dev reset $(IMAGE):$(TAG)

prepare-buildx: ## Create buildx builder for multi-arch build, if not exists
docker buildx inspect $(BUILDER) || docker buildx create --name=$(BUILDER) --driver=docker-container --driver-opt=network=host

push-extension: prepare-buildx ## Build & Upload extension image to hub. Do not push if tag already exists: make push-extension tag=0.1
docker pull $(IMAGE):$(TAG) && echo "Failure: Tag already exists" || docker buildx build --push --builder=$(BUILDER) --platform=linux/amd64,linux/arm64 --build-arg TAG=$(TAG) --tag=$(IMAGE):$(TAG) .

help: ## Show this help
@echo Please specify a build target. The choices are:
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "$(INFO_COLOR)%-30s$(NO_COLOR) %s\n", $$1, $$2}'

.PHONY: help
201 changes: 201 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
# Krs Extension for Docker Desktop

![krs_logo](https://github.com/user-attachments/assets/a24f03df-ef85-44c4-a489-ba5c9b0e9352)


## Overview

This project is a Docker Desktop extension for KRS(Kubetools Recommender System) - a Gen-AI powered tool designed to recommend and manage tools for Kubernetes clusters. The extension provides a user-friendly interface for Kubernetes cluster operations such as initialization, scanning, recommendation, and healthcheck for tools, with support for different Kubernetes environments.

## Table of Contents

1. [Requirements](#requirements)
2. [Build and Install the Docker Extension](#build-and-install-the-docker-extension)
3. [Debug the Docker Extension](#debug-the-docker-extension)
4. [Dockerfile Explanation](#dockerfile-explanation)
5. [User Interface (UI)](#user-interface-ui)
6. [Running the KRS Commands](#running-the-krs-commands)
7. [Handling Kubernetes Configurations](#handling-kubernetes-configurations)
8. [Handling Additional Configuration Requirements for Different Kubernetes Clusters](#handling-additional-configuration-requirements-for-different-kubernetes-clusters)

## Prerequisite

Before you begin, ensure you have the following installed:
- **Docker Desktop** (for building and running Docker Desktop extensions)
- **Node.js**
- **Go**
- **Python**

Before you install the Krs Docker Extension, ensure that Kubernetes is enabled using Docker Desktop.
Don't forget to select the "Show System containers" option under Docker Desktop > Settings > Kubernetes.



<img width="1039" alt="image" src="https://github.com/user-attachments/assets/2edebbca-8581-4e14-92e0-82ca2e942347">



## Build and Install the Docker Extension

### Step 1: Build the Extension
In the project root, run the following commands to build the extension:

```bash
make build-extension
```

### Step 2: Install the Extension in Docker Desktop
You can install the built extension using Docker Desktop's command-line interface:

```bash
make install-extension
```

After installation, you will see the KRS - Kubetools Recommender System extension under Docker Desktop's Extensions tab.

### Additional Step: Update the Extension in Docker Desktop
Whenever you make a change to your extension, you only need to hit the following command. It will help you rebuild the extension and update it:

```bash
make update-extension
```

## Debug the Docker Extension

### Step 1: Debug the Extension
In the project root, run the following commands to debug the extension:

```bash
make debug-extension
```

### Step 2: Reset the debug mode
You can turn off the debug mode by hitting this below command

```bash
make reset-extension
```


## Dockerfile Explanation

The [Dockerfile](https://github.com/kubetoolsio/krs-dockerx/blob/add-krs-extension/Dockerfile) is divided into three main stages:

### Stage 1: Backend Service (Go)
- **Base Image**: golang:1.21-alpine
- This stage builds the backend service from the Go source files.

### Stage 2: Frontend (UI)

- **Base Image**: node:21.6-alpine
- This stage builds the frontend UI using Node.js.

### Stage 3: KRS (Python)

- **Base Image**: python:3.12.5-alpine
- This stage sets up the KRS tool, installs required dependencies, and prepares the service to interact with Kubernetes.

## User Interface (UI)
![alt text](images/image.png)
The Docker extension provides a graphical user interface (GUI) that allows users to initialize the Kubernetes environment and run various KRS commands.

- **React-based Frontend**: The UI is built using React and Material-UI.
- **Buttons** so far:
- ``krs init``: Initializes the services and loads the scanner. (**WORKING**) ✅
- ``krs scan``: Scans the cluster and extracts a list of tools that are currently used. (**WORKING**) ✅
- ``krs recommend``: Generates a table of recommended tools from our ranking database and their CNCF project status. (**WORKING**) ✅
- ``krs namespaces``: Lists all the namespaces. (**WORKING**) ✅
- ``krs pods``: Lists all the pods with namespaces, or lists pods under a specified namespace. (**WORKING**) ✅
- ``krs health``: Starts an interactive terminal using an LLM of your choice to detect and fix issues with your cluster. (**WORKING**) ✅
- ``krs exit``: Ends krs services safely and deletes all state files from system. Removes all cached data. (**WORKING**) ✅

## Running the KRS Commands
### Step 1: Starting the KRS-EXTENSION Container

The `krs` commands are executed inside a Docker container. This container is started in detached mode and can run commands via exec:

``` typescript
export const startKrsContainer = async (ddClient: v1.DockerDesktopClient) => {
// Start container in detached mode with kube config mounted
};
```


### Step 2: Running the ``krs init`` Command
![alt text](images/image1.png)

This command initializes the services and loads the scanner.

``` typescript
export const initKRS = async (ddClient: v1.DockerDesktopClient) => {
// Ensure the container is running, and execute "krs init" inside the container
};
```

### Step 3: Running the ``krs scan`` Command
![alt text](images/image2.png)
This command scans the cluster and extracts a list of tools that are currently used.

``` typescript
export const krsScan = async (ddClient: v1.DockerDesktopClient) => {
// Ensure the container is running, and execute "krs scan" inside the container
};
```

### Step 4: Running the ``krs recommend`` Command
![alt text](images/image3.png)
This command scans the cluster and generates a table of recommended tools from our ranking database and their CNCF project status.
``` typescript
export const krsRecommend = async (ddClient: v1.DockerDesktopClient) => {
// Ensure the container is running, and execute "krs scan" inside the container
};
```

### Step 5: Running the ``krs namespaces`` Command
![alt text](images/image4.png)
This command lists all the namespaces.
``` typescript
export const krsNamespaces = async (ddClient: v1.DockerDesktopClient) => {
// Ensure the container is running, and execute "krs scan" inside the container
};
```

### Step 5: Running the ``krs pods`` Command
![alt text](images/image5.png)
This command lists all the pods with namespaces, or lists pods under a specified namespace.
``` typescript
export const krsPods = async (ddClient: v1.DockerDesktopClient) => {
// Ensure the container is running, and execute "krs scan" inside the container
};
```

### Step 6: Running the ``krs health`` Command
![alt text](images/image6.png)
This command starts an interactive terminal using an LLM of your choice to detect and fix issues with your cluster.
``` typescript
export const krsHealth = async (ddClient: v1.DockerDesktopClient) => {
// Ensure the container is running, and execute "krs scan" inside the container
};
```

This command will allow you to interact with your cluster.

### Step 7: Running the ``krs exit`` Command
![alt text](images/image7.png)
This command ends krs services safely and deletes all state files from system. Removes all cached data.

``` typescript
export const krsExit = async (ddClient: v1.DockerDesktopClient) => {
// Ensure the container is running, and execute "krs scan" inside the container
};
```

## Handling Kubernetes Configurations
The Docker extension dynamically handles various Kubernetes configurations by mounting the `~/.kube/config` file from the host system into the container. This file contains the necessary configurations to connect to the local Kubernetes clusters.

## Handling Additional Configuration Requirements for Different Kubernetes Clusters
Different Kubernetes clusters may require additional configuration, such as specific authentication methods or additional certificate files.




10 changes: 10 additions & 0 deletions automateKrsHealth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Store the container ID in a variable and execute the 'krs health' command
containerID=$(docker ps -q --filter ancestor=dminhph/krs-extension:latest | head -n 1)
if [ -n "$containerID" ]; then
docker exec -it $containerID krs health
echo "ttyd is running, visit http://localhost:57681/ to interact with krs health."
else
echo "No running container found for dminhph/krs-extension:latest"
fi
12 changes: 12 additions & 0 deletions client/.browserslistrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is automatically converted to a Chromium version
# See: https://github.com/kilian/electron-to-chromium

# One day, we could distribute a config package from pinata with a Chrome version derived by
# feeding `require("electron").version` into an up-to-date `electron-to-chromium`.
# https://github.com/browserslist/browserslist#shareable-configs

Chrome 91

# Ideally we'd do (at time of writing) "Electron 13.1.4", but the version of electron-to-chromium
# in our dependency tree is a bit outdated
# See https://github.com/Kilian/electron-to-chromium/blob/master/versions.js for full list
6 changes: 6 additions & 0 deletions client/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[*]
root = true
end_of_line = lf

indent_size = 2
indent_style = space
3 changes: 3 additions & 0 deletions client/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BUILD_PATH=dist
PUBLIC_URL=.
BROWSER=none
33 changes: 33 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build
/dist

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Yarn-related
.yarn/*
!.yarn/patches
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.pnp.*
4 changes: 4 additions & 0 deletions client/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
Loading

0 comments on commit e5a00dd

Please sign in to comment.