diff --git a/.gitignore b/.gitignore index 3b735ec..ad148f2 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ # Go workspace file go.work + +bin/ diff --git a/scripts/fleet-up.sh b/scripts/fleet-up.sh new file mode 100755 index 0000000..4c4fc87 --- /dev/null +++ b/scripts/fleet-up.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +# This script creates a fleet of Kubernetes clusters using kind. + +# Copyright 2024 The Flux authors. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +# Prerequisites +# - docker v25.0 +# - kind v0.22 +# - kubectl v1.29 + +set -o errexit +set -o pipefail + +repo_root=$(git rev-parse --show-toplevel) +mkdir -p "${repo_root}/bin" + +CLUSTER_VERSION="${CLUSTER_VERSION:=v1.29.2}" + +CLUSTER_HUB="flux-hub" +echo "INFO - Creating cluster ${CLUSTER_HUB}" + +kind create cluster --name "${CLUSTER_HUB}" \ +--image "kindest/node:${CLUSTER_VERSION}" \ +--wait 5m + +CLUSTER_STAGING="flux-staging" +echo "INFO - Creating cluster ${CLUSTER_STAGING}" + +kind create cluster --name "${CLUSTER_STAGING}" \ +--image "kindest/node:${CLUSTER_VERSION}" \ +--wait 5m + +CLUSTER_PRODUCTION="flux-production" +echo "INFO - Creating cluster ${CLUSTER_PRODUCTION}" + +kind create cluster --name "${CLUSTER_PRODUCTION}" \ +--image "kindest/node:${CLUSTER_VERSION}" \ +--wait 5m + +echo "INFO - Creating kubeconfig secrets in the hub cluster" + +kubectl config use-context "kind-${CLUSTER_HUB}" + +kind get kubeconfig --internal --name ${CLUSTER_STAGING} > "${repo_root}/bin/staging.kubeconfig" +kubectl --context "kind-${CLUSTER_HUB}" create ns staging +kubectl --context "kind-${CLUSTER_HUB}" create secret generic -n staging cluster-kubeconfig \ +--from-file=value="${repo_root}/bin/staging.kubeconfig" + +kind get kubeconfig --internal --name ${CLUSTER_PRODUCTION} > "${repo_root}/bin/production.kubeconfig" +kubectl --context "kind-${CLUSTER_HUB}" create ns production +kubectl --context "kind-${CLUSTER_HUB}" create secret generic -n production cluster-kubeconfig \ +--from-file=value="${repo_root}/bin/production.kubeconfig" + +echo "INFO - Clusters created successfully" diff --git a/scripts/flux-up.sh b/scripts/flux-up.sh new file mode 100755 index 0000000..e3884b6 --- /dev/null +++ b/scripts/flux-up.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# This script configures Flux on the hub cluster. + +# Copyright 2024 The Flux authors. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +set -o errexit +set -o pipefail + +repo_root=$(git rev-parse --show-toplevel) +mkdir -p "${repo_root}/bin" + +CLUSTER_VERSION="${CLUSTER_VERSION:=v1.29.2}" + +CLUSTER_HUB="flux-hub" + +echo "INFO - Installing Flux in the hub cluster" + +flux --context "kind-${CLUSTER_HUB}" install \ +--components-extra=image-reflector-controller,image-automation-controller + +flux --context "kind-${CLUSTER_HUB}" create source git flux-system \ +--url=https://github.com/fluxcd/flux2-hub-spoke-example \ +--branch=main \ +--interval=1m \ +--username=git \ +--password=${GITHUB_TOKEN} + +flux --context "kind-${CLUSTER_HUB}" create kustomization flux-system \ +--source=GitRepository/flux-system \ +--ignore-paths="hub/flux-system/" +--path="./hub" \ +--prune=true \ +--interval=10m + +echo "INFO - Flux configured successfully"