-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix nil panic when SecurityProfile
is nil
#23392
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR @yangzuo0621.
I have a request to change where we nil check SecurityProfile
. If you can take a look at that when we can give this another look and get this merged.
Thanks!
if props.SecurityProfile == nil { | ||
props.SecurityProfile = &managedclusters.ManagedClusterSecurityProfile{} | ||
} | ||
customCaTrustCertList := flattenCustomCaTrustCerts(props.SecurityProfile.CustomCATrustCertificates) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We nil check SecurityProfile
at multiple points in the Read where we set security property values into state.
For consistency could we actually update flattenCustomCaTrustCerts
to do the nil check instead of doing a general one here
if props.SecurityProfile == nil { | |
props.SecurityProfile = &managedclusters.ManagedClusterSecurityProfile{} | |
} | |
customCaTrustCertList := flattenCustomCaTrustCerts(props.SecurityProfile.CustomCATrustCertificates) | |
customCaTrustCertList := flattenCustomCaTrustCerts(props.SecurityProfile) |
flattenCustomCaTrustCerts
would then become
func flattenCustomCaTrustCerts(input *managedclusters.ManagedClusterSecurityProfile) []interface{} {
if input == nil || input.CustomCATrustCertificates == nil {
return make([]interface{}, 0)
}
customCaTrustCertInterface := make([]interface{}, len(*input.CustomCATrustCertificates))
for index, value := range *input.CustomCATrustCertificates {
customCaTrustCertInterface[index] = value
}
return customCaTrustCertInterface
}
This PR is being labeled as "stale" because it has not been updated for 30 or more days. If this PR is still valid, please remove the "stale" label. If this PR is blocked, please add it to the "Blocked" milestone. If you need some help completing this PR, please leave a comment letting us know. Thank you! |
Since it's been over a month I looked into finalising this PR for you but stumbled onto some other issues with the I'm going to close this PR in favour of #23737. Thanks again for your contribution. |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
As not all clusters have property
SecurityProfile
, whenSecurityProfile
is nil, it will panic with nil pointer.