Skip to content

Commit 2e0c856

Browse files
committed
chore(KFLUXVNGD-434): Consolidate squid-exporter containerfile to squid
Update the squid-exporter Containerfile to consolidate into squid container image. Jira-Url: https://issues.redhat.com/browse/KFLUXVNGD-434 Signed-off-by: Homaja Marisetty <[email protected]> Assisted-by: Cursor
1 parent b46e762 commit 2e0c856

File tree

7 files changed

+138
-231
lines changed

7 files changed

+138
-231
lines changed

Containerfile

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM registry.access.redhat.com/ubi10/ubi-minimal@sha256:5a57b4c2509df8df587e19cc7c2d9cfa45b012139f5decd77f942daeb2334228
1+
FROM registry.access.redhat.com/ubi10/ubi-minimal@sha256:5a57b4c2509df8df587e19cc7c2d9cfa45b012139f5decd77f942daeb2334228 AS squid-base
22

33
ENV NAME="konflux-ci/squid"
44
ENV SUMMARY="The Squid proxy caching server for Konflux CI"
@@ -41,6 +41,55 @@ RUN echo "pid_filename /run/squid/squid.pid" >> /etc/squid/squid.conf && \
4141
chown -R root:root /etc/squid/squid.conf /var/log/squid /var/spool/squid /run/squid && \
4242
chmod g=u /etc/squid/squid.conf /run/squid /var/spool/squid /var/log/squid
4343

44+
# ==========================================
45+
# Stage 2: Build squid-exporter
46+
# ==========================================
47+
FROM registry.access.redhat.com/ubi10/ubi-minimal@sha256:5a57b4c2509df8df587e19cc7c2d9cfa45b012139f5decd77f942daeb2334228 AS squid-exporter-builder
48+
49+
# Install required packages for Go build
50+
RUN microdnf install -y \
51+
tar \
52+
gzip \
53+
gcc \
54+
curl \
55+
ca-certificates && \
56+
microdnf clean all
57+
58+
# Install Go (version-locked)
59+
ARG GO_VERSION=1.24.4
60+
ARG GO_SHA256=77e5da33bb72aeaef1ba4418b6fe511bc4d041873cbf82e5aa6318740df98717
61+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
62+
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" -o go.tar.gz && \
63+
echo "${GO_SHA256} go.tar.gz" | sha256sum -c - && \
64+
tar -C /usr/local -xzf go.tar.gz && \
65+
rm go.tar.gz
66+
67+
# Set Go environment
68+
ENV PATH="/usr/local/go/bin:/root/go/bin:$PATH"
69+
ENV GOPATH="/root/go"
70+
ENV GOCACHE="/tmp/go-cache"
71+
72+
# Set working directory for build
73+
WORKDIR /workspace
74+
75+
# Install squid-exporter directly from the konflux-ci fork and copy to expected location
76+
RUN CGO_ENABLED=0 GOOS=linux go install github.com/konflux-ci/squid-exporter@latest && \
77+
cp /root/go/bin/squid-exporter /workspace/squid-exporter
78+
79+
# ==========================================
80+
# Final Stage: Squid with integrated exporter
81+
# ==========================================
82+
FROM squid-base
83+
84+
# Copy squid-exporter binary from builder stage
85+
COPY --from=squid-exporter-builder /workspace/squid-exporter /usr/local/bin/squid-exporter
86+
87+
# Set permissions for squid-exporter
88+
RUN chmod +x /usr/local/bin/squid-exporter
89+
90+
# Expose squid-exporter metrics port (only in final stage where the binary exists)
91+
EXPOSE 9301
92+
4493
USER 1001
4594

4695
ENTRYPOINT ["/usr/sbin/container-entrypoint.sh"]

README.md

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mage all
7878

7979
This single command will:
8080
- Create the 'caching' kind cluster (or connect to existing)
81-
- Build the squid container image
81+
- Build the consolidated squid container image (with integrated squid-exporter)
8282
- Load the image into the cluster
8383
- Deploy the Helm chart with all dependencies
8484
- Verify the deployment status
@@ -94,11 +94,9 @@ mage kind:status # Check cluster status
9494
mage kind:down # Remove cluster
9595
mage kind:upClean # Force recreate cluster
9696
97-
# Image management
98-
mage build:squid # Build squid image
99-
mage build:squidExporter # Build squid-exporter image
100-
mage build:loadSquid # Load squid image into cluster
101-
mage build:loadSquidExporter # Load squid-exporter image into cluster
97+
# Image management
98+
mage build:squid # Build consolidated squid image (includes integrated squid-exporter)
99+
mage build:loadSquid # Load squid image into cluster
102100
103101
# Deployment management
104102
mage squidHelm:up # Deploy/upgrade helm chart
@@ -288,7 +286,7 @@ When adding new tests:
288286
5. **Update VS Code config**: Add debug configurations for new test files
289287
## Prometheus Monitoring
290288
291-
This chart includes comprehensive Prometheus monitoring capabilities through the [squid-exporter](https://github.com/konflux-ci/squid-exporter) (forked from the original boynux implementation). The monitoring system provides detailed metrics about Squid's operational status, including:
289+
This chart includes comprehensive Prometheus monitoring capabilities through the integrated [squid-exporter](https://github.com/konflux-ci/squid-exporter) (forked from the original boynux implementation). The squid-exporter is built into the main Squid container, providing a single, consolidated image. The monitoring system provides detailed metrics about Squid's operational status, including:
292290

293291
- **Liveness**: Squid service information and connection status
294292
- **Bandwidth Usage**: Client HTTP and Server HTTP traffic metrics
@@ -398,16 +396,16 @@ curl http://squid.proxy.svc.cluster.local:9301/metrics
398396

399397
#### No Metrics Appearing
400398

401-
1. **Check if the exporter is running**:
399+
1. **Check if the squid container is running**:
402400
```bash
403401
kubectl get pods -n proxy
404-
kubectl logs -n proxy deployment/squid -c squid-exporter
402+
kubectl logs -n proxy deployment/squid
405403
```
406404

407405
2. **Verify cache manager access**:
408406
```bash
409407
# Test from within the pod
410-
kubectl exec -n proxy deployment/squid -c squid-exporter -- \
408+
kubectl exec -n proxy deployment/squid -- \
411409
curl -s http://localhost:3128/squid-internal-mgr/info
412410
```
413411

@@ -700,7 +698,7 @@ kubectl wait --for=condition=Ready pod -l app.kubernetes.io/name=squid -n proxy
700698
kubectl get pods -n proxy -o wide
701699
```
702700
703-
**Expected Result**: Pod shows `2/2 Running` (squid + squid-exporter containers).
701+
**Expected Result**: Pod shows `1/1 Running` (consolidated squid container with integrated exporter).
704702
705703
##### 2.3 Verify Service Creation
706704
```bash
@@ -736,20 +734,17 @@ echo "Testing pod: $POD_NAME"
736734
kubectl get pod $POD_NAME -n proxy -o jsonpath='{.spec.containers[*].name}'
737735
```
738736
739-
**Expected Result**: Shows both `squid` and `squid-exporter` containers.
737+
**Expected Result**: Shows single `squid` container with integrated squid-exporter.
740738
741739
##### 3.2 Check Container Logs
742740
```bash
743-
# Check squid container logs
744-
kubectl logs -n proxy $POD_NAME -c squid --tail=10
745-
746-
# Check squid-exporter container logs
747-
kubectl logs -n proxy $POD_NAME -c squid-exporter --tail=10
741+
# Check consolidated squid container logs
742+
kubectl logs -n proxy $POD_NAME --tail=20
748743
```
749744
750745
**Expected Result**:
751746
- Squid logs show successful startup with no permission errors
752-
- Squid-exporter logs show successful connection to cache manager
747+
- Squid-exporter startup messages show successful connection to cache manager
753748
754749
#### 4. Metrics Endpoint Tests
755750
@@ -901,10 +896,10 @@ kill $PF_METRICS_PID 2>/dev/null || true
901896
After completing all tests, verify:
902897

903898
- [ ] **Deployment**: Chart installs successfully
904-
- [ ] **Containers**: Both squid and squid-exporter containers running
899+
- [ ] **Container**: Single consolidated squid container running with integrated exporter
905900
- [ ] **Service**: Ports 3128 and 9301 accessible
906901
- [ ] **ServiceMonitor**: Created (if Prometheus Operator available)
907-
- [ ] **Metrics**: squid-exporter provides Prometheus metrics
902+
- [ ] **Metrics**: Integrated squid-exporter provides Prometheus metrics
908903
- [ ] **Cache Manager**: Accessible via localhost manager interface
909904
- [ ] **Proxy**: Functions correctly for external requests
910905
- [ ] **Integration**: Metrics update after proxy usage
@@ -970,7 +965,6 @@ kind delete cluster --name caching
970965
```bash
971966
# Remove the local container images
972967
podman rmi localhost/konflux-ci/squid:latest
973-
podman rmi localhost/konflux-ci/squid-exporter:latest
974968
podman rmi localhost/konflux-ci/squid-test:latest
975969
```
976970

magefile.go

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ const (
3333
testImageTag = "localhost/konflux-ci/squid-test:latest"
3434
// TestContainerfile is the path to the Containerfile for tests
3535
testContainerfile = "test.Containerfile"
36-
// SquidExporterImageTag is the tag used for the squid-exporter container image
37-
squidExporterImageTag = "localhost/konflux-ci/squid-exporter:latest"
38-
// SquidExporterContainerfile is the path to the Containerfile for squid-exporter
39-
squidExporterContainerfile = "squid-exporter/Containerfile"
4036
)
4137

4238
// Default target - shows available targets
@@ -275,52 +271,14 @@ func (Build) LoadTestImage() error {
275271
return nil
276272
}
277273

278-
// Build:SquidExporter builds the Squid Exporter container image
279-
func (Build) SquidExporter() error {
280-
fmt.Println("📊 Building Squid Exporter container image...")
281274

282-
// Build the squid-exporter image using podman
283-
fmt.Printf("📦 Building image with tag '%s'...\n", squidExporterImageTag)
284-
err := sh.Run("podman", "build", "-t", squidExporterImageTag, "-f", squidExporterContainerfile, "squid-exporter")
285-
if err != nil {
286-
return fmt.Errorf("failed to build squid-exporter image: %w", err)
287-
}
288-
289-
fmt.Printf("✅ Squid Exporter image built successfully\n")
290-
291-
// Verify the image was built
292-
fmt.Printf("🔍 Verifying image exists...\n")
293-
err = sh.Run("podman", "images", squidExporterImageTag)
294-
if err != nil {
295-
return fmt.Errorf("failed to verify squid-exporter image: %w", err)
296-
}
297-
298-
fmt.Printf("✅ Squid Exporter image '%s' is ready!\n", squidExporterImageTag)
299-
return nil
300-
}
301275

302-
// Build:LoadSquidExporter loads the Squid Exporter image into the kind cluster
303-
func (Build) LoadSquidExporter() error {
304-
// Ensure dependencies are met
305-
mg.Deps(Kind.Up, Build.SquidExporter)
306276

307-
fmt.Println("📦 Loading Squid Exporter image into kind cluster...")
308-
309-
// Load image into kind cluster using process substitution
310-
fmt.Printf("📤 Loading image into kind cluster '%s'...\n", clusterName)
311-
err := sh.Run("bash", "-c", fmt.Sprintf("kind load image-archive --name %s <(podman save %s)", clusterName, squidExporterImageTag))
312-
if err != nil {
313-
return fmt.Errorf("failed to load squid-exporter image into kind cluster: %w", err)
314-
}
315-
316-
fmt.Printf("✅ Squid Exporter image loaded successfully into kind cluster '%s'!\n", clusterName)
317-
return nil
318-
}
319277

320278
// SquidHelm:Up deploys the Squid Helm chart to the cluster
321279
func (SquidHelm) Up() error {
322-
// Ensure dependencies are met (squid, squid-exporter, and test images needed)
323-
mg.Deps(Build.LoadSquid, Build.LoadSquidExporter, Build.LoadTestImage)
280+
// Ensure dependencies are met (squid and test images needed)
281+
mg.Deps(Build.LoadSquid, Build.LoadTestImage)
324282

325283
fmt.Println("⚓ Deploying Squid Helm chart...")
326284

@@ -509,11 +467,6 @@ func Clean() error {
509467
fmt.Printf("⚠️ Warning: Failed to remove squid image: %v\n", err)
510468
}
511469

512-
err = sh.Run("podman", "rmi", squidExporterImageTag)
513-
if err != nil {
514-
fmt.Printf("⚠️ Warning: Failed to remove squid-exporter image: %v\n", err)
515-
}
516-
517470
err = sh.Run("podman", "rmi", testImageTag)
518471
if err != nil {
519472
fmt.Printf("⚠️ Warning: Failed to remove test image: %v\n", err)

squid-exporter/Containerfile

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

0 commit comments

Comments
 (0)