Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/actions/kind-diagnostics/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Kind resource diagnostics
description: Capture runner, Docker, Kubernetes, and kind cgroup memory settings
runs:
using: composite
steps:
- name: Runner resources
shell: bash
continue-on-error: true
run: |
uname -a
lscpu
free -h
swapon --show
df -h /
docker version
docker info
docker stats --no-stream
- name: Kubernetes resources
shell: bash
continue-on-error: true
run: |
kubectl get nodes -o wide
kubectl describe nodes
kubectl get pods -A -o wide
kubectl get pods -A -o json
kubectl get events -A --sort-by=.metadata.creationTimestamp
- name: Kind node limits and memory accounting
shell: bash
continue-on-error: true
run: |
for node in $(kind get nodes --name chart-testing); do
echo "::group::Kind node $node"
docker inspect "$node" --format 'Memory={{.HostConfig.Memory}} MemorySwap={{.HostConfig.MemorySwap}} NanoCpus={{.HostConfig.NanoCpus}} CpuQuota={{.HostConfig.CpuQuota}} CpuPeriod={{.HostConfig.CpuPeriod}} CgroupParent={{.HostConfig.CgroupParent}}'
docker exec "$node" bash -c '
uname -a
free -h
ps -eo pid,ppid,comm,rss,vsz --sort=-rss | head -40
while IFS= read -r events; do
dir=${events%/*}
echo "=== $dir ==="
for metric in memory.current memory.peak memory.max memory.events memory.stat cpu.max cpuset.cpus.effective; do
if [[ -r "$dir/$metric" ]]; then
echo "--- $metric"
cat "$dir/$metric"
fi
done
done < <(find /sys/fs/cgroup -name memory.events \( -path "*/kubepods*" -o -path /sys/fs/cgroup/memory.events \))
'
echo "::endgroup::"
done
8 changes: 7 additions & 1 deletion .github/actions/setup-kind-registry/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ runs:
steps:
- name: start kind
id: kind
uses: helm/kind-action@92086f6be054225fa813e0a4b13787fc9088faab # v1.13.0
uses: helm/kind-action@ea822c7bf1874f08e5a491df991c228edffc3376 # v1.15.2
with:
version: v0.33.0
kubectl_version: v1.34.11
node_image: kindest/node:v1.34.11@sha256:44e222ee2132dab25ff87301682f89eb82c7880ea3a1bf543bfe9708fd08d67d
registry: true
registry_name: kind-registry
registry_port: ${{ inputs.registry-port }}
- name: Capture runner and kind resources
uses: ./.github/actions/kind-diagnostics
if: always()
- name: wait for registry
shell: bash
run: |
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/integration-per-language.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ jobs:
kubectl get po
echo "Deployment failed, check above logs and previous steps to isolate the issue"
exit 6
- name: Capture failure resource diagnostics
if: failure()
uses: ./.github/actions/kind-diagnostics
kustomize-dry-run:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -347,6 +350,9 @@ jobs:
kubectl get po
echo "Deployment failed, check above logs and previous steps to isolate the issue"
exit 6
- name: Capture failure resource diagnostics
if: failure()
uses: ./.github/actions/kind-diagnostics
manifests-dry-run:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -497,6 +503,9 @@ jobs:
- name: Fail if any error
if: steps.deploy.outcome != 'success' || steps.rollout.outcome != 'success'
run: exit 6
- name: Capture failure resource diagnostics
if: failure()
uses: ./.github/actions/kind-diagnostics
manifest-update:
needs: manifests-create
runs-on: ubuntu-latest
Expand Down Expand Up @@ -548,6 +557,9 @@ jobs:
kubectl get po
echo "Deployment failed, check above logs and previous steps to isolate the issue"
exit 6
- name: Capture failure resource diagnostics
if: failure()
uses: ./.github/actions/kind-diagnostics
win-helm-create:
runs-on: windows-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions pkg/fixtures/dockerfiles/erlang/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ COPY --from=builder /opt/rel /opt/rel
EXPOSE 80 80

RUN ln -s /opt/rel/bin/$(cat /opt/rel/__relname) /opt/rel/bin/start_script
ENTRYPOINT ["/opt/rel/bin/start_script"]
# Bound Erlang's file-descriptor-sized tables on runtimes with huge nofile limits.
ENTRYPOINT ["/bin/sh", "-c", "ulimit -n 65536 && exec /opt/rel/bin/start_script \"$@\"", "--"]

CMD ["foreground"]

11 changes: 10 additions & 1 deletion pkg/templatewriter/writers/localfswriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ func (w *LocalFSWriter) WriteFile(path string, data []byte) error {
mode = 0644
}

return os.WriteFile(path, data, mode)
// Reject a symlink at the destination before it can be truncated.
f, err := openFileNoFollow(path, mode)
if err != nil {
return err
}
_, err = f.Write(data)
if closeErr := f.Close(); err == nil {
err = closeErr
}
return err
}
func (w *LocalFSWriter) EnsureDirectory(path string) error {
return osutil.EnsureDirectory(path)
Expand Down
56 changes: 56 additions & 0 deletions pkg/templatewriter/writers/localfswriter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package writers

import (
"errors"
"os"
"path/filepath"
"runtime"
"syscall"
"testing"

"github.com/stretchr/testify/require"
)

func TestLocalFSWriterWriteFile(t *testing.T) {
path := filepath.Join(t.TempDir(), "service.yaml")
w := &LocalFSWriter{}
require.NoError(t, w.WriteFile(path, []byte("original contents")))
require.NoError(t, w.WriteFile(path, []byte("new")))
data, err := os.ReadFile(path)
require.NoError(t, err)
require.Equal(t, "new", string(data))
}

func TestLocalFSWriterWriteFileRejectsSymlink(t *testing.T) {
for _, existing := range []bool{true, false} {
name := "dangling target"
if existing {
name = "existing target"
}
t.Run(name, func(t *testing.T) {
target := filepath.Join(t.TempDir(), "outside.txt")
if existing {
require.NoError(t, os.WriteFile(target, []byte("keep me"), 0600))
}
path := filepath.Join(t.TempDir(), "service.yaml")
err := os.Symlink(target, path)
if runtime.GOOS == "windows" && errors.Is(err, syscall.Errno(1314)) {
t.Skip("creating symlinks requires privileges on Windows")
}
require.NoError(t, err)

w := &LocalFSWriter{}
require.Error(t, w.WriteFile(path, []byte("generated manifest")))
linkTarget, err := os.Readlink(path)
require.NoError(t, err)
require.Equal(t, target, linkTarget)
data, err := os.ReadFile(target)
if existing {
require.NoError(t, err)
require.Equal(t, "keep me", string(data))
} else {
require.ErrorIs(t, err, os.ErrNotExist)
}
})
}
}
12 changes: 12 additions & 0 deletions pkg/templatewriter/writers/localfswriter_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !windows

package writers

import (
"os"
"syscall"
)

func openFileNoFollow(path string, mode os.FileMode) (*os.File, error) {
return os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|syscall.O_NOFOLLOW, mode)
}
39 changes: 39 additions & 0 deletions pkg/templatewriter/writers/localfswriter_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package writers

import (
"os"
"syscall"
)

func openFileNoFollow(path string, mode os.FileMode) (*os.File, error) {
name, err := syscall.UTF16PtrFromString(path)
if err != nil {
return nil, &os.PathError{Op: "open", Path: path, Err: err}
}
attributes := uint32(syscall.FILE_ATTRIBUTE_NORMAL | syscall.FILE_FLAG_OPEN_REPARSE_POINT)
if mode.Perm()&0200 == 0 {
attributes |= syscall.FILE_ATTRIBUTE_READONLY
}
// Open the reparse point itself without truncating. Inspect and truncate the
// same handle so replacing the path cannot redirect the write to a link target.
handle, err := syscall.CreateFile(name, syscall.GENERIC_WRITE,
syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE, nil, syscall.OPEN_ALWAYS, attributes, 0)
if err != nil {
return nil, &os.PathError{Op: "open", Path: path, Err: err}
}
var info syscall.ByHandleFileInformation
if err = syscall.GetFileInformationByHandle(handle, &info); err != nil {
syscall.CloseHandle(handle)
return nil, &os.PathError{Op: "open", Path: path, Err: err}
}
if info.FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT != 0 {
syscall.CloseHandle(handle)
return nil, &os.PathError{Op: "open", Path: path, Err: os.ErrInvalid}
}
f := os.NewFile(uintptr(handle), path)
if err := f.Truncate(0); err != nil {
f.Close()
return nil, err
}
return f, nil
}
4 changes: 2 additions & 2 deletions template/dockerfiles/erlang/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ COPY --from=builder /opt/rel /opt/rel
EXPOSE {{ .Config.GetVariableValue "PORT" }} {{ .Config.GetVariableValue "PORT" }}

RUN ln -s /opt/rel/bin/$(cat /opt/rel/__relname) /opt/rel/bin/start_script
ENTRYPOINT ["/opt/rel/bin/start_script"]
# Bound Erlang's file-descriptor-sized tables on runtimes with huge nofile limits.
ENTRYPOINT ["/bin/sh", "-c", "ulimit -n 65536 && exec /opt/rel/bin/start_script \"$@\"", "--"]

CMD ["foreground"]

Loading