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

Thick plugin should not wait for API readiness on CNI DEL #1279

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: 9 additions & 0 deletions pkg/server/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,12 @@ func WaitUntilAPIReady(socketPath string) error {
return err == nil, nil
})
}

// CheckAPIReadyNow checks API readiness once
func CheckAPIReadyNow(socketPath string) error {
_, err := DoCNI(GetAPIEndpoint(MultusHealthAPIEndpoint), nil, SocketPath(socketPath))
if err != nil {
return fmt.Errorf("CheckAPIReadyNow: Daemon not reachable over socketfile: %v", err)
}
return nil
}
15 changes: 9 additions & 6 deletions pkg/server/api/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@
LogToStderr bool `json:"logToStderr,omitempty"`
}

// Define a type for API readiness check functions

Check warning on line 43 in pkg/server/api/shim.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

comment on exported type APIReadyCheckFunc should be of the form "APIReadyCheckFunc ..." (with optional leading article)

Check warning on line 43 in pkg/server/api/shim.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

comment on exported type APIReadyCheckFunc should be of the form "APIReadyCheckFunc ..." (with optional leading article)
type APIReadyCheckFunc func(string) error

Check warning on line 44 in pkg/server/api/shim.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

type name will be used as api.APIReadyCheckFunc by other packages, and that stutters; consider calling this ReadyCheckFunc

Check warning on line 44 in pkg/server/api/shim.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

type name will be used as api.APIReadyCheckFunc by other packages, and that stutters; consider calling this ReadyCheckFunc

// CmdAdd implements the CNI spec ADD command handler
func CmdAdd(args *skel.CmdArgs) error {
response, cniVersion, err := postRequest(args)
response, cniVersion, err := postRequest(args, WaitUntilAPIReady)
if err != nil {
return logging.Errorf("CmdAdd (shim): %v", err)
}
Expand All @@ -53,7 +56,7 @@

// CmdCheck implements the CNI spec CHECK command handler
func CmdCheck(args *skel.CmdArgs) error {
_, _, err := postRequest(args)
_, _, err := postRequest(args, WaitUntilAPIReady)
if err != nil {
return logging.Errorf("CmdCheck (shim): %v", err)
}
Expand All @@ -63,22 +66,22 @@

// CmdDel implements the CNI spec DEL command handler
func CmdDel(args *skel.CmdArgs) error {
_, _, err := postRequest(args)
_, _, err := postRequest(args, CheckAPIReadyNow)
if err != nil {
// No error in DEL (as of CNI spec)
logging.Errorf("CmdDel (shim): %v", err)
}
return nil
}

func postRequest(args *skel.CmdArgs) (*Response, string, error) {
func postRequest(args *skel.CmdArgs, readinessCheck APIReadyCheckFunc) (*Response, string, error) {
multusShimConfig, err := shimConfig(args.StdinData)
if err != nil {
return nil, "", fmt.Errorf("invalid CNI configuration passed to multus-shim: %w", err)
}

// check API readiness
if err := WaitUntilAPIReady(multusShimConfig.MultusSocketDir); err != nil {
// Execute the readiness check as necessary (e.g. don't wait on CNI DEL)
if err := readinessCheck(multusShimConfig.MultusSocketDir); err != nil {
return nil, multusShimConfig.CNIVersion, err
}

Expand Down
Loading