Repository: mariadb-operator/mariadb-operator

Issue:
[Bug] priorityClassName should be mutable
<!--
Bugs should be filed for issues encountered whilst operating mariadb-operator.
Please provide as much detail as possible. 
-->

**Documentation**
- [x] I acknowledge that I have read the relevant [documentation](https://github.com/mariadb-operator/mariadb-operator/tree/main/docs).

**Describe the bug**

I'm adding priorityClassName to all my Databases but quickly noticed that the priorityClassName is inmutable:

```
Failed to compare desired state to live state: failed to calculate diff: error calculating server side diff: serverSideDiff error: error running server side apply in dryrun mode for resource MariaDB/grafana-mariadb: admission webhook "vmariadb-v1alpha1.kb.io" denied the request: MariaDB.k8s.mariadb.com "grafana-mariadb" is invalid: spec.priorityClassName: Invalid value: "administrative-services": 'spec.priorityClassName' field is inmutable
```

**Expected behaviour**

I don't see an reason why this field should be inmutable. It's not even an limitation on the StatefulSet. You can easily update it there.

**Environment details**:
```
Client Version: v1.32.3
Kustomize Version: v5.5.0
Server Version: v1.32.2-eks-bc803b4
```
- MariaDB Server version: 0.38.0
- Install method: Helm Version 0.38.0

**Additional context**

Related PR: https://github.com/mariadb-operator/mariadb-operator/pull/337


Hints from issue comments:
@mmontes11: Hey there @Skaronator ! Thanks for bringing this up.

If the `StatefulSet` field is mutable, the `MariaDB` field should be mutable as well. To make that happen, we need to remove the `webhook` tag here:

https://github.com/mariadb-operator/mariadb-operator/blob/b63954b40fd38d7913c46417dfb0a0b67b8b9e4f/api/v1alpha1/base_types.go#L288

And add a test case to prove it is really immutable:

https://github.com/mariadb-operator/mariadb-operator/blob/b63954b40fd38d7913c46417dfb0a0b67b8b9e4f/internal/webhook/v1alpha1/mariadb_webhook_test.go#L646

Contributions are welcome! This could potentially be included in `0.38.1`, which we are planning to release shortly with some fixes.@mohitsethia: Hi @mmontes11 , can I work on this one?@Skaronator: @mohitsethia go for it. Otherwise I would take a look on monday myself.@mohitsethia: I will do it today itself.@Skaronator: Awesome, thank you!@mohitsethia: Hey, there are multiple places where we have PriorityClassName property with webhook:"immutable ", should I change it in all the places in the same file? 
https://github.com/mariadb-operator/mariadb-operator/blob/b63954b40fd38d7913c46417dfb0a0b67b8b9e4f/api/v1alpha1/base_types.go#L288
https://github.com/mariadb-operator/mariadb-operator/blob/b63954b40fd38d7913c46417dfb0a0b67b8b9e4f/api/v1alpha1/base_types.go#L346
https://github.com/mariadb-operator/mariadb-operator/blob/b63954b40fd38d7913c46417dfb0a0b67b8b9e4f/api/v1alpha1/base_types.go#L837
@mmontes11: Hey @mohitsethia ! Thanks for looking into it. The `priorityClassName` in the scope of this issue is:

https://github.com/mariadb-operator/mariadb-operator/blob/b63954b40fd38d7913c46417dfb0a0b67b8b9e4f/api/v1alpha1/base_types.go#L288

Which is the one that applies to the `StatefulSet` object. Please stick to this one, as the others apply to other objects, such as `Job`, which might have other immutability rules.@mohitsethia: Hey, I have made the change, but the tests are not directly using the PriorityClassName field. Let me explore a bit more to find out how to write tests for such case.
Here is the draft PR https://github.com/mariadb-operator/mariadb-operator/pull/1238

Solution patch:
diff --git a/api/v1alpha1/base_types.go b/api/v1alpha1/base_types.go
index c8b47877..db3ad0ce 100644
--- a/api/v1alpha1/base_types.go
+++ b/api/v1alpha1/base_types.go
@@ -285,7 +285,7 @@ type PodTemplate struct {
 	// PriorityClassName to be used in the Pod.
 	// +optional
 	// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:advanced"}
-	PriorityClassName *string `json:"priorityClassName,omitempty" webhook:"inmutable"`
+	PriorityClassName *string `json:"priorityClassName,omitempty"`
 	// TopologySpreadConstraints to be used in the Pod.
 	// +optional
 	// +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:advanced"}



Test patch:
diff --git a/internal/webhook/v1alpha1/mariadb_webhook_test.go b/internal/webhook/v1alpha1/mariadb_webhook_test.go
index a2f2f5a9..08ed8bf3 100644
--- a/internal/webhook/v1alpha1/mariadb_webhook_test.go
+++ b/internal/webhook/v1alpha1/mariadb_webhook_test.go
@@ -657,6 +657,9 @@ var _ = Describe("v1alpha1.MariaDB webhook", func() {
 				Spec: v1alpha1.MariaDBSpec{
 					Image:           "mariadb:11.3.3",
 					ImagePullPolicy: corev1.PullIfNotPresent,
+					PodTemplate: v1alpha1.PodTemplate{
+						PriorityClassName: ptr.To("PriorityClassName"),
+					},
 					ContainerTemplate: v1alpha1.ContainerTemplate{
 						Resources: &v1alpha1.ResourceRequirements{
 							Requests: corev1.ResourceList{
@@ -887,6 +890,13 @@ var _ = Describe("v1alpha1.MariaDB webhook", func() {
 				},
 				false,
 			),
+			Entry(
+				"Updating PriorityClassName",
+				func(mdb *v1alpha1.MariaDB) {
+					mdb.Spec.PriorityClassName = ptr.To("new-PriorityClassName")
+				},
+				false,
+			),
 		)
 	})