Skip to content

Commit

Permalink
Cleanup Dockerfile & update volume mount paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud Tincelin committed Jun 11, 2021
1 parent 147b24b commit 5670798
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/docs
/tests
/builder
/deployment
*.md
34 changes: 25 additions & 9 deletions builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
FROM golang AS builder
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build github.com/Azure/aks-periscope/cmd/aks-periscope
# Builder
FROM golang:alpine AS builder

ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64

WORKDIR /build

COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .

RUN go build ./cmd/aks-periscope

# Runner
FROM alpine

RUN apk --no-cache add ca-certificates curl openssl bash

ADD https://storage.googleapis.com/kubernetes-release/release/v1.16.0/bin/linux/amd64/kubectl /usr/local/bin/kubectl
RUN chmod +x /usr/local/bin/kubectl

RUN curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 \
&& chmod +x get_helm.sh \
&& ./get_helm.sh
RUN mkdir /app
WORKDIR /app
COPY --from=builder /app/aks-periscope .
CMD ["./aks-periscope"]

COPY --from=builder /build/aks-periscope /

ENTRYPOINT ["/aks-periscope"]
10 changes: 5 additions & 5 deletions cmd/aks-periscope/aks-periscope.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"log"
"os"
"path/filepath"
"strings"
"sync"

Expand Down Expand Up @@ -136,16 +137,15 @@ func zipAndExport(exporter interfaces.Exporter) error {
return err
}

sourcePathOnHost := "/var/log/aks-periscope/" + strings.Replace(creationTimeStamp, ":", "-", -1) + "/" + hostName
zipFileOnHost := sourcePathOnHost + "/" + hostName + ".zip"
zipFileOnContainer := strings.TrimPrefix(zipFileOnHost, "/var/log")
sourcePath := filepath.Join("/mnt", strings.Replace(creationTimeStamp, ":", "-", -1), hostName)
zipFile := filepath.Join(sourcePath, hostName+".zip")

_, err = utils.RunCommandOnHost("zip", "-r", zipFileOnHost, sourcePathOnHost)
_, err = utils.RunCommandOnHost("zip", "-r", zipFile, sourcePath)
if err != nil {
return err
}

err = exporter.Export([]string{zipFileOnContainer})
err = exporter.Export([]string{zipFile})
if err != nil {
return err
}
Expand Down
14 changes: 9 additions & 5 deletions deployment/aks-periscope.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ spec:
- secretRef:
name: azureblob-secret
volumeMounts:
- mountPath: /aks-periscope
name: aks-periscope-storage
- name: varlog
mountPath: /var/log
- name: aks-periscope-cache
mountPath: /mnt
resources:
requests:
memory: "500Mi"
Expand All @@ -97,10 +99,12 @@ spec:
memory: "2000Mi"
cpu: "1000m"
volumes:
- name: aks-periscope-storage
- name: varlog
hostPath:
path: /var/log/aks-periscope
type: DirectoryOrCreate
path: /var/log
- name: aks-periscope-cache
hostPath:
path: /mnt
---
apiVersion: v1
kind: Secret
Expand Down
14 changes: 9 additions & 5 deletions deployment/daemon-set.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ spec:
- configMapRef:
name: nodelogs-config
volumeMounts:
- mountPath: /aks-periscope
name: aks-periscope-storage
- name: varlog
mountPath: /var/log
- name: aks-periscope-cache
mountPath: /mnt
resources:
requests:
memory: "500Mi"
Expand All @@ -42,7 +44,9 @@ spec:
memory: "2000Mi"
cpu: "1000m"
volumes:
- name: aks-periscope-storage
- name: varlog
hostPath:
path: /var/log/aks-periscope
type: DirectoryOrCreate
path: /var/log
- name: aks-periscope-cache
hostPath:
path: /mnt
2 changes: 1 addition & 1 deletion pkg/exporter/azureblob_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (exporter *AzureBlobExporter) Export(files []string) error {
}

for _, file := range files {
appendBlobURL := containerURL.NewAppendBlobURL(strings.TrimPrefix(file, "/aks-periscope/"))
appendBlobURL := containerURL.NewAppendBlobURL(strings.TrimPrefix(file, "/mnt/"))

blobGetPropertiesResponse, err := appendBlobURL.GetProperties(ctx, azblob.BlobAccessConditions{})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func CreateCollectorDir(name string) (string, error) {
return "", err
}

rootPath := filepath.Join("/aks-periscope", strings.Replace(creationTimeStamp, ":", "-", -1), hostName, "collector", name)
rootPath := filepath.Join("/mnt", strings.Replace(creationTimeStamp, ":", "-", -1), hostName, "collector", name)
err = os.MkdirAll(rootPath, os.ModePerm)
if err != nil {
return "", fmt.Errorf("Fail to create dir %s: %+v", rootPath, err)
Expand All @@ -186,7 +186,7 @@ func CreateDiagnosticDir() (string, error) {
return "", err
}

rootPath := filepath.Join("/aks-periscope", strings.Replace(creationTimeStamp, ":", "-", -1), hostName, "diagnoser")
rootPath := filepath.Join("/mnt", strings.Replace(creationTimeStamp, ":", "-", -1), hostName, "diagnoser")
err = os.MkdirAll(rootPath, os.ModePerm)
if err != nil {
return "", fmt.Errorf("Fail to create dir %s: %+v", rootPath, err)
Expand Down

0 comments on commit 5670798

Please sign in to comment.