Skip to content

Commit

Permalink
Removed duplicate and updated error message
Browse files Browse the repository at this point in the history
  • Loading branch information
KeerthanaAP committed Dec 14, 2023
1 parent db680d5 commit 6776eb5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 0 additions & 2 deletions api/v1beta1/ibmvpcmachinetemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ type IBMVPCMachineTemplateStatus struct {
// Important: Run "make" to regenerate code after modifying this file
}

// +kubebuilder:object:root=true

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=ibmvpcmachinetemplates,scope=Namespaced,categories=cluster-api

Expand Down
17 changes: 14 additions & 3 deletions controllers/ibmvpcmachinetemplate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (r *IBMVPCMachineTemplateReconciler) SetupWithManager(mgr ctrl.Manager) err

func (r *IBMVPCMachineTemplateReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := ctrl.LoggerFrom(ctx)
log.V(1).Info("Reconciling IBMVPCMachineTemplate")
log.Info("Reconciling IBMVPCMachineTemplate")

var machineTemplate infrav1beta2.IBMVPCMachineTemplate
if err := r.Get(ctx, req.NamespacedName, &machineTemplate); err != nil {
Expand Down Expand Up @@ -88,6 +88,18 @@ func (r *IBMVPCMachineTemplateReconciler) Reconcile(ctx context.Context, req ctr

func getIBMVPCMachineCapacity(machineTemplate infrav1beta2.IBMVPCMachineTemplate) (corev1.ResourceList, error) {
capacity := make(corev1.ResourceList)
// VPC profile will be in the below pattern
// PATTERN: "Alpha numeric value followed by '-' decimal which indicates cpu followed by 'x' followed by decimal which indicates memory and might be followed by GPU "
// Examples :
// 1. VPC profile with GPU = 'gx2-32x256x2v100'
// CPU = 32
// Memory = 256G
// Capacity = {cpu: "32", memory: "256G" }
// 2. VPC profile without GPU = 'cx2d-16x32'
// CPU = 16
// Memory = 32G
// Capacity = {cpu: "16", memory: "32G" }

regex := "\\S+[-]\\d+[x]\\d+\\S*$"
re, err := regexp.Compile(regex)
if err != nil {
Expand All @@ -97,8 +109,7 @@ func getIBMVPCMachineCapacity(machineTemplate infrav1beta2.IBMVPCMachineTemplate
Profile := strings.Split(strings.Split(machineTemplate.Spec.Template.Spec.Profile, "-")[1], "x")
capacity[corev1.ResourceCPU] = resource.MustParse(Profile[0])
capacity[corev1.ResourceMemory] = resource.MustParse(fmt.Sprintf("%sG", Profile[1]))
fmt.Printf("capacity : %+v", capacity)
return capacity, nil
}
return nil, fmt.Errorf("invalid Profile")
return nil, fmt.Errorf("failed to find capacity for profile %s", machineTemplate.Spec.Template.Spec.Profile)
}
2 changes: 1 addition & 1 deletion controllers/ibmvpcmachinetemplate_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestGetIBMVPCMachineCapacity(t *testing.T) {
capacity, err := getIBMVPCMachineCapacity(tc.VPCMachineTemplate)
if tc.expectErr {
if err == nil {
t.Fatal("getIBMPowerVSMachineCapacity expected to return an error")
t.Fatal("getIBMVPCMachineCapacity expected to return an error")
}
} else {
if err != nil {
Expand Down

0 comments on commit 6776eb5

Please sign in to comment.