Skip to content

OCPBUGS-55217: CombineCABundleConfigMaps: use optimistic create/update #1936

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

vrutkovs
Copy link
Member

@vrutkovs vrutkovs commented Feb 19, 2025

Instead of re-creating configmap from scratch every time this function should attempt to use existing configmap and replace the contents only. This would prevent extra configmap updates when metadata changes.

Tested in openshift/cluster-kube-apiserver-operator#1812

@openshift-ci openshift-ci bot requested review from deads2k and hexfusion February 19, 2025 07:37
@vrutkovs vrutkovs force-pushed the combine-cas-optimistic-update branch from 5fd5ebc to 7eaf2a0 Compare February 19, 2025 07:49
@vrutkovs vrutkovs closed this Feb 24, 2025
@vrutkovs vrutkovs reopened this Feb 25, 2025
@vrutkovs vrutkovs force-pushed the combine-cas-optimistic-update branch from 7eaf2a0 to 7af439c Compare February 25, 2025 09:46
@vrutkovs vrutkovs changed the title CombineCABundleConfigMaps: use optimistic create/update API-1802: CombineCABundleConfigMaps: use optimistic create/update Feb 25, 2025
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Feb 25, 2025
@openshift-ci-robot
Copy link

openshift-ci-robot commented Feb 25, 2025

@vrutkovs: This pull request references API-1802 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target either version "4.19." or "openshift-4.19.", but it targets "4.18.0" instead.

In response to this:

Instead of re-creating configmap from scratch every time this function should attempt to use existing configmap and replace the contents only. This would prevent extra configmap updates when metadata changes.

Tested in openshift/cluster-kube-apiserver-operator#1812

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@vrutkovs vrutkovs changed the title API-1802: CombineCABundleConfigMaps: use optimistic create/update WIP API-1802: CombineCABundleConfigMaps: use optimistic create/update Feb 27, 2025
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 27, 2025
@vrutkovs vrutkovs force-pushed the combine-cas-optimistic-update branch from 7af439c to d5dd901 Compare April 22, 2025 08:19
@vrutkovs vrutkovs changed the title WIP API-1802: CombineCABundleConfigMaps: use optimistic create/update API-1802: CombineCABundleConfigMaps: use optimistic create/update Apr 22, 2025
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 22, 2025
@vrutkovs vrutkovs changed the title API-1802: CombineCABundleConfigMaps: use optimistic create/update OCPBUGS-55217: CombineCABundleConfigMaps: use optimistic create/update Apr 22, 2025
@openshift-ci-robot openshift-ci-robot added the jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. label Apr 22, 2025
@openshift-ci-robot
Copy link

@vrutkovs: This pull request references Jira Issue OCPBUGS-55217, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.19.0) matches configured target version for branch (4.19.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @wangke19

The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

Instead of re-creating configmap from scratch every time this function should attempt to use existing configmap and replace the contents only. This would prevent extra configmap updates when metadata changes.

Tested in openshift/cluster-kube-apiserver-operator#1812

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot requested a review from wangke19 April 22, 2025 12:42
@benluddy
Copy link
Contributor

/cc

Comment on lines 68 to 132
"ca-bundle.crt": string(caBytes),
},
modified := additionalAnnotations.EnsureTLSMetadataUpdate(&cm.ObjectMeta)
cm.Data = map[string]string{
"ca-bundle.crt": string(caBytes),
}
return cm, nil
return cm, modified, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

How is the bool return value supposed to be interpreted? It's unclear to me what it means when EnsureTLSMetadataUpdate returns false (and so the returned bool value is false) but Data has been mutated.

Copy link
Member Author

Choose a reason for hiding this comment

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

modified here returns if update is necessary:

requiredConfigMap, updateRequired, err := resourcesynccontroller.CombineCABundleConfigMaps(

It means either metadata or contents has changed. I think I missed "content has changed, but not the metadata", so I'll add some unittests to verify that

Comment on lines 13 to 14
applyoperatorv1 "github.com/openshift/client-go/operator/applyconfigurations/operator/v1"

Copy link
Contributor

Choose a reason for hiding this comment

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

Could this make backporting more painful?

Copy link
Member Author

Choose a reason for hiding this comment

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

This may complicate it, yes, but I'd prefer to avoid packports to 4.18 and earlier as we don't have stable rotation tests for them anyway

@@ -14,15 +14,22 @@ import (
"github.com/openshift/library-go/pkg/operator/certrotation"
)

func CombineCABundleConfigMaps(destinationConfigMap ResourceLocation, lister corev1listers.ConfigMapLister, additionalAnnotations certrotation.AdditionalAnnotations, inputConfigMaps ...ResourceLocation) (*corev1.ConfigMap, error) {
func CombineCABundleConfigMaps(destinationConfigMap *corev1.ConfigMap, lister corev1listers.ConfigMapLister, additionalAnnotations certrotation.AdditionalAnnotations, inputConfigMaps ...ResourceLocation) (*corev1.ConfigMap, bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This must not have any unit test coverage... could you add some to cover the behavior change being made please?

@vrutkovs vrutkovs force-pushed the combine-cas-optimistic-update branch from d5dd901 to f4c068a Compare April 24, 2025 08:23
Copy link
Contributor

openshift-ci bot commented Apr 24, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vrutkovs
Once this PR has been reviewed and has the lgtm label, please assign p0lyn0mial for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@@ -14,15 +14,21 @@ import (
"github.com/openshift/library-go/pkg/operator/certrotation"
)

func CombineCABundleConfigMaps(destinationConfigMap ResourceLocation, lister corev1listers.ConfigMapLister, additionalAnnotations certrotation.AdditionalAnnotations, inputConfigMaps ...ResourceLocation) (*corev1.ConfigMap, error) {
func CombineCABundleConfigMaps(destinationConfigMap *corev1.ConfigMap, lister corev1listers.ConfigMapLister, additionalAnnotations certrotation.AdditionalAnnotations, inputConfigMaps ...ResourceLocation) (*corev1.ConfigMap, bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reasonable way to introduce this as a function with a different name, and deprecate the existing one, to avoid lockstep updates to hypershift, kas-o, kcm-o, and scheduler-o?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think it would be a good idea

Comment on lines 71 to 75
if !reflect.DeepEqual(cm.Data, newCMData) {
modified = true
}
return cm, nil

cm.Data = newCMData
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I expected to see the assignment to cm.Data inside the "then" block with the assignment to modified. It looks correct to me either way.

}

func (m *mockConfigMapNamespaceLister) List(selector labels.Selector) ([]*corev1.ConfigMap, error) {
return nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Panic in unimplemented stubs to prevent someone later using them by mistake.

if err == nil && result == nil {
t.Errorf("Expected result to not be nil when no error occurred")
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to compare the full returned CM against an expected CM?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, it would verify removal of expired certs too

@vrutkovs vrutkovs force-pushed the combine-cas-optimistic-update branch from f4c068a to f1ee606 Compare May 6, 2025 08:53
vrutkovs added 2 commits May 13, 2025 16:07
Instead of re-creating configmap from scratch every time this function
should attempt to use existing configmap and replace the contents only.
This would prevent extra configmap updates when metadata changes
@vrutkovs vrutkovs force-pushed the combine-cas-optimistic-update branch from f1ee606 to 855d77f Compare May 13, 2025 14:07
Copy link
Contributor

openshift-ci bot commented May 13, 2025

@vrutkovs: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants