Skip to content

Commit 4bb7a56

Browse files
committed
Fix tests after rebasing on main
* Test new ServiceAccount behavior (role binds to individual serviceaccounts rather than all SAs in namespace) * Set default PodSecurityContext when using a config for testing to accomodate changes around how PodSecurityContext is handled in OpenShift Signed-off-by: Angel Misevski <[email protected]>
1 parent 0746ad7 commit 4bb7a56

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

controllers/workspace/devworkspace_controller_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ var _ = Describe("DevWorkspace Controller", func() {
177177
})
178178

179179
It("Creates roles and rolebindings", func() {
180+
devworkspace := getExistingDevWorkspace(devWorkspaceName)
180181
By("Checking that common role is created")
181182
dwRole := &rbacv1.Role{}
182183
Eventually(func() bool {
@@ -196,9 +197,9 @@ var _ = Describe("DevWorkspace Controller", func() {
196197
}, timeout, interval).Should(BeTrue(), "Common RoleBinding should be created for DevWorkspace")
197198
Expect(dwRoleBinding.RoleRef.Name).Should(Equal(dwRole.Name), "Rolebinding should refer to DevWorkspace role")
198199
expectedSubject := rbacv1.Subject{
199-
APIGroup: "rbac.authorization.k8s.io",
200-
Kind: "Group",
201-
Name: fmt.Sprintf("system:serviceaccounts:%s", testNamespace),
200+
Kind: rbacv1.ServiceAccountKind,
201+
Name: common.ServiceAccountName(&common.DevWorkspaceWithConfig{DevWorkspace: devworkspace, Config: testControllerCfg}),
202+
Namespace: testNamespace,
202203
}
203204
Expect(dwRoleBinding.Subjects).Should(ContainElement(expectedSubject), "Rolebinding should bind to serviceaccounts in current namespace")
204205
})
@@ -272,7 +273,7 @@ var _ = Describe("DevWorkspace Controller", func() {
272273

273274
sa := &corev1.ServiceAccount{}
274275
Eventually(func() error {
275-
saNN := namespacedName(common.ServiceAccountName(workspaceID), testNamespace)
276+
saNN := namespacedName(common.ServiceAccountName(&common.DevWorkspaceWithConfig{DevWorkspace: devworkspace, Config: testControllerCfg}), testNamespace)
276277
return k8sClient.Get(ctx, saNN, sa)
277278
}, timeout, interval).Should(Succeed(), "Should create DevWorkspace ServiceAccount")
278279

controllers/workspace/suite_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/devfile/devworkspace-operator/controllers/workspace/internal/testutil"
2828
appsv1 "k8s.io/api/apps/v1"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
"k8s.io/utils/pointer"
3031
"sigs.k8s.io/yaml"
3132

3233
workspacecontroller "github.com/devfile/devworkspace-operator/controllers/workspace"
@@ -37,7 +38,6 @@ import (
3738
. "github.com/onsi/gomega"
3839
corev1 "k8s.io/api/core/v1"
3940
"k8s.io/client-go/kubernetes/scheme"
40-
"k8s.io/client-go/rest"
4141
ctrl "sigs.k8s.io/controller-runtime"
4242
"sigs.k8s.io/controller-runtime/pkg/client"
4343
"sigs.k8s.io/controller-runtime/pkg/envtest"
@@ -51,16 +51,17 @@ const (
5151
)
5252

5353
var (
54-
cfg *rest.Config
5554
k8sClient client.Client
5655
testEnv *envtest.Environment
5756
ctx context.Context
5857
cancel context.CancelFunc
59-
testControllerCfg = &controllerv1alpha1.OperatorConfiguration{
58+
testControllerCfg = config.GetConfigForTesting(&controllerv1alpha1.OperatorConfiguration{
59+
Workspace: &controllerv1alpha1.WorkspaceConfig{},
6060
Routing: &controllerv1alpha1.RoutingConfig{
6161
ClusterHostSuffix: "test-environment-cluster-suffix",
6262
},
63-
}
63+
EnableExperimentalFeatures: pointer.Bool(true),
64+
})
6465
)
6566

6667
func TestAPIs(t *testing.T) {
@@ -93,6 +94,7 @@ var _ = BeforeSuite(func() {
9394
Expect(cfg).NotTo(BeNil())
9495

9596
infrastructure.InitializeForTesting(infrastructure.Kubernetes)
97+
config.SetGlobalConfigForTesting(testControllerCfg)
9698

9799
err = controllerv1alpha1.AddToScheme(scheme.Scheme)
98100
Expect(err).NotTo(HaveOccurred())
@@ -125,8 +127,6 @@ var _ = BeforeSuite(func() {
125127
})
126128
Expect(err).NotTo(HaveOccurred())
127129

128-
config.SetGlobalConfigForTesting(testControllerCfg)
129-
130130
// Don't set up DevWorkspaceRouting Reconciler so that we can manage routings
131131

132132
err = (&workspacecontroller.DevWorkspaceReconciler{

pkg/config/sync.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func GetConfigForTesting(customConfig *controller.OperatorConfiguration) *contro
9999
func SetGlobalConfigForTesting(testConfig *controller.OperatorConfiguration) {
100100
configMutex.Lock()
101101
defer configMutex.Unlock()
102+
setDefaultPodSecurityContext()
102103
internalConfig = defaultConfig.DeepCopy()
103104
mergeConfig(testConfig, internalConfig)
104105
}

pkg/provision/workspace/deployment.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ func SyncDeploymentToCluster(
9494
return DeploymentProvisioningStatus{ProvisioningStatus{Err: err}}
9595
}
9696
clusterDeployment := clusterObj.(*appsv1.Deployment)
97-
9897
deploymentReady := status.CheckDeploymentStatus(clusterDeployment)
9998
if deploymentReady {
10099
return DeploymentProvisioningStatus{

0 commit comments

Comments
 (0)