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

Allow custom annotations on service accounts #3106

Merged
merged 4 commits into from
Jul 8, 2024

Conversation

pavolloffay
Copy link
Member

Description:

Allow custom annotations on service accounts. OpenShift 4.16 adds an annotation (openshift.io/internal-registry-pull-secret-ref: simplest-collector-dockercfg-jwq66) to SA which then configures pull secret.

See https://docs.openshift.com/container-platform/4.16/release_notes/ocp-4-16-release-notes.html (Legacy service account API token secrets are no longer generated for each service account)

Link to tracking Issue(s):

  • Resolves: #issue-number

Testing:

Documentation:

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
@pavolloffay pavolloffay requested a review from a team as a code owner July 5, 2024 15:25
.chloggen/main.yaml Show resolved Hide resolved
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
@@ -194,7 +194,6 @@ func mutateConfigMap(existing, desired *corev1.ConfigMap) {
}

func mutateServiceAccount(existing, desired *corev1.ServiceAccount) {
existing.Annotations = desired.Annotations
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't this mean that if a user were to add an annotation that is expected to propagate to their serviceaccount, we would no longer do this? Also, if we remove an annotation it will no longer be removed? should we do some type of merge here?

Copy link
Member Author

Choose a reason for hiding this comment

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

doesn't this mean that if a user were to add an annotation that is expected to propagate to their serviceaccount, we would no longer do this?

This PR actually makes sure that the user-added annotations on SA are not reverted by the operator. The mutate.go by default keeps user-defined annotations but for some kinds those annotations are removed (e.g. SA) and this PR relaxes that for SA.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, but what about annotations added to the desired SA? i.e. the current logic allows us to update the existing SA with the desired new annotations

Copy link
Member Author

Choose a reason for hiding this comment

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

The logic in this PR makes sure that the desired annotations (set by the operator) are enforced and the user-defined annotations are not removed.

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 add a test for the serviceaccount annotation updating to verify that in here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added a test

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
@@ -198,6 +204,12 @@ func TestOpenTelemetryCollectorReconciler_Reconcile(t *testing.T) {
"app.kubernetes.io/managed-by": "opentelemetry-operator",
"app.kubernetes.io/part-of": "opentelemetry",
})

sa := &v1.ServiceAccount{}
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 update the collector we update here to add an annotation as well to confirm that the SA gets that new annotation as well?

i.e. we apply addedMetadataDeployment initially and then deploymentExtraPorts, we should add another annotation to deploymentExtraPorts to verify that new annotations propagate to the existing SA

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the test already covers what was changed in the PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

not entirely – my worry is that on updates we will no longer be able to add new annotations to service accounts because we no longer take the desired SA annotations and put them on the existing SA. this is good for external systems that are adding annotations as they will not be overridden, but would result in an odd user experience for ourselves where users can not add new annotations to their existing SA via the otelcol CR.

Copy link
Member Author

Choose a reason for hiding this comment

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

if err := mergeWithOverride(&existingAnnotations, desired.GetAnnotations()); err != nil {
enforces that desired annotations take precedence.

The single line this PR removes ensures that user-defined annotations are added as well.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added an extra annotation to deploymentExtraPorts and it is propagated to the SA after the update

Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
@pavolloffay pavolloffay merged commit 0f66c09 into open-telemetry:main Jul 8, 2024
33 checks passed
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.

None yet

4 participants