Skip to content

Commit 7644266

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 63db021 commit 7644266

File tree

7 files changed

+100
-190
lines changed

7 files changed

+100
-190
lines changed

Containerfile

Lines changed: 51 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,56 @@ 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+
git && \
57+
microdnf clean all
58+
59+
# Install Go (version-locked)
60+
ARG GO_VERSION=1.24.4
61+
ARG GO_SHA256=77e5da33bb72aeaef1ba4418b6fe511bc4d041873cbf82e5aa6318740df98717
62+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
63+
RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" -o go.tar.gz && \
64+
echo "${GO_SHA256} go.tar.gz" | sha256sum -c - && \
65+
tar -C /usr/local -xzf go.tar.gz && \
66+
rm go.tar.gz
67+
68+
# Set Go environment
69+
ENV PATH="/usr/local/go/bin:/root/go/bin:$PATH"
70+
ENV GOPATH="/root/go"
71+
ENV GOCACHE="/tmp/go-cache"
72+
73+
# Set working directory for build
74+
WORKDIR /workspace
75+
76+
# Install squid-exporter directly from upstream and copy to expected location
77+
RUN CGO_ENABLED=0 GOOS=linux go install github.com/boynux/[email protected] && \
78+
cp /root/go/bin/squid-exporter /workspace/squid-exporter
79+
80+
# ==========================================
81+
# Final Stage: Squid with integrated exporter
82+
# ==========================================
83+
FROM squid-base
84+
85+
# Copy squid-exporter binary from builder stage
86+
COPY --from=squid-exporter-builder /workspace/squid-exporter /usr/local/bin/squid-exporter
87+
88+
# Set permissions for squid-exporter
89+
RUN chmod +x /usr/local/bin/squid-exporter
90+
91+
# Expose squid-exporter metrics port (only in final stage where the binary exists)
92+
EXPOSE 9301
93+
4494
USER 1001
4595

4696
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/boynux/squid-exporter) (upstream). 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 & 53 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,10 @@ 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...")
281-
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-
}
301-
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)
306-
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-
}
319-
320274
// SquidHelm:Up deploys the Squid Helm chart to the cluster
321275
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)
276+
// Ensure dependencies are met (squid and test images needed)
277+
mg.Deps(Build.LoadSquid, Build.LoadTestImage)
324278

325279
fmt.Println("⚓ Deploying Squid Helm chart...")
326280

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

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-
517466
err = sh.Run("podman", "rmi", testImageTag)
518467
if err != nil {
519468
fmt.Printf("⚠️ Warning: Failed to remove test image: %v\n", err)

squid-exporter/Containerfile

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

squid/templates/deployment.yaml

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ spec:
6363
{{- toYaml .Values.securityContext | nindent 12 }}
6464
image: "{{ include "squid.image" . }}"
6565
imagePullPolicy: {{ .Values.image.pullPolicy }}
66+
command: ["/usr/sbin/container-entrypoint.sh"]
6667
ports:
6768
- name: http
6869
containerPort: 3128
@@ -88,31 +89,13 @@ spec:
8889
mountPath: /var/spool/squid
8990
{{- if .Values.squidExporter.enabled }}
9091
- name: squid-exporter
91-
image: "{{ .Values.squidExporter.image.repository }}:{{ .Values.squidExporter.image.tag }}"
92-
imagePullPolicy: {{ .Values.squidExporter.image.pullPolicy }}
92+
image: "{{ include "squid.image" . }}"
93+
imagePullPolicy: {{ .Values.image.pullPolicy }}
94+
command: ["/usr/sbin/container-entrypoint.sh", "exporter"]
9395
ports:
9496
- name: metrics
9597
containerPort: {{ .Values.squidExporter.port }}
9698
protocol: TCP
97-
env:
98-
- name: SQUID_HOSTNAME
99-
value: "localhost"
100-
- name: SQUID_PORT
101-
value: "{{ .Values.service.port }}"
102-
- name: SQUID_EXPORTER_LISTEN
103-
value: ":{{ .Values.squidExporter.port }}"
104-
- name: SQUID_EXPORTER_METRICS_PATH
105-
value: "{{ .Values.squidExporter.metricsPath }}"
106-
- name: SQUID_EXTRACTSERVICETIMES
107-
value: "{{ .Values.squidExporter.extractServiceTimes }}"
108-
{{- if .Values.squidExporter.squidLogin }}
109-
- name: SQUID_LOGIN
110-
value: "{{ .Values.squidExporter.squidLogin }}"
111-
{{- end }}
112-
{{- if .Values.squidExporter.squidPassword }}
113-
- name: SQUID_PASSWORD
114-
value: "{{ .Values.squidExporter.squidPassword }}"
115-
{{- end }}
11699
args:
117100
- -squid-hostname
118101
- "localhost"

squid/values.yaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,14 @@ service:
7676

7777
# Squid Prometheus Exporter Configuration
7878
# This enables monitoring of Squid metrics via Prometheus
79-
# Note: hostname is hardcoded to "localhost" in deployment template since
80-
# the exporter runs as a sidecar in the same pod as squid
79+
# Note: squid-exporter is now integrated into the main squid image
8180
# Note: squid port is referenced from service.port to avoid duplication
8281
squidExporter:
83-
# Enable or disable the squid-exporter sidecar
82+
# Enable or disable the integrated squid-exporter
8483
enabled: true
85-
# Squid exporter container image - using konflux-ci fork instead of third-party
84+
# Squid exporter image (now integrated into main squid image)
8685
image:
87-
repository: localhost/konflux-ci/squid-exporter
86+
repository: localhost/konflux-ci/squid
8887
tag: "latest"
8988
pullPolicy: IfNotPresent
9089
# Port on which the exporter will serve metrics

0 commit comments

Comments
 (0)