Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skips checking for readiness on CNI DEL #1235

Merged
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
9 changes: 7 additions & 2 deletions pkg/multus/multus.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,13 @@ func CmdDel(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) er
}

if in.ReadinessIndicatorFile != "" {
s1061123 marked this conversation as resolved.
Show resolved Hide resolved
if err := types.GetReadinessIndicatorFile(in.ReadinessIndicatorFile); err != nil {
return cmdErr(k8sArgs, "PollImmediate error waiting for ReadinessIndicatorFile (on del): %v", err)
readinessfileexists, err := types.ReadinessIndicatorExistsNow(in.ReadinessIndicatorFile)
if err != nil {
return cmdErr(k8sArgs, "error checking readinessindicatorfile on CNI DEL @ %v: %v", in.ReadinessIndicatorFile, err)
}

if !readinessfileexists {
logging.Verbosef("warning: readinessindicatorfile @ %v does not exist on CNI DEL", in.ReadinessIndicatorFile)
}
}

Expand Down
30 changes: 27 additions & 3 deletions pkg/types/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
"fmt"
"net"
"os"
"path/filepath"
"strings"
"time"

utilwait "k8s.io/apimachinery/pkg/util/wait"

"github.com/containernetworking/cni/libcni"
"github.com/containernetworking/cni/pkg/skel"
cni100 "github.com/containernetworking/cni/pkg/types/100"
"github.com/containernetworking/cni/pkg/version"
nadutils "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/utils"
"gopkg.in/k8snetworkplumbingwg/multus-cni.v4/pkg/logging"
utilwait "k8s.io/apimachinery/pkg/util/wait"
)

const (
Expand Down Expand Up @@ -610,11 +610,35 @@
}

// GetReadinessIndicatorFile waits for readinessIndicatorFile
func GetReadinessIndicatorFile(readinessIndicatorFile string) error {
func GetReadinessIndicatorFile(readinessIndicatorFileRaw string) error {
cleanpath := filepath.Clean(readinessIndicatorFileRaw)
readinessIndicatorFile, err := filepath.Abs(cleanpath)
if err != nil {
return fmt.Errorf("failed to get absolute path of readinessIndicatorFile: %v", err)
}

pollDuration := 1000 * time.Millisecond
pollTimeout := 45 * time.Second
return utilwait.PollImmediate(pollDuration, pollTimeout, func() (bool, error) {
_, err := os.Stat(readinessIndicatorFile)
return err == nil, nil
})
}

// ReadinessIndicatorExistsNow reports if the readiness indicator exists immediately.
func ReadinessIndicatorExistsNow(readinessIndicatorFileRaw string) (bool, error) {
s1061123 marked this conversation as resolved.
Show resolved Hide resolved
cleanpath := filepath.Clean(readinessIndicatorFileRaw)
readinessIndicatorFile, err := filepath.Abs(cleanpath)
if err != nil {
return false, fmt.Errorf("failed to get absolute path of readinessIndicatorFile: %v", err)
}

_, err = os.Stat(readinessIndicatorFile)

Check failure

Code scanning / CodeQL

Uncontrolled data used in path expression High

This path depends on a
user-provided value
.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to read up on this, and I think it wants you to limit it to a subset of directories given a "base path", but, that doesn't work here, and it's just a presence indicator, and not a destructive action, so it should be fine.

if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
return true, nil
}
Loading