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

do not overwirte user added labels added to the deployment template #183

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

laurafitzgerald
Copy link
Contributor

@laurafitzgerald laurafitzgerald commented Feb 6, 2025

Closes #176

Verification

  • Checkout locally.
  • Run make run
  • kubectl edit deployment
  • Add label to spec.template.labels something like useradded: label
  • Verify that the deployment spec.template.labels includes the following labels
app: limitador
limitador-resource: limitador-sample
useradded: label

@codecov-commenter
Copy link

codecov-commenter commented Feb 6, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 86.36364% with 3 lines in your changes missing coverage. Please review.

Project coverage is 82.76%. Comparing base (515d57b) to head (470589b).

Files with missing lines Patch % Lines
pkg/helpers/helpers.go 78.57% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #183      +/-   ##
==========================================
- Coverage   83.71%   82.76%   -0.96%     
==========================================
  Files          18       18              
  Lines        1210     1230      +20     
==========================================
+ Hits         1013     1018       +5     
- Misses        150      160      +10     
- Partials       47       52       +5     
Flag Coverage Δ
integration 76.42% <54.54%> (-1.43%) ⬇️
unit 61.31% <65.00%> (-2.34%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
api/v1alpha1 (u) 100.00% <ø> (ø)
pkg/helpers (u) 82.35% <78.57%> (-1.44%) ⬇️
pkg/log (u) 93.18% <ø> (ø)
pkg/reconcilers (u) 73.61% <100.00%> (+0.34%) ⬆️
pkg/limitador (u) 97.65% <100.00%> (ø)
controllers (i) 72.15% <100.00%> (-2.92%) ⬇️
pkg/upgrades ∅ <ø> (∅)
Files with missing lines Coverage Δ
controllers/limitador_controller.go 70.48% <100.00%> (-1.90%) ⬇️
pkg/limitador/k8s_objects.go 95.87% <100.00%> (ø)
pkg/reconcilers/deployment.go 95.97% <100.00%> (+0.11%) ⬆️
pkg/helpers/helpers.go 83.87% <78.57%> (-4.37%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@laurafitzgerald laurafitzgerald force-pushed the label-propagation branch 4 times, most recently from c77999c to d142de1 Compare February 7, 2025 09:35
@laurafitzgerald laurafitzgerald force-pushed the label-propagation branch 3 times, most recently from bd6f1d8 to 04eaa19 Compare February 7, 2025 10:55
@laurafitzgerald laurafitzgerald requested review from KevFan and removed request for adam-cattermole February 7, 2025 10:55
@laurafitzgerald laurafitzgerald marked this pull request as ready for review February 7, 2025 11:02
@laurafitzgerald laurafitzgerald force-pushed the label-propagation branch 2 times, most recently from b792015 to 2f46bc6 Compare February 10, 2025 09:57
@eguzki
Copy link
Contributor

eguzki commented Feb 10, 2025

Propagate Limitador CR labels to deployment labels as well here https://github.com/Kuadrant/limitador-operator/blob/main/pkg/limitador/k8s_objects.go#L77

Copy link
Contributor

@eguzki eguzki left a comment

Choose a reason for hiding this comment

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

Looking very nice

@laurafitzgerald laurafitzgerald force-pushed the label-propagation branch 2 times, most recently from 18b0c08 to 8f40569 Compare February 12, 2025 11:55
@laurafitzgerald laurafitzgerald force-pushed the label-propagation branch 2 times, most recently from 97168ec to 519d065 Compare February 13, 2025 14:40
KevFan
KevFan previously approved these changes Feb 19, 2025
Copy link
Contributor

@KevFan KevFan left a comment

Choose a reason for hiding this comment

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

Verified and working as expected, looks good to me 👍

@@ -33,3 +33,19 @@ func IsObjectTaggedToDelete(obj client.Object) bool {
annotation, ok := annotations[DeleteTagAnnotation]
return ok && annotation == "true"
}

func MergeMapStringString(modified *bool, existing *map[string]string, desired map[string]string) {
if *existing == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

add extra guard

if existing == nil {
		// early return, as there is no ref to initialize map
		return
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added this check but as part of the testing of the changes I've noticed a problem. If the existing map pointer is nil and we don't add that, then we never are able to add the desired labels to the existing one which is the one that we use in the cluster. If the user removes the label map and as such there is nothing there we don't have an opportunity to put that back. In the case of the deployment object meta, this is possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

when testing live against k8s, removing the label map results in the default ones being added back in so in this case there doesn't appear to be a nil pointer. in this case i don't know if we need this extra guard rail. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm good with not neeing this 👍

Copy link
Contributor

@eguzki eguzki left a comment

Choose a reason for hiding this comment

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

almost done. Good job!

I am a bit confused. From the last community call I understood you would be implementing the option 2 (labels will be externally added and not removed). However, I see that option 1 is being implemented here, so Limitador CR labels are propagated to the deployment, not to other resources though.

@laurafitzgerald laurafitzgerald changed the title propogate labels from limitador to deployment template do not overwirte existing user added lables added to the deployment template Mar 4, 2025
@laurafitzgerald laurafitzgerald changed the title do not overwirte existing user added lables added to the deployment template do not overwirte user added lables added to the deployment template Mar 4, 2025
@laurafitzgerald laurafitzgerald changed the title do not overwirte user added lables added to the deployment template do not overwirte user added labels added to the deployment template Mar 4, 2025
@@ -219,8 +218,8 @@ func ValidatePDB(pdb *policyv1.PodDisruptionBudget) error {

func Labels(limitador *limitadorv1alpha1.Limitador) map[string]string {
return map[string]string{
"app": "limitador",
"limitador-resource": limitador.ObjectMeta.Name,
helpers.LabelKeyApp: "limitador",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we may not need this change.

@laurafitzgerald laurafitzgerald force-pushed the label-propagation branch 3 times, most recently from 025a0a6 to 7d171f9 Compare March 6, 2025 15:36
Copy link
Contributor

@KevFan KevFan left a comment

Choose a reason for hiding this comment

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

Verified and changes looks good to me! 💯

@laurafitzgerald
Copy link
Contributor Author

@eguzki i'll wait for your approval before adding this to the merge queue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants