Skip to content

Commit fc5e26c

Browse files
committed
Allow build and deploy of operator from main Makefile
deploy_from_helm.sh is refactored to reuse as much as possible and avoid divergence. a new makefile target is added for deploy-from-operator.
1 parent 1e8690d commit fc5e26c

File tree

9 files changed

+378
-90
lines changed

9 files changed

+378
-90
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
8383
$(GOLANGCI_LINT) run --fix
8484

8585
##@ Build
86+
.PHONY: build-operator
87+
build-operator:
88+
make -C deploy/operator build build-installer
8689

8790
.PHONY: build
8891
build: manifests generate fmt vet ## Build manager binary.
@@ -152,6 +155,9 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
152155
deploy: docker-build cluster grpcurl
153156
./hack/deploy_with_helm.sh
154157

158+
deploy-with-operator: docker-build cluster grpcurl
159+
./hack/deploy_with_operator.sh
160+
155161
.PHONY: deploy-exporters
156162
deploy-exporters:
157163
./hack/demoenv/prepare_exporters.sh

deploy/operator/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
2929
#
3030
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
3131
# jumpstarter.dev/jumpstarter-operator-bundle:$VERSION and jumpstarter.dev/jumpstarter-operator-catalog:$VERSION.
32-
IMAGE_TAG_BASE ?= jumpstarter.dev/jumpstarter-operator
32+
IMAGE_TAG_BASE ?= quay.io/jumpstarter-dev/jumpstarter-operator
3333

3434
# BUNDLE_IMG defines the image:tag used for the bundle.
3535
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
resources:
22
- manager.yaml
3+
apiVersion: kustomize.config.k8s.io/v1beta1
4+
kind: Kustomization
5+
images:
6+
- name: controller
7+
newName: controller
8+
newTag: latest

deploy/operator/config/manager/manager.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec:
6363
args:
6464
- --leader-elect
6565
- --health-probe-bind-address=:8081
66-
image: controller:latest
66+
image: quay.io/jumpstarter-dev/jumpstarter-operator:latest
6767
name: manager
6868
ports: []
6969
securityContext:

hack/deploy_vars

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
# Common deployment variables for Jumpstarter hack scripts
3+
# This file should be sourced after utils
4+
5+
# Calculate external IP and networking configuration
6+
IP=$(get_external_ip)
7+
BASEDOMAIN="jumpstarter.${IP}.nip.io"
8+
9+
# Determine networking mode and endpoints based on INGRESS_ENABLED
10+
if [ "${INGRESS_ENABLED}" == "true" ]; then
11+
NETWORKING_MODE="ingress"
12+
GRPC_ENDPOINT="grpc.${BASEDOMAIN}:5080"
13+
GRPC_ROUTER_ENDPOINT="router.${BASEDOMAIN}:5080"
14+
else
15+
NETWORKING_MODE="nodeport"
16+
GRPC_ENDPOINT="grpc.${BASEDOMAIN}:8082"
17+
GRPC_ROUTER_ENDPOINT="router.${BASEDOMAIN}:8083"
18+
fi
19+
20+
# Extract image repository and tag from IMG variable
21+
IMAGE_REPO=$(echo "${IMG}" | cut -d: -f1)
22+
IMAGE_TAG=$(echo "${IMG}" | cut -d: -f2)
23+
24+
# Export all variables for use in scripts
25+
export IP
26+
export BASEDOMAIN
27+
export NETWORKING_MODE
28+
export GRPC_ENDPOINT
29+
export GRPC_ROUTER_ENDPOINT
30+
export IMAGE_REPO
31+
export IMAGE_TAG
32+

hack/deploy_with_helm.sh

Lines changed: 18 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,86 +2,37 @@
22
set -eo pipefail
33
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
44

5-
KIND=${KIND:-bin/kind}
6-
GRPCURL=${GRPCURL:-bin/grpcurl}
7-
IMG=${IMG:-quay.io/jumpstarter-dev/jumpstarter-controller:latest}
8-
INGRESS_ENABLED=${INGRESS_ENABLED:-false}
5+
# Source common utilities
6+
source "${SCRIPT_DIR}/utils"
97

10-
GREEN='\033[0;32m'
11-
NC='\033[0m' # No Color
8+
# Source common deployment variables
9+
source "${SCRIPT_DIR}/deploy_vars"
1210

1311
METHOD=install
14-
IP=$("${SCRIPT_DIR}"/get_ext_ip.sh)
15-
1612

1713
kubectl config use-context kind-jumpstarter
1814

19-
HELM_SETS=""
15+
# Install nginx ingress if in ingress mode
2016
if [ "${INGRESS_ENABLED}" == "true" ]; then
21-
echo -e "${GREEN}Deploying nginx ingress in kind ...${NC}"
22-
23-
lsmod | grep ip_tables || \
24-
(echo "ip_tables module not loaded needed by nginx ingress, please run 'sudo modprobe ip_tables'" && exit 1)
25-
26-
# before our helm installs, we make sure that kind has an ingress installed
27-
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
28-
29-
echo -e "${GREEN}Waiting for nginx to be ready ...${NC}"
30-
31-
while ! kubectl get pods --namespace ingress-nginx --selector=app.kubernetes.io/component=controller > /dev/null; do
32-
sleep 1
33-
done
34-
35-
kubectl wait --namespace ingress-nginx \
36-
--for=condition=ready pod \
37-
--selector=app.kubernetes.io/component=controller \
38-
--timeout=90s
39-
40-
HELM_SETS="${HELM_SETS} --set jumpstarter-controller.grpc.ingress.enabled=true"
41-
BASEDOMAIN="jumpstarter.${IP}.nip.io"
42-
GRPC_ENDPOINT="grpc.${BASEDOMAIN}:5080"
43-
GRPC_ROUTER_ENDPOINT="router.${BASEDOMAIN}:5080"
17+
install_nginx_ingress
4418
else
4519
echo -e "${GREEN}Deploying with nodeport ...${NC}"
46-
HELM_SETS="${HELM_SETS} --set jumpstarter-controller.grpc.nodeport.enabled=true"
47-
BASEDOMAIN="jumpstarter.${IP}.nip.io"
48-
GRPC_ENDPOINT="grpc.${BASEDOMAIN}:8082"
49-
GRPC_ROUTER_ENDPOINT="router.${BASEDOMAIN}:8083"
5020
fi
5121

22+
# Build Helm sets based on configuration
23+
HELM_SETS=""
5224
HELM_SETS="${HELM_SETS} --set global.baseDomain=${BASEDOMAIN}"
5325
HELM_SETS="${HELM_SETS} --set jumpstarter-controller.grpc.endpoint=${GRPC_ENDPOINT}"
5426
HELM_SETS="${HELM_SETS} --set jumpstarter-controller.grpc.routerEndpoint=${GRPC_ROUTER_ENDPOINT}"
55-
56-
57-
IMAGE_REPO=$(echo ${IMG} | cut -d: -f1)
58-
IMAGE_TAG=$(echo ${IMG} | cut -d: -f2)
5927
HELM_SETS="${HELM_SETS} --set jumpstarter-controller.image=${IMAGE_REPO}"
6028
HELM_SETS="${HELM_SETS} --set jumpstarter-controller.tag=${IMAGE_TAG}"
6129

62-
# Function to save images to kind, with workaround for github CI and other environment issues
63-
# In github CI, kind gets confused and tries to pull the image from docker instead
64-
# of podman, so if regular docker-image fails we need to:
65-
# * save it to OCI image format
66-
# * then load it into kind
67-
kind_load_image() {
68-
local image=$1
69-
70-
# First, try to load the image directly
71-
if ${KIND} load docker-image "${image}" --name jumpstarter; then
72-
echo "Image ${image} loaded successfully."
73-
return
74-
fi
75-
76-
# Save to tar file
77-
podman save "${image}" | ${KIND} load image-archive /dev/stdin --name jumpstarter
78-
if [ $? -eq 0 ]; then
79-
echo "Image loaded successfully."
80-
else
81-
echo "Error loading image ${image}."
82-
exit 1
83-
fi
84-
}
30+
# Enable appropriate networking mode
31+
if [ "${NETWORKING_MODE}" == "ingress" ]; then
32+
HELM_SETS="${HELM_SETS} --set jumpstarter-controller.grpc.ingress.enabled=true"
33+
else
34+
HELM_SETS="${HELM_SETS} --set jumpstarter-controller.grpc.nodeport.enabled=true"
35+
fi
8536

8637
echo -e "${GREEN}Loading the ${IMG} in kind ...${NC}"
8738
# load the docker image into the kind cluster
@@ -105,21 +56,8 @@ helm ${METHOD} --namespace jumpstarter-lab \
10556

10657
kubectl config set-context --current --namespace=jumpstarter-lab
10758

108-
echo -e "${GREEN}Waiting for grpc endpoints to be ready:${NC}"
109-
for ep in ${GRPC_ENDPOINT} ${GRPC_ROUTER_ENDPOINT}; do
110-
RETRIES=60
111-
echo -e "${GREEN} * Checking ${ep} ... ${NC}"
112-
while ! ${GRPCURL} -insecure ${ep} list; do
113-
sleep 2
114-
RETRIES=$((RETRIES-1))
115-
if [ ${RETRIES} -eq 0 ]; then
116-
echo -e "${GREEN} * ${ep} not ready after 120s, exiting ... ${NC}"
117-
exit 1
118-
fi
119-
done
120-
done
121-
59+
# Check gRPC endpoints are ready
60+
check_grpc_endpoints
12261

123-
echo -e "${GREEN}Jumpstarter controller deployed successfully!${NC}"
124-
echo -e " gRPC endpoint: ${GRPC_ENDPOINT}"
125-
echo -e " gRPC router endpoint: ${GRPC_ROUTER_ENDPOINT}"
62+
# Print success banner
63+
print_deployment_success "Helm"

hack/deploy_with_operator.sh

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/usr/bin/env bash
2+
set -eo pipefail
3+
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
4+
5+
# Source common utilities
6+
source "${SCRIPT_DIR}/utils"
7+
8+
# Source common deployment variables
9+
source "${SCRIPT_DIR}/deploy_vars"
10+
11+
kubectl config use-context kind-jumpstarter
12+
13+
# Install nginx ingress if in ingress mode
14+
if [ "${INGRESS_ENABLED}" == "true" ]; then
15+
install_nginx_ingress
16+
else
17+
echo -e "${GREEN}Deploying with nodeport ...${NC}"
18+
fi
19+
20+
echo -e "${GREEN}Loading the ${IMG} in kind ...${NC}"
21+
# load the docker image into the kind cluster
22+
kind_load_image "${IMG}"
23+
24+
# Deploy the operator
25+
echo -e "${GREEN}Deploying Jumpstarter operator ...${NC}"
26+
kubectl apply -f deploy/operator/dist/install.yaml
27+
28+
# Wait for operator to be ready
29+
echo -e "${GREEN}Waiting for operator to be ready ...${NC}"
30+
kubectl wait --namespace jumpstarter-operator-system \
31+
--for=condition=available deployment/jumpstarter-operator-controller-manager \
32+
--timeout=120s
33+
34+
# Create namespace for Jumpstarter deployment
35+
echo -e "${GREEN}Creating jumpstarter-lab namespace ...${NC}"
36+
kubectl create namespace jumpstarter-lab --dry-run=client -o yaml | kubectl apply -f -
37+
38+
# Generate Jumpstarter CR based on networking mode
39+
echo -e "${GREEN}Creating Jumpstarter custom resource ...${NC}"
40+
41+
# Generate endpoint configuration based on networking mode
42+
if [ "${NETWORKING_MODE}" == "ingress" ]; then
43+
CONTROLLER_ENDPOINT_CONFIG=$(cat <<-END
44+
- hostname: grpc.${BASEDOMAIN}
45+
ingress:
46+
enabled: true
47+
class: ""
48+
END
49+
)
50+
ROUTER_ENDPOINT_CONFIG=$(cat <<-END
51+
- hostname: router.${BASEDOMAIN}
52+
ingress:
53+
enabled: true
54+
class: ""
55+
END
56+
)
57+
else
58+
CONTROLLER_ENDPOINT_CONFIG=$(cat <<-END
59+
- hostname: grpc.${BASEDOMAIN}
60+
nodeport:
61+
enabled: true
62+
port: 8082
63+
END
64+
)
65+
ROUTER_ENDPOINT_CONFIG=$(cat <<-END
66+
- hostname: router.${BASEDOMAIN}
67+
nodeport:
68+
enabled: true
69+
port: 8083
70+
END
71+
)
72+
fi
73+
74+
# Apply the Jumpstarter CR with the appropriate endpoint configuration
75+
cat <<EOF | kubectl apply -f -
76+
apiVersion: operator.jumpstarter.dev/v1alpha1
77+
kind: Jumpstarter
78+
metadata:
79+
name: jumpstarter
80+
namespace: jumpstarter-lab
81+
spec:
82+
baseDomain: ${BASEDOMAIN}
83+
useCertManager: false
84+
controller:
85+
image: ${IMAGE_REPO}
86+
imagePullPolicy: IfNotPresent
87+
replicas: 2
88+
resources:
89+
requests:
90+
cpu: 100m
91+
memory: 100Mi
92+
exporterOptions:
93+
offlineTimeout: 180s
94+
grpc:
95+
keepalive:
96+
minTime: 3s
97+
permitWithoutStream: true
98+
endpoints:
99+
${CONTROLLER_ENDPOINT_CONFIG}
100+
authentication:
101+
internal:
102+
prefix: "internal:"
103+
enabled: true
104+
routers:
105+
image: ${IMAGE_REPO}
106+
imagePullPolicy: IfNotPresent
107+
replicas: 3
108+
resources:
109+
requests:
110+
cpu: 100m
111+
memory: 100Mi
112+
topologySpreadConstraints:
113+
- topologyKey: "kubernetes.io/hostname"
114+
whenUnsatisfiable: ScheduleAnyway
115+
maxSkew: 1
116+
- topologyKey: "kubernetes.io/zone"
117+
whenUnsatisfiable: ScheduleAnyway
118+
maxSkew: 1
119+
grpc:
120+
keepalive:
121+
minTime: 3s
122+
permitWithoutStream: true
123+
endpoints:
124+
${ROUTER_ENDPOINT_CONFIG}
125+
EOF
126+
127+
# Set context to jumpstarter-lab namespace
128+
kubectl config set-context --current --namespace=jumpstarter-lab
129+
130+
# Wait for Jumpstarter resources to be ready
131+
wait_for_jumpstarter_resources
132+
133+
# Check gRPC endpoints are ready
134+
check_grpc_endpoints
135+
136+
# Print success banner
137+
print_deployment_success "operator"
138+

hack/get_ext_ip.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)