Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion api/v1/perconaservermysql_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,14 @@ func (cr *PerconaServerMySQL) DefaultSSLSecretName() string {
return cr.Name + "-ssl"
}

func (cr *PerconaServerMySQL) DefaultOrchestratorServiceAccountName() string {
if cr.Spec.CRVersion != "" && cr.CompareVersion("1.3.0") >= 0 {
return cr.Name + "-orchestrator"
}

return "percona-server-mysql-operator-orchestrator"
}

// CheckNSetDefaults validates and sets default values for the PerconaServerMySQL custom resource.
func (cr *PerconaServerMySQL) CheckNSetDefaults(_ context.Context, serverVersion *platform.ServerVersion) error {
if len(cr.Spec.MySQL.ClusterType) == 0 {
Expand Down Expand Up @@ -1272,7 +1280,7 @@ func (cr *PerconaServerMySQL) CheckNSetDefaults(_ context.Context, serverVersion
}

if cr.Spec.Orchestrator.ServiceAccountName == "" {
cr.Spec.Orchestrator.ServiceAccountName = "percona-server-mysql-operator-orchestrator"
cr.Spec.Orchestrator.ServiceAccountName = cr.DefaultOrchestratorServiceAccountName()
}

var err error
Expand Down
29 changes: 29 additions & 0 deletions api/v1/perconaservermysql_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/percona/percona-server-mysql-operator/pkg/naming"
)
Expand Down Expand Up @@ -849,3 +850,31 @@ func TestPiTREnabled(t *testing.T) {
})
}
}

func TestDefaultOrchestratorServiceAccountName(t *testing.T) {
t.Run("empty crVersion", func(t *testing.T) {
cr := &PerconaServerMySQL{
ObjectMeta: metav1.ObjectMeta{Name: "cluster-a"},
}

assert.Equal(t, "percona-server-mysql-operator-orchestrator", cr.DefaultOrchestratorServiceAccountName())
})

t.Run("before 1.3.0", func(t *testing.T) {
cr := &PerconaServerMySQL{
ObjectMeta: metav1.ObjectMeta{Name: "cluster-a"},
Spec: PerconaServerMySQLSpec{CRVersion: "1.2.0"},
}

assert.Equal(t, "percona-server-mysql-operator-orchestrator", cr.DefaultOrchestratorServiceAccountName())
})

t.Run("since 1.3.0", func(t *testing.T) {
cr := &PerconaServerMySQL{
ObjectMeta: metav1.ObjectMeta{Name: "cluster-a"},
Spec: PerconaServerMySQLSpec{CRVersion: "1.3.0"},
}

assert.Equal(t, "cluster-a-orchestrator", cr.DefaultOrchestratorServiceAccountName())
})
}
6 changes: 3 additions & 3 deletions cmd/example-gen/pkg/defaults/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func ManualCluster(cr *apiv1.PerconaServerMySQL) {
mysqlDefaults(&cr.Spec.MySQL)
haproxyDefaults(cr.Spec.Proxy.HAProxy)
routerDefaults(cr.Spec.Proxy.Router)
orchestratorDefaults(&cr.Spec.Orchestrator)
orchestratorDefaults(cr, &cr.Spec.Orchestrator)
pmmDefaults(cr.Spec.PMM)
toolkitDefaults(cr.Spec.Toolkit)
backupDefaults(cr.Spec.Backup)
Expand Down Expand Up @@ -107,12 +107,12 @@ func routerDefaults(spec *apiv1.MySQLRouterSpec) {
}
}

func orchestratorDefaults(spec *apiv1.OrchestratorSpec) {
func orchestratorDefaults(cr *apiv1.PerconaServerMySQL, spec *apiv1.OrchestratorSpec) {
podSpecDefaults(&spec.PodSpec, ImageOrchestrator, resources("128M", "", "256M", ""), "", 30, envList("ORC_ENV", "VALUE"), envFromList("orc-env-secret"))

spec.Enabled = false
spec.Configuration = `{"FailMasterPromotionOnLagMinutes": 10}`
spec.ServiceAccountName = "percona-server-mysql-operator-orchestrator"
spec.ServiceAccountName = cr.DefaultOrchestratorServiceAccountName()
spec.PodSecurityContext = &corev1.PodSecurityContext{
SupplementalGroups: []int64{1001},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ func ConfigMapData(cr *apiv1.PerconaServerMySQL) (string, error) {
func RBAC(cr *apiv1.PerconaServerMySQL) (*rbacv1.Role, *rbacv1.RoleBinding, *corev1.ServiceAccount) {
meta := metav1.ObjectMeta{
Namespace: cr.Namespace,
Name: "percona-server-mysql-operator-orchestrator",
Name: cr.Spec.Orchestrator.ServiceAccountName,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe the default orchestrator service account name should be changed as well to include cr.Name, so you don't need to set a custom name for the 2nd cluster

this should be done with a version check and should only apply >=1.3.0

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point, thanks. Updated the PR:

  • Added DefaultOrchestratorServiceAccountName() with a version gate:
    • for crVersion >= 1.3.0 the default is now {cr.Name}-orchestrator (aligned with {cr.Name}-clusterset and other per-cluster resources; happy to use percona-{cr.Name}-orchestrator if you prefer a vendor prefix)
    • for crVersion < 1.3.0 the legacy default percona-server-mysql-operator-orchestrator is preserved
  • orchestrator.RBAC() continues to use spec.orchestrator.serviceAccountName, so ServiceAccount, Role, and RoleBinding stay in sync

Upgrade path:

Operator upgrade to 1.3.0 alone does not change behavior for clusters with crVersion < 1.3.0
After bumping spec.crVersion to 1.3.0, the operator creates new per-cluster RBAC resources
The legacy shared SA/Role/RoleBinding can be removed manually if no longer used

Labels: cr.GlobalLabels(),
Annotations: cr.GlobalAnnotations(),
}
Expand Down
47 changes: 47 additions & 0 deletions pkg/orchestrator/orchestrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,53 @@ func TestStatefulSet(t *testing.T) {
assert.Equal(t, serviceAccountName, sts.Spec.Template.Spec.ServiceAccountName)
})

t.Run("RBAC", func(t *testing.T) {
cluster := cr.DeepCopy()
cluster.Spec.CRVersion = "1.2.0"
cluster.Spec.Orchestrator.ServiceAccountName = ""

if err := cluster.CheckNSetDefaults(t.Context(), &platform.ServerVersion{
Platform: platform.PlatformKubernetes,
}); err != nil {
t.Fatal(err)
}

role, binding, sa := RBAC(cluster)
const legacyDefaultName = "percona-server-mysql-operator-orchestrator"
assert.Equal(t, legacyDefaultName, sa.Name)
assert.Equal(t, legacyDefaultName, role.Name)
assert.Equal(t, legacyDefaultName, binding.Name)
assert.Equal(t, legacyDefaultName, binding.Subjects[0].Name)
assert.Equal(t, legacyDefaultName, binding.RoleRef.Name)

cluster.Spec.CRVersion = "1.3.0"
cluster.Spec.Orchestrator.ServiceAccountName = ""

if err := cluster.CheckNSetDefaults(t.Context(), &platform.ServerVersion{
Platform: platform.PlatformKubernetes,
}); err != nil {
t.Fatal(err)
}

role, binding, sa = RBAC(cluster)
const modernDefaultName = "cluster-orchestrator"
assert.Equal(t, modernDefaultName, sa.Name)
assert.Equal(t, modernDefaultName, role.Name)
assert.Equal(t, modernDefaultName, binding.Name)
assert.Equal(t, modernDefaultName, binding.Subjects[0].Name)
assert.Equal(t, modernDefaultName, binding.RoleRef.Name)

const customName = "custom-orchestrator"
cluster.Spec.Orchestrator.ServiceAccountName = customName

role, binding, sa = RBAC(cluster)
assert.Equal(t, customName, sa.Name)
assert.Equal(t, customName, role.Name)
assert.Equal(t, customName, binding.Name)
assert.Equal(t, customName, binding.Subjects[0].Name)
assert.Equal(t, customName, binding.RoleRef.Name)
})

t.Run("tolerations", func(t *testing.T) {
cluster := cr.DeepCopy()
sts := StatefulSet(cluster, initImage, configHash, tlsHash)
Expand Down
Loading