Skip to content

Commit

Permalink
Add devworkspace controller test for duplicate target port on contain…
Browse files Browse the repository at this point in the history
…er and kubernetes component

Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
  • Loading branch information
AObuchow committed Oct 16, 2023
1 parent d8cf3a7 commit 0f1d799
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
46 changes: 46 additions & 0 deletions controllers/workspace/devworkspace_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,4 +929,50 @@ var _ = Describe("DevWorkspace Controller", func() {
}, timeout, interval).Should(BeTrue(), "Finalizer should be cleared and workspace should be deleted")
})
})

Context("Edge cases", func() {

It("Allows Kubernetes and Container components to share same target port on endpoint", func() {
createDevWorkspace(devWorkspaceName, "test-devworkspace-duplicate-ports.yaml")
defer deleteDevWorkspace(devWorkspaceName)
devworkspace := getExistingDevWorkspace(devWorkspaceName)
workspaceID := devworkspace.Status.DevWorkspaceId

workspacecontroller.SetupHttpClientsForTesting(&http.Client{
Transport: &testutil.TestRoundTripper{
Data: map[string]testutil.TestResponse{
"test-url/healthz": {
StatusCode: http.StatusOK,
},
},
},
})
By("Manually making Routing ready to continue")
markRoutingReady("test-url", common.DevWorkspaceRoutingName(workspaceID))

By("Setting the deployment to have 1 ready replica")
markDeploymentReady(common.DeploymentName(workspaceID))

currDW := &dw.DevWorkspace{}
Eventually(func() (dw.DevWorkspacePhase, error) {
err := k8sClient.Get(ctx, namespacedName(devworkspace.Name, devworkspace.Namespace), currDW)
if err != nil {
return "", err
}
GinkgoWriter.Printf("Waiting for DevWorkspace to enter running phase -- Phase: %s, Message %s\n", currDW.Status.Phase, currDW.Status.Message)
return currDW.Status.Phase, nil
}, timeout, interval).Should(Equal(dw.DevWorkspaceStatusRunning), "Workspace did not enter Running phase before timeout")

// Verify DevWorkspace is Running as expected
Expect(currDW.Status.Message).Should(Equal(currDW.Status.MainUrl))
runningCondition := conditions.GetConditionByType(currDW.Status.Conditions, dw.DevWorkspaceReady)
Expect(runningCondition).NotTo(BeNil())
Expect(runningCondition.Status).Should(Equal(corev1.ConditionTrue))

// Clean up
workspacecontroller.SetupHttpClientsForTesting(getBasicTestHttpClient())
})

})

})
4 changes: 4 additions & 0 deletions controllers/workspace/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
dwv2 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
"github.com/devfile/devworkspace-operator/controllers/workspace/internal/testutil"
kubesync "github.com/devfile/devworkspace-operator/pkg/library/kubernetes"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
Expand Down Expand Up @@ -108,6 +109,9 @@ var _ = BeforeSuite(func() {
Expect(k8sClient).NotTo(BeNil())

// Replicate controller setup similarly to how we do for main.go
err = kubesync.InitializeDeserializer(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

cacheFunc, err := cache.GetCacheFunc()
Expect(err).NotTo(HaveOccurred())

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
kind: DevWorkspace
apiVersion: workspace.devfile.io/v1alpha2
metadata:
labels:
controller.devfile.io/creator: ""
spec:
started: true
routingClass: 'basic'
template:
attributes:
controller.devfile.io/storage-type: ephemeral
projects:
- name: web-nodejs-sample
git:
remotes:
origin: "https://github.com/che-samples/web-nodejs-sample.git"
components:
- name: kubernetes-deploy
kubernetes:
deployByDefault: true
endpoints:
- name: http-8080
path: /
targetPort: 8080
inlined: |
apiVersion: v1
kind: Pod
metadata:
name: webserver-dwo-deployed
namespace: devworkspace-controller
spec:
containers:
- name: webserver
image: nginx:latest
ports:
- containerPort: 8080
- name: web-terminal
container:
image: quay.io/wto/web-terminal-tooling:next
memoryRequest: 256Mi
memoryLimit: 512Mi
mountSources: true
command:
- "tail"
- "-f"
- "/dev/null"
endpoints:
- name: 'http'
protocol: http
targetPort: 8080
exposure: public

0 comments on commit 0f1d799

Please sign in to comment.