Skip to content

Commit 39b394f

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 272e76e commit 39b394f

File tree

9 files changed

+394
-91
lines changed

9 files changed

+394
-91
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-installer docker-build
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: build-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: 2 additions & 2 deletions
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>)
@@ -50,7 +50,7 @@ endif
5050
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
5151
OPERATOR_SDK_VERSION ?= v1.41.1
5252
# Image URL to use all building/pushing image targets
53-
IMG ?= controller:latest
53+
IMG ?= quay.io/jumpstarter-dev/jumpstarter-operator:latest
5454

5555
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
5656
ifeq (,$(shell go env GOBIN))
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: quay.io/jumpstarter-dev/jumpstarter-operator
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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
IMG=${IMG:-quay.io/jumpstarter-dev/jumpstarter-controller:latest}
9+
OPERATOR_IMG=${OPERATOR_IMG:-quay.io/jumpstarter-dev/jumpstarter-operator:latest}
10+
11+
# Determine networking mode and endpoints based on INGRESS_ENABLED
12+
if [ "${INGRESS_ENABLED}" == "true" ]; then
13+
NETWORKING_MODE="ingress"
14+
GRPC_ENDPOINT="grpc.${BASEDOMAIN}:5080"
15+
GRPC_ROUTER_ENDPOINT="router.${BASEDOMAIN}:5080"
16+
else
17+
NETWORKING_MODE="nodeport"
18+
GRPC_ENDPOINT="grpc.${BASEDOMAIN}:8082"
19+
GRPC_ROUTER_ENDPOINT="router.${BASEDOMAIN}:8083"
20+
fi
21+
22+
# Extract image repository and tag from IMG variable
23+
IMAGE_REPO=$(echo "${IMG}" | cut -d: -f1)
24+
IMAGE_TAG=$(echo "${IMG}" | cut -d: -f2)
25+
26+
# Export all variables for use in scripts
27+
export IP
28+
export BASEDOMAIN
29+
export NETWORKING_MODE
30+
export GRPC_ENDPOINT
31+
export GRPC_ROUTER_ENDPOINT
32+
export IMAGE_REPO
33+
export IMAGE_TAG
34+
export IMG
35+
export OPERATOR_IMG
36+

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: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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+
kind_load_image "${OPERATOR_IMG}"
24+
25+
# Deploy the operator
26+
echo -e "${GREEN}Deploying Jumpstarter operator ...${NC}"
27+
kubectl apply -f deploy/operator/dist/install.yaml
28+
29+
# If operator deployment already exists, restart it to pick up the new image
30+
if kubectl get deployment jumpstarter-operator-controller-manager -n jumpstarter-operator-system > /dev/null 2>&1; then
31+
echo -e "${GREEN}Restarting operator deployment to pick up new image ...${NC}"
32+
kubectl scale deployment jumpstarter-operator-controller-manager -n jumpstarter-operator-system --replicas=0
33+
kubectl wait --namespace jumpstarter-operator-system \
34+
--for=delete pod \
35+
--selector=control-plane=controller-manager \
36+
--timeout=60s 2>/dev/null || true
37+
kubectl scale deployment jumpstarter-operator-controller-manager -n jumpstarter-operator-system --replicas=1
38+
fi
39+
40+
# Wait for operator to be ready
41+
echo -e "${GREEN}Waiting for operator to be ready ...${NC}"
42+
kubectl wait --namespace jumpstarter-operator-system \
43+
--for=condition=available deployment/jumpstarter-operator-controller-manager \
44+
--timeout=120s
45+
46+
# Create namespace for Jumpstarter deployment
47+
echo -e "${GREEN}Creating jumpstarter-lab namespace ...${NC}"
48+
kubectl create namespace jumpstarter-lab --dry-run=client -o yaml | kubectl apply -f -
49+
50+
# Generate Jumpstarter CR based on networking mode
51+
echo -e "${GREEN}Creating Jumpstarter custom resource ...${NC}"
52+
53+
# Generate endpoint configuration based on networking mode
54+
if [ "${NETWORKING_MODE}" == "ingress" ]; then
55+
CONTROLLER_ENDPOINT_CONFIG=$(cat <<-END
56+
- hostname: grpc.${BASEDOMAIN}
57+
ingress:
58+
enabled: true
59+
class: ""
60+
END
61+
)
62+
ROUTER_ENDPOINT_CONFIG=$(cat <<-END
63+
- hostname: router.${BASEDOMAIN}
64+
ingress:
65+
enabled: true
66+
class: ""
67+
END
68+
)
69+
else
70+
CONTROLLER_ENDPOINT_CONFIG=$(cat <<-END
71+
- hostname: grpc.${BASEDOMAIN}
72+
nodeport:
73+
enabled: true
74+
port: 8082
75+
END
76+
)
77+
ROUTER_ENDPOINT_CONFIG=$(cat <<-END
78+
- hostname: router.${BASEDOMAIN}
79+
nodeport:
80+
enabled: true
81+
port: 8083
82+
END
83+
)
84+
fi
85+
86+
# Apply the Jumpstarter CR with the appropriate endpoint configuration
87+
cat <<EOF | kubectl apply -f -
88+
apiVersion: operator.jumpstarter.dev/v1alpha1
89+
kind: Jumpstarter
90+
metadata:
91+
name: jumpstarter
92+
namespace: jumpstarter-lab
93+
spec:
94+
baseDomain: ${BASEDOMAIN}
95+
useCertManager: false
96+
controller:
97+
image: ${IMAGE_REPO}
98+
imagePullPolicy: IfNotPresent
99+
replicas: 2
100+
resources:
101+
requests:
102+
cpu: 100m
103+
memory: 100Mi
104+
exporterOptions:
105+
offlineTimeout: 180s
106+
grpc:
107+
keepalive:
108+
minTime: 3s
109+
permitWithoutStream: true
110+
endpoints:
111+
${CONTROLLER_ENDPOINT_CONFIG}
112+
authentication:
113+
internal:
114+
prefix: "internal:"
115+
enabled: true
116+
routers:
117+
image: ${IMAGE_REPO}
118+
imagePullPolicy: IfNotPresent
119+
replicas: 3
120+
resources:
121+
requests:
122+
cpu: 100m
123+
memory: 100Mi
124+
topologySpreadConstraints:
125+
- topologyKey: "kubernetes.io/hostname"
126+
whenUnsatisfiable: ScheduleAnyway
127+
maxSkew: 1
128+
- topologyKey: "kubernetes.io/zone"
129+
whenUnsatisfiable: ScheduleAnyway
130+
maxSkew: 1
131+
grpc:
132+
keepalive:
133+
minTime: 3s
134+
permitWithoutStream: true
135+
endpoints:
136+
${ROUTER_ENDPOINT_CONFIG}
137+
EOF
138+
139+
# Set context to jumpstarter-lab namespace
140+
kubectl config set-context --current --namespace=jumpstarter-lab
141+
142+
# Wait for Jumpstarter resources to be ready
143+
wait_for_jumpstarter_resources
144+
145+
# Check gRPC endpoints are ready
146+
check_grpc_endpoints
147+
148+
# Print success banner
149+
print_deployment_success "operator"
150+

hack/get_ext_ip.sh

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

0 commit comments

Comments
 (0)