Skip to content

Commit

Permalink
fix: nci env pcislot only from the template name
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiGuranIonos committed Jul 11, 2024
1 parent dff7aba commit 6465798
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions internal/controller/serverset/bootvolume_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,12 @@ func setPatcher(ctx context.Context, cr *v1alpha1.ServerSet, replicaIndex int, n

func setPCINICSlotEnv(ctx context.Context, nics []v1alpha1.ServerSetTemplateNIC, serversetName string, replicaIndex int, kube client.Client, userDataPatcher ccpatch.CloudInitPatcher) error {
for nicIndex := range nics {
nicName, pciSlot, err := getNameAndPCISlotFromNIC(ctx, kube, serversetName, replicaIndex, nicIndex)
pciSlot, err := getPCISlotFromNIC(ctx, kube, serversetName, replicaIndex, nicIndex)
if err != nil {
return err
}
if nicName != "" {
const nicPCISlotPrefix = "nic-pcislot-"
userDataPatcher.SetEnv(nicPCISlotPrefix+nicName, strconv.Itoa(int(pciSlot)))
}
const nicPCISlotSuffix = "-nic-pcislot"
userDataPatcher.SetEnv(nics[nicIndex].Name+nicPCISlotSuffix, strconv.Itoa(int(pciSlot)))
}
return nil
}
Expand Down
8 changes: 4 additions & 4 deletions internal/controller/serverset/nic_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,17 @@ func (k *kubeNicController) ensure(ctx context.Context, cr *v1alpha1.ServerSet,
return nil
}

func getNameAndPCISlotFromNIC(ctx context.Context, kube client.Client, serversetName string, replicaIndex, nicIndex int) (name string, pciSlot int32, err error) {
func getPCISlotFromNIC(ctx context.Context, kube client.Client, serversetName string, replicaIndex, nicIndex int) (pciSlot int32, err error) {
obj := &v1alpha1.NicList{}
err = kube.List(ctx, obj, client.MatchingLabels{
fmt.Sprintf(indexLabel, serversetName, resourceNIC): strconv.Itoa(replicaIndex),
fmt.Sprintf(nicIndexLabel, serversetName, resourceNIC): fmt.Sprintf("%d", nicIndex),
})
if err != nil {
return "", 0, err
return 0, err
}
if len(obj.Items) > 0 {
return obj.Items[0].Spec.ForProvider.Name, obj.Items[0].Status.AtProvider.PCISlot, nil
return obj.Items[0].Status.AtProvider.PCISlot, nil
}
return "", 0, fmt.Errorf("no nics found for serversetName %s and replicaIndex %d", serversetName, replicaIndex)
return 0, fmt.Errorf("no nics found for serversetName %s and replicaIndex %d", serversetName, replicaIndex)
}

0 comments on commit 6465798

Please sign in to comment.