-
Notifications
You must be signed in to change notification settings - Fork 69
fix (storage) : use operator podSecurityContext for PVC cleanup job on OpenShift #1638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // | ||
| // Copyright (c) 2019-2025 Red Hat, Inc. | ||
| // 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 As per coding guidelines: 🤖 Prompt for AI Agents |
||
|
|
||
| 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) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the copyright year in the file header.
Line 2 still uses
2019-2025; this should be2019-2026for 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