Skip to content

Commit

Permalink
Merge pull request #4256 from yastij/allow-defaulting-template
Browse files Browse the repository at this point in the history
🐛 Allow the defaulting of InstanceMetadataOptions to go through for AWSMachineTemplates
  • Loading branch information
k8s-ci-robot authored May 9, 2023
2 parents f9ac5c1 + 4b01746 commit e767f37
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
10 changes: 9 additions & 1 deletion api/v1beta2/awsmachinetemplate_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,15 @@ func (r *AWSMachineTemplateWebhook) ValidateUpdate(ctx context.Context, oldRaw r
var allErrs field.ErrorList

if !topology.ShouldSkipImmutabilityChecks(req, newAWSMachineTemplate) && !cmp.Equal(newAWSMachineTemplate.Spec, oldAWSMachineTemplate.Spec) {
allErrs = append(allErrs, field.Invalid(field.NewPath("spec"), newAWSMachineTemplate, "AWSMachineTemplate.Spec is immutable"))
if oldAWSMachineTemplate.Spec.Template.Spec.InstanceMetadataOptions == nil {
oldAWSMachineTemplate.Spec.Template.Spec.InstanceMetadataOptions = newAWSMachineTemplate.Spec.Template.Spec.InstanceMetadataOptions
}

if !cmp.Equal(newAWSMachineTemplate.Spec.Template.Spec, oldAWSMachineTemplate.Spec.Template.Spec) {
allErrs = append(allErrs,
field.Invalid(field.NewPath("spec", "template", "spec"), newAWSMachineTemplate, "AWSMachineTemplate.Spec is immutable"),
)
}
}

return aggregateObjErrors(newAWSMachineTemplate.GroupVersionKind().GroupKind(), newAWSMachineTemplate.Name, allErrs)
Expand Down
21 changes: 21 additions & 0 deletions api/v1beta2/awsmachinetemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ func TestAWSMachineTemplateValidateUpdate(t *testing.T) {
},
wantError: true,
},
{
name: "allow defaulted values to update",
modifiedTemplate: &AWSMachineTemplate{
ObjectMeta: metav1.ObjectMeta{},
Spec: AWSMachineTemplateSpec{
Template: AWSMachineTemplateResource{
Spec: AWSMachineSpec{
CloudInit: CloudInit{},
InstanceType: "test",
InstanceMetadataOptions: &InstanceMetadataOptions{
HTTPEndpoint: InstanceMetadataEndpointStateEnabled,
HTTPPutResponseHopLimit: 1,
HTTPTokens: HTTPTokensStateRequired,
InstanceMetadataTags: InstanceMetadataEndpointStateDisabled,
},
},
},
},
},
wantError: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit e767f37

Please sign in to comment.