Skip to content
14 changes: 6 additions & 8 deletions pkg/webhooks/machine_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ func (a awsDefaulter) defaultAWS(m *machinev1beta1.Machine, config *admissionCon

if providerSpec.UserDataSecret == nil {
providerSpec.UserDataSecret = &corev1.LocalObjectReference{Name: defaultUserDataSecret}
} else if providerSpec.UserDataSecret.Name == "" {
providerSpec.UserDataSecret.Name = defaultUserDataSecret
}

if providerSpec.CredentialsSecret == nil {
Expand Down Expand Up @@ -723,14 +725,10 @@ func validateAWS(m *machinev1beta1.Machine, config *admissionConfig) (bool, []st
)
}

if providerSpec.UserDataSecret == nil {
errs = append(
errs,
field.Required(
field.NewPath("providerSpec", "userDataSecret"),
"expected providerSpec.userDataSecret to be populated",
),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect we still want this, and the new validation. Though looking at the new defaulting, can we ever get here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @JoelSpeed
My understanding was that there's a test that is checking that we can remove completely:

userDataSecret:
name: xxxxx

That's why I have switched to validate only that the name cannot be empty if the sctructure exists that is what the ocpbugs states as improvement.

If I re-add those lines and there's a test removing the full userDataSecret information, we will have the failure.

if providerSpec.UserDataSecret != nil {
if providerSpec.UserDataSecret.Name == "" {
errs = append(errs, field.Required(field.NewPath("providerSpec", "userDataSecret", "name"), "name must be provided"))
}
}

if providerSpec.CredentialsSecret == nil {
Expand Down