@@ -164,30 +164,45 @@ func (o *workspace) Validate(ctx context.Context, a admission.Attributes, _ admi
164164 return fmt .Errorf ("failed to convert unstructured to Workspace: %w" , err )
165165 }
166166
167- if old .Spec .Cluster != "" && ws .Spec .Cluster == "" {
168- return admission .NewForbidden (a , errors .New ("spec.cluster cannot be unset" ))
169- }
170- if old .Spec .Cluster != ws .Spec .Cluster && ! isSystemPrivileged {
171- return admission .NewForbidden (a , errors .New ("spec.cluster can only be changed by system privileged users" ))
172- }
173- if old .Spec .URL != ws .Spec .URL && ! isSystemPrivileged {
174- return admission .NewForbidden (a , errors .New ("spec.URL can only be changed by system privileged users" ))
175- }
176-
177- if errs := validation .ValidateImmutableField (ws .Spec .Type , old .Spec .Type , field .NewPath ("spec" , "type" )); len (errs ) > 0 {
178- return admission .NewForbidden (a , errs .ToAggregate ())
179- }
180- if old .Spec .Type .Path != ws .Spec .Type .Path || old .Spec .Type .Name != ws .Spec .Type .Name {
181- return admission .NewForbidden (a , errors .New ("spec.type is immutable" ))
182- }
167+ if ! old .Spec .IsMounted () {
168+ if old .Spec .Cluster != "" && ws .Spec .Cluster == "" {
169+ return admission .NewForbidden (a , errors .New ("spec.cluster cannot be unset" ))
170+ }
171+ if old .Spec .Cluster != ws .Spec .Cluster && ! isSystemPrivileged {
172+ return admission .NewForbidden (a , errors .New ("spec.cluster can only be changed by system privileged users" ))
173+ }
174+ if old .Spec .URL != ws .Spec .URL && ! isSystemPrivileged {
175+ return admission .NewForbidden (a , errors .New ("spec.URL can only be changed by system privileged users" ))
176+ }
183177
184- // If we're transitioning to "Ready", make sure that spec.cluster and spec.URL are set.
185- if old .Status .Phase != corev1alpha1 .LogicalClusterPhaseReady && ws .Status .Phase == corev1alpha1 .LogicalClusterPhaseReady {
186- if ws .Spec .Cluster == "" {
187- return admission .NewForbidden (a , fmt .Errorf ("spec.cluster must be set for phase %s" , ws .Status .Phase ))
178+ if errs := validation .ValidateImmutableField (ws .Spec .Type , old .Spec .Type , field .NewPath ("spec" , "type" )); len (errs ) > 0 {
179+ return admission .NewForbidden (a , errs .ToAggregate ())
180+ }
181+ if old .Spec .Type .Path != ws .Spec .Type .Path || old .Spec .Type .Name != ws .Spec .Type .Name {
182+ return admission .NewForbidden (a , errors .New ("spec.type is immutable" ))
183+ }
184+ // If we're transitioning to "Ready", make sure that spec.cluster and spec.URL are set.
185+ // This applies only for non-mounted workspaces.
186+ if old .Status .Phase != corev1alpha1 .LogicalClusterPhaseReady && ws .Status .Phase == corev1alpha1 .LogicalClusterPhaseReady {
187+ if ws .Spec .Cluster == "" {
188+ return admission .NewForbidden (a , fmt .Errorf ("spec.cluster must be set for phase %s" , ws .Status .Phase ))
189+ }
190+ if ws .Spec .URL == "" {
191+ return admission .NewForbidden (a , fmt .Errorf ("spec.URL must be set for phase %s" , ws .Status .Phase ))
192+ }
193+ }
194+ } else {
195+ if old .Spec .Mount .Reference .Kind != ws .Spec .Mount .Reference .Kind {
196+ return admission .NewForbidden (a , errors .New ("spec.mount.kind is immutable" ))
197+ }
198+ if old .Spec .Mount .Reference .Name != ws .Spec .Mount .Reference .Name {
199+ return admission .NewForbidden (a , errors .New ("spec.mount.name is immutable" ))
200+ }
201+ if old .Spec .Mount .Reference .Namespace != ws .Spec .Mount .Reference .Namespace {
202+ return admission .NewForbidden (a , errors .New ("spec.mount.namespace is immutable" ))
188203 }
189- if ws .Spec .URL == "" {
190- return admission .NewForbidden (a , fmt . Errorf ("spec.URL must be set for phase %s" , ws . Status . Phase ))
204+ if old .Spec .Mount . Reference . APIVersion != ws . Spec . Mount . Reference . APIVersion {
205+ return admission .NewForbidden (a , errors . New ("spec.mount.apiVersion is immutable" ))
191206 }
192207 }
193208 case admission .Create :
0 commit comments