Skip to content

Commit ad76427

Browse files
committed
improve config
1 parent 0fdcff7 commit ad76427

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

api/core/v2alpha1/constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package v2alpha1
33
const (
44
// DefaultOIDCProviderName is the identifier for the default OIDC provider.
55
DefaultOIDCProviderName = "default"
6+
// DefaultMCPClusterPurpose is the default purpose for ManagedControlPlane clusters.
7+
DefaultMCPClusterPurpose = "mcp"
68
)
79

810
const (

internal/config/config_managedcontrolplane.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ type ManagedControlPlaneConfig struct {
1616
// MCPClusterPurpose is the purpose that is used for ClusterRequests created for ManagedControlPlane resources.
1717
MCPClusterPurpose string `json:"mcpClusterPurpose"`
1818

19-
// StandardOIDCProvider is the standard OIDC provider that is enabled for all ManagedControlPlane resources, unless explicitly disabled.
19+
// DefaultOIDCProvider is the standard OIDC provider that is enabled for all ManagedControlPlane resources, unless explicitly disabled.
2020
// If nil, no standard OIDC provider will be used.
21-
StandardOIDCProvider *commonapi.OIDCProviderConfig `json:"standardOIDCProvider,omitempty"`
21+
DefaultOIDCProvider *commonapi.OIDCProviderConfig `json:"defaultOIDCProvider,omitempty"`
2222

2323
// ReconcileMCPEveryXDays specifies after how many days an MCP should be reconciled.
2424
// This is useful if the AccessRequests created by the MCP use an expiring authentication method and the MCP needs to refresh the access regularly.
@@ -28,9 +28,12 @@ type ManagedControlPlaneConfig struct {
2828
}
2929

3030
func (c *ManagedControlPlaneConfig) Default(_ *field.Path) error {
31-
c.StandardOIDCProvider.Default()
32-
if c.StandardOIDCProvider.Name == "" {
33-
c.StandardOIDCProvider.Name = corev2alpha1.DefaultOIDCProviderName
31+
c.DefaultOIDCProvider.Default()
32+
if c.DefaultOIDCProvider.Name == "" {
33+
c.DefaultOIDCProvider.Name = corev2alpha1.DefaultOIDCProviderName
34+
}
35+
if c.MCPClusterPurpose == "" {
36+
c.MCPClusterPurpose = corev2alpha1.DefaultMCPClusterPurpose
3437
}
3538
return nil
3639
}
@@ -44,13 +47,13 @@ func (c *ManagedControlPlaneConfig) Validate(fldPath *field.Path) error {
4447
if c.ReconcileMCPEveryXDays < 0 {
4548
errs = append(errs, field.Invalid(fldPath.Child("reconcileMCPEveryXDays"), c.ReconcileMCPEveryXDays, "reconcile interval must be 0 or greater"))
4649
}
47-
if c.StandardOIDCProvider == nil {
48-
oidcFldPath := fldPath.Child("standardOIDCProvider")
49-
if len(c.StandardOIDCProvider.RoleBindings) > 0 {
50+
if c.DefaultOIDCProvider == nil {
51+
oidcFldPath := fldPath.Child("defaultOIDCProvider")
52+
if len(c.DefaultOIDCProvider.RoleBindings) > 0 {
5053
errs = append(errs, field.Forbidden(oidcFldPath.Child("roleBindings"), "role bindings are specified in the MCP spec and may not be set in the config"))
5154
}
52-
if c.StandardOIDCProvider.Name != "" && c.StandardOIDCProvider.Name != corev2alpha1.DefaultOIDCProviderName {
53-
errs = append(errs, field.Invalid(oidcFldPath.Child("name"), c.StandardOIDCProvider.Name, fmt.Sprintf("standard OIDC provider name must be '%s' or left empty (in which case it will be defaulted)", corev2alpha1.DefaultOIDCProviderName)))
55+
if c.DefaultOIDCProvider.Name != "" && c.DefaultOIDCProvider.Name != corev2alpha1.DefaultOIDCProviderName {
56+
errs = append(errs, field.Invalid(oidcFldPath.Child("name"), c.DefaultOIDCProvider.Name, fmt.Sprintf("standard OIDC provider name must be '%s' or left empty (in which case it will be defaulted)", corev2alpha1.DefaultOIDCProviderName)))
5457
}
5558
}
5659

internal/controllers/managedcontrolplane/access.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ func (r *ManagedControlPlaneReconciler) createOrUpdateDesiredAccessRequests(ctx
9090
// create or update AccessRequests for the ManagedControlPlane
9191
if mcp.DeletionTimestamp.IsZero() {
9292
oidcProviders = make([]*commonapi.OIDCProviderConfig, 0, len(mcp.Spec.IAM.OIDCProviders)+1)
93-
if r.Config.StandardOIDCProvider != nil && len(mcp.Spec.IAM.RoleBindings) > 0 {
93+
if r.Config.DefaultOIDCProvider != nil && len(mcp.Spec.IAM.RoleBindings) > 0 {
9494
// add default OIDC provider, unless it has been disabled
95-
defaultOidc := r.Config.StandardOIDCProvider.DeepCopy()
95+
defaultOidc := r.Config.DefaultOIDCProvider.DeepCopy()
9696
defaultOidc.Name = corev2alpha1.DefaultOIDCProviderName
9797
defaultOidc.RoleBindings = mcp.Spec.IAM.RoleBindings
9898
oidcProviders = append(oidcProviders, defaultOidc)

internal/controllers/managedcontrolplane/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ var _ = Describe("ManagedControlPlane Controller", func() {
155155
WithStatus(metav1.ConditionFalse).
156156
WithReason(cconst.ReasonWaitingForAccessRequest)),
157157
))
158-
oidcProviders := []commonapi.OIDCProviderConfig{*rec.Config.StandardOIDCProvider.DeepCopy()}
158+
oidcProviders := []commonapi.OIDCProviderConfig{*rec.Config.DefaultOIDCProvider.DeepCopy()}
159159
oidcProviders[0].RoleBindings = mcp.Spec.IAM.RoleBindings
160160
for _, addProv := range mcp.Spec.IAM.OIDCProviders {
161161
oidcProviders = append(oidcProviders, *addProv.DeepCopy())

0 commit comments

Comments
 (0)