diff --git a/api/v1beta1/ibmvpcmachinetemplate_types.go b/api/v1beta1/ibmvpcmachinetemplate_types.go index 4c8fad894..25e42cfd9 100644 --- a/api/v1beta1/ibmvpcmachinetemplate_types.go +++ b/api/v1beta1/ibmvpcmachinetemplate_types.go @@ -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 diff --git a/controllers/ibmvpcmachinetemplate_controller.go b/controllers/ibmvpcmachinetemplate_controller.go index a76a5a803..88031f1e5 100644 --- a/controllers/ibmvpcmachinetemplate_controller.go +++ b/controllers/ibmvpcmachinetemplate_controller.go @@ -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 { @@ -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 { @@ -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) } diff --git a/controllers/ibmvpcmachinetemplate_controller_test.go b/controllers/ibmvpcmachinetemplate_controller_test.go index 98a547627..2d75391ac 100644 --- a/controllers/ibmvpcmachinetemplate_controller_test.go +++ b/controllers/ibmvpcmachinetemplate_controller_test.go @@ -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 {