diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 449d295..6358d4a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -34,3 +34,12 @@ jobs: - uses: actions/checkout@v4 - name: Test run: just test-cluster-class-import + - name: Collect artifacts + if: always() + run: just collect-test-cluster-class-import + - name: Store run artifacts + uses: actions/upload-artifact@v4 + if: always() + with: + name: artifacts + path: _out/gather diff --git a/justfile b/justfile index d558661..24f46de 100644 --- a/justfile +++ b/justfile @@ -5,15 +5,13 @@ TAG := "dev" HOME_DIR := env_var('HOME') YQ_VERSION := "v4.43.1" CLUSTERCTL_VERSION := "v1.7.1" -YQ_BIN := "_out/yq" OUT_DIR := "_out" -KOPIUM_BIN := "_out/bin/kopium" KUSTOMIZE_VERSION := "v5.4.1" -KUSTOMIZE_BIN := "_out/kustomize" -CLUSTERCTL_BIN := "_out/clusterctl" ARCH := if arch() == "aarch64" { "arm64"} else { "amd64" } DIST := os() +export PATH := "_out:_out/bin:" + env_var('PATH') + [private] default: @just --list --unsorted --color=always @@ -25,15 +23,15 @@ generate features="": # generates files for CRDS generate-crds: _create-out-dir _install-kopium _download-yq - just _generate-kopium-url {{KOPIUM_BIN}} "https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/main/config/crd/bases/cluster.x-k8s.io_clusters.yaml" "src/api/capi_cluster.rs" "" - just _generate-kopium-url {{KOPIUM_BIN}} "https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/main/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml" "src/api/capi_clusterclass.rs" "" - just _generate-kopium-url {{KOPIUM_BIN}} "https://raw.githubusercontent.com/rancher/fleet/main/charts/fleet-crd/templates/crds.yaml" "src/api/fleet_cluster.rs" "select(.spec.names.singular==\"cluster\")" "--no-condition" - just _generate-kopium-url {{KOPIUM_BIN}} "https://raw.githubusercontent.com/rancher/fleet/main/charts/fleet-crd/templates/crds.yaml" "src/api/fleet_clustergroup.rs" "select(.spec.names.singular==\"clustergroup\")" "--no-condition" - just _generate-kopium-url {{KOPIUM_BIN}} "https://raw.githubusercontent.com/rancher/fleet/main/charts/fleet-crd/templates/crds.yaml" "src/api/fleet_cluster_registration_token.rs" "select(.spec.names.singular==\"clusterregistrationtoken\")" "" + just _generate-kopium-url kopium "https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/main/config/crd/bases/cluster.x-k8s.io_clusters.yaml" "src/api/capi_cluster.rs" "" + just _generate-kopium-url kopium "https://raw.githubusercontent.com/kubernetes-sigs/cluster-api/main/config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml" "src/api/capi_clusterclass.rs" "" + just _generate-kopium-url kopium "https://raw.githubusercontent.com/rancher/fleet/main/charts/fleet-crd/templates/crds.yaml" "src/api/fleet_cluster.rs" "select(.spec.names.singular==\"cluster\")" "--no-condition" + just _generate-kopium-url kopium "https://raw.githubusercontent.com/rancher/fleet/main/charts/fleet-crd/templates/crds.yaml" "src/api/fleet_clustergroup.rs" "select(.spec.names.singular==\"clustergroup\")" "--no-condition" + just _generate-kopium-url kopium "https://raw.githubusercontent.com/rancher/fleet/main/charts/fleet-crd/templates/crds.yaml" "src/api/fleet_cluster_registration_token.rs" "select(.spec.names.singular==\"clusterregistrationtoken\")" "" [private] _generate-kopium-url kpath="" source="" dest="" yqexp="." condition="": - curl -sSL {{source}} | {{YQ_BIN}} '{{yqexp}}' | {{kpath}} -D Default {{condition}} -f - > {{dest}} + curl -sSL {{source}} | yq '{{yqexp}}' | {{kpath}} -D Default {{condition}} -f - > {{dest}} generate-addon-crds features="": cargo run --features={{features}} --bin crdgen > config/crds/fleet-addon-config.yaml @@ -63,7 +61,7 @@ compile features="": _create-out-dir -w /volume \ -t clux/muslrust:stable \ cargo build --release --features={{features}} --bin controller - cp target/x86_64-unknown-linux-musl/release/controller _out/controller + cp target/{{arch()}}-unknown-linux-musl/release/controller _out/controller [private] _build features="": @@ -91,12 +89,11 @@ load-base features="": start-dev: _cleanup-out-dir _create-out-dir just update-helm-repos kind delete cluster --name dev || true - export LOCAL_IP=$(ip -4 -j route list default | jq -r .[0].prefsrc) - envsubst < testdata/kind-config.yaml > _out/kind-config.yaml + LOCAL_IP=$(ip -4 -j route list default | jq -r .[0].prefsrc) envsubst < testdata/kind-config.yaml > _out/kind-config.yaml kind create cluster --config --image=kindest/node:v{{KUBE_VERSION}} --config _out/kind-config.yaml just install-fleet just install-capi - kubectl wait pods --for=condition=Ready --timeout=300s --all --all-namespaces + kubectl wait pods --for=condition=Ready --timeout=150s --all --all-namespaces # Stop the local dev environment stop-dev: @@ -112,6 +109,7 @@ deploy-child-cluster: # Deploy child cluster-call based cluster using docker & kubeadm deploy-child-cluster-class: + kind delete cluster --name capi-quickstart || true kubectl --context kind-dev apply -f testdata/capi-quickstart.yaml # Add and update helm repos used @@ -134,34 +132,55 @@ install-fleet: _create-out-dir # Install cluster api and any providers install-capi: _download-clusterctl - EXP_CLUSTER_RESOURCE_SET=true CLUSTER_TOPOLOGY=true {{CLUSTERCTL_BIN}} init -i docker + EXP_CLUSTER_RESOURCE_SET=true CLUSTER_TOPOLOGY=true clusterctl init -i docker # Deploy will deploy the operator deploy features="": _download-kustomize just generate {{features}} just load-base {{features}} - {{KUSTOMIZE_BIN}} build config/default | kubectl apply -f - + kustomize build config/default | kubectl apply -f - undeploy: _download-kustomize - {{KUSTOMIZE_BIN}} build config/default | kubectl delete --ignore-not-found=true -f - + kustomize build config/default | kubectl delete --ignore-not-found=true -f - release-manifests: _create-out-dir _download-kustomize - {{KUSTOMIZE_BIN}} build config/default > _out/addon-components.yaml + kustomize build config/default > _out/addon-components.yaml # Full e2e test of importing cluster in fleet -test-import: start-dev deploy deploy-child-cluster deploy-crs - kubectl wait pods --for=condition=Ready --timeout=300s --all --all-namespaces - kubectl wait clusters.fleet.cattle.io --timeout=300s --for=condition=Ready docker-demo +test-import: start-dev deploy deploy-child-cluster deploy-crs && collect-test-import + kubectl wait pods --for=condition=Ready --timeout=150s --all --all-namespaces + kubectl wait clusters.fleet.cattle.io --timeout=150s --for=condition=Ready docker-demo + +collect-test-import: + -just collect-artifacts dev + -just collect-artifacts docker-demo # Full e2e test of importing cluster in fleet -test-cluster-class-import: start-dev +test-cluster-class-import: start-dev deploy _test-import-all && collect-test-cluster-class-import + +collect-test-cluster-class-import: + -just collect-artifacts dev + -just collect-artifacts capi-quickstart + +# Test e2e with agent initiated connection procedure +test-cluster-class-import-agent-initated: start-dev && collect-test-cluster-class-import just deploy "agent-initiated" + just _test-import-all + +collect-artifacts cluster: + kind get kubeconfig --name {{cluster}} > {{OUT_DIR}}/kubeconfig + just crust-gather collect -f {{OUT_DIR}}/gather/{{cluster}} -k {{OUT_DIR}}/kubeconfig + +# Full e2e test of importing cluster and ClusterClass in fleet +[private] +_test-import-all: just deploy-child-cluster-class just deploy-crs - kubectl wait pods --for=condition=Ready --timeout=300s --all --all-namespaces - kubectl wait clustergroups.fleet.cattle.io --timeout=300s --for=jsonpath='{.status.clusterCount}=1' quick-start - kubectl wait clustergroups.fleet.cattle.io --timeout=300s --for=condition=Ready quick-start - kubectl wait clusters.fleet.cattle.io --timeout=300s --for=condition=Ready capi-quickstart + kubectl wait pods --for=condition=Ready --timeout=150s --all --all-namespaces + kubectl wait clustergroups.fleet.cattle.io --timeout=150s --for=jsonpath='{.status.clusterCount}=1' quick-start + kubectl wait clustergroups.fleet.cattle.io --timeout=150s --for=condition=Ready=true quick-start + kubectl wait clusters.fleet.cattle.io --timeout=150s --for=condition=Ready=false capi-quickstart + kubectl wait clusters.fleet.cattle.io --timeout=150s --for=condition=Ready=true capi-quickstart # Install kopium [private] @@ -173,34 +192,34 @@ _install-kopium: [linux] [macos] _download-kustomize: - curl -sSL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/{{KUSTOMIZE_VERSION}}/kustomize_{{KUSTOMIZE_VERSION}}_{{DIST}}_{{ARCH}}.tar.gz -o {{KUSTOMIZE_BIN}}.tar.gz - tar -xzf {{KUSTOMIZE_BIN}}.tar.gz -C _out - chmod +x {{KUSTOMIZE_BIN}} + curl -sSL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/{{KUSTOMIZE_VERSION}}/kustomize_{{KUSTOMIZE_VERSION}}_{{DIST}}_{{ARCH}}.tar.gz -o {{OUT_DIR}}/kustomize.tar.gz + tar -xzf {{OUT_DIR}}/kustomize.tar.gz -C _out + chmod +x {{OUT_DIR}}/kustomize [private] [linux] _download-clusterctl: - curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/{{CLUSTERCTL_VERSION}}/clusterctl-linux-amd64 -o {{CLUSTERCTL_BIN}} - chmod +x {{CLUSTERCTL_BIN}} + curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/{{CLUSTERCTL_VERSION}}/clusterctl-linux-{{ARCH}} -o {{OUT_DIR}}/clusterctl + chmod +x {{OUT_DIR}}/clusterctl [private] [macos] _download-clusterctl: - curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/{{CLUSTERCTL_VERSION}}/clusterctl-darwin-amd64 -o {{CLUSTERCTL_BIN}} - chmod +x {{CLUSTERCTL_BIN}} + curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/{{CLUSTERCTL_VERSION}}/clusterctl-darwin-{{ARCH}} -o {{OUT_DIR}}/clusterctl + chmod +x {{OUT_DIR}}/clusterctl # Download yq [private] [linux] _download-yq: - curl -sSL https://github.com/mikefarah/yq/releases/download/{{YQ_VERSION}}/yq_linux_{{ARCH}} -o {{YQ_BIN}} - chmod +x {{YQ_BIN}} + curl -sSL https://github.com/mikefarah/yq/releases/download/{{YQ_VERSION}}/yq_linux_{{ARCH}} -o {{OUT_DIR}}/yq + chmod +x {{OUT_DIR}}/yq [private] [macos] _download-yq: - curl -sSL https://github.com/mikefarah/yq/releases/download/{{YQ_VERSION}}/yq_darwin_{{ARCH}} -o {{YQ_BIN}} - chmod +x {{YQ_BIN}} + curl -sSL https://github.com/mikefarah/yq/releases/download/{{YQ_VERSION}}/yq_darwin_{{ARCH}} -o {{OUT_DIR}}/yq + chmod +x {{OUT_DIR}}/yq [private] _create-out-dir: @@ -210,3 +229,10 @@ _create-out-dir: _cleanup-out-dir: rm -rf _out/ || true +crust-gather *flags: _download-crust-gather + crust-gather {{flags}} + +[private] +_download-crust-gather: _create-out-dir + [ -f {{OUT_DIR}}/crust-gather ] || curl -sSfL https://github.com/crust-gather/crust-gather/raw/main/install.sh | sh -s - -f -b {{OUT_DIR}} + diff --git a/shell.nix b/shell.nix index 6fb0856..bcf61f4 100644 --- a/shell.nix +++ b/shell.nix @@ -8,6 +8,7 @@ pkgs.mkShell { rustfmt # Formatter clippy # Linter just + fzf kind kubernetes-helm clusterctl