mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-06-26 23:56:52 +00:00
commit
003fbd5785
@ -73,15 +73,15 @@ var (
|
|||||||
// ControllerName provides controller name
|
// ControllerName provides controller name
|
||||||
ControllerName = "csr-approver"
|
ControllerName = "csr-approver"
|
||||||
// NamePrefix specifies which name in certification request should be target to approve
|
// NamePrefix specifies which name in certification request should be target to approve
|
||||||
NamePrefix = "system:multus"
|
NamePrefix = "system:multus"
|
||||||
// Organization specifies which org in certification request should be target to approve
|
// Organization specifies which org in certification request should be target to approve
|
||||||
Organization = []string{"system:multus"}
|
Organization = []string{"system:multus"}
|
||||||
// Groups specifies which group in certification request should be target to approve
|
// Groups specifies which group in certification request should be target to approve
|
||||||
Groups = sets.New[string]("system:nodes", "system:multus", "system:authenticated")
|
Groups = sets.New[string]("system:nodes", "system:multus", "system:authenticated")
|
||||||
// UserPrefixes specifies which name prefix in certification request should be target to approve
|
// UserPrefixes specifies which name prefix in certification request should be target to approve
|
||||||
UserPrefixes = sets.New[string]("system:node", NamePrefix)
|
UserPrefixes = sets.New[string]("system:node", NamePrefix)
|
||||||
// Usages specifies which usage in certification request should be target to approve
|
// Usages specifies which usage in certification request should be target to approve
|
||||||
Usages = sets.New[certificatesv1.KeyUsage](
|
Usages = sets.New[certificatesv1.KeyUsage](
|
||||||
certificatesv1.UsageDigitalSignature,
|
certificatesv1.UsageDigitalSignature,
|
||||||
certificatesv1.UsageClientAuth)
|
certificatesv1.UsageClientAuth)
|
||||||
)
|
)
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
|
||||||
|
|
||||||
utilwait "k8s.io/apimachinery/pkg/util/wait"
|
utilwait "k8s.io/apimachinery/pkg/util/wait"
|
||||||
|
|
||||||
@ -113,7 +112,7 @@ func main() {
|
|||||||
|
|
||||||
// Wait until daemon ready
|
// Wait until daemon ready
|
||||||
logging.Verbosef("API readiness check")
|
logging.Verbosef("API readiness check")
|
||||||
if waitUntilAPIReady(daemonConf.SocketDir) != nil {
|
if api.WaitUntilAPIReady(daemonConf.SocketDir) != nil {
|
||||||
logging.Panicf("failed to ready multus-daemon socket: %v", err)
|
logging.Panicf("failed to ready multus-daemon socket: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
@ -140,16 +139,6 @@ func main() {
|
|||||||
logging.Verbosef("multus daemon is exited")
|
logging.Verbosef("multus daemon is exited")
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitUntilAPIReady(socketPath string) error {
|
|
||||||
apiReadyPollDuration := 100 * time.Millisecond
|
|
||||||
apiReadyPollTimeout := 1000 * time.Millisecond
|
|
||||||
|
|
||||||
return utilwait.PollImmediate(apiReadyPollDuration, apiReadyPollTimeout, func() (bool, error) {
|
|
||||||
_, err := api.DoCNI(api.GetAPIEndpoint(api.MultusHealthAPIEndpoint), nil, api.SocketPath(socketPath))
|
|
||||||
return err == nil, nil
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func startMultusDaemon(ctx context.Context, daemonConfig *srv.ControllerNetConf, ignoreReadinessIndicator bool) error {
|
func startMultusDaemon(ctx context.Context, daemonConfig *srv.ControllerNetConf, ignoreReadinessIndicator bool) error {
|
||||||
if user, err := user.Current(); err != nil || user.Uid != "0" {
|
if user, err := user.Current(); err != nil || user.Uid != "0" {
|
||||||
return fmt.Errorf("failed to run multus-daemon with root: %v, now running in uid: %s", err, user.Uid)
|
return fmt.Errorf("failed to run multus-daemon with root: %v, now running in uid: %s", err, user.Uid)
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2" //nolint:golint
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega" //nolint:golint
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestThinEntrypoint(t *testing.T) {
|
func TestThinEntrypoint(t *testing.T) {
|
||||||
|
@ -22,9 +22,17 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
utilwait "k8s.io/apimachinery/pkg/util/wait"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// APIReadyPollDuration specifies duration for API readiness check polling
|
||||||
|
APIReadyPollDuration = 100 * time.Millisecond
|
||||||
|
// APIReadyPollTimeout specifies timeout for API readiness check polling
|
||||||
|
APIReadyPollTimeout = 60000 * time.Millisecond
|
||||||
|
|
||||||
// MultusCNIAPIEndpoint is an endpoint for multus CNI request (for multus-shim)
|
// MultusCNIAPIEndpoint is an endpoint for multus CNI request (for multus-shim)
|
||||||
MultusCNIAPIEndpoint = "/cni"
|
MultusCNIAPIEndpoint = "/cni"
|
||||||
// MultusDelegateAPIEndpoint is an endpoint for multus delegate request (for hotplug)
|
// MultusDelegateAPIEndpoint is an endpoint for multus delegate request (for hotplug)
|
||||||
@ -88,3 +96,11 @@ func CreateDelegateRequest(cniCommand, cniContainerID, cniNetNS, cniIFName, podN
|
|||||||
InterfaceAttributes: interfaceAttributes,
|
InterfaceAttributes: interfaceAttributes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WaitUntilAPIReady checks API readiness
|
||||||
|
func WaitUntilAPIReady(socketPath string) error {
|
||||||
|
return utilwait.PollImmediate(APIReadyPollDuration, APIReadyPollTimeout, func() (bool, error) {
|
||||||
|
_, err := DoCNI(GetAPIEndpoint(MultusHealthAPIEndpoint), nil, SocketPath(socketPath))
|
||||||
|
return err == nil, nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -24,6 +24,8 @@ import (
|
|||||||
cnitypes "github.com/containernetworking/cni/pkg/types"
|
cnitypes "github.com/containernetworking/cni/pkg/types"
|
||||||
|
|
||||||
"gopkg.in/k8snetworkplumbingwg/multus-cni.v4/pkg/logging"
|
"gopkg.in/k8snetworkplumbingwg/multus-cni.v4/pkg/logging"
|
||||||
|
|
||||||
|
utilwait "k8s.io/apimachinery/pkg/util/wait"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ShimNetConf for the SHIM cni config file written in json
|
// ShimNetConf for the SHIM cni config file written in json
|
||||||
@ -77,12 +79,21 @@ func postRequest(args *skel.CmdArgs) (*Response, string, error) {
|
|||||||
return nil, "", fmt.Errorf("invalid CNI configuration passed to multus-shim: %w", err)
|
return nil, "", fmt.Errorf("invalid CNI configuration passed to multus-shim: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check API readiness
|
||||||
|
if err := WaitUntilAPIReady(multusShimConfig.MultusSocketDir); err != nil {
|
||||||
|
return nil, multusShimConfig.CNIVersion, err
|
||||||
|
}
|
||||||
|
|
||||||
cniRequest, err := newCNIRequest(args)
|
cniRequest, err := newCNIRequest(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, multusShimConfig.CNIVersion, err
|
return nil, multusShimConfig.CNIVersion, err
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := DoCNI("http://dummy/cni", cniRequest, SocketPath(multusShimConfig.MultusSocketDir))
|
var body []byte
|
||||||
|
err = utilwait.PollImmediate(APIReadyPollDuration, APIReadyPollTimeout, func() (bool, error) {
|
||||||
|
body, err = DoCNI("http://dummy/cni", cniRequest, SocketPath(multusShimConfig.MultusSocketDir))
|
||||||
|
return err == nil, nil
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, multusShimConfig.CNIVersion, err
|
return nil, multusShimConfig.CNIVersion, err
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package config
|
package config
|
||||||
|
|
||||||
|
// disable dot-imports only for testing
|
||||||
|
//revive:disable:dot-imports
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
Loading…
Reference in New Issue
Block a user