Skip to content

Commit

Permalink
fix warnings getting fd limit in distroless (istio#49761)
Browse files Browse the repository at this point in the history
* fix warnings getting fd limit in distroless

Signed-off-by: Tianpeng Wang <tpwang@alauda.io>

* fix copyright lint

Signed-off-by: Tianpeng Wang <tpwang@alauda.io>

---------

Signed-off-by: Tianpeng Wang <tpwang@alauda.io>
  • Loading branch information
timonwong authored Mar 6, 2024
1 parent 5396475 commit 43d0be4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pilot/cmd/pilot-agent/app/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"net"
"net/netip"
"os/exec"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -386,11 +385,10 @@ func getExcludeInterfaces() sets.String {
}

func logLimits() {
out, err := exec.Command("bash", "-c", "ulimit -n").Output()
outStr := strings.TrimSpace(string(out))
limit, err := GetFDLimit()
if err != nil {
log.Warnf("failed running ulimit command: %v", outStr)
log.Warnf("failed getting fd limit: %s", err)
} else {
log.Infof("Maximum file descriptors (ulimit -n): %v", outStr)
log.Infof("Maximum file descriptors (ulimit -n): %d", limit)
}
}
19 changes: 19 additions & 0 deletions pilot/cmd/pilot-agent/app/fds.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package app

func GetFDLimit() (uint64, error) {
return getFDLimit()
}
29 changes: 29 additions & 0 deletions pilot/cmd/pilot-agent/app/fds_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris

// Copyright Istio Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package app

import "golang.org/x/sys/unix"

func getFDLimit() (uint64, error) {
rlimit := unix.Rlimit{}
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rlimit); err != nil {
return 0, err
}

return rlimit.Cur, nil
}

0 comments on commit 43d0be4

Please sign in to comment.