Skip to content

Commit 0d49b43

Browse files
committed
fixup: Avoid deploying to non-kind cluster without base accessible uri
1 parent 6fddd52 commit 0d49b43

File tree

5 files changed

+62
-8
lines changed

5 files changed

+62
-8
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ jobs:
255255
- uses: ./.github/actions/run-monitored-tmpnet-cmd
256256
with:
257257
run: ./scripts/run_task.sh test-load-kube
258+
runtime: kube
258259
artifact_prefix: load-kube
259260
prometheus_username: ${{ secrets.PROMETHEUS_ID || '' }}
260261
prometheus_password: ${{ secrets.PROMETHEUS_PASSWORD || '' }}

scripts/tests.e2e.kube.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,17 @@ else
2323
XSVM_IMAGE="${XSVM_IMAGE}" AVALANCHEGO_IMAGE="${AVALANCHEGO_IMAGE}" bash -x ./scripts/build_xsvm_image.sh
2424
fi
2525

26-
bash -x ./scripts/tests.e2e.sh --runtime=kube --kube-image="${XSVM_IMAGE}" "$@"
26+
# Determine kubeconfig context to use
27+
KUBECONFIG_CONTEXT=""
28+
29+
# Check if --kubeconfig-context is already provided in arguments
30+
if [[ "$*" =~ --kubeconfig-context ]]; then
31+
# User provided a context, use it as-is
32+
echo "Using provided kubeconfig context from arguments"
33+
else
34+
# Default to the RBAC context
35+
KUBECONFIG_CONTEXT="--kubeconfig-context=kind-kind-tmpnet"
36+
echo "Defaulting to limited-permission context 'kind-kind-tmpnet' to test RBAC Role permissions"
37+
fi
38+
39+
bash -x ./scripts/tests.e2e.sh --runtime=kube --kube-image="${XSVM_IMAGE}" "$KUBECONFIG_CONTEXT" "$@"

tests/fixture/tmpnet/flags/kube_runtime.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (v *kubeRuntimeVars) register(stringVar varFunc[string], uintVar varFunc[ui
9292
stringVar(
9393
&v.baseAccessibleURI,
9494
"kube-base-accessible-uri",
95-
"http://localhost:30791",
95+
"",
9696
kubeDocPrefix+"The base URI for constructing node URIs when running outside of the cluster hosting nodes",
9797
)
9898
}
@@ -110,7 +110,15 @@ func (v *kubeRuntimeVars) getKubeRuntimeConfig() (*tmpnet.KubeRuntimeConfig, err
110110
if v.useExclusiveScheduling && (len(v.schedulingLabelKey) == 0 || len(v.schedulingLabelValue) == 0) {
111111
return nil, errKubeSchedulingLabelRequired
112112
}
113-
if !tmpnet.IsRunningInCluster() && len(v.baseAccessibleURI) == 0 {
113+
baseAccessibleURI := v.baseAccessibleURI
114+
if strings.HasPrefix(v.config.Context, "kind-kind") && len(baseAccessibleURI) == 0 {
115+
// Use the base uri expected for the kind cluster deployed by tmpnet. Not supplying this as a default
116+
// ensures that an explicit value is required for non-kind clusters.
117+
//
118+
// TODO(marun) Log why this value is being used. This will require passing a log through the call chain.
119+
baseAccessibleURI = "http://localhost:30791"
120+
}
121+
if !tmpnet.IsRunningInCluster() && len(baseAccessibleURI) == 0 {
114122
return nil, errKubeBaseAccessibleURIRequired
115123
}
116124
return &tmpnet.KubeRuntimeConfig{

tests/fixture/tmpnet/kube_runtime.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,14 +1020,14 @@ func (p *KubeRuntime) waitForIngressReadiness(ctx context.Context, serviceName s
10201020
return err
10211021
}
10221022

1023-
// Wait for the ingress to exist and service endpoints to be available
1023+
// Wait for the ingress to exist, be processed by the controller, and service endpoints to be available
10241024
err = wait.PollUntilContextCancel(
10251025
ctx,
10261026
statusCheckInterval,
10271027
true, // immediate
10281028
func(ctx context.Context) (bool, error) {
1029-
// Check if ingress exists
1030-
_, err := clientset.NetworkingV1().Ingresses(namespace).Get(ctx, serviceName, metav1.GetOptions{})
1029+
// Check if ingress exists and is processed by the controller
1030+
ingress, err := clientset.NetworkingV1().Ingresses(namespace).Get(ctx, serviceName, metav1.GetOptions{})
10311031
if apierrors.IsNotFound(err) {
10321032
log.Verbo("waiting for Ingress to be created",
10331033
zap.String("nodeID", nodeID),
@@ -1046,6 +1046,37 @@ func (p *KubeRuntime) waitForIngressReadiness(ctx context.Context, serviceName s
10461046
return false, nil
10471047
}
10481048

1049+
// Check if ingress controller has processed the ingress
1050+
// The ingress controller should populate the Status.LoadBalancer.Ingress field
1051+
// when it has successfully processed and exposed the ingress
1052+
hasIngressIP := len(ingress.Status.LoadBalancer.Ingress) > 0
1053+
if !hasIngressIP {
1054+
log.Verbo("waiting for Ingress controller to process and expose the Ingress",
1055+
zap.String("nodeID", nodeID),
1056+
zap.String("namespace", namespace),
1057+
zap.String("ingress", serviceName),
1058+
)
1059+
return false, nil
1060+
}
1061+
1062+
// Validate that at least one ingress has an IP or hostname
1063+
hasValidIngress := false
1064+
for _, ing := range ingress.Status.LoadBalancer.Ingress {
1065+
if ing.IP != "" || ing.Hostname != "" {
1066+
hasValidIngress = true
1067+
break
1068+
}
1069+
}
1070+
1071+
if !hasValidIngress {
1072+
log.Verbo("waiting for Ingress controller to assign IP or hostname",
1073+
zap.String("nodeID", nodeID),
1074+
zap.String("namespace", namespace),
1075+
zap.String("ingress", serviceName),
1076+
)
1077+
return false, nil
1078+
}
1079+
10491080
// Check if service endpoints are available
10501081
endpoints, err := clientset.CoreV1().Endpoints(namespace).Get(ctx, serviceName, metav1.GetOptions{})
10511082
if apierrors.IsNotFound(err) {
@@ -1084,7 +1115,7 @@ func (p *KubeRuntime) waitForIngressReadiness(ctx context.Context, serviceName s
10841115
return false, nil
10851116
}
10861117

1087-
log.Debug("Ingress and Service endpoints are ready",
1118+
log.Debug("Ingress is exposed by controller and Service endpoints are ready",
10881119
zap.String("nodeID", nodeID),
10891120
zap.String("namespace", namespace),
10901121
zap.String("ingress", serviceName),

tests/log.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ func LoggerForFormat(prefix string, rawLogFormat string) (logging.Logger, error)
2525
if err != nil {
2626
return nil, err
2727
}
28-
return logging.NewLogger(prefix, logging.NewWrappedCore(logging.Verbo, writeCloser, logFormat.ConsoleEncoder())), nil
28+
// TODO(marun) Make the log level configurable
29+
return logging.NewLogger(prefix, logging.NewWrappedCore(logging.Debug, writeCloser, logFormat.ConsoleEncoder())), nil
2930
}

0 commit comments

Comments
 (0)