From c869b79113dfe7c68c27b9f772dab270a22b2bfb Mon Sep 17 00:00:00 2001 From: yuridekim Date: Sun, 10 Nov 2024 12:41:23 -0800 Subject: [PATCH] Add readme to project --- README.md | 210 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 209 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9242240..9a41034 100644 --- a/README.md +++ b/README.md @@ -1 +1,209 @@ -# Aviator \ No newline at end of file +# Aviator: VM Provisioning Kubernetes Controller + +A custom Kubernetes controller for automating OS provisioning in cloud environments, with integrated support for the Naver Cloud Platform (NCP) through the Aviator service SDK. +The [Aviator-service](https://github.com/cloud-club/Aviator-service) repository contains the core SDK implementation for cloud infrastructure automation. + +## Overview + +This Kubernetes controller automates the provisioning and management of virtual machines through custom resources. It integrates with NCP APIs to handle VM lifecycle operations including creation, updates, deletion, and status monitoring. + +## Features + +- **Custom Resource Definitions (CRDs)** + - Group: `vm.cloudclub.io` + - Version: `v1` + - Resources: + - `Provision`: Manages VM provisioning lifecycle + - `Plan`: Handles VM planning and configuration + +- **Integrated NCP Operations** + - Server instance creation and management + - Network interface configuration + - Block storage management + - Access control group handling + - Status monitoring and updates + +## Architecture + +### Component Structure + +1. **Controller Core** + - Custom Resource Definitions + - Reconciliation Logic + - Status Management + +2. **Aviator Service SDK Integration** + - ServerService: Handles VM operations + - KeyService: Manages authentication + - Error handling and status checking + - NCP API integration + +### Server Operations Interface +```go +type ServerInterface interface { + List(url string, request *types.ListServerRequest) (*types.ListServerResponse, error) + Create(url string, request *types.CreateServerRequest, params []int) (*types.CreateServerResponse, error) + Update(url string, request *types.UpdateServerRequest) (*types.UpdateServerResponse, error) + Start(url string, request *types.StartServerRequest) (*types.StartServerResponse, error) + Stop(url string, request *types.StopServerRequest) (*types.StopServerResponse, error) + Delete(url string, request *types.DeleteServerRequest) (*types.DeleteServerResponse, error) +} +``` + +### Custom Resources + +#### Provision Resource Example +```yaml +apiVersion: vm.cloudclub.io/v1 +kind: Provision +spec: + regionCode: KR + server: + imageProductCode: UBUNTU20 + productCode: SPSVRSTAND000056 + vpcNo: "vpc-123" + subnetNo: "subnet-456" + phase: Create +``` + +## Development + +### Prerequisites +- Go 1.16+ +- Kubernetes cluster (1.19+) +- Docker or compatible container runtime +- NCP Account and API Credentials +- Aviator Service SDK + +### Setting Up Development Environment + +1. Clone the repositories: +```bash +# Main controller +git clone https://github.com/your-org/vm-controller +# Aviator Service SDK +git clone https://github.com/cloud-club/Aviator-service +``` + +2. Configure NCP credentials: +```bash +export NCP_ACCESS_KEY="your-access-key" +export NCP_SECRET_KEY="your-secret-key" +``` + +### Build and Test + +```bash +# Build the controller +make build + +# Run tests +make test + +# Run linter +make lint +``` + +## CI/CD Pipeline + +The project uses GitHub Actions for CI/CD with the following stages: + +1. **Build & Test** + - Code compilation + - Unit tests + - Integration tests + - Code coverage reporting + +2. **Quality Gates** + - Linting + - Security scanning + - Dependency checking + +3. **Deployment** + - Container image building + - Image scanning + - Registry push + - Kubernetes deployment + +### Pipeline Configuration + +```yaml +# Example workflow stages +name: CI/CD Pipeline + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build + run: make build + - name: Test + run: make test +``` + +## Usage + +### 1. Installation + +```bash +# Install CRDs +make install + +# Deploy controller +make deploy IMG=/controller:tag +``` + +### 2. Create a VM Instance + +```yaml +apiVersion: vm.cloudclub.io/v1 +kind: Provision +metadata: + name: example-vm +spec: + phase: Create + server: + imageProductCode: "UBUNTU20" + productCode: "SPSVRSTAND000056" + vpcNo: "vpc-123" + subnetNo: "subnet-456" +``` + +### 3. Monitor Status + +```bash +kubectl get provisions +kubectl describe provision example-vm +``` + +## Error Handling + +The controller includes robust error handling for common scenarios: + +```go +var errorNotStopped = errors.New("Server is not stopped before update or deletion") + +// Status checking before operations +func checkStatus(server *ServerService, condition string, repeat int) bool { + // Implementation +} +``` + +## Contributing + +1. Fork both repositories (controller and [Aviator-service](https://github.com/cloud-club/Aviator-service)) +2. Create feature branches +3. Run tests and linting +4. Submit Pull Requests to both repos if needed +5. Ensure CI pipeline passes + +## License + +Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for details.