From 106de9c6fe9c66b52b07e47b528402a9e247e866 Mon Sep 17 00:00:00 2001 From: Joel Borg <63634458+joelborg@users.noreply.github.com> Date: Wed, 17 Dec 2025 14:44:21 +0100 Subject: [PATCH] add flux-cli --- README.md | 12 ++-- flux-cli/README.md | 83 ++++++++++++++++++++++++++++ flux-cli/install.sh | 128 +++++++++++++++++++++++++++++++++++++++++++ flux-cli/test.sh | 130 ++++++++++++++++++++++++++++++++++++++++++++ install.sh | 3 + 5 files changed, 351 insertions(+), 5 deletions(-) create mode 100644 flux-cli/README.md create mode 100755 flux-cli/install.sh create mode 100755 flux-cli/test.sh diff --git a/README.md b/README.md index 277d6e0..7aef486 100644 --- a/README.md +++ b/README.md @@ -153,11 +153,12 @@ This will install all modules in the following predefined order: 6. **vim** - Neovim text editor 7. **kitty** - Terminal emulator 8. **kubectl** - Kubernetes CLI tools -9. **github-cli** - GitHub command-line interface -10. **slack** - Slack desktop application -11. **docker** - Docker configuration -12. **nvm** - Node Version Manager -13. **gitlab-cli** - GitLab command-line interface +9. **flux-cli** - GitOps toolkit for Kubernetes +10. **github-cli** - GitHub command-line interface +11. **slack** - Slack desktop application +12. **docker** - Docker configuration +13. **nvm** - Node Version Manager +14. **gitlab-cli** - GitLab command-line interface ### Individual Module Installation @@ -200,6 +201,7 @@ This will: This project includes the following configuration modules: - **Kubectl** - Kubernetes command-line tool configuration +- **Flux** - GitOps toolkit for Kubernetes - **ZSH** - Enhanced shell with plugins and themes - **Kitty** - Modern terminal emulator configuration - **Certificates** - SSL/TLS certificate management diff --git a/flux-cli/README.md b/flux-cli/README.md new file mode 100644 index 0000000..1310664 --- /dev/null +++ b/flux-cli/README.md @@ -0,0 +1,83 @@ +# Flux CLI Configuration + +This module provides installation and setup for Flux CLI, the GitOps toolkit for Kubernetes. + +## Features + +- Flux CLI installation (latest version) +- Automatic OS and architecture detection (Linux/macOS, amd64/arm64) +- ZSH completion support +- Automatic version checking +- Clean installation process + +## What is Flux? + +Flux is a set of continuous and progressive delivery solutions for Kubernetes that are open and extensible. It allows you to: + +- Automate deployment of applications to Kubernetes clusters +- Keep clusters in sync with configuration sources (Git repositories) +- Provide GitOps workflow for Kubernetes +- Manage Helm releases and Kubernetes manifests +- Support multi-tenancy and RBAC + +## Installation + +To install the Flux CLI: + +```bash +cd flux-cli +./install.sh +``` + +The installation process includes: +1. Detecting your OS and architecture +2. Fetching the latest Flux CLI version from GitHub +3. Downloading and installing the appropriate binary +4. Setting up ZSH completion (if Oh My ZSH is installed) +5. Verifying the installation + +## Testing + +To verify the installation: + +```bash +./test.sh +``` + +## Usage + +After installation, you can use the `flux` command: + +```bash +# Check version +flux version + +# Bootstrap Flux on a cluster +flux bootstrap github \ + --owner= \ + --repository= \ + --path=clusters/my-cluster \ + --personal + +# Check Flux system status +flux check + +# Get all Flux resources +flux get all + +# Reconcile a source +flux reconcile source git +``` + +## Requirements + +- `curl` for downloading files +- `sudo` access for system-wide installation +- Kubernetes cluster (for actual Flux operations) +- Git repository (for GitOps workflow) + +## Links + +- [Flux Documentation](https://fluxcd.io/docs/) +- [Flux GitHub Repository](https://github.com/fluxcd/flux2) +- [Getting Started Guide](https://fluxcd.io/docs/get-started/) diff --git a/flux-cli/install.sh b/flux-cli/install.sh new file mode 100755 index 0000000..4f2f0ae --- /dev/null +++ b/flux-cli/install.sh @@ -0,0 +1,128 @@ +#!/bin/bash + +# Exit on any error +set -e + +# Script directory and module info +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +BACKUP_DIR="$SCRIPT_DIR/../backup" +MODULE_NAME="flux" + +# Catppuccin Mocha color scheme +# Base colors +BASE="\033[0m" +TEXT="\033[38;2;205;214;244m" # Text +SUBTEXT="\033[38;2;166;173;200m" # Subtext +OVERLAY="\033[38;2;108;112;134m" # Overlay +SURFACE="\033[38;2;49;50;68m" # Surface +BASE_COLOR="\033[38;2;30;30;46m" # Base +MANTLE="\033[38;2;24;24;37m" # Mantle +CRUST="\033[38;2;17;17;27m" # Crust + +# Accent colors +RED="\033[38;2;243;139;168m" # Red +GREEN="\033[38;2;166;227;161m" # Green +YELLOW="\033[38;2;249;226;175m" # Yellow +BLUE="\033[38;2;137;180;250m" # Blue +PINK="\033[38;2;245;194;231m" # Pink +MAUVE="\033[38;2;203;166;247m" # Mauve +TEAL="\033[38;2;148;226;213m" # Teal + +# Print functions +print_status() { + echo -e "${BLUE}[i]${BASE} $1" +} + +print_success() { + echo -e "${GREEN}[✓]${BASE} $1" +} + +print_error() { + echo -e "${RED}[✗]${BASE} $1" +} + +print_warning() { + echo -e "${YELLOW}[!]${BASE} $1" +} + +print_header() { + echo -e "\n${MAUVE}=== $1 ===${BASE}\n" +} + +# Function to install flux CLI +install_flux() { + print_status "Installing Flux CLI using official installation script..." + + # Install Flux using the official installation script + if curl -s https://fluxcd.io/install.sh | sudo bash; then + print_success "Flux CLI installed successfully!" + + # Verify installation and display version + if command -v flux &> /dev/null; then + flux version --client + fi + else + print_error "Failed to install Flux CLI" + exit 1 + fi +} + +# Function to setup flux completion +setup_completion() { + print_status "Setting up Flux completion for ZSH..." + + local ZSH_COMPLETION_DIR="${HOME}/.oh-my-zsh/custom/completions" + + # Create completions directory if it doesn't exist + mkdir -p "$ZSH_COMPLETION_DIR" + + # Generate flux completion + flux completion zsh > "${ZSH_COMPLETION_DIR}/_flux" + + print_success "Flux ZSH completion installed!" +} + +# Function to create backup directory +create_backup_dir() { + if [ ! -d "$BACKUP_DIR" ]; then + mkdir -p "$BACKUP_DIR" + print_status "Created backup directory: $BACKUP_DIR" + fi +} + +# Main installation +main() { + print_header "Installing Flux CLI" + + # Create backup directory + create_backup_dir + + # Check if flux is already installed + if command -v flux &> /dev/null; then + print_warning "Flux is already installed. Current version:" + flux version --client + read -p "Do you want to reinstall? (y/N) " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + print_status "Skipping installation" + else + install_flux + fi + else + install_flux + fi + + # Setup completion + if [ -d "$HOME/.oh-my-zsh" ]; then + setup_completion + else + print_warning "Oh My ZSH not detected. Skipping completion setup." + fi + + print_header "Flux CLI Installation Complete!" + print_success "You can now use 'flux' command" + print_status "Try: flux --help" +} + +# Run main installation +main "$@" diff --git a/flux-cli/test.sh b/flux-cli/test.sh new file mode 100755 index 0000000..a0be705 --- /dev/null +++ b/flux-cli/test.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +# Exit on error +set -e + +# Script directory and module info +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +MODULE_NAME="flux" + +# Catppuccin Mocha color scheme +# Base colors +BASE="\033[0m" +TEXT="\033[38;2;205;214;244m" # Text +SUBTEXT="\033[38;2;166;173;200m" # Subtext +OVERLAY="\033[38;2;108;112;134m" # Overlay +SURFACE="\033[38;2;49;50;68m" # Surface +BASE_COLOR="\033[38;2;30;30;46m" # Base +MANTLE="\033[38;2;24;24;37m" # Mantle +CRUST="\033[38;2;17;17;27m" # Crust + +# Accent colors +RED="\033[38;2;243;139;168m" # Red +GREEN="\033[38;2;166;227;161m" # Green +YELLOW="\033[38;2;249;226;175m" # Yellow +BLUE="\033[38;2;137;180;250m" # Blue +PINK="\033[38;2;245;194;231m" # Pink +MAUVE="\033[38;2;203;166;247m" # Mauve +TEAL="\033[38;2;148;226;213m" # Teal + +# Print functions +print_status() { + echo -e "${BLUE}[i]${BASE} $1" +} + +print_success() { + echo -e "${GREEN}[✓]${BASE} $1" +} + +print_error() { + echo -e "${RED}[✗]${BASE} $1" +} + +print_warning() { + echo -e "${YELLOW}[!]${BASE} $1" +} + +print_header() { + echo -e "\n${MAUVE}=== $1 ===${BASE}\n" +} + +# Test counters +TESTS_PASSED=0 +TESTS_FAILED=0 + +# Test function +run_test() { + local test_name="$1" + local test_command="$2" + + print_status "Testing: $test_name" + + if eval "$test_command"; then + print_success "PASSED: $test_name" + ((TESTS_PASSED++)) + return 0 + else + print_error "FAILED: $test_name" + ((TESTS_FAILED++)) + return 1 + fi +} + +# Main test suite +main() { + print_header "Running Flux CLI Tests" + + # Test 1: Check if flux is installed + run_test "Flux CLI is installed" "command -v flux &> /dev/null" + + # Test 2: Check flux version + run_test "Flux version command works" "flux version --client &> /dev/null" + + # Test 3: Check flux help + run_test "Flux help command works" "flux --help &> /dev/null" + + # Test 4: Check flux check (pre-flight checks) + print_status "Testing: Flux check command (may fail if no cluster is configured)" + if flux check &> /dev/null; then + print_success "PASSED: Flux check command (cluster configured)" + ((TESTS_PASSED++)) + else + print_warning "WARNING: Flux check failed (expected if no cluster is configured)" + print_status "This is normal if you don't have a Kubernetes cluster configured" + fi + + # Test 5: Verify flux binary location + run_test "Flux is in PATH" "[ -x \$(which flux) ]" + + # Test 6: Check ZSH completion (if Oh My ZSH is installed) + if [ -d "$HOME/.oh-my-zsh" ]; then + local completion_file="$HOME/.oh-my-zsh/custom/completions/_flux" + run_test "Flux ZSH completion is installed" "[ -f \"$completion_file\" ]" + else + print_status "Skipping ZSH completion test (Oh My ZSH not detected)" + fi + + # Test 7: Display flux version info + print_header "Flux Version Information" + flux version --client + + # Test 8: List available flux commands + print_header "Available Flux Commands" + flux --help | grep -A 100 "Available Commands:" | head -20 + + # Summary + print_header "Test Summary" + echo -e "${GREEN}Tests Passed: $TESTS_PASSED${BASE}" + echo -e "${RED}Tests Failed: $TESTS_FAILED${BASE}" + + if [ $TESTS_FAILED -eq 0 ]; then + print_success "All tests passed!" + exit 0 + else + print_error "Some tests failed!" + exit 1 + fi +} + +# Run tests +main "$@" diff --git a/install.sh b/install.sh index d7276bf..bdd3dd8 100755 --- a/install.sh +++ b/install.sh @@ -156,6 +156,8 @@ show_help() { echo -e " ${BLUE}11.${BASE} docker # Docker configuration" echo -e " ${BLUE}12.${BASE} nvm # Node Version Manager" echo -e " ${BLUE}13.${BASE} gitlab-cli # GitLab command-line interface" + echo -e " ${BLUE}14.${BASE} flux-cli # GitOps toolkit for Kubernetes" + echo echo -e "${TEXT}Examples:${BASE}" echo -e " ${BLUE}./install.sh${BASE} # Interactive installation" @@ -232,6 +234,7 @@ install_all_modules() { "docker" "nvm" "gitlab-cli" + "flux-cli" ) # Install modules in the specified order