@@ -164,30 +164,46 @@ func (o *workspace) Validate(ctx context.Context, a admission.Attributes, _ admi
164
164
return fmt .Errorf ("failed to convert unstructured to Workspace: %w" , err )
165
165
}
166
166
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
- }
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
+ }
176
177
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
- }
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
+ }
183
194
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 ))
195
+ } else {
196
+ if old .Spec .Mount .Reference .Kind != ws .Spec .Mount .Reference .Kind {
197
+ return admission .NewForbidden (a , errors .New ("spec.mount.kind is immutable" ))
198
+ }
199
+ if old .Spec .Mount .Reference .Name != ws .Spec .Mount .Reference .Name {
200
+ return admission .NewForbidden (a , errors .New ("spec.mount.name is immutable" ))
201
+ }
202
+ if old .Spec .Mount .Reference .Namespace != ws .Spec .Mount .Reference .Namespace {
203
+ return admission .NewForbidden (a , errors .New ("spec.mount.namespace is immutable" ))
188
204
}
189
- if ws .Spec .URL == "" {
190
- return admission .NewForbidden (a , fmt . Errorf ("spec.URL must be set for phase %s" , ws . Status . Phase ))
205
+ if old .Spec .Mount . Reference . APIVersion != ws . Spec . Mount . Reference . APIVersion {
206
+ return admission .NewForbidden (a , errors . New ("spec.mount.apiVersion is immutable" ))
191
207
}
192
208
}
193
209
case admission .Create :
0 commit comments