Skip to content

Commit

Permalink
DRA: Fix the comments of the review
Browse files Browse the repository at this point in the history
Signed-off-by: cyclinder <[email protected]>
  • Loading branch information
cyclinder committed Apr 10, 2024
1 parent d75b9c1 commit 94dc667
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 30 deletions.
3 changes: 2 additions & 1 deletion charts/spiderpool/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ data:
enableKubevirtStaticIP: {{ .Values.ipam.enableKubevirtStaticIP }}
enableSpiderSubnet: {{ .Values.ipam.enableSpiderSubnet }}
enableDRA: {{ .Values.dra.enabled }}
cdiRoot: {{ .Values.dra.cdiRoot }}
cdiRootPath: {{ .Values.dra.cdiRootPath }}
draLibraryPath: {{ .Values.dra.libraryPath }}
{{- if .Values.ipam.enableSpiderSubnet }}
clusterSubnetDefaultFlexibleIPNumber: {{ .Values.ipam.subnetDefaultFlexibleIPNumber }}
{{- else}}
Expand Down
6 changes: 2 additions & 4 deletions charts/spiderpool/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,6 @@ spec:
value: {{ .Values.spiderpoolAgent.httpPort | quote }}
- name: SPIDERPOOL_GOPS_LISTEN_PORT
value: {{ .Values.spiderpoolAgent.debug.gopsPort | quote }}
{{- if and .Values.dra.enabled .Values.dra.libraryPath }}
- name: SPIDERPOOL_DRA_LIBRARY_PATH
value: {{ .Values.dra.libraryPath }}
{{- end }}
{{- if .Values.multus.multusCNI.defaultCniCRName }}
- name: MULTUS_CLUSTER_NETWORK
value: {{ .Release.Namespace }}/{{ .Values.multus.multusCNI.defaultCniCRName }}
Expand All @@ -249,7 +245,9 @@ spec:
{{- end }}
{{- if or .Values.dra.enabled .Values.spiderpoolAgent.securityContext }}
securityContext:
{{- if .Values.dra.enabled }}
privileged: true
{{- end }}
{{- with .Values.spiderpoolAgent.securityContext }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down
6 changes: 3 additions & 3 deletions charts/spiderpool/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ multus:
dra:
## @param dra.enabled to enable dra feature
enabled: false
## @param dra.cdiRoot the dir of cdi root
cdiRoot: "/var/run/cdi"
## @param dra.libraryPath
## @param dra.cdiRootPath the dir of cdi root
cdiRootPath: "/var/run/cdi"
## @param dra.libraryPath the dir path of the library
libraryPath: ""

## @section plugins parameters
Expand Down
22 changes: 10 additions & 12 deletions cmd/spiderpool-agent/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ var envInfo = []envConf{
{"SPIDERPOOL_WAIT_SUBNET_POOL_MAX_RETRIES", "25", false, nil, nil, &agentContext.Cfg.WaitSubnetPoolMaxRetries},

{"MULTUS_CLUSTER_NETWORK", "", false, &agentContext.Cfg.MultusClusterNetwork, nil, nil},

{"SPIDERPOOL_DRA_LIBRARY_PATH", "", false, &agentContext.Cfg.LibraryPath, nil, nil},
}

type Config struct {
Expand All @@ -92,7 +90,6 @@ type Config struct {
MetricHttpPort string
GopsListenPort string
PyroscopeAddress string
LibraryPath string

IPPoolMaxAllocatedIPs int
WaitSubnetPoolTime int
Expand All @@ -101,15 +98,16 @@ type Config struct {
MultusClusterNetwork string

// configmap
IpamUnixSocketPath string `yaml:"ipamUnixSocketPath"`
EnableIPv4 bool `yaml:"enableIPv4"`
EnableIPv6 bool `yaml:"enableIPv6"`
EnableStatefulSet bool `yaml:"enableStatefulSet"`
EnableKubevirtStaticIP bool `yaml:"enableKubevirtStaticIP"`
EnableSpiderSubnet bool `yaml:"enableSpiderSubnet"`
EnableDRA bool `yaml:"enableDRA"`
DRACDIRoot string `yaml:"cdiRoot"`
ClusterSubnetDefaultFlexibleIPNum int `yaml:"clusterSubnetDefaultFlexibleIPNumber"`
IpamUnixSocketPath string `yaml:"ipamUnixSocketPath"`
EnableIPv4 bool `yaml:"enableIPv4"`
EnableIPv6 bool `yaml:"enableIPv6"`
EnableStatefulSet bool `yaml:"enableStatefulSet"`
EnableKubevirtStaticIP bool `yaml:"enableKubevirtStaticIP"`
EnableSpiderSubnet bool `yaml:"enableSpiderSubnet"`
EnableDRA bool `yaml:"enableDRA"`
DraCdiRootPath string `yaml:"cdiRootPath"`
DraLibraryPath []string `yaml:"draLibraryPath"`
ClusterSubnetDefaultFlexibleIPNum int `yaml:"clusterSubnetDefaultFlexibleIPNumber"`
}

type AgentContext struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/spiderpool-agent/cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ func DaemonMain() {
}
agentContext.unixClient = spiderpoolAgentAPI

if agentContext.Cfg.EnableDRA && agentContext.Cfg.LibraryPath != "" {
if agentContext.Cfg.EnableDRA {
logger.Info("Begin to start dra-plugin Server")
agentContext.DraPlugin, err = draplugin.StartDRAPlugin(logger, agentContext.Cfg.DRACDIRoot, agentContext.Cfg.LibraryPath)
agentContext.DraPlugin, err = draplugin.StartDRAPlugin(logger, agentContext.Cfg.DraCdiRootPath, agentContext.Cfg.DraLibraryPath)
if err != nil {
logger.Fatal(err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/dra/dra-controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func StartController(ctx context.Context,
}
}()

informerFactory.Start(ctx.Done())
informerFactory.Start(innerCtx.Done())
controller.Run(1)
}
}()
Expand Down
11 changes: 6 additions & 5 deletions pkg/dra/dra-plugin/cdi.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ func (cdi *CDIHandler) GetClaimDevices(claimUID string) []string {
return devices
}

// CreateClaimSpecFile create CDI file for the claim
func (cdi *CDIHandler) CreateClaimSpecFile(claimUID string, scp *v2beta1.SpiderClaimParameter) error {
cdiSpec := cdispec.Spec{
// TODO(@cyclinder): should be make it to configurable?
// TODO(@cyclinder): should make it to configurable?
Version: cdiapi.CurrentVersion,
Kind: cdi.cdiKind(),
Devices: []cdispec.Device{{
Name: claimUID,
ContainerEdits: cdi.getContaineEdits(claimUID, scp.Spec.Rdma),
ContainerEdits: cdi.getContaineEdits(claimUID, scp.Spec.RdmaAcc),
}},
}

Expand Down Expand Up @@ -122,8 +123,7 @@ func (cdi *CDIHandler) DeleteClaimSpecFile(claimUID string) error {
}

// nolint: all
func (cdi *CDIHandler) getContaineEdits(claim string, rdma bool) cdispec.ContainerEdits {
soName := path.Base(cdi.so)
func (cdi *CDIHandler) getContaineEdits(claim string, rdmaAcc bool) cdispec.ContainerEdits {
ce := cdispec.ContainerEdits{
// why do we need this?
// a device MUST be have at lease a ContainerEdits, so if rdma is false:
Expand All @@ -134,7 +134,8 @@ func (cdi *CDIHandler) getContaineEdits(claim string, rdma bool) cdispec.Contain
},
}

if rdma {
if rdmaAcc {
soName := path.Base(cdi.so)
ce.Env = append(ce.Env, fmt.Sprintf("LD_PRELOAD=%s", soName))
ce.Mounts = []*cdispec.Mount{
{
Expand Down
7 changes: 7 additions & 0 deletions pkg/dra/dra-plugin/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func NewDriver(logger *zap.Logger, cdiRoot string, so string) (*driver, error) {
}, nil
}

// NodePrepareResources prepares several ResourceClaims
// for use on the node. If an error is returned, the
// response is ignored. Failures for individual claims
// can be reported inside NodePrepareResourcesResponse.
func (d *driver) NodePrepareResources(ctx context.Context, req *drapbv1.NodePrepareResourcesRequest) (*drapbv1.NodePrepareResourcesResponse, error) {
d.logger.Info("NodePrepareResource is called")
preparedResources := &drapbv1.NodePrepareResourcesResponse{Claims: map[string]*drapbv1.NodePrepareResourceResponse{}}
Expand Down Expand Up @@ -95,6 +99,7 @@ func (d *driver) prepare(ctx context.Context, claim *drapbv1.Claim) ([]string, e
return err
}

// prepare CDI file for the claim
prepared, err = d.State.Prepare(ctx, claim.Uid, scp)
if err != nil {
return err
Expand All @@ -114,6 +119,8 @@ func (d *driver) isPrepared(ctx context.Context, claimUID string) (bool, []strin
return false, nil, nil
}

// NodeUnprepareResources is the opposite of NodePrepareResources.
// The same error handling rules apply
func (d *driver) NodeUnprepareResources(ctx context.Context, req *drapbv1.NodeUnprepareResourcesRequest) (*drapbv1.NodeUnprepareResourcesResponse, error) {
d.logger.Info("NodeUnprepareResources is called")
response := make(map[string]*drapbv1.NodeUnprepareResourceResponse, len(req.Claims))
Expand Down
2 changes: 1 addition & 1 deletion pkg/dra/dra-plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"k8s.io/dynamic-resource-allocation/kubeletplugin"
)

func StartDRAPlugin(logger *zap.Logger, cdiRoot, so string) (kubeletplugin.DRAPlugin, error) {
func StartDRAPlugin(logger *zap.Logger, cdiRoot string, so string) (kubeletplugin.DRAPlugin, error) {
err := os.MkdirAll(constant.DRADriverPluginPath, 0750)
if err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type ClaimParameterSpec struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default=false
Rdma bool `json:"rdma,omitempty"`
RdmaAcc bool `json:"rdma,omitempty"`

// +kubebuilder:validation:Optional
MultusNames []string `json:"multusNames,omitempty"`
Expand Down

0 comments on commit 94dc667

Please sign in to comment.