Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions pkg/provision/storage/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"time"

"github.com/devfile/devworkspace-operator/pkg/dwerrors"
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
"github.com/devfile/devworkspace-operator/pkg/library/status"
nsconfig "github.com/devfile/devworkspace-operator/pkg/provision/config"
"github.com/devfile/devworkspace-operator/pkg/provision/sync"
Expand Down Expand Up @@ -138,13 +137,6 @@ func getSpecCommonPVCCleanupJob(workspace *common.DevWorkspaceWithConfig, cluste
jobLabels[constants.DevWorkspaceRestrictedAccessAnnotation] = restrictedAccess
}

var securityContext *corev1.PodSecurityContext
if infrastructure.IsOpenShift() {
securityContext = &corev1.PodSecurityContext{}
} else {
securityContext = workspace.Config.Workspace.PodSecurityContext
}

job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: common.PVCCleanupJobName(workspaceId),
Expand All @@ -160,7 +152,7 @@ func getSpecCommonPVCCleanupJob(workspace *common.DevWorkspaceWithConfig, cluste
},
Spec: corev1.PodSpec{
RestartPolicy: "Never",
SecurityContext: securityContext,
SecurityContext: workspace.Config.Workspace.PodSecurityContext,
Volumes: []corev1.Volume{
{
Name: pvcName,
Expand Down
81 changes: 81 additions & 0 deletions pkg/provision/storage/cleanup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// Copyright (c) 2019-2025 Red Hat, Inc.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Update the copyright year in the file header.

Line 2 still uses 2019-2025; this should be 2019-2026 for current-year compliance.

As per coding guidelines: **/*.go: All Go source files MUST start with the copyright header: '// Copyright (c) 2019-{CURRENT_YEAR} Red Hat, Inc.' followed by Apache License 2.0 license text.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/provision/storage/cleanup_test.go` at line 2, Update the copyright header
string in this Go source to reflect the current year: change the header text
that reads "// Copyright (c) 2019-2025 Red Hat, Inc." to "// Copyright (c)
2019-2026 Red Hat, Inc." so it matches the required pattern for Go files (the
header followed by the Apache License 2.0 text); ensure the exact header line in
the file is replaced accordingly.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package storage

import (
"context"
"testing"

dw "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
"github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
"github.com/devfile/devworkspace-operator/pkg/common"
"github.com/devfile/devworkspace-operator/pkg/constants"
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
"github.com/devfile/devworkspace-operator/pkg/provision/sync"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)
Comment on lines +18 to +33
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Reorder imports into the required three groups.

Lines 18-33 currently mix third-party/Kubernetes and project-local imports in one block; split into: standard library, third-party+Kubernetes, then project-local (or run make fmt).

As per coding guidelines: **/*.go: Organize imports into three groups separated by blank lines: (1) standard library, (2) third-party + Kubernetes, (3) project-local. Run 'make fmt' to enforce automatically.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/provision/storage/cleanup_test.go` around lines 18 - 33, Reorder the
import block in cleanup_test.go into three groups separated by single blank
lines: first put standard library imports (context, testing), then third-party +
Kubernetes imports (github.com/stretchr/testify/assert,
sigs.k8s.io/controller-runtime/pkg/log/zap,
sigs.k8s.io/controller-runtime/pkg/client/fake, k8s.io/api/core/v1,
k8s.io/apimachinery/pkg/apis/meta/v1, and any other non-local packages), and
finally project-local imports (github.com/devfile/api/v2/...,
github.com/devfile/devworkspace-operator/...,
github.com/devfile/devworkspace-operator/pkg/..., etc.); run make fmt or
goimports to enforce formatting. Ensure the import names shown in the diff
(context, testing, dw, assert, corev1, metav1, fake, zap and project packages
like common, constants, infrastructure, sync, v1alpha1) are placed into the
correct groups.


func TestGetSpecCommonPVCCleanupJobUsesConfigPodSecurityContext(t *testing.T) {
infrastructure.InitializeForTesting(infrastructure.OpenShiftv4)

fsGroupChangeOnRootMismatch := corev1.FSGroupChangeOnRootMismatch
customPodSecurityContext := &corev1.PodSecurityContext{
FSGroupChangePolicy: &fsGroupChangeOnRootMismatch,
SELinuxOptions: &corev1.SELinuxOptions{Type: "spc_t"},
}

namespace := "test-ns"
pvcName := "claim-devworkspace"
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(
&corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}},
).Build()

workspace := &common.DevWorkspaceWithConfig{
DevWorkspace: &dw.DevWorkspace{
ObjectMeta: metav1.ObjectMeta{
Name: "test-workspace",
Namespace: namespace,
Labels: map[string]string{
constants.DevWorkspaceCreatorLabel: "test-creator",
},
},
Status: dw.DevWorkspaceStatus{
DevWorkspaceId: "test-workspace-id",
},
},
Config: &v1alpha1.OperatorConfiguration{
Workspace: &v1alpha1.WorkspaceConfig{
PVCName: pvcName,
PodSecurityContext: customPodSecurityContext,
},
},
}

clusterAPI := sync.ClusterAPI{
Client: fakeClient,
Scheme: scheme,
Logger: zap.New(zap.UseDevMode(true)),
Ctx: context.Background(),
}

job, err := getSpecCommonPVCCleanupJob(workspace, clusterAPI)
assert.NoError(t, err)
assert.Equal(t, customPodSecurityContext, job.Spec.Template.Spec.SecurityContext)
}
Loading