8000 Fix for final inventory update by seans3 · Pull Request #319 · kubernetes-sigs/cli-utils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix for final inventory update #319

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

Merged
merged 1 commit into from
Feb 1, 2021

Conversation

seans3
Copy link
Contributor
@seans3 seans3 commented Jan 26, 2021
  • Updates the Prune function to correctly store the final inventory items. These items are:
    1. the successfully applied objects
    2. the prune failures
  • Fixes error where unsuccessfully applied objects were included in the final inventory.
  • Adds to Prune unit test to validate the final inventory stored is correct.
  • Small clean-up for TaskContext in apply_task to ensure only successfully applied objects are added to context.
  • Many new debug logging statements.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 26, 2021
@seans3 seans3 requested a review from mortent January 26, 2021 06:37
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: seans3

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 26, 2021
@seans3 seans3 removed the request for review from soltysh January 26, 2021 06:37
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 26, 2021
Copy link
Contributor
@Liujingfang1 Liujingfang1 left a comment

Choose a reason for hiding this comment

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

Overall looks good to me.

}
})
}
}
}

// unionObjects returns the union of sliceA and sliceB as a slice of unstructured objects.
Copy link
Contributor

Choose a reason for hiding this comment

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

If both sliceA and sliceB contains the unstructured object with the same ObjMeta, the one from sliceB is taken.

localIds = append(localIds, clusterObj)
klog.V(4).Infof("skip prune for lifecycle directive %s/%s", pruneObj.Namespace, pruneObj.Name)
taskContext.EventChannel() <- createPruneEvent(pruneObj, obj, event.PruneSkipped)
pruneFailures = append(pruneFailures, pruneObj)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add a comment here for why adding it to pruneFailures. It's actually not a failure, we want to use pruneFailures to keep it in the final inventory list.

continue
}
err = namespacedClient.Delete(context.TODO(), pruneObj.Name, metav1.DeleteOptions{})
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

The error handling here is the same as the one after namespacedClient, err := po.namespacedClient(pruneObj). We can combine the getting client and deleting the object into one function, like what you have done for getObject. The new function can be deleteObject.

@mortent
Copy link
Member
mortent commented Jan 27, 2021

So overall looks good, but I want to understand how we decide whether a resource that we failed to apply should be included in the inventory or not. I want to make sure that a situation where a resource already exists in the cluster and apply (which in this case would be an update/patch) fails, we don't end up orphaning the resource. I don't think this were among the testcases.

@seans3
Copy link
Contributor Author
seans3 commented Feb 1, 2021

So overall looks good, but I want to understand how we decide whether a resource that we failed to apply should be included in the inventory or not. I want to make sure that a situation where a resource already exists in the cluster and apply (which in this case would be an update/patch) fails, we don't end up orphaning the resource. I don't think this were among the testcases.

We had an informative discussion about this corner case, and we believe we know a way forward to make the final inventory storage step even more error tolerant. This PR is strictly better than before, so we will merge this current PR. The improvements to the algorithm will be instituted in a future PR. The following is documentation of our discussion to further improve the final inventory calculation.

The apply operation currently does a get before the apply. From these operations we believe we have the information necessary to pass to the Step 4 final inventory (through the TaskContext) to improve its error tolerance. Currently, we are only storing the UID of successfully applied objects. We will enhance this data structure according to the following decision tree.

  1. If we are able to successfully get the object, and the apply succeeds, the o 8000 bject remains in the inventory.
  2. If we are able to successfully get the object, but the apply fails, then we know it exists in the cluster, and it should therefore remain in the inventory.
  3. If the get fails with a Not Found error, then we know the item is not in the cluster. This is considered an initial creation. If the apply succeeds for this initial creation, then it will be added to the final inventory. If the apply fails it will not be added to the final inventory because it is not in the cluster.
  4. If the get fails with a different error, then we check if the item was in the previous inventory.
    a. If the item was in the previous inventory, then we assume it is still in the cluster and we keep it in the inventory
    b. If the item was not in the previous inventory, then we can confidently assume it is not in the cluster and we do not add it to the inventory.

Implementing this decision tree (in a future PR) would have two prerequisites:

  1. We need to store more than UIDs for successful applies in the TaskContext. We would probably have to store a Map<ObjMetadata, UID> for all objects we intend to store in the final inventory.
  2. We would need to pass the set of previous inventory into the apply step, since we do not keep this separate after the initial union inventory storage.

Implementing this decision tree would allow us to remove the final get iteration on all currently applied objects in the Step 4 final inventory calculation.

@Liujingfang1
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 1, 2021
@k8s-ci-robot k8s-ci-robot merged commit 152b41c into kubernetes-sigs:master Feb 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0