-
Notifications
You must be signed in to change notification settings - Fork 27
Autodetect kind cluster configuration #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Flight Control UI configuration | ||
|
|
||
| This document describes all environment variables and configuration options available for the Flight Control UI. | ||
|
|
||
| ## Feature toggles | ||
|
|
||
| | Variable | Description | Default | Values | | ||
| | ---------------------- | ----------------------------------------- | ------- | --------------- | | ||
| | `ENABLE_ORGANIZATIONS` | Enable/disable organizations support | `false` | `true`, `false` | | ||
| | `ENABLE_CLI_ARTIFACTS` | Enable/disable CLI download functionality | `true` | `true`, `false` | | ||
| | `ENABLE_ALERTMANAGER` | Enable/disable alerts functionality | `true` | `true`, `false` | | ||
|
|
||
| ## Backend configuration | ||
|
|
||
| | Variable | Description | Default | Values | | ||
| | --------------------------------------- | ------------------------------------ | ------------------------ | -------------------------------------- | | ||
| | `BASE_UI_URL` | Base URL for UI application | `http://localhost:9000` | `https://ui.flightctl.example.com` | | ||
| | `FLIGHTCTL_SERVER` | Flight Control API server URL | `https://localhost:3443` | `https://api.flightctl.example.com` | | ||
| | `FLIGHTCTL_SERVER_INSECURE_SKIP_VERIFY` | Skip backend server TLS verification | `false` | `true`, `false` | | ||
| | `FLIGHTCTL_CLI_ARTIFACTS_SERVER` | CLI artifacts server URL | `http://localhost:8090` | `https://cli.flightctl.example.com` | | ||
| | `FLIGHTCTL_ALERTMANAGER_PROXY` | AlertManager proxy server URL | `https://localhost:8443` | `https://alerts.flightctl.example.com` | | ||
| | `INTERNAL_AUTH_URL` | Internal authentication URL | _(empty)_ | `https://auth.internal.example.com` | | ||
| | `AUTH_INSECURE_SKIP_VERIFY` | Skip auth server TLS verification | `false` | `true`, `false` | | ||
| | `AUTH_CLIENT_ID` | OAuth client ID for authentication | `flightctl` | Custom client ID | | ||
| | `TLS_CERT` | Path to TLS certificate | _(empty)_ | `/path/to/server.crt` | | ||
| | `TLS_KEY` | Path to TLS private key | _(empty)_ | `/path/to/server.key` | | ||
| | `API_PORT` | UI proxy server port | `3001` | `8080`, `3000`, etc. | | ||
| | `K8S_RBAC_NS` | Kubernetes RBAC namespace | _(empty)_ | `flightctl` | | ||
| | `IS_OCP_PLUGIN` | Run as OpenShift Console plugin | `false` | `true`, `false` | | ||
| | `IS_RHEM` | Red Hat Enterprise Mode | _(empty)_ | `true`, `false` | | ||
|
|
||
| ## Configuration examples | ||
|
|
||
| ```shell | ||
| # Use auto-detection of all configuration settings | ||
| npm run dev:kind | ||
| ``` | ||
|
|
||
| ```shell | ||
| # Use auto-detection and override desired settings | ||
| ENABLE_CLI_ARTIFACTS=false npm run dev:kind | ||
| ``` | ||
|
|
||
| ```shell | ||
| # Use remote backend and custom settings | ||
| FLIGHTCTL_SERVER=https://flightctl.prod.example.com \ | ||
| ENABLE_ORGANIZATIONS=false \ | ||
| ENABLE_CLI_ARTIFACTS=false \ | ||
| npm run dev | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,24 @@ | ||
| #!/usr/bin/env bash | ||
| #!/bin/sh | ||
|
|
||
| flightctl_namespace="flightctl-external" | ||
|
|
||
| # Validates that the script can run properly to detect the backend deployment setttings | ||
| validate_prerequisites() { | ||
| if ! command -v kubectl >/dev/null 2>&1; then | ||
| echo "❌ Error: kubectl not found. " >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! kubectl config get-contexts kind-kind >/dev/null 2>&1; then | ||
| echo "❌ Error: kind-kind context not found. Please deploy flightctl first." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if ! kubectl get namespaces --context kind-kind >/dev/null 2>&1; then | ||
| echo "❌ Error: Cannot connect to kind cluster. Please check your setup." >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| # Function to get external IP address | ||
| get_external_ip() { | ||
|
|
@@ -11,6 +31,43 @@ get_external_ip() { | |
| fi | ||
| } | ||
|
|
||
| # Function that determines if a setting is enabled based on the presence of a service in the kind cluster | ||
| detect_service_setting() { | ||
| setting_name="$1" | ||
| service_name="$2" | ||
|
|
||
| if kubectl get service "$service_name" -n "$flightctl_namespace" --context kind-kind >/dev/null 2>&1; then | ||
| echo "Autodetected: $setting_name enabled ✅" >&2 | ||
| echo "true" | ||
| else | ||
| echo "Autodetected: $setting_name disabled ❌" >&2 | ||
| echo "false" | ||
| fi | ||
| return 0 | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Comment on lines
+35
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better distinguish between "service not found" and kubectl errors. Line 39 silently suppresses all error output from Consider capturing the exit code to differentiate between actual "not found" (exit 1 with "NotFound" message) and other errors that should be surfaced to the user. -detect_service_setting() {
- setting_name="$1"
- service_name="$2"
-
- if kubectl get service "$service_name" -n "$flightctl_namespace" --context kind-kind >/dev/null 2>&1; then
+detect_service_setting() {
+ setting_name="$1"
+ service_name="$2"
+
+ if kubectl get service "$service_name" -n "$flightctl_namespace" --context kind-kind >/dev/null 2>&1; then
echo "Autodetected: $setting_name enabled ✅" >&2
echo "true"
else
echo "Autodetected: $setting_name disabled ❌" >&2
echo "false"
fiAlternatively, if the current behavior is acceptable for development, add a comment explaining why all errors are treated as "not found".
|
||
|
|
||
| # Function that determines if organizations are enabled based on the "organizations.enabled" setting from "flightctl-api-config" ConfigMap | ||
| detect_organizations_setting() { | ||
| SETTING_VALUE=$(kubectl get configmap flightctl-api-config -n "$flightctl_namespace" --context kind-kind -o jsonpath='{.data.config\.yaml}' 2>/dev/null | grep -A1 "organizations:" | grep "enabled:" | awk '{print $2}' | tr -d ' ') | ||
|
|
||
| if [ -n "$SETTING_VALUE" ]; then | ||
| if [ "$SETTING_VALUE" = "true" ]; then | ||
| echo "Autodetected: Organizations enabled ✅" >&2 | ||
| else | ||
| echo "Autodetected: Organizations disabled ❌" >&2 | ||
| fi | ||
| echo "$SETTING_VALUE" | ||
| else | ||
| echo "Autodetected: Organizations disabled ❌ (no setting found in ConfigMap)" >&2 | ||
| echo "false" | ||
| fi | ||
| return 0 | ||
| } | ||
|
Comment on lines
+50
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strengthen the ConfigMap YAML parsing with defensive coding. Line 51 uses a fragile grep chain that assumes a specific YAML format. If the ConfigMap structure varies (different spacing, comments, format changes), the parsing silently fails and defaults to "false", potentially disabling organizations features even when enabled in the backend. The pattern also assumes Consider using a more robust approach. If -detect_organizations_setting() {
- SETTING_VALUE=$(kubectl get configmap flightctl-api-config -n "$flightctl_namespace" --context kind-kind -o jsonpath='{.data.config\.yaml}' 2>/dev/null | grep -A1 "organizations:" | grep "enabled:" | awk '{print $2}' | tr -d ' ')
+detect_organizations_setting() {
+ SETTING_VALUE=$(kubectl get configmap flightctl-api-config -n "$flightctl_namespace" --context kind-kind -o jsonpath='{.data.config\.yaml}' 2>/dev/null | grep -oP 'organizations:\s+enabled:\s+\K(true|false)' | head -n1)
if [ -n "$SETTING_VALUE" ]; then
if [ "$SETTING_VALUE" = "true" ]; then
echo "Autodetected: Organizations enabled ✅" >&2
else
echo "Autodetected: Organizations disabled ❌" >&2
fi
echo "$SETTING_VALUE"
else
echo "Autodetected: Organizations disabled ❌ (no setting found in ConfigMap)" >&2
echo "false"
fi
return 0
}Alternatively, use
|
||
|
|
||
|
|
||
| # Check that the Backend is running in a kind cluster and we can access it | ||
| validate_prerequisites | ||
|
|
||
| # Get the external IP address | ||
| EXTERNAL_IP=$(get_external_ip) | ||
|
|
||
|
|
@@ -21,42 +78,48 @@ fi | |
|
|
||
| echo "Using external IP: $EXTERNAL_IP" >&2 | ||
|
|
||
| # Read configuration flags from environment variables (with defaults) | ||
| ENABLE_CLI_ARTIFACTS=${ENABLE_CLI_ARTIFACTS:-false} | ||
| ENABLE_ALERTMANAGER=${ENABLE_ALERTMANAGER:-false} | ||
| ENABLE_ORGANIZATIONS=${ENABLE_ORGANIZATIONS:-false} | ||
|
|
||
| # Set core environment variables for kind development | ||
| export FLIGHTCTL_SERVER_INSECURE_SKIP_VERIFY='true' | ||
| export FLIGHTCTL_SERVER="https://$EXTERNAL_IP:3443" | ||
|
|
||
| # CLI Artifacts - conditionally set or unset | ||
| # Organizations - get setting from kind cluster, unless it has been configured already | ||
| if [ -z "$ENABLE_ORGANIZATIONS" ]; then | ||
| ENABLE_ORGANIZATIONS=$(detect_organizations_setting) | ||
| fi | ||
| export ENABLE_ORGANIZATIONS | ||
| if [ "$ENABLE_ORGANIZATIONS" = "true" ]; then | ||
| export ORGANIZATIONS_ENABLED="true" | ||
| else | ||
| export ORGANIZATIONS_ENABLED="false" | ||
| fi | ||
|
|
||
| # CLI artifacts - get setting from kind cluster, unless it has been configured already | ||
| if [ -z "$ENABLE_CLI_ARTIFACTS" ]; then | ||
| ENABLE_CLI_ARTIFACTS=$(detect_service_setting "CLI artifacts" "flightctl-cli-artifacts") | ||
| fi | ||
| export ENABLE_CLI_ARTIFACTS | ||
| if [ "$ENABLE_CLI_ARTIFACTS" = "true" ]; then | ||
| export FLIGHTCTL_CLI_ARTIFACTS_SERVER="http://$EXTERNAL_IP:8090" | ||
| else | ||
| unset FLIGHTCTL_CLI_ARTIFACTS_SERVER | ||
| fi | ||
|
|
||
| # AlertManager - conditionally set or unset | ||
| # AlertManager - get setting from kind cluster, unless it has been configured already | ||
| if [ -z "$ENABLE_ALERTMANAGER" ]; then | ||
| ENABLE_ALERTMANAGER=$(detect_service_setting "AlertManager" "flightctl-alertmanager-proxy") | ||
| fi | ||
| export ENABLE_ALERTMANAGER | ||
| if [ "$ENABLE_ALERTMANAGER" = "true" ]; then | ||
| export FLIGHTCTL_ALERTMANAGER_PROXY="https://$EXTERNAL_IP:8443" | ||
| else | ||
| unset FLIGHTCTL_ALERTMANAGER_PROXY | ||
| fi | ||
|
|
||
| # Organizations - conditionally set or unset | ||
| if [ "$ENABLE_ORGANIZATIONS" = "true" ]; then | ||
| export ORGANIZATIONS_ENABLED="true" | ||
| else | ||
| export ORGANIZATIONS_ENABLED="false" | ||
| fi | ||
|
|
||
| echo "Environment variables set:" >&2 | ||
| echo "" | ||
| echo "🌐 Environment variables set:" >&2 | ||
| echo " FLIGHTCTL_SERVER_INSECURE_SKIP_VERIFY=$FLIGHTCTL_SERVER_INSECURE_SKIP_VERIFY" >&2 | ||
| echo " FLIGHTCTL_SERVER=$FLIGHTCTL_SERVER" >&2 | ||
| echo " FLIGHTCTL_CLI_ARTIFACTS_SERVER=${FLIGHTCTL_CLI_ARTIFACTS_SERVER:-'(disabled)'}" >&2 | ||
| echo " FLIGHTCTL_ALERTMANAGER_PROXY=${FLIGHTCTL_ALERTMANAGER_PROXY:-'(disabled)'}" >&2 | ||
| echo " ORGANIZATIONS_ENABLED=$ORGANIZATIONS_ENABLED" >&2 | ||
| echo >&2 | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Well-structured and comprehensive variable documentation.
The tables clearly document all configuration options with descriptions, defaults, and acceptable values. Variable naming is consistent and conventions are followed throughout.
Verify that all documented variables are actually supported and autodetected by the
apps/standalone/scripts/setup_env.shscript, and that all environment variables used in that script are documented here.🏁 Script executed:
Length of output: 742
🏁 Script executed:
Length of output: 2360
🏁 Script executed:
Length of output: 4501
Missing documentation for exported variable and scope mismatch between setup script and configuration documentation.
The verification revealed critical discrepancies:
Undocumented variable: The setup script exports
ORGANIZATIONS_ENABLED(line exporting it based onENABLE_ORGANIZATIONS), but this variable is not documented in CONFIGURATION.md. Add it to the Feature toggles table.Incomplete coverage: Nine documented variables are not set by
setup_env.sh:BASE_UI_URL,INTERNAL_AUTH_URL,AUTH_INSECURE_SKIP_VERIFY,AUTH_CLIENT_ID,TLS_CERT,TLS_KEY,API_PORT,K8S_RBAC_NS,IS_OCP_PLUGIN,IS_RHEM. Either these require separate configuration outside this script, or the CONFIGURATION.md scope needs clarification (e.g., add a note explaining which variables are auto-detected vs. manually configured).🤖 Prompt for AI Agents