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

Add support for annotations on Deployment/StatefulSet resources in DruidNodeSpec #145

Merged
merged 4 commits into from Mar 28, 2024

Conversation

SamWheating
Copy link
Contributor

Fixes #142

Description

Adding a ReplicationControllerAnnotations field to the DruidNodeSpec schema. This allows users to specify annotations to be applied to the StatefulSet / Deployment object.

I'm not 100% sure of the naming - what do you think? I didn't want to call it StatefulSetAnnotations since the user can opt for a deployment instead.

Also regenerated the API docs, which led to a huge diff as it appears they weren't regenerated after #53 (hence the huge diff)

This PR has:

  • been tested on a real K8S cluster to ensure creation of a brand new Druid cluster works.
  • been tested for backward compatibility on a real K*S cluster by applying the changes introduced here on an existing Druid cluster. If there are any backward incompatible changes then they have been noted in the PR description.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added documentation for new or modified features or behaviors.

I haven't tested this on a real kube cluster, but all of the e2e tests run. Is that sufficient for an overall minor/straightforward change?

Copy link
Contributor

@AdheipSingh AdheipSingh left a comment

Choose a reason for hiding this comment

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

Can we also add this field in druidSpec ?
You can merge the annotations if specified in both the spec druid nodeSpec and druidSpec. The latter is cluster scoped. Its common to all druid nodes.

@SamWheating
Copy link
Contributor Author

You can merge the annotations if specified in both the spec druid nodeSpec and druidSpec

Done ✅

Any strong preference on how these are merged? In my opinion it makes sense for the finer-grained DruidNodeSpec-level annotations to override the DruidSpec-level annotations (see implementation), but I see that we do the opposite with PodLabels.

@itamar-marom
Copy link
Collaborator

@SamWheating does Reddit use the operator? if so, can we add you as users in the ADOPTERS.md ?

@SamWheating
Copy link
Contributor Author

does Reddit use the operator?

Not in any official capacity, this work was completed on my own time and mostly just out of personal interest.

Copy link
Collaborator

@itamar-marom itamar-marom left a comment

Choose a reason for hiding this comment

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

Hi @SamWheating just fix the function name and I'll approve

@@ -1287,6 +1289,22 @@ func makeLabelsForNodeSpec(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid,
return labels
}

// makeAnnotationsForReplicationController returns the annotations for a Deployment or StatefulSet
// If a given key is set in both the DruidSpec and DruidNodeSpec, the node-scoped value will take precedence.
func makeAnnotationsForReplicationController(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid) map[string]string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func makeAnnotationsForReplicationController(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid) map[string]string {
func makeAnnotationsForWorkload(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid) map[string]string {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah whoops, I totally missed this 🤦 thanks for spotting!

@@ -1287,6 +1289,22 @@ func makeLabelsForNodeSpec(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid,
return labels
}

// makeAnnotationsForReplicationController returns the annotations for a Deployment or StatefulSet
Copy link
Collaborator

Choose a reason for hiding this comment

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

``

Suggested change
// makeAnnotationsForReplicationController returns the annotations for a Deployment or StatefulSet
// makeAnnotationsForWorkload returns the annotations for a Deployment or StatefulSet

Namespace: m.Namespace,
Labels: ls,
Name: fmt.Sprintf("%s", nodeSpecUniqueStr),
Annotations: makeAnnotationsForReplicationController(nodeSpec, m),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Annotations: makeAnnotationsForReplicationController(nodeSpec, m),
Annotations: makeAnnotationsForWorkload(nodeSpec, m),

Namespace: m.Namespace,
Labels: ls,
Name: fmt.Sprintf("%s", nodeSpecUniqueStr),
Annotations: makeAnnotationsForReplicationController(nodeSpec, m),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Annotations: makeAnnotationsForReplicationController(nodeSpec, m),
Annotations: makeAnnotationsForWorkload(nodeSpec, m),

Copy link
Collaborator

@itamar-marom itamar-marom left a comment

Choose a reason for hiding this comment

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

LGTM!

@AdheipSingh AdheipSingh merged commit 6eb2937 into datainfrahq:master Mar 28, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add annotations on STS
3 participants