@@ -82,23 +82,25 @@ func (n Validation) Reconcile(ctx context.Context, nodeClass *v1.EC2NodeClass) (
82
82
createFleetInput .DryRun = aws .Bool (true )
83
83
84
84
if _ , err := n .ec2api .CreateFleet (ctx , createFleetInput ); awserrors .IgnoreDryRunError (err ) != nil {
85
- nodeClass .StatusConditions ().SetFalse (v1 .ConditionTypeValidationSucceeded , "CreateFleetAuthCheckFailed" , "Controller isn't authorized to call CreateFleet" )
86
85
if awserrors .IgnoreUnauthorizedOperationError (err ) != nil {
86
+ // Dry run should only ever return UnauthorizedOperation or DryRunOperation so if we receive any other error
87
+ // it would be an unexpected state
87
88
return reconcile.Result {}, fmt .Errorf ("unexpected error during CreateFleet validation: %w" , err )
88
89
}
90
+ nodeClass .StatusConditions ().SetFalse (v1 .ConditionTypeValidationSucceeded , "CreateFleetAuthCheckFailed" , "Controller isn't authorized to call CreateFleet" )
89
91
return reconcile.Result {}, nil
90
92
}
91
93
92
94
createLaunchTemplateInput := launchtemplate .GetCreateLaunchTemplateInput (mockOptions (* nodeClaim , nodeClass , tags ), corev1 .IPv4Protocol , "" )
93
95
createLaunchTemplateInput .DryRun = aws .Bool (true )
94
96
95
97
if _ , err := n .ec2api .CreateLaunchTemplate (ctx , createLaunchTemplateInput ); awserrors .IgnoreDryRunError (err ) != nil {
96
- nodeClass .StatusConditions ().SetFalse (v1 .ConditionTypeValidationSucceeded , "CreateLaunchTemplateAuthCheckFailed" , "Controller isn't authorized to call CreateLaunchTemplate" )
97
98
if awserrors .IgnoreUnauthorizedOperationError (err ) != nil {
98
99
// Dry run should only ever return UnauthorizedOperation or DryRunOperation so if we receive any other error
99
100
// it would be an unexpected state
100
101
return reconcile.Result {}, fmt .Errorf ("unexpected error during CreateLaunchTemplate validation: %w" , err )
101
102
}
103
+ nodeClass .StatusConditions ().SetFalse (v1 .ConditionTypeValidationSucceeded , "CreateLaunchTemplateAuthCheckFailed" , "Controller isn't authorized to call CreateLaunchTemplate" )
102
104
return reconcile.Result {}, nil
103
105
}
104
106
@@ -108,19 +110,18 @@ func (n Validation) Reconcile(ctx context.Context, nodeClass *v1.EC2NodeClass) (
108
110
}
109
111
110
112
var instanceType ec2types.InstanceType
111
- if len (nodeClass .Status .AMIs ) > 0 {
112
- requirements := scheduling .NewRequirements (lo .Map (nodeClass .Status .AMIs [0 ].Requirements , func (req corev1.NodeSelectorRequirement , _ int ) * scheduling.Requirement {
113
- return scheduling .NewRequirement (req .Key , req .Operator , req .Values ... )
114
- })... )
115
-
116
- if arch := requirements .Get ("kubernetes.io/arch" ); len (arch .Values ()) > 0 {
117
- switch arch .Values ()[0 ] {
118
- case "amd64" :
119
- instanceType = ec2types .InstanceTypeM5Large
120
- case "arm64" :
121
- instanceType = ec2types .InstanceTypeM6gLarge
122
- }
113
+ requirements := scheduling .NewNodeSelectorRequirements (lo .Map (nodeClass .Status .AMIs [0 ].Requirements , func (req corev1.NodeSelectorRequirement , _ int ) corev1.NodeSelectorRequirement {
114
+ return corev1.NodeSelectorRequirement {
115
+ Key : req .Key ,
116
+ Operator : req .Operator ,
117
+ Values : req .Values ,
123
118
}
119
+ })... )
120
+
121
+ if requirements .Get (corev1 .LabelArchStable ).Has (karpv1 .ArchitectureAmd64 ) {
122
+ instanceType = ec2types .InstanceTypeM5Large
123
+ } else if requirements .Get (corev1 .LabelArchStable ).Has (karpv1 .ArchitectureArm64 ) {
124
+ instanceType = ec2types .InstanceTypeM6gLarge
124
125
}
125
126
126
127
runInstancesInput := & ec2.RunInstancesInput {
@@ -129,9 +130,11 @@ func (n Validation) Reconcile(ctx context.Context, nodeClass *v1.EC2NodeClass) (
129
130
MinCount : aws .Int32 (1 ),
130
131
InstanceType : instanceType ,
131
132
MetadataOptions : & ec2types.InstanceMetadataOptionsRequest {
132
- HttpTokens : ec2types .HttpTokensStateRequired ,
133
- HttpEndpoint : ec2types .InstanceMetadataEndpointStateDisabled ,
134
- HttpPutResponseHopLimit : aws .Int32 (2 ),
133
+ HttpEndpoint : ec2types .InstanceMetadataEndpointState (lo .FromPtr (nodeClass .Spec .MetadataOptions .HTTPEndpoint )),
134
+ HttpTokens : ec2types .HttpTokensState (lo .FromPtr (nodeClass .Spec .MetadataOptions .HTTPTokens )),
135
+ //aws sdk v2 changed this type to *int32 instead of *int64
136
+ //nolint: gosec
137
+ HttpPutResponseHopLimit : aws .Int32 (int32 (lo .FromPtr (nodeClass .Spec .MetadataOptions .HTTPPutResponseHopLimit ))),
135
138
},
136
139
TagSpecifications : []ec2types.TagSpecification {
137
140
{
@@ -151,12 +154,12 @@ func (n Validation) Reconcile(ctx context.Context, nodeClass *v1.EC2NodeClass) (
151
154
}
152
155
153
156
if _ , err = n .ec2api .RunInstances (ctx , runInstancesInput ); awserrors .IgnoreDryRunError (err ) != nil {
154
- nodeClass .StatusConditions ().SetFalse (v1 .ConditionTypeValidationSucceeded , "RunInstancesAuthCheckFailed" , "Controller isn't authorized to call RunInstances" )
155
157
if awserrors .IgnoreUnauthorizedOperationError (err ) != nil {
156
158
// Dry run should only ever return UnauthorizedOperation or DryRunOperation so if we receive any other error
157
159
// it would be an unexpected state
158
160
return reconcile.Result {}, fmt .Errorf ("unexpected error during RunInstances validation: %w" , err )
159
161
}
162
+ nodeClass .StatusConditions ().SetFalse (v1 .ConditionTypeValidationSucceeded , "RunInstancesAuthCheckFailed" , "Controller isn't authorized to call RunInstances" )
160
163
return reconcile.Result {}, nil
161
164
}
162
165
nodeClass .StatusConditions ().SetTrue (v1 .ConditionTypeValidationSucceeded )
@@ -195,7 +198,7 @@ func mockOptions(nodeClaim karpv1.NodeClaim, nodeClass *v1.EC2NodeClass, tags ma
195
198
HTTPEndpoint : nodeClass .Spec .MetadataOptions .HTTPEndpoint ,
196
199
HTTPTokens : nodeClass .Spec .MetadataOptions .HTTPTokens ,
197
200
HTTPProtocolIPv6 : nodeClass .Spec .MetadataOptions .HTTPProtocolIPv6 ,
198
- HTTPPutResponseHopLimit : aws . Int64 ( 1 ) ,
201
+ HTTPPutResponseHopLimit : nodeClass . Spec . MetadataOptions . HTTPPutResponseHopLimit ,
199
202
},
200
203
AMIID : nodeClaim .Status .ImageID ,
201
204
BlockDeviceMappings : nodeClass .Spec .BlockDeviceMappings ,
0 commit comments