Skip to content

Commit 975b9c4

Browse files
committed
tmp
1 parent 3294a57 commit 975b9c4

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

exp/controllers/rosamachinepool_controller.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,28 @@ func (r *ROSAMachinePoolReconciler) reconcileNormal(ctx context.Context,
202202

203203
failureMessage, err := validateMachinePoolSpec(machinePoolScope)
204204
if err != nil {
205+
205206
return ctrl.Result{}, fmt.Errorf("failed to validate ROSAMachinePool.spec: %w", err)
206207
}
207208
if failureMessage != nil {
208-
machinePoolScope.RosaMachinePool.Status.FailureMessage = failureMessage
209+
// fmt.Println("FAIL", machinePoolScope.RosaMachinePool.Name)
210+
211+
// machinePoolScope.RosaMachinePool.Status.FailureMessage = failureMessage
212+
// conditions.MarkFalse(machinePoolScope.RosaMachinePool,
213+
// expinfrav1.RosaMachinePoolReadyCondition,
214+
// expinfrav1.RosaMachinePoolReconciliationFailedReason,
215+
// clusterv1.ConditionSeverityError,
216+
// "failed to create ROSAMachinePool: %s", *failureMessage)
217+
// machinePoolScope.Close()
218+
// annotations.AddAnnotations(machinePoolScope.RosaMachinePool, map[string]string{
219+
// clusterv1.ReplicasManagedByAnnotation: "rosa",
220+
// })
221+
// if err := machinePoolScope.PatchRosaMachinePoolObject(ctx); err != nil {
222+
// fmt.Println("ERRRRR PatchRosaMachinePoolObject", err.Error())
223+
// return ctrl.Result{}, err
224+
// }
225+
// machinePoolScope.Patch(ctx, machinePoolScope.RosaMachinePool)
226+
// r.Status().Update(ctx, machinePoolScope.RosaMachinePool)
209227
// dont' requeue because input is invalid and manual intervention is needed.
210228
return ctrl.Result{}, nil
211229
}

exp/controllers/rosamachinepool_controller_test.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package controllers
22

33
import (
44
"context"
5+
"fmt"
56
"testing"
67
"time"
78

@@ -174,12 +175,18 @@ func TestRosaMachinePoolReconcile(t *testing.T) {
174175
ObjectMeta: metav1.ObjectMeta{
175176
Name: "rosa-machinepool",
176177
Namespace: ns.Name,
178+
UID: "rosa-machinepool-1",
177179
},
178180
TypeMeta: metav1.TypeMeta{
179181
Kind: "ROSAMachinePool",
180182
APIVersion: expinfrav1.GroupVersion.String(),
181183
},
182-
Spec: expinfrav1.RosaMachinePoolSpec{},
184+
Spec: expinfrav1.RosaMachinePoolSpec{
185+
NodePoolName: "test-nodepool",
186+
Version: "4.14.5",
187+
Subnet: "subnet-id",
188+
InstanceType: "m5.large",
189+
},
183190
}
184191

185192
ownerMachinePool = &expclusterv1.MachinePool{
@@ -220,7 +227,7 @@ func TestRosaMachinePoolReconcile(t *testing.T) {
220227
},
221228
}
222229

223-
objects = []client.Object{secret, ownerCluster, ownerMachinePool}
230+
objects = []client.Object{secret, ownerCluster, ownerMachinePool, rosaMachinePool}
224231

225232
for _, obj := range objects {
226233
createObject(g, obj, ns.Name)
@@ -267,8 +274,16 @@ func TestRosaMachinePoolReconcile(t *testing.T) {
267274
req.NamespacedName = types.NamespacedName{Name: "rosa-machinepool", Namespace: ns.Name}
268275

269276
result, err := r.Reconcile(ctx, req)
277+
m := &expinfrav1.ROSAMachinePool{}
278+
// key := client.ObjectKey{Name: ownerMachinePool.Name, Namespace: ns.Name}
279+
key := client.ObjectKey{Name: rosaMachinePool.Name, Namespace: ns.Name}
280+
281+
c.Get(ctx, key, m)
282+
fmt.Println("Aaaaaaaaaaaaaaaaa", m.Status, m.Annotations, m.GetAnnotations())
283+
// g.Expect(m.Annotations).To(Equal(map[string]string{"cluster.x-k8s.io/replicas-managed-by": "rosa"}))
270284

271285
g.Expect(err).ToNot(HaveOccurred())
286+
272287
g.Expect(result).To(Equal(ctrl.Result{}))
273288
})
274289

exp/controllers/suite_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ import (
2121
"path"
2222
"testing"
2323

24+
corev1 "k8s.io/api/core/v1"
2425
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2526
"k8s.io/client-go/kubernetes/scheme"
2627
ctrl "sigs.k8s.io/controller-runtime"
2728

2829
// +kubebuilder:scaffold:imports
2930
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
31+
rosacontrolplanev1 "sigs.k8s.io/cluster-api-provider-aws/v2/controlplane/rosa/api/v1beta2"
3032
expinfrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/exp/api/v1beta2"
3133
"sigs.k8s.io/cluster-api-provider-aws/v2/test/helpers"
3234
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -52,6 +54,8 @@ func setup() {
5254
utilruntime.Must(clusterv1.AddToScheme(scheme.Scheme))
5355
utilruntime.Must(expinfrav1.AddToScheme(scheme.Scheme))
5456
utilruntime.Must(expclusterv1.AddToScheme(scheme.Scheme))
57+
utilruntime.Must(corev1.AddToScheme(scheme.Scheme))
58+
utilruntime.Must(rosacontrolplanev1.AddToScheme(scheme.Scheme))
5559
testEnvConfig := helpers.NewTestEnvironmentConfiguration([]string{
5660
path.Join("config", "crd", "bases"),
5761
},
@@ -76,6 +80,12 @@ func setup() {
7680
if err := (&expinfrav1.AWSManagedMachinePool{}).SetupWebhookWithManager(testEnv); err != nil {
7781
panic(fmt.Sprintf("Unable to setup AWSManagedMachinePool webhook: %v", err))
7882
}
83+
if err := (&expinfrav1.ROSAMachinePool{}).SetupWebhookWithManager(testEnv); err != nil {
84+
panic(fmt.Sprintf("Unable to setup ROSAMachinePool webhook: %v", err))
85+
}
86+
if err := (&rosacontrolplanev1.ROSAControlPlane{}).SetupWebhookWithManager(testEnv); err != nil {
87+
panic(fmt.Sprintf("Unable to setup ROSAMachinePool webhook: %v", err))
88+
}
7989
go func() {
8090
fmt.Println("Starting the manager")
8191
if err := testEnv.StartManager(ctx); err != nil {

pkg/cloud/scope/rosamachinepool.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ func (s *RosaMachinePoolScope) PatchCAPIMachinePoolObject(ctx context.Context) e
227227
)
228228
}
229229

230+
func (s *RosaMachinePoolScope) PatchRosaMachinePoolObject(ctx context.Context) error {
231+
return s.patchHelper.Patch(
232+
ctx,
233+
s.RosaMachinePool,
234+
)
235+
}
236+
230237
// Close closes the current scope persisting the control plane configuration and status.
231238
func (s *RosaMachinePoolScope) Close() error {
232239
return s.PatchObject()

0 commit comments

Comments
 (0)