Skip to content

Commit c0fc17a

Browse files
authored
feat: allow to control the high availability config of ps mcp (#191)
1 parent 6680414 commit c0fc17a

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

cmd/openmcp-operator/app/init.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ func (o *InitOptions) Run(ctx context.Context) error {
218218
ps.Spec.RunCommand = append(ps.Spec.RunCommand, "--config="+cp)
219219
}
220220
ps.Spec.Verbosity = verbosity
221+
ps.Spec.RunReplicas = *o.Config.ManagedControlPlane.PlatformService.Replicas
222+
ps.Spec.TopologySpreadConstraints = o.Config.ManagedControlPlane.PlatformService.TopologySpreadConstraints
221223
return nil
222224
}); err != nil {
223225
return fmt.Errorf("error creating/updating PlatformService %s: %w", ps.Name, err)

cmd/openmcp-operator/app/mcp/run.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,11 +269,6 @@ func (o *RunOptions) Run(ctx context.Context) error {
269269
TLSOpts: o.WebhookTLSOpts,
270270
})
271271

272-
podNamespace := os.Getenv(apiconst.EnvVariablePodNamespace)
273-
if podNamespace == "" {
274-
return fmt.Errorf("environment variable %s is not set", apiconst.EnvVariablePodNamespace)
275-
}
276-
277272
mgr, err := ctrl.NewManager(onboardingCluster.RESTConfig(), ctrl.Options{
278273
Scheme: onboardingCluster.Scheme(),
279274
Metrics: o.MetricsServerOptions,
@@ -282,7 +277,7 @@ func (o *RunOptions) Run(ctx context.Context) error {
282277
PprofBindAddress: o.PprofAddr,
283278
LeaderElection: o.EnableLeaderElection,
284279
LeaderElectionID: "github.com/openmcp-project/openmcp-operator--mcp-controller",
285-
LeaderElectionNamespace: podNamespace,
280+
LeaderElectionNamespace: providerSystemNamespace,
286281
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
287282
// when the Manager ends. This requires the binary to immediately end when the
288283
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly

internal/config/config_managedcontrolplane.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package config
22

33
import (
4+
corev1 "k8s.io/api/core/v1"
45
"k8s.io/apimachinery/pkg/util/validation/field"
6+
"k8s.io/utils/ptr"
57

68
commonapi "github.com/openmcp-project/openmcp-operator/api/common"
79
corev2alpha1 "github.com/openmcp-project/openmcp-operator/api/core/v2alpha1"
@@ -23,6 +25,21 @@ type ManagedControlPlaneConfig struct {
2325
// A value of 0 disables the periodic reconciliation.
2426
// +optional
2527
ReconcileMCPEveryXDays int `json:"reconcileMCPEveryXDays,omitempty"`
28+
29+
// PlatformService specifies the configuration for the ManagedControlPlane platform service.
30+
PlatformService ManagedControlPlaneConfigPlatformService `json:"platformService,omitempty"`
31+
}
32+
type ManagedControlPlaneConfigPlatformService struct {
33+
// Replicas specifies the default number of replicas for ManagedControlPlane platform service.
34+
// Default is 1.
35+
// +optional
36+
Replicas *int32 `json:"replicas,omitempty"`
37+
38+
// TopologySpreadConstraints specifies the default topology spread constraints for ManagedControlPlane platform service.
39+
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-topology-spread-constraints/
40+
// The label selector for the topology spread constraints is set to match the labels of the ManagedControlPlane platform service.
41+
// +optional
42+
TopologySpreadConstraints []corev1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"`
2643
}
2744

2845
func (c *ManagedControlPlaneConfig) Default(_ *field.Path) error {
@@ -35,6 +52,9 @@ func (c *ManagedControlPlaneConfig) Default(_ *field.Path) error {
3552
if c.MCPClusterPurpose == "" {
3653
c.MCPClusterPurpose = corev2alpha1.DefaultMCPClusterPurpose
3754
}
55+
if c.PlatformService.Replicas == nil {
56+
c.PlatformService.Replicas = ptr.To[int32](1)
57+
}
3858
return nil
3959
}
4060

@@ -56,6 +76,9 @@ func (c *ManagedControlPlaneConfig) Validate(fldPath *field.Path) error {
5676
errs = append(errs, field.Invalid(oidcFldPath.Child("name"), c.DefaultOIDCProvider.Name, "'system' is a reserved string and may not be used as name for the default OIDC provider"))
5777
}
5878
}
79+
if c.PlatformService.Replicas != nil && *c.PlatformService.Replicas < 1 {
80+
errs = append(errs, field.Invalid(fldPath.Child("replicas"), c.PlatformService.Replicas, "replicas must be at least 1"))
81+
}
5982

6083
return errs.ToAggregate()
6184
}

0 commit comments

Comments
 (0)