-
Notifications
You must be signed in to change notification settings - Fork 67
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: missing status update in KMP controller #1761
Conversation
Codecov ReportAttention: Patch coverage is
|
isFetchSuccessful = true | ||
emptyErrorString := "" | ||
|
||
writeKMProviderStatus(ctx, r, &keyManagementProvider, logger, isFetchSuccessful, emptyErrorString, lastFetchedTime, status) |
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.
nit: we can remove line 122 and pass true directly, same to emptyErrorString
return ctrl.Result{}, err | ||
} | ||
|
||
config := map[string]interface{}{ |
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 can define a struct instead of creating a map.
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.
That would make things a bit easier. Great suggestion, I'll start working on converting the map to a struct.
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.
@binbin-li I've got some questions on how we could use a struct instead of a map and support other refresher types without pulling in refresher specific values into the controller logic. Or even if that's a necessary concern. I'll bring it up at the next community meeting. :)
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.
discussed in community meeting, see example at
Line 36 in 7519519
type VerificationResponse struct { |
} | ||
|
||
config := map[string]interface{}{ | ||
"type": refresherType, |
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.
nit: I would rename it to refresherType since we have another providerType
// Create creates a new KubeRefresher instance | ||
func (kr *KubeRefresher) Create(config map[string]interface{}) (Refresher, error) { | ||
client, ok := config["client"].(client.Client) | ||
provider, ok := config["provider"].(kmp.KeyManagementProvider) |
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.
Usually we need to check exist first and then do type assertion to avoid panic. But if we make config a struct instead of map, we could fetch it via config.Provider.
func (r *KeyManagementProviderReconciler) ReconcileWithType(ctx context.Context, req ctrl.Request, refresherType string) (ctrl.Result, error) { | ||
logger := logrus.WithContext(ctx) | ||
|
||
var resource = req.Name |
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.
QQ: Shall we use resource := req.Name
here
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.
Excellent catch, you have a keen eye @junczhu! Yes :=
should be used here.
// updateKMProviderErrorStatus updates the key management provider status with error, brief error and last fetched time | ||
func updateKMProviderErrorStatus(keyManagementProvider *configv1beta1.KeyManagementProvider, errorString string, operationTime *metav1.Time) { | ||
// truncate brief error string to maxBriefErrLength | ||
briefErr := errorString |
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.
actually we made some updates to the briefErr construction recently, could you help update it following the new pattern: https://github.com/ratify-project/ratify/blob/dev/pkg/controllers/clusterresource/policy_controller.go#L121
thanks!
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.
Done. :) I think I implemented it correctly.
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.
wonder if it's the latest commit, we can set briefErr
by:
keyManagementProvider.Status.BriefError = err.GetConciseError(constants.MaxBriefErrLength)
GetStatus() interface{} | ||
} | ||
|
||
type RefresherConfig struct { |
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.
nit: could add some comments to Exported
struct and fields
// updateKMProviderErrorStatus updates the key management provider status with error, brief error and last fetched time | ||
func updateKMProviderErrorStatus(keyManagementProvider *configv1beta1.KeyManagementProvider, errorString string, operationTime *metav1.Time) { | ||
// truncate brief error string to maxBriefErrLength | ||
briefErr := errorString |
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.
wonder if it's the latest commit, we can set briefErr
by:
keyManagementProvider.Status.BriefError = err.GetConciseError(constants.MaxBriefErrLength)
if err != nil { | ||
writeKMProviderStatus(ctx, r, &keyManagementProvider, logger, false, err.Error(), lastFetchedTime, nil) |
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.
probably we also need to set KMP errors since keys/certs are not fetched yet.
kmp.SetCertificateError(resource, kmpErr)
kmp.SetKeyError(resource, kmpErr)
@duffney PR lgtm, could you update commits to be verified so that we can merge it? |
Head branch was pushed to by a user without write access
Signed-off-by: akashsinghal <[email protected]>
Description
What this PR does / why we need it:
In this PR the
writeKMProviderStatus
and helper functions were moved from therefresher
back to the controller to ensure status messages get written to the KMP resource.Which issue(s) this PR fixes (optional, using
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when the PR gets merged):Fixes #
#1733
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Please also list any relevant details for your test configuration
Checklist:
Post Merge Requirements
Helm Chart Change