|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2025 The Kubernetes Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | + |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +REPO_ROOT=$(git rev-parse --show-toplevel) |
| 21 | +cd "${REPO_ROOT}/" |
| 22 | + |
| 23 | +# Enable feature flag for APIServer Nodes support |
| 24 | +export KOPS_FEATURE_FLAGS=+APIServerNodes |
| 25 | + |
| 26 | +# Override some settings |
| 27 | +CLUSTER_NAME="splitkcp.k8s.local" |
| 28 | + |
| 29 | +CLOUD_PROVIDER=gce |
| 30 | +ZONES="us-west1-a,us-west1-b,us-west1-c" # Currently the zone name gets encoded in the machinedeployment name (maybe we can use labels instead?) |
| 31 | + |
| 32 | +OVERRIDES="${OVERRIDES-} --node-count=2" # We need at least 2 nodes for CoreDNS to validate |
| 33 | +OVERRIDES="${OVERRIDES} --control-plane-count=3" # We need at least 3 control plane nodes to ensure etcd comes up as raft |
| 34 | +OVERRIDES="${OVERRIDES} --api-server-count=1" # We need at least 1 api-server node to split the control plane |
| 35 | +OVERRIDES="${OVERRIDES} --networking=kubenet" # |
| 36 | +OVERRIDES="${OVERRIDES} --node-size=e2-standard-2" # |
| 37 | +OVERRIDES="${OVERRIDES} --api-server-size=e2-standard-2" # |
| 38 | +OVERRIDES="${OVERRIDES} --control-plane-size=e2-standard-4" # |
| 39 | +OVERRIDES="${OVERRIDES} --gce-service-account=default" # Use default service account because boskos permissions are limited |
| 40 | + |
| 41 | +# Create kOps cluster |
| 42 | +source "${REPO_ROOT}/tests/e2e/scenarios/lib/common.sh" |
| 43 | + |
| 44 | +kops-acquire-latest |
| 45 | + |
| 46 | +kops-up |
| 47 | + |
| 48 | +# Export KUBECONFIG; otherwise the precedence for controllers is wrong (?) |
| 49 | +KUBECONFIG=$(mktemp -t kops.XXXXXXXXX) |
| 50 | +export KUBECONFIG |
| 51 | +"${KOPS}" export kubecfg --name "${CLUSTER_NAME}" --admin --kubeconfig "${KUBECONFIG}" |
| 52 | + |
| 53 | + |
| 54 | +# Install kOps CRDs (Cluster & InstanceGroup) |
| 55 | +# Ideally we would install these as part of kops-up, but while we're developing CAPI support it's easier to do it here |
| 56 | +kubectl apply --server-side -k "${REPO_ROOT}/k8s" |
| 57 | +#kubectl apply --server-side -k "${REPO_ROOT}/clusterapi/config" |
| 58 | + |
| 59 | +# Install extra RBAC for kops-controller CAPI support |
| 60 | +kubectl apply --server-side -f "${REPO_ROOT}/clusterapi/examples/kopscontroller.yaml" |
| 61 | + |
| 62 | +# Bounce kops-controller in case it went into backoff before the CRDs were installed |
| 63 | +kubectl delete pod -n kube-system -l k8s-app=kops-controller |
| 64 | + |
| 65 | +# Install cert-manager |
| 66 | +kubectl apply --server-side -f https://github.com/cert-manager/cert-manager/releases/download/v1.18.2/cert-manager.yaml |
| 67 | + |
| 68 | +kubectl wait --for=condition=Available --timeout=5m -n cert-manager deployment/cert-manager |
| 69 | +kubectl wait --for=condition=Available --timeout=5m -n cert-manager deployment/cert-manager-cainjector |
| 70 | +kubectl wait --for=condition=Available --timeout=5m -n cert-manager deployment/cert-manager-webhook |
| 71 | + |
| 72 | +# Install cluster-api core and cluster-api-provider-gcp |
| 73 | +kubectl apply --server-side -k "${REPO_ROOT}/clusterapi/manifests/cluster-api" |
| 74 | +kubectl wait --for=condition=Available --timeout=5m -n capi-system deployment/capi-controller-manager |
| 75 | + |
| 76 | +kubectl apply --server-side -k "${REPO_ROOT}/clusterapi/manifests/cluster-api-provider-gcp" |
| 77 | +kubectl wait --for=condition=Available --timeout=5m -n capg-system deployment/capg-controller-manager |
| 78 | + |
| 79 | + |
| 80 | +# Install extra RBAC for capi-manager loopback connection to cluster (used to check node health etc) |
| 81 | +kubectl apply --server-side -f "${REPO_ROOT}/clusterapi/examples/capi-loopback.yaml" |
| 82 | + |
| 83 | +# Debug: log kops-controller |
| 84 | +kubectl logs -n kube-system -l k8s-app=kops-controller --follow & |
| 85 | + |
| 86 | +# Print the nodes, machines and gcpmachines |
| 87 | +kubectl get nodes -owide |
| 88 | +kubectl get machine -A -owide |
| 89 | +kubectl get gcpmachine -A -owide |
| 90 | + |
| 91 | +# Print the nodes, machines and gcpmachines again |
| 92 | +kubectl get nodes -owide |
| 93 | +kubectl get machine -A -owide |
| 94 | +kubectl get gcpmachine -A -owide |
| 95 | + |
| 96 | +# CAPI currently creates some firewall rules that otherwise are not cleaned up, and block kops cluster cleanup |
| 97 | +function cleanup_capi_leaks() { |
| 98 | + gcloud compute firewall-rules delete allow-clusterapi-k8s-local-cluster --quiet || true |
| 99 | + gcloud compute firewall-rules delete allow-clusterapi-k8s-local-healthchecks --quiet || true |
| 100 | + |
| 101 | + #gcloud compute networks subnets delete us-east4-clusterapi-k8s-local --region us-east4 --quiet |
| 102 | + #gcloud compute networks delete clusterapi-k8s-local --quiet |
| 103 | +} |
| 104 | +cleanup_capi_leaks |
0 commit comments