Skip to content

Commit b721c59

Browse files
committed
Apply review feedback
Signed-off-by: Borja Clemente <[email protected]>
1 parent 15706dd commit b721c59

File tree

6 files changed

+7
-25
lines changed

6 files changed

+7
-25
lines changed

api/v1beta2/tags.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"k8s.io/apimachinery/pkg/types"
2424
"k8s.io/apimachinery/pkg/util/validation/field"
2525

26-
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
26+
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
2727
)
2828

2929
// Tags defines a map of tags.
@@ -239,7 +239,7 @@ type BuildParams struct {
239239

240240
// WithMachineName tags the namespaced machine name
241241
// The machine name will be tagged with key "MachineName".
242-
func (b BuildParams) WithMachineName(m *clusterv1beta1.Machine) BuildParams {
242+
func (b BuildParams) WithMachineName(m *clusterv1.Machine) BuildParams {
243243
machineNamespacedName := types.NamespacedName{Namespace: m.Namespace, Name: m.Name}
244244
b.Additional[MachineNameTagKey] = machineNamespacedName.String()
245245
return b

controllers/awsmachine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func (r *AWSMachineReconciler) reconcileNormal(ctx context.Context, machineScope
509509
return ctrl.Result{}, nil
510510
}
511511

512-
if !*machineScope.Cluster.Status.Initialization.InfrastructureProvisioned {
512+
if !ptr.Deref(machineScope.Cluster.Status.Initialization.InfrastructureProvisioned, false) {
513513
machineScope.Info("Cluster infrastructure is not ready yet")
514514
v1beta1conditions.MarkFalse(machineScope.AWSMachine, infrav1.InstanceReadyCondition, infrav1.WaitingForClusterInfrastructureReason, clusterv1beta1.ConditionSeverityInfo, "")
515515
return ctrl.Result{}, nil

controlplane/eks/controllers/awsmanagedcontrolplane_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (r *AWSManagedControlPlaneReconciler) reconcileNormal(ctx context.Context,
314314
// infrastructureRef and controlplaneRef.
315315
if managedScope.Cluster.Spec.InfrastructureRef.Kind != awsManagedControlPlaneKind {
316316
// Wait for the cluster infrastructure to be ready before creating machines
317-
if !*managedScope.Cluster.Status.Initialization.InfrastructureProvisioned {
317+
if !ptr.Deref(managedScope.Cluster.Status.Initialization.InfrastructureProvisioned, false) {
318318
managedScope.Info("Cluster infrastructure is not ready yet")
319319
return ctrl.Result{RequeueAfter: r.WaitInfraPeriod}, nil
320320
}

exp/controllers/awsmachinepool_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/apimachinery/pkg/runtime/schema"
3333
"k8s.io/client-go/tools/record"
3434
"k8s.io/klog/v2"
35+
"k8s.io/utils/ptr"
3536
ctrl "sigs.k8s.io/controller-runtime"
3637
"sigs.k8s.io/controller-runtime/pkg/client"
3738
"sigs.k8s.io/controller-runtime/pkg/controller"
@@ -279,7 +280,7 @@ func (r *AWSMachinePoolReconciler) reconcileNormal(ctx context.Context, machineP
279280
}
280281
}
281282

282-
if !*machinePoolScope.Cluster.Status.Initialization.InfrastructureProvisioned {
283+
if !ptr.Deref(machinePoolScope.Cluster.Status.Initialization.InfrastructureProvisioned, false) {
283284
machinePoolScope.Info("Cluster infrastructure is not ready yet")
284285
v1beta1conditions.MarkFalse(machinePoolScope.AWSMachinePool, expinfrav1.ASGReadyCondition, infrav1.WaitingForClusterInfrastructureReason, clusterv1beta1.ConditionSeverityInfo, "")
285286
return ctrl.Result{}, nil

pkg/cloud/services/ec2/instances.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/record"
4141
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/utils"
4242
clusterv1beta1 "sigs.k8s.io/cluster-api/api/core/v1beta1"
43-
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
4443
)
4544

4645
// GetRunningInstanceByTags returns the existing instance or nothing if it doesn't exist.
@@ -124,19 +123,6 @@ func (s *Service) CreateInstance(ctx context.Context, scope *scope.MachineScope,
124123
NetworkInterfaceType: scope.AWSMachine.Spec.NetworkInterfaceType,
125124
}
126125

127-
if err := clusterv1beta1.AddToScheme(s.scheme); err != nil {
128-
return nil, fmt.Errorf("error adding clusterv1beta1 to schema for conversion: %s", err)
129-
}
130-
if err := clusterv1.AddToScheme(s.scheme); err != nil {
131-
return nil, fmt.Errorf("error adding clusterv1 to schema for conversion: %s", err)
132-
}
133-
134-
var v1beta1Machine clusterv1beta1.Machine
135-
// Convert v1beta1 to v1beta2
136-
if err := s.scheme.Convert(scope.Machine, &v1beta1Machine, nil); err != nil {
137-
return nil, fmt.Errorf("error converting v1beta2.Machine to v1beta1.Machine: %s", err)
138-
}
139-
140126
// Make sure to use the MachineScope here to get the merger of AWSCluster and AWSMachine tags
141127
additionalTags := scope.AdditionalTags()
142128
input.Tags = infrav1.Build(infrav1.BuildParams{
@@ -145,7 +131,7 @@ func (s *Service) CreateInstance(ctx context.Context, scope *scope.MachineScope,
145131
Name: aws.String(scope.Name()),
146132
Role: aws.String(scope.Role()),
147133
Additional: additionalTags,
148-
}.WithCloudProvider(s.scope.KubernetesClusterName()).WithMachineName(&v1beta1Machine))
134+
}.WithCloudProvider(s.scope.KubernetesClusterName()).WithMachineName(scope.Machine))
149135

150136
var err error
151137

pkg/cloud/services/ec2/service.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ limitations under the License.
1818
package ec2
1919

2020
import (
21-
"k8s.io/apimachinery/pkg/runtime"
22-
2321
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/scope"
2422
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/common"
2523
"sigs.k8s.io/cluster-api-provider-aws/v2/pkg/cloud/services/network"
@@ -40,8 +38,6 @@ type Service struct {
4038
// RetryEC2Client is used for dedicated host operations with enhanced retry configuration
4139
// If nil, a new retry client will be created as needed
4240
RetryEC2Client common.EC2API
43-
44-
scheme *runtime.Scheme
4541
}
4642

4743
// NewService returns a new service given the ec2 api client.
@@ -51,6 +47,5 @@ func NewService(clusterScope scope.EC2Scope) *Service {
5147
EC2Client: scope.NewEC2Client(clusterScope, clusterScope, clusterScope, clusterScope.InfraCluster()),
5248
SSMClient: scope.NewSSMClient(clusterScope, clusterScope, clusterScope, clusterScope.InfraCluster()),
5349
netService: network.NewService(clusterScope.(scope.NetworkScope)),
54-
scheme: runtime.NewScheme(),
5550
}
5651
}

0 commit comments

Comments
 (0)