cybozu-go / moco

MySQL operator on Kubernetes using GTID-based semi-synchronous replication.
https://cybozu-go.github.io/moco/
Apache License 2.0
269 stars 22 forks source link

Unable to update Primary/Replica services when updating Ports section. #721

Closed donch closed 1 month ago

donch commented 1 month ago

Describe the bug Hi, I'm trying to customize the Primary/Replica services with custom NodePort. For the serviceType, all is fine, but when i'm customising the Ports section, i'm getting this error :

{"level":"error","ts":"2024-07-18T13:44:29Z","msg":"Reconciler error","controller":"mysqlcluster","controllerGroup":"moco.cybozu.com","controllerKind":"MySQLCluster","MySQLCluster":{"name":"moco","namespace":"enix"},"namespace":"enix","name":"moco","reconcileID":"5b23fa63-bc2e-4311-b649-81705e00a3dc","error":"failed to reconcile moco-moco-primary service: failed to create typed patch object (enix/moco-moco-primary; /v1, Kind=Service): errors:\n .spec.ports: duplicate entries for key [port=3306,protocol=\"TCP\"]\n .spec.ports: duplicate entries for key [port=33060,protocol=\"TCP\"]","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.15.3/pkg/internal/controller/controller.go:324\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.15.3/pkg/internal/controller/controller.go:265\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.15.3/pkg/internal/controller/controller.go:226"}

It seems the merge can't be done since the Ports section is a List

Environments

To Reproduce Steps to reproduce the behavior: Create a simple cluster with the following customisation:

  primaryServiceTemplate:
    spec:
      ports:
      - name: mysql
        nodePort: 31500
        port: 3306
        protocol: TCP
        targetPort: mysql
      type: NodePort

Expected behavior I want to be able to customize my services NodePorts

Thanks !

masa213f commented 1 month ago

@donch Thanks for reporing the issue.

This behavior is by design. MOCO does not allow users to customize the ports fields. However, the nodePort may not affect MOCO's operation, so it may be a good idea to allow customization of the nodePort.

https://cybozu-go.github.io/moco/reconcile.html#service

The following fields in Service spec may not be customized, though. clusterIP ports selector

masa213f commented 1 month ago

@donch I updated. Please wait for the next release.