diff --git a/.gitignore b/.gitignore index 5a8e8cf2..250f4bdd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /set-nas-status /nvidia-dra-controller /nvidia-dra-plugin +.idea [._]*.sw[a-p] diff --git a/cmd/nvidia-dra-plugin/device_state.go b/cmd/nvidia-dra-plugin/device_state.go index ca15c7ae..8e8ea2eb 100644 --- a/cmd/nvidia-dra-plugin/device_state.go +++ b/cmd/nvidia-dra-plugin/device_state.go @@ -169,7 +169,7 @@ func NewDeviceState(ctx context.Context, config *Config) (*DeviceState, error) { nvdevlib: nvdevlib, } - err = state.syncPreparedDevicesFromCRDSpec(ctx, &config.nascrd.Spec) + err = state.syncPreparedDevicesFromCRDSpec(ctx, &config.nascr.Spec) if err != nil { return nil, fmt.Errorf("unable to sync prepared devices from CRD: %w", err) } diff --git a/cmd/nvidia-dra-plugin/driver.go b/cmd/nvidia-dra-plugin/driver.go index a972658f..ac1b810c 100644 --- a/cmd/nvidia-dra-plugin/driver.go +++ b/cmd/nvidia-dra-plugin/driver.go @@ -38,15 +38,14 @@ const ( type driver struct { sync.Mutex - // TODO: Rename to nascr - nascrd *nascrd.NodeAllocationState + nascr *nascrd.NodeAllocationState nasclient *nasclient.Client state *DeviceState } func NewDriver(ctx context.Context, config *Config) (*driver, error) { var d *driver - client := nasclient.New(config.nascrd, config.clientset.Nvidia.NasV1alpha1()) + client := nasclient.New(config.nascr, config.clientsets.Nvidia.NasV1alpha1()) err := retry.RetryOnConflict(retry.DefaultRetry, func() error { err := client.GetOrCreate(ctx) if err != nil { @@ -63,7 +62,7 @@ func NewDriver(ctx context.Context, config *Config) (*driver, error) { return err } - err = client.Update(ctx, state.GetUpdatedSpec(&config.nascrd.Spec)) + err = client.Update(ctx, state.GetUpdatedSpec(&config.nascr.Spec)) if err != nil { return err } @@ -74,7 +73,7 @@ func NewDriver(ctx context.Context, config *Config) (*driver, error) { } d = &driver{ - nascrd: config.nascrd, + nascr: config.nascr, nasclient: client, state: state, } @@ -137,7 +136,7 @@ func (d *driver) IsPrepared(ctx context.Context, claimUID string) (bool, []strin if err != nil { return false, nil, err } - if _, exists := d.nascrd.Spec.PreparedClaims[claimUID]; exists { + if _, exists := d.nascr.Spec.PreparedClaims[claimUID]; exists { return true, d.state.cdi.GetClaimDevices(claimUID), nil } return false, nil, nil @@ -152,12 +151,12 @@ func (d *driver) Prepare(ctx context.Context, claimUID string) ([]string, error) return err } - prepared, err = d.state.Prepare(ctx, claimUID, d.nascrd.Spec.AllocatedClaims[claimUID]) + prepared, err = d.state.Prepare(ctx, claimUID, d.nascr.Spec.AllocatedClaims[claimUID]) if err != nil { return err } - err = d.nasclient.Update(ctx, d.state.GetUpdatedSpec(&d.nascrd.Spec)) + err = d.nasclient.Update(ctx, d.state.GetUpdatedSpec(&d.nascr.Spec)) if err != nil { return err } @@ -182,7 +181,7 @@ func (d *driver) Unprepare(ctx context.Context, claimUID string) error { return err } - err = d.nasclient.Update(ctx, d.state.GetUpdatedSpec(&d.nascrd.Spec)) + err = d.nasclient.Update(ctx, d.state.GetUpdatedSpec(&d.nascr.Spec)) if err != nil { return err } @@ -212,7 +211,7 @@ func (d *driver) CleanupStaleStateContinuously(ctx context.Context) { func (d *driver) cleanupStaleStateOnce(ctx context.Context) (string, error) { listOptions := metav1.ListOptions{ - FieldSelector: fmt.Sprintf("metadata.name=%s", d.nascrd.Name), + FieldSelector: fmt.Sprintf("metadata.name=%s", d.nascr.Name), } list, err := d.nasclient.List(ctx, listOptions) @@ -237,7 +236,7 @@ func (d *driver) cleanupStaleStateContinuously(ctx context.Context, resourceVers watchOptions := metav1.ListOptions{ Watch: true, ResourceVersion: resourceVersion, - FieldSelector: fmt.Sprintf("metadata.name=%s", d.nascrd.Name), + FieldSelector: fmt.Sprintf("metadata.name=%s", d.nascr.Name), } if previousError != nil { diff --git a/cmd/nvidia-dra-plugin/main.go b/cmd/nvidia-dra-plugin/main.go index d5adef66..c40b02ae 100644 --- a/cmd/nvidia-dra-plugin/main.go +++ b/cmd/nvidia-dra-plugin/main.go @@ -54,11 +54,9 @@ type Flags struct { } type Config struct { - flags *Flags - // TODO: Rename to nascr - nascrd *nascrd.NodeAllocationState - // TODO: Rename to clientsets - clientset flags.ClientSets + flags *Flags + nascr *nascrd.NodeAllocationState + clientsets flags.ClientSets } func main() { @@ -132,9 +130,9 @@ func newApp() *cli.App { } config := &Config{ - flags: flags, - nascrd: nascr, - clientset: clientSets, + flags: flags, + nascr: nascr, + clientsets: clientSets, } return StartPlugin(ctx, config) diff --git a/cmd/nvidia-dra-plugin/sharing.go b/cmd/nvidia-dra-plugin/sharing.go index 6262897f..9f177373 100644 --- a/cmd/nvidia-dra-plugin/sharing.go +++ b/cmd/nvidia-dra-plugin/sharing.go @@ -131,8 +131,8 @@ func NewMpsManager(config *Config, deviceLib *deviceLib, controlFilesRoot, hostD func (m *MpsManager) NewMpsControlDaemon(claim *nascrd.ClaimInfo, devices *PreparedDevices, config *nascrd.MpsConfig) *MpsControlDaemon { return &MpsControlDaemon{ - nodeName: m.config.nascrd.Name, - namespace: m.config.nascrd.Namespace, + nodeName: m.config.nascr.Name, + namespace: m.config.nascr.Namespace, name: fmt.Sprintf(MpsControlDaemonNameFmt, claim.UID), claim: claim, rootDir: fmt.Sprintf("%s/%s", m.controlFilesRoot, claim.UID), @@ -147,7 +147,7 @@ func (m *MpsManager) NewMpsControlDaemon(claim *nascrd.ClaimInfo, devices *Prepa func (m *MpsManager) IsControlDaemonStarted(ctx context.Context, claim *nascrd.ClaimInfo) (bool, error) { name := fmt.Sprintf(MpsControlDaemonNameFmt, claim.UID) - _, err := m.config.clientset.Core.AppsV1().Deployments(m.config.nascrd.Namespace).Get(ctx, name, metav1.GetOptions{}) + _, err := m.config.clientsets.Core.AppsV1().Deployments(m.config.nascr.Namespace).Get(ctx, name, metav1.GetOptions{}) if errors.IsNotFound(err) { return false, nil } @@ -159,7 +159,7 @@ func (m *MpsManager) IsControlDaemonStarted(ctx context.Context, claim *nascrd.C func (m *MpsManager) IsControlDaemonStopped(ctx context.Context, claim *nascrd.ClaimInfo) (bool, error) { name := fmt.Sprintf(MpsControlDaemonNameFmt, claim.UID) - _, err := m.config.clientset.Core.AppsV1().Deployments(m.config.nascrd.Namespace).Get(ctx, name, metav1.GetOptions{}) + _, err := m.config.clientsets.Core.AppsV1().Deployments(m.config.nascr.Namespace).Get(ctx, name, metav1.GetOptions{}) if errors.IsNotFound(err) { return true, nil } @@ -263,7 +263,7 @@ func (m *MpsControlDaemon) Start(ctx context.Context) error { } } - _, err = m.manager.config.clientset.Core.AppsV1().Deployments(m.namespace).Create(ctx, &deployment, metav1.CreateOptions{}) + _, err = m.manager.config.clientsets.Core.AppsV1().Deployments(m.namespace).Create(ctx, &deployment, metav1.CreateOptions{}) if errors.IsAlreadyExists(err) { return nil } @@ -289,7 +289,7 @@ func (m *MpsControlDaemon) AssertReady(ctx context.Context) error { return true }, func() error { - deployment, err := m.manager.config.clientset.Core.AppsV1().Deployments(m.namespace).Get( + deployment, err := m.manager.config.clientsets.Core.AppsV1().Deployments(m.namespace).Get( ctx, m.name, metav1.GetOptions{}, @@ -304,7 +304,7 @@ func (m *MpsControlDaemon) AssertReady(ctx context.Context) error { selector := deployment.Spec.Selector.MatchLabels - pods, err := m.manager.config.clientset.Core.CoreV1().Pods(m.namespace).List( + pods, err := m.manager.config.clientsets.Core.CoreV1().Pods(m.namespace).List( ctx, metav1.ListOptions{ LabelSelector: labels.Set(selector).AsSelector().String(), @@ -366,7 +366,7 @@ func (m *MpsControlDaemon) Stop(ctx context.Context) error { PropagationPolicy: &deletePolicy, } - err = m.manager.config.clientset.Core.AppsV1().Deployments(m.namespace).Delete(ctx, m.name, deleteOptions) + err = m.manager.config.clientsets.Core.AppsV1().Deployments(m.namespace).Delete(ctx, m.name, deleteOptions) if err != nil && !errors.IsNotFound(err) { return fmt.Errorf("failed to delete deployment: %w", err) }