Skip to content

Commit 14a31bc

Browse files
committed
Propagate restricted-access to cleanup job and handle in webhook
* Propagate restricted-access annotation from DevWorkspace to the cleanup job * Handle restricted-access annotation as normal for Jobs Signed-off-by: Angel Misevski <[email protected]>
1 parent 980767e commit 14a31bc

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

controllers/workspace/finalize.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,17 @@ func (r *DevWorkspaceReconciler) finalize(ctx context.Context, log logr.Logger,
111111
func (r *DevWorkspaceReconciler) getSpecCleanupJob(workspace *v1alpha2.DevWorkspace) (*batchv1.Job, error) {
112112
workspaceId := workspace.Status.WorkspaceId
113113
pvcName := config.ControllerCfg.GetWorkspacePVCName()
114-
114+
jobLabels := map[string]string{
115+
config.WorkspaceIDLabel: workspaceId,
116+
}
117+
if restrictedAccess, needsRestrictedAccess := workspace.Annotations[config.WorkspaceRestrictedAccessAnnotation]; needsRestrictedAccess {
118+
jobLabels[config.WorkspaceRestrictedAccessAnnotation] = restrictedAccess
119+
}
115120
job := &batchv1.Job{
116121
ObjectMeta: metav1.ObjectMeta{
117122
Name: common.PVCCleanupJobName(workspaceId),
118123
Namespace: workspace.Namespace,
119-
Labels: map[string]string{
120-
config.WorkspaceIDLabel: workspaceId,
121-
},
124+
Labels: jobLabels,
122125
},
123126
Spec: batchv1.JobSpec{
124127
Completions: &cleanupJobCompletions,

webhook/workspace/handler/kind.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
//
1212
package handler
1313

14-
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14+
import (
15+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16+
)
1517

1618
var (
1719
V1alpha1DevWorkspaceKind = metav1.GroupVersionKind{Kind: "DevWorkspace", Group: "workspace.devfile.io", Version: "v1alpha1"}
@@ -23,5 +25,6 @@ var (
2325
V1PodKind = metav1.GroupVersionKind{Kind: "Pod", Group: "", Version: "v1"}
2426
V1ServiceKind = metav1.GroupVersionKind{Kind: "Service", Group: "", Version: "v1"}
2527
V1beta1IngressKind = metav1.GroupVersionKind{Kind: "Ingress", Group: "extensions", Version: "v1beta1"}
28+
V1JobKind = metav1.GroupVersionKind{Kind: "Job", Group: "batch", Version: "v1"}
2629
V1RouteKind = metav1.GroupVersionKind{Kind: "Route", Group: "route.openshift.io", Version: "v1"}
2730
)

webhook/workspace/mutate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (m *ResourcesMutator) Handle(ctx context.Context, req admission.Request) ad
4545
return m.MutatePodOnCreate(ctx, req)
4646
case handler.AppsV1DeploymentKind:
4747
return m.MutateDeploymentOnCreate(ctx, req)
48-
case handler.V1ServiceKind, handler.V1beta1IngressKind, handler.V1RouteKind,
48+
case handler.V1ServiceKind, handler.V1beta1IngressKind, handler.V1RouteKind, handler.V1JobKind,
4949
handler.V1alpha1ComponentKind, handler.V1alpha1WorkspaceRoutingKind:
5050

5151
return m.HandleRestrictedAccessCreate(ctx, req)
@@ -62,7 +62,7 @@ func (m *ResourcesMutator) Handle(ctx context.Context, req admission.Request) ad
6262
return m.MutatePodOnUpdate(ctx, req)
6363
case handler.AppsV1DeploymentKind:
6464
return m.MutateDeploymentOnUpdate(ctx, req)
65-
case handler.V1ServiceKind, handler.V1beta1IngressKind, handler.V1RouteKind,
65+
case handler.V1ServiceKind, handler.V1beta1IngressKind, handler.V1RouteKind, handler.V1JobKind,
6666
handler.V1alpha1ComponentKind, handler.V1alpha1WorkspaceRoutingKind:
6767

6868
return m.HandleRestrictedAccessUpdate(ctx, req)

webhook/workspace/mutating_cfg.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ func BuildMutateWebhookCfg(namespace string) *v1beta1.MutatingWebhookConfigurati
109109
Resources: []string{"ingresses"},
110110
},
111111
},
112+
{
113+
Operations: []v1beta1.OperationType{v1beta1.Create, v1beta1.Update},
114+
Rule: v1beta1.Rule{
115+
APIGroups: []string{"batch"},
116+
APIVersions: []string{"v1"},
117+
Resources: []string{"jobs"},
118+
},
119+
},
112120
},
113121
}
114122
// n.b. Routes do not get UserInfo.UID filled in webhooks for some reason

0 commit comments

Comments
 (0)