Skip to content

Commit f4e38be

Browse files
authored
fix: access request handling for MCP V2 (#172)
1 parent 5bf1ea6 commit f4e38be

File tree

7 files changed

+100
-9
lines changed

7 files changed

+100
-9
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.15.0-dev
1+
v0.15.1

api/core/v2alpha1/constants.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ const (
4040
)
4141

4242
const (
43-
OIDCNamePrefix = "oidc:"
44-
TokenNamePrefix = "token:"
43+
OIDCNamePrefix = "oidc_"
44+
TokenNamePrefix = "token_"
4545
)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ require (
1414
github.com/onsi/ginkgo/v2 v2.25.3
1515
github.com/onsi/gomega v1.38.2
1616
github.com/openmcp-project/controller-utils v0.22.0
17-
github.com/openmcp-project/openmcp-operator/api v0.15.0
18-
github.com/openmcp-project/openmcp-operator/lib v0.15.0
17+
github.com/openmcp-project/openmcp-operator/api v0.15.1
18+
github.com/openmcp-project/openmcp-operator/lib v0.15.1
1919
github.com/spf13/cobra v1.10.1
2020
k8s.io/api v0.34.1
2121
k8s.io/apimachinery v0.34.1

internal/controllers/managedcontrolplane/access.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,27 @@ func (r *ManagedControlPlaneReconciler) createOrUpdateDesiredAccessRequests(ctx
9090

9191
// create or update AccessRequests for the ManagedControlPlane
9292
if mcp.DeletionTimestamp.IsZero() {
93-
oidcProviders = make([]commonapi.OIDCProviderConfig, 0, len(mcp.Spec.IAM.OIDC.ExtraProviders)+1)
94-
if r.Config.DefaultOIDCProvider != nil && len(mcp.Spec.IAM.OIDC.DefaultProvider.RoleBindings) > 0 {
93+
oidcProvidersLen := 1
94+
defaultProviderRoleBindingsLen := 0
95+
96+
if mcp.Spec.IAM.OIDC != nil {
97+
oidcProvidersLen += len(mcp.Spec.IAM.OIDC.ExtraProviders)
98+
defaultProviderRoleBindingsLen = len(mcp.Spec.IAM.OIDC.DefaultProvider.RoleBindings)
99+
}
100+
101+
oidcProviders = make([]commonapi.OIDCProviderConfig, 0, oidcProvidersLen)
102+
103+
if r.Config.DefaultOIDCProvider != nil && defaultProviderRoleBindingsLen > 0 {
95104
// add default OIDC provider, unless it has been disabled
96105
defaultOidc := r.Config.DefaultOIDCProvider.DeepCopy()
97106
defaultOidc.Name = corev2alpha1.DefaultOIDCProviderName
98107
defaultOidc.RoleBindings = mcp.Spec.IAM.OIDC.DefaultProvider.RoleBindings
99108
oidcProviders = append(oidcProviders, *defaultOidc)
100109
}
101-
oidcProviders = append(oidcProviders, mcp.Spec.IAM.OIDC.ExtraProviders...)
110+
111+
if mcp.Spec.IAM.OIDC != nil && len(mcp.Spec.IAM.OIDC.ExtraProviders) > 0 {
112+
oidcProviders = append(oidcProviders, mcp.Spec.IAM.OIDC.ExtraProviders...)
113+
}
102114

103115
tokenProviders = mcp.Spec.IAM.Tokens
104116
}

internal/controllers/managedcontrolplane/controller_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,4 +814,57 @@ var _ = Describe("ManagedControlPlane Controller", func() {
814814
Expect(cr.Spec.WaitForClusterDeletion).To(PointTo(BeTrue()))
815815
})
816816

817+
It("should correctly handle an MCP without OIDC providers", func() {
818+
rec, env := defaultTestSetup("testdata", "test-01")
819+
820+
mcp := &corev2alpha1.ManagedControlPlaneV2{}
821+
mcp.SetName("mcp-03")
822+
mcp.SetNamespace("test")
823+
Expect(env.Client(onboarding).Get(env.Ctx, client.ObjectKeyFromObject(mcp), mcp)).To(Succeed())
824+
env.ShouldReconcile(mcpRec, testutils.RequestFromObject(mcp))
825+
826+
platformNamespace, err := libutils.StableMCPNamespace(mcp.Name, mcp.Namespace)
827+
Expect(err).ToNot(HaveOccurred())
828+
829+
cr := &clustersv1alpha1.ClusterRequest{}
830+
cr.SetName(mcp.Name)
831+
cr.SetNamespace(platformNamespace)
832+
Expect(env.Client(platform).Get(env.Ctx, client.ObjectKeyFromObject(cr), cr)).To(Succeed())
833+
834+
// fake ClusterRequest ready status and Cluster resource
835+
By("fake: ClusterRequest readiness")
836+
cluster := &clustersv1alpha1.Cluster{}
837+
cluster.SetName("cluster-01")
838+
cluster.SetNamespace(platformNamespace)
839+
cluster.Spec.Purposes = []string{rec.Config.MCPClusterPurpose}
840+
Expect(env.Client(platform).Create(env.Ctx, cluster)).To(Succeed())
841+
cluster.Status.Conditions = []metav1.Condition{
842+
{
843+
Type: "TestCondition1",
844+
Status: metav1.ConditionTrue,
845+
Reason: "TestReason",
846+
Message: "This is a test condition",
847+
LastTransitionTime: metav1.Now(),
848+
ObservedGeneration: 1,
849+
},
850+
{
851+
Type: "TestCondition2",
852+
Status: metav1.ConditionFalse,
853+
Reason: "TestReason",
854+
Message: "This is another test condition",
855+
LastTransitionTime: metav1.Now(),
856+
ObservedGeneration: 1,
857+
},
858+
}
859+
Expect(env.Client(platform).Status().Update(env.Ctx, cluster)).To(Succeed())
860+
cr.Status.Phase = clustersv1alpha1.REQUEST_GRANTED
861+
cr.Status.Cluster = &commonapi.ObjectReference{
862+
Name: cluster.Name,
863+
Namespace: cluster.Namespace,
864+
}
865+
Expect(env.Client(platform).Status().Update(env.Ctx, cr)).To(Succeed())
866+
867+
env.ShouldReconcile(mcpRec, testutils.RequestFromObject(mcp))
868+
})
869+
817870
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: core.openmcp.cloud/v2alpha1
2+
kind: ManagedControlPlaneV2
3+
metadata:
4+
name: mcp-03
5+
namespace: test
6+
finalizers:
7+
- services.openmcp.cloud/sp-01
8+
- services.openmcp.cloud/sp-02
9+
spec:
10+
iam:
11+
tokens:
12+
- name: admin
13+
roleRefs:
14+
- kind: ClusterRole
15+
name: cluster-admin
16+
permissions:
17+
- rules:
18+
- apiGroups: [ '' ]
19+
resources: [ 'secretcs']
20+
verbs: [ '*' ]
21+
- name: viewer
22+
permissions:
23+
- rules:
24+
- apiGroups: [ '' ]
25+
resources: [ 'pods', 'services' ]
26+
verbs: [ 'get', 'list', 'watch' ]

lib/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/onsi/ginkgo/v2 v2.25.3
99
github.com/onsi/gomega v1.38.2
1010
github.com/openmcp-project/controller-utils v0.22.0
11-
github.com/openmcp-project/openmcp-operator/api v0.15.0
11+
github.com/openmcp-project/openmcp-operator/api v0.15.1
1212
k8s.io/api v0.34.1
1313
k8s.io/apimachinery v0.34.1
1414
k8s.io/client-go v0.34.1

0 commit comments

Comments
 (0)