-
Notifications
You must be signed in to change notification settings - Fork 213
Bug 1984414: Log resource diffs on update only in reconcile mode #628
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
openshift-merge-robot
merged 1 commit into
openshift:master
from
arjunrn:reconcile-log-resource-diff
Jul 22, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,19 +3,18 @@ package resourceapply | |
| import ( | ||
| "context" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| "github.com/openshift/cluster-version-operator/lib/resourcemerge" | ||
| appsv1 "k8s.io/api/apps/v1" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/util/diff" | ||
| appsclientv1 "k8s.io/client-go/kubernetes/typed/apps/v1" | ||
| appslisterv1 "k8s.io/client-go/listers/apps/v1" | ||
| "k8s.io/klog/v2" | ||
| "k8s.io/utils/pointer" | ||
| ) | ||
|
|
||
| // ApplyDeploymentv1 applies the required deployment to the cluster. | ||
| func ApplyDeploymentv1(ctx context.Context, client appsclientv1.DeploymentsGetter, required *appsv1.Deployment) (*appsv1.Deployment, bool, error) { | ||
| func ApplyDeploymentv1(ctx context.Context, client appsclientv1.DeploymentsGetter, required *appsv1.Deployment, reconciling bool) (*appsv1.Deployment, bool, error) { | ||
| existing, err := client.Deployments(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{}) | ||
| if apierrors.IsNotFound(err) { | ||
| klog.V(2).Infof("Deployment %s/%s not found, creating", required.Namespace, required.Name) | ||
|
|
@@ -35,42 +34,16 @@ func ApplyDeploymentv1(ctx context.Context, client appsclientv1.DeploymentsGette | |
| if !*modified { | ||
| return existing, false, nil | ||
| } | ||
| klog.V(2).Infof("Updating Deployment %s/%s due to diff: %v", required.Namespace, required.Name, diff.ObjectDiff(existing, required)) | ||
|
|
||
| actual, err := client.Deployments(required.Namespace).Update(ctx, existing, metav1.UpdateOptions{}) | ||
| return actual, true, err | ||
| } | ||
|
|
||
| // ApplyDeploymentFromCache applies the required deployment to the cluster. | ||
| func ApplyDeploymentFromCache(ctx context.Context, lister appslisterv1.DeploymentLister, client appsclientv1.DeploymentsGetter, required *appsv1.Deployment) (*appsv1.Deployment, bool, error) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| existing, err := lister.Deployments(required.Namespace).Get(required.Name) | ||
| if apierrors.IsNotFound(err) { | ||
| klog.V(2).Infof("Deployment %s/%s not found, creating", required.Namespace, required.Name) | ||
| actual, err := client.Deployments(required.Namespace).Create(ctx, required, metav1.CreateOptions{}) | ||
| return actual, true, err | ||
| } | ||
| if err != nil { | ||
| return nil, false, err | ||
| } | ||
| // if we only create this resource, we have no need to continue further | ||
| if IsCreateOnly(required) { | ||
| return nil, false, nil | ||
| if reconciling { | ||
| klog.V(4).Infof("Updating Deployment %s/%s due to diff: %v", required.Namespace, required.Name, cmp.Diff(existing, required)) | ||
| } | ||
|
|
||
| existing = existing.DeepCopy() | ||
| modified := pointer.BoolPtr(false) | ||
| resourcemerge.EnsureDeployment(modified, existing, *required) | ||
| if !*modified { | ||
| return existing, false, nil | ||
| } | ||
| klog.V(2).Infof("Updating Deployment %s/%s due to diff: %v", required.Namespace, required.Name, diff.ObjectDiff(existing, required)) | ||
|
|
||
| actual, err := client.Deployments(required.Namespace).Update(ctx, existing, metav1.UpdateOptions{}) | ||
| return actual, true, err | ||
| } | ||
|
|
||
| // ApplyDaemonSetv1 applies the required daemonset to the cluster. | ||
| func ApplyDaemonSetv1(ctx context.Context, client appsclientv1.DaemonSetsGetter, required *appsv1.DaemonSet) (*appsv1.DaemonSet, bool, error) { | ||
| func ApplyDaemonSetv1(ctx context.Context, client appsclientv1.DaemonSetsGetter, required *appsv1.DaemonSet, reconciling bool) (*appsv1.DaemonSet, bool, error) { | ||
| existing, err := client.DaemonSets(required.Namespace).Get(ctx, required.Name, metav1.GetOptions{}) | ||
| if apierrors.IsNotFound(err) { | ||
| klog.V(2).Infof("DaemonSet %s/%s not found, creating", required.Namespace, required.Name) | ||
|
|
@@ -91,36 +64,9 @@ func ApplyDaemonSetv1(ctx context.Context, client appsclientv1.DaemonSetsGetter, | |
| return existing, false, nil | ||
| } | ||
|
|
||
| klog.V(2).Infof("Updating DaemonSet %s/%s due to diff: %v", required.Namespace, required.Name, diff.ObjectDiff(existing, required)) | ||
|
|
||
| actual, err := client.DaemonSets(required.Namespace).Update(ctx, existing, metav1.UpdateOptions{}) | ||
| return actual, true, err | ||
| } | ||
|
|
||
| // ApplyDaemonSetFromCache applies the required deployment to the cluster. | ||
| func ApplyDaemonSetFromCache(ctx context.Context, lister appslisterv1.DaemonSetLister, client appsclientv1.DaemonSetsGetter, required *appsv1.DaemonSet) (*appsv1.DaemonSet, bool, error) { | ||
| existing, err := lister.DaemonSets(required.Namespace).Get(required.Name) | ||
| if apierrors.IsNotFound(err) { | ||
| klog.V(2).Infof("DaemonSet %s/%s not found, creating", required.Namespace, required.Name) | ||
| actual, err := client.DaemonSets(required.Namespace).Create(ctx, required, metav1.CreateOptions{}) | ||
| return actual, true, err | ||
| } | ||
| if err != nil { | ||
| return nil, false, err | ||
| if reconciling { | ||
| klog.V(4).Infof("Updating DaemonSet %s/%s due to diff: %v", required.Namespace, required.Name, cmp.Diff(existing, required)) | ||
| } | ||
| // if we only create this resource, we have no need to continue further | ||
| if IsCreateOnly(required) { | ||
| return nil, false, nil | ||
| } | ||
|
|
||
| existing = existing.DeepCopy() | ||
| modified := pointer.BoolPtr(false) | ||
| resourcemerge.EnsureDaemonSet(modified, existing, *required) | ||
| if !*modified { | ||
| return existing, false, nil | ||
| } | ||
|
|
||
| klog.V(2).Infof("Updating DaemonSet %s/%s due to diff: %v", required.Namespace, required.Name, diff.ObjectDiff(existing, required)) | ||
|
|
||
| actual, err := client.DaemonSets(required.Namespace).Update(ctx, existing, metav1.UpdateOptions{}) | ||
| return actual, true, err | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Can we pass in the mode instead of passing in a
reconcilingbool? Like we do for ClusterOperators here. That way we don't have to bump cluster signatures if we need to make some other mode distinction later on.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.
I considered that and decided against it because it would leak abstractions.
Modeis part of theresourcebuilderpackage, where as the resource creation/update logic is in theinternal. If in the future the full mode is required more refactoring can be done where the mode is moved to a common package and then it can be passed to the apply function.