Skip to content

Commit ae2ca7e

Browse files
committed
update nits
1 parent db09add commit ae2ca7e

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

pkg/admission/workspace/admission.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,16 @@ func (o *workspace) Validate(ctx context.Context, a admission.Attributes, _ admi
212212
if !isSystemPrivileged && ws.Spec.Type != nil {
213213
return admission.NewForbidden(a, errors.New("spec.type cannot be set for mounted workspaces"))
214214
}
215-
216-
if old.Spec.Type.Path != ws.Spec.Type.Path || old.Spec.Type.Name != ws.Spec.Type.Name {
215+
// Check for immutability of spec.type via pointers checks first.
216+
if (old.Spec.Type == nil && ws.Spec.Type != nil) || (old.Spec.Type != nil && ws.Spec.Type == nil) {
217217
return admission.NewForbidden(a, errors.New("spec.type is immutable"))
218218
}
219+
// Check for immutability of spec.type via field checks.
220+
if old.Spec.Type != nil && ws.Spec.Type != nil {
221+
if old.Spec.Type.Path != ws.Spec.Type.Path || old.Spec.Type.Name != ws.Spec.Type.Name {
222+
return admission.NewForbidden(a, errors.New("spec.type is immutable"))
223+
}
224+
}
219225
}
220226
case admission.Create:
221227
// only system users can set spec.Cluster or spec.URL

test/e2e/mounts/mounts_machinery_test.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,19 @@ func TestMountsMachinery(t *testing.T) {
7070
ctx, cancelFunc := context.WithCancel(context.Background())
7171
t.Cleanup(cancelFunc)
7272

73-
_, _ = kcptesting.NewWorkspaceFixture(t, server, core.RootCluster.Path())
74-
75-
orgSource, _ := kcptesting.NewWorkspaceFixture(t, server, core.RootCluster.Path(),
76-
kcptesting.WithName("source"),
77-
kcptesting.WithType(core.RootCluster.Path(), "organization"))
78-
orgDestination, _ := kcptesting.NewWorkspaceFixture(t, server, core.RootCluster.Path(),
79-
kcptesting.WithName("destination"),
80-
kcptesting.WithType(core.RootCluster.Path(), "organization"))
81-
82-
sourcePath, _ := kcptesting.NewWorkspaceFixture(t, server, orgSource, kcptesting.WithName("source"))
83-
_, destinationWorkspaceObj := kcptesting.NewWorkspaceFixture(t, server, orgDestination, kcptesting.WithName("destination"))
73+
// This will create structure as bellow for testing:
74+
// └── root
75+
// └── e2e-workspace-n784f
76+
// ├── destination
77+
// └── source
78+
// └── mount
79+
//
80+
rootOrg, _ := kcptesting.NewWorkspaceFixture(t, server, core.RootCluster.Path())
81+
82+
sourcePath, _ := kcptesting.NewWorkspaceFixture(t, server, rootOrg,
83+
kcptesting.WithName("source"))
84+
_, destinationWorkspaceObj := kcptesting.NewWorkspaceFixture(t, server, rootOrg,
85+
kcptesting.WithName("destination"))
8486

8587
cfg := server.BaseConfig(t)
8688
kcpClusterClient, err := kcpclientset.NewForConfig(cfg)
@@ -142,7 +144,7 @@ func TestMountsMachinery(t *testing.T) {
142144
Resource: "kubeclusters",
143145
}
144146
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
145-
destinationWorkspace, err := kcpClusterClient.Cluster(orgDestination).TenancyV1alpha1().Workspaces().Get(ctx, destinationWorkspaceObj.Name, metav1.GetOptions{})
147+
destinationWorkspace, err := kcpClusterClient.Cluster(rootOrg).TenancyV1alpha1().Workspaces().Get(ctx, destinationWorkspaceObj.Name, metav1.GetOptions{})
146148
require.NoError(t, err)
147149

148150
if destinationWorkspace.Spec.URL == "" {

0 commit comments

Comments
 (0)