mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-13 18:43:34 +00:00
rebase: bump the golang-dependencies group with 1 update
Bumps the golang-dependencies group with 1 update: [golang.org/x/crypto](https://github.com/golang/crypto). Updates `golang.org/x/crypto` from 0.16.0 to 0.17.0 - [Commits](https://github.com/golang/crypto/compare/v0.16.0...v0.17.0) --- updated-dependencies: - dependency-name: golang.org/x/crypto dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
committed by
mergify[bot]
parent
1ad79314f9
commit
e5d9b68d36
173
vendor/k8s.io/kubernetes/pkg/util/filesystem/defaultfs.go
generated
vendored
Normal file
173
vendor/k8s.io/kubernetes/pkg/util/filesystem/defaultfs.go
generated
vendored
Normal file
@ -0,0 +1,173 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes 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 filesystem
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DefaultFs implements Filesystem using same-named functions from "os" and "io"
|
||||
type DefaultFs struct {
|
||||
root string
|
||||
}
|
||||
|
||||
var _ Filesystem = &DefaultFs{}
|
||||
|
||||
// NewTempFs returns a fake Filesystem in temporary directory, useful for unit tests
|
||||
func NewTempFs() Filesystem {
|
||||
path, _ := os.MkdirTemp("", "tmpfs")
|
||||
return &DefaultFs{
|
||||
root: path,
|
||||
}
|
||||
}
|
||||
|
||||
func (fs *DefaultFs) prefix(path string) string {
|
||||
if len(fs.root) == 0 {
|
||||
return path
|
||||
}
|
||||
return filepath.Join(fs.root, path)
|
||||
}
|
||||
|
||||
// Stat via os.Stat
|
||||
func (fs *DefaultFs) Stat(name string) (os.FileInfo, error) {
|
||||
return os.Stat(fs.prefix(name))
|
||||
}
|
||||
|
||||
// Create via os.Create
|
||||
func (fs *DefaultFs) Create(name string) (File, error) {
|
||||
file, err := os.Create(fs.prefix(name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &defaultFile{file}, nil
|
||||
}
|
||||
|
||||
// Rename via os.Rename
|
||||
func (fs *DefaultFs) Rename(oldpath, newpath string) error {
|
||||
if !strings.HasPrefix(oldpath, fs.root) {
|
||||
oldpath = fs.prefix(oldpath)
|
||||
}
|
||||
if !strings.HasPrefix(newpath, fs.root) {
|
||||
newpath = fs.prefix(newpath)
|
||||
}
|
||||
return os.Rename(oldpath, newpath)
|
||||
}
|
||||
|
||||
// MkdirAll via os.MkdirAll
|
||||
func (fs *DefaultFs) MkdirAll(path string, perm os.FileMode) error {
|
||||
return os.MkdirAll(fs.prefix(path), perm)
|
||||
}
|
||||
|
||||
// MkdirAllWithPathCheck checks if path exists already. If not, it creates a directory
|
||||
// named path, along with any necessary parents, and returns nil, or else returns an error.
|
||||
// Permission bits perm (before umask) are used for all directories that
|
||||
// MkdirAllWithPathCheck creates.
|
||||
// If path is already a directory, MkdirAllWithPathCheck does nothing and returns nil.
|
||||
// NOTE: In case of Windows NTFS, mount points are implemented as reparse-point
|
||||
// (similar to symlink) and do not represent actual directory. Hence Directory existence
|
||||
// check for windows NTFS will NOT check for dir, but for symlink presence.
|
||||
func MkdirAllWithPathCheck(path string, perm os.FileMode) error {
|
||||
if dir, err := os.Lstat(path); err == nil {
|
||||
// If the path exists already,
|
||||
// 1. for Unix/Linux OS, check if the path is directory.
|
||||
// 2. for windows NTFS, check if the path is symlink instead of directory.
|
||||
if dir.IsDir() ||
|
||||
(runtime.GOOS == "windows" && (dir.Mode()&os.ModeSymlink != 0)) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("path %v exists but is not a directory", path)
|
||||
}
|
||||
// If existence of path not known, attempt to create it.
|
||||
if err := os.MkdirAll(path, perm); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Chtimes via os.Chtimes
|
||||
func (fs *DefaultFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
|
||||
return os.Chtimes(fs.prefix(name), atime, mtime)
|
||||
}
|
||||
|
||||
// RemoveAll via os.RemoveAll
|
||||
func (fs *DefaultFs) RemoveAll(path string) error {
|
||||
return os.RemoveAll(fs.prefix(path))
|
||||
}
|
||||
|
||||
// Remove via os.Remove
|
||||
func (fs *DefaultFs) Remove(name string) error {
|
||||
return os.Remove(fs.prefix(name))
|
||||
}
|
||||
|
||||
// ReadFile via os.ReadFile
|
||||
func (fs *DefaultFs) ReadFile(filename string) ([]byte, error) {
|
||||
return os.ReadFile(fs.prefix(filename))
|
||||
}
|
||||
|
||||
// TempDir via os.MkdirTemp
|
||||
func (fs *DefaultFs) TempDir(dir, prefix string) (string, error) {
|
||||
return os.MkdirTemp(fs.prefix(dir), prefix)
|
||||
}
|
||||
|
||||
// TempFile via os.CreateTemp
|
||||
func (fs *DefaultFs) TempFile(dir, prefix string) (File, error) {
|
||||
file, err := os.CreateTemp(fs.prefix(dir), prefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &defaultFile{file}, nil
|
||||
}
|
||||
|
||||
// ReadDir via os.ReadDir
|
||||
func (fs *DefaultFs) ReadDir(dirname string) ([]os.DirEntry, error) {
|
||||
return os.ReadDir(fs.prefix(dirname))
|
||||
}
|
||||
|
||||
// Walk via filepath.Walk
|
||||
func (fs *DefaultFs) Walk(root string, walkFn filepath.WalkFunc) error {
|
||||
return filepath.Walk(fs.prefix(root), walkFn)
|
||||
}
|
||||
|
||||
// defaultFile implements File using same-named functions from "os"
|
||||
type defaultFile struct {
|
||||
file *os.File
|
||||
}
|
||||
|
||||
// Name via os.File.Name
|
||||
func (file *defaultFile) Name() string {
|
||||
return file.file.Name()
|
||||
}
|
||||
|
||||
// Write via os.File.Write
|
||||
func (file *defaultFile) Write(b []byte) (n int, err error) {
|
||||
return file.file.Write(b)
|
||||
}
|
||||
|
||||
// Sync via os.File.Sync
|
||||
func (file *defaultFile) Sync() error {
|
||||
return file.file.Sync()
|
||||
}
|
||||
|
||||
// Close via os.File.Close
|
||||
func (file *defaultFile) Close() error {
|
||||
return file.file.Close()
|
||||
}
|
52
vendor/k8s.io/kubernetes/pkg/util/filesystem/filesystem.go
generated
vendored
Normal file
52
vendor/k8s.io/kubernetes/pkg/util/filesystem/filesystem.go
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes 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 filesystem
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Filesystem is an interface that we can use to mock various filesystem operations
|
||||
type Filesystem interface {
|
||||
// from "os"
|
||||
Stat(name string) (os.FileInfo, error)
|
||||
Create(name string) (File, error)
|
||||
Rename(oldpath, newpath string) error
|
||||
MkdirAll(path string, perm os.FileMode) error
|
||||
Chtimes(name string, atime time.Time, mtime time.Time) error
|
||||
RemoveAll(path string) error
|
||||
Remove(name string) error
|
||||
|
||||
// from "os"
|
||||
ReadFile(filename string) ([]byte, error)
|
||||
TempDir(dir, prefix string) (string, error)
|
||||
TempFile(dir, prefix string) (File, error)
|
||||
ReadDir(dirname string) ([]os.DirEntry, error)
|
||||
Walk(root string, walkFn filepath.WalkFunc) error
|
||||
}
|
||||
|
||||
// File is an interface that we can use to mock various filesystem operations typically
|
||||
// accessed through the File object from the "os" package
|
||||
type File interface {
|
||||
// for now, the only os.File methods used are those below, add more as necessary
|
||||
Name() string
|
||||
Write(b []byte) (n int, err error)
|
||||
Sync() error
|
||||
Close() error
|
||||
}
|
37
vendor/k8s.io/kubernetes/pkg/util/filesystem/util_unix.go
generated
vendored
Normal file
37
vendor/k8s.io/kubernetes/pkg/util/filesystem/util_unix.go
generated
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
//go:build freebsd || linux || darwin
|
||||
// +build freebsd linux darwin
|
||||
|
||||
/*
|
||||
Copyright 2023 The Kubernetes 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 filesystem
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// IsUnixDomainSocket returns whether a given file is a AF_UNIX socket file
|
||||
func IsUnixDomainSocket(filePath string) (bool, error) {
|
||||
fi, err := os.Stat(filePath)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("stat file %s failed: %v", filePath, err)
|
||||
}
|
||||
if fi.Mode()&os.ModeSocket == 0 {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
87
vendor/k8s.io/kubernetes/pkg/util/filesystem/util_windows.go
generated
vendored
Normal file
87
vendor/k8s.io/kubernetes/pkg/util/filesystem/util_windows.go
generated
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
/*
|
||||
Copyright 2023 The Kubernetes 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 filesystem
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
const (
|
||||
// Amount of time to wait between attempting to use a Unix domain socket.
|
||||
// As detailed in https://github.com/kubernetes/kubernetes/issues/104584
|
||||
// the first attempt will most likely fail, hence the need to retry
|
||||
socketDialRetryPeriod = 1 * time.Second
|
||||
// Overall timeout value to dial a Unix domain socket, including retries
|
||||
socketDialTimeout = 4 * time.Second
|
||||
)
|
||||
|
||||
// IsUnixDomainSocket returns whether a given file is a AF_UNIX socket file
|
||||
// Note that due to the retry logic inside, it could take up to 4 seconds
|
||||
// to determine whether or not the file path supplied is a Unix domain socket
|
||||
func IsUnixDomainSocket(filePath string) (bool, error) {
|
||||
// Due to the absence of golang support for os.ModeSocket in Windows (https://github.com/golang/go/issues/33357)
|
||||
// we need to dial the file and check if we receive an error to determine if a file is Unix Domain Socket file.
|
||||
|
||||
// Note that querrying for the Reparse Points (https://docs.microsoft.com/en-us/windows/win32/fileio/reparse-points)
|
||||
// for the file (using FSCTL_GET_REPARSE_POINT) and checking for reparse tag: reparseTagSocket
|
||||
// does NOT work in 1809 if the socket file is created within a bind mounted directory by a container
|
||||
// and the FSCTL is issued in the host by the kubelet.
|
||||
|
||||
// If the file does not exist, it cannot be a Unix domain socket.
|
||||
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||
return false, fmt.Errorf("File %s not found. Err: %v", filePath, err)
|
||||
}
|
||||
|
||||
klog.V(6).InfoS("Function IsUnixDomainSocket starts", "filePath", filePath)
|
||||
// As detailed in https://github.com/kubernetes/kubernetes/issues/104584 we cannot rely
|
||||
// on the Unix Domain socket working on the very first try, hence the potential need to
|
||||
// dial multiple times
|
||||
var lastSocketErr error
|
||||
err := wait.PollImmediate(socketDialRetryPeriod, socketDialTimeout,
|
||||
func() (bool, error) {
|
||||
klog.V(6).InfoS("Dialing the socket", "filePath", filePath)
|
||||
var c net.Conn
|
||||
c, lastSocketErr = net.Dial("unix", filePath)
|
||||
if lastSocketErr == nil {
|
||||
c.Close()
|
||||
klog.V(6).InfoS("Socket dialed successfully", "filePath", filePath)
|
||||
return true, nil
|
||||
}
|
||||
klog.V(6).InfoS("Failed the current attempt to dial the socket, so pausing before retry",
|
||||
"filePath", filePath, "err", lastSocketErr, "socketDialRetryPeriod",
|
||||
socketDialRetryPeriod)
|
||||
return false, nil
|
||||
})
|
||||
|
||||
// PollImmediate will return "timed out waiting for the condition" if the function it
|
||||
// invokes never returns true
|
||||
if err != nil {
|
||||
klog.V(2).InfoS("Failed all attempts to dial the socket so marking it as a non-Unix Domain socket. Last socket error along with the error from PollImmediate follow",
|
||||
"filePath", filePath, "lastSocketErr", lastSocketErr, "err", err)
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
89
vendor/k8s.io/kubernetes/pkg/util/filesystem/watcher.go
generated
vendored
Normal file
89
vendor/k8s.io/kubernetes/pkg/util/filesystem/watcher.go
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes 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 filesystem
|
||||
|
||||
import (
|
||||
"github.com/fsnotify/fsnotify"
|
||||
)
|
||||
|
||||
// FSWatcher is a callback-based filesystem watcher abstraction for fsnotify.
|
||||
type FSWatcher interface {
|
||||
// Initializes the watcher with the given watch handlers.
|
||||
// Called before all other methods.
|
||||
Init(FSEventHandler, FSErrorHandler) error
|
||||
|
||||
// Starts listening for events and errors.
|
||||
// When an event or error occurs, the corresponding handler is called.
|
||||
Run()
|
||||
|
||||
// Add a filesystem path to watch
|
||||
AddWatch(path string) error
|
||||
}
|
||||
|
||||
// FSEventHandler is called when a fsnotify event occurs.
|
||||
type FSEventHandler func(event fsnotify.Event)
|
||||
|
||||
// FSErrorHandler is called when a fsnotify error occurs.
|
||||
type FSErrorHandler func(err error)
|
||||
|
||||
type fsnotifyWatcher struct {
|
||||
watcher *fsnotify.Watcher
|
||||
eventHandler FSEventHandler
|
||||
errorHandler FSErrorHandler
|
||||
}
|
||||
|
||||
var _ FSWatcher = &fsnotifyWatcher{}
|
||||
|
||||
// NewFsnotifyWatcher returns an implementation of FSWatcher that continuously listens for
|
||||
// fsnotify events and calls the event handler as soon as an event is received.
|
||||
func NewFsnotifyWatcher() FSWatcher {
|
||||
return &fsnotifyWatcher{}
|
||||
}
|
||||
|
||||
func (w *fsnotifyWatcher) AddWatch(path string) error {
|
||||
return w.watcher.Add(path)
|
||||
}
|
||||
|
||||
func (w *fsnotifyWatcher) Init(eventHandler FSEventHandler, errorHandler FSErrorHandler) error {
|
||||
var err error
|
||||
w.watcher, err = fsnotify.NewWatcher()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w.eventHandler = eventHandler
|
||||
w.errorHandler = errorHandler
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *fsnotifyWatcher) Run() {
|
||||
go func() {
|
||||
defer w.watcher.Close()
|
||||
for {
|
||||
select {
|
||||
case event := <-w.watcher.Events:
|
||||
if w.eventHandler != nil {
|
||||
w.eventHandler(event)
|
||||
}
|
||||
case err := <-w.watcher.Errors:
|
||||
if w.errorHandler != nil {
|
||||
w.errorHandler(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
2
vendor/k8s.io/kubernetes/pkg/util/parsers/parsers.go
generated
vendored
2
vendor/k8s.io/kubernetes/pkg/util/parsers/parsers.go
generated
vendored
@ -23,7 +23,7 @@ import (
|
||||
// Import the crypto/sha512 algorithm for the docker image parser to work with 384 and 512 sha hashes
|
||||
_ "crypto/sha512"
|
||||
|
||||
dockerref "github.com/docker/distribution/reference"
|
||||
dockerref "github.com/distribution/reference"
|
||||
)
|
||||
|
||||
// ParseImageName parses a docker image string into three parts: repo, tag and digest.
|
||||
|
Reference in New Issue
Block a user