Skip to content
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

Added SetDefault() for each Reconcile function #464

Merged
merged 1 commit into from
Jun 22, 2021
Merged

Added SetDefault() for each Reconcile function #464

merged 1 commit into from
Jun 22, 2021

Conversation

njtran
Copy link
Contributor

@njtran njtran commented Jun 18, 2021

Issue #, if available:
#463
Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@@ -76,6 +76,7 @@ func NewController(kubeClient client.Client, coreV1Client corev1.CoreV1Interface
// Reconcile executes an allocation control loop for the resource
func (c *Controller) Reconcile(ctx context.Context, object client.Object) (reconcile.Result, error) {
provisioner := object.(*v1alpha1.Provisioner)
provisioner.SetDefaults(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use the defaultable interface and put this in the generic controller?

if _, err := c.Controller.Reconcile(ctx, resource); err != nil {
zap.S().Errorf("Controller failed to reconcile kind %s, %s",
resource.GetObjectKind().GroupVersionKind().Kind, err.Error())
return reconcile.Result{Requeue: true}, nil
}
// 5. Update Status using a merge patch
// 6. Update Status using a merge patch
if !reflect.DeepEqual(resource, persisted) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated to your PR, but I realized the other day that we should be comparing statuses and patching statuses, or comparing objects and patching objects. This is currently mismatched: we compare the objects, but only patch the statuses. If resource has a changed spec, we'll send an empty patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Additionally, if we only update the status, this actually won't call the patch. I think until we have the statuses working, we should delete this line.

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM -- can you own this?

if _, ok := resource.(apis.Defaultable); ok {
resource.(apis.Defaultable).SetDefaults(ctx)
}
// 4. Set to true to remove race condition
// TODO: remove status conditions on provisioners
if provisioner, ok := resource.(*v1alpha1.Provisioner); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly, can you use the condition manager interface while you're in here? This would remove any special provisioner logic in this file.

@@ -72,7 +71,6 @@ var _ = Describe("Reallocation", func() {
},
Spec: v1alpha1.ProvisionerSpec{
Cluster: &v1alpha1.ClusterSpec{Name: "test-cluster", Endpoint: "http://test-cluster", CABundle: "dGVzdC1jbHVzdGVyCg=="},
TTLSeconds: ptr.Int32(300),
Copy link
Contributor

Choose a reason for hiding this comment

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

Does your test rely on the TTL behavior at all? Will it change tests to have nodes instantly deleted after underutilized?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the end of the first test in this suite, it checks to see if the TTL annotation is part of the node. Therefore, if our default logic fails here, the test will fail.

if provisioner, ok := resource.(*v1alpha1.Provisioner); ok {
provisioner.StatusConditions().MarkTrue(v1alpha1.Active)
if _, ok := resource.(apis.ConditionManager); ok {
resource.(apis.ConditionManager).SetCondition(apis.Condition{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can do

if conditionManager, ok := resource.(apis.ConditionManager); ok {
  conditionsManager.StatusConditions().MarkTrue(v1alpha1.Active)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the knative apis.ConditionManager interface does not have a StatusConditions() method.

ellistarn
ellistarn previously approved these changes Jun 21, 2021
@@ -49,22 +49,24 @@ func (c *GenericController) Reconcile(ctx context.Context, req reconcile.Request
}
// 2. Copy object for merge patch base
persisted := resource.DeepCopyObject()
// 3. Set to true to remove race condition
// 3. Set Defaults
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to explain why here - I could see eventually someone removes this code because they think it's redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Will do

if _, ok := resource.(apis.Defaultable); ok {
resource.(apis.Defaultable).SetDefaults(ctx)
}
// 4. Set to true to remove race condition
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is confusing - what race condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we have multiple controllers reconciling a provisioner, they can set the status of the provisioner to different statuses, where last write wins. We're setting this to true for now while we change what resources the controllers are reconciling. I'll add this in too to make it clearer.

@njtran njtran merged commit ba219bf into aws:main Jun 22, 2021
@njtran njtran deleted the fixDefaultRaceCondition branch July 1, 2021 19:54
gfcroft pushed a commit to gfcroft/karpenter-provider-aws that referenced this pull request Nov 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants