generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Anatolii Bazko <[email protected]>
- Loading branch information
Showing
21 changed files
with
834 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
src/main/kotlin/com/github/devspaces/gateway/DevSpacesView.kt
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/github/devspaces/gateway/help/DevSpacesWebHelp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) 2024 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package com.github.devspaces.gateway.help | ||
|
||
const val DEVSPACES_DOC_LINK = "https://access.redhat.com/documentation/en-us/red_hat_openshift_dev_spaces" | ||
|
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/github/devspaces/gateway/openshift/DevSpacesContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright (c) 2024 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package com.github.devspaces.gateway.openshift | ||
|
||
import io.kubernetes.client.openapi.ApiClient | ||
|
||
class DevSpacesContext() { | ||
lateinit var client: ApiClient | ||
lateinit var devWorkspace: Any | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/kotlin/com/github/devspaces/gateway/openshift/DevSpacesGatewayConnection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2024 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package com.github.devspaces.gateway.openshift | ||
|
||
import io.kubernetes.client.openapi.models.V1Pod | ||
import java.io.IOException | ||
|
||
class DevSpacesGatewayConnection(private val devSpacesContext: DevSpacesContext) { | ||
@Throws(Exception::class) | ||
fun connect() { | ||
val name = Utils.getValue(devSpacesContext.devWorkspace, arrayOf("metadata", "name")) as String | ||
val namespace = Utils.getValue(devSpacesContext.devWorkspace, arrayOf("metadata", "namespace")) as String | ||
|
||
val podList = Pods(devSpacesContext.client).list( | ||
namespace, | ||
String.format("controller.devfile.io/devworkspace_name=%s", name) | ||
) | ||
|
||
if (podList.items.size != 1) throw IOException(String.format("Expected 1 pod, but found %d", podList.items.size)) | ||
val pod = podList.items[0] | ||
|
||
val connectionURI = getConnectionURI(pod) | ||
if (connectionURI == "") throw IOException("Connection URI not found") | ||
|
||
val devSpacesPortForward = DevSpacesPortForward(devSpacesContext.client) | ||
devSpacesPortForward.start(pod) | ||
|
||
// TODO CONNECT | ||
} | ||
|
||
private fun getConnectionURI(pod: V1Pod): String { | ||
for (container in pod.spec?.containers!!) { | ||
try { | ||
val result = Exec(devSpacesContext.client).run( | ||
pod, | ||
arrayOf("grep", "-Eo", "-m1", "tcp://.*", "/idea-server/std.out"), | ||
container.name | ||
) | ||
if (result != "") return result | ||
} catch (e: Exception) { | ||
continue | ||
} | ||
} | ||
|
||
return "" | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/kotlin/com/github/devspaces/gateway/openshift/DevSpacesPortForward.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (c) 2024 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package com.github.devspaces.gateway.openshift | ||
|
||
import io.kubernetes.client.PortForward | ||
import io.kubernetes.client.openapi.ApiClient | ||
import io.kubernetes.client.openapi.Configuration | ||
import io.kubernetes.client.openapi.models.V1Pod | ||
import io.kubernetes.client.util.Streams | ||
import java.net.ServerSocket | ||
|
||
|
||
// Sample: | ||
// https://github.com/kubernetes-client/java/blob/master/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PortForwardExample.java | ||
class DevSpacesPortForward(private val client: ApiClient) { | ||
private val port = 5990 | ||
private lateinit var toLocalFromRemoteThread: Thread | ||
private lateinit var fromLocalToRemoteThread: Thread | ||
fun start(pod: V1Pod) { | ||
Configuration.setDefaultApiClient(client) | ||
val forwarding = PortForward().forward( | ||
pod.metadata?.namespace, | ||
pod.metadata?.name, | ||
arrayListOf(port) | ||
) | ||
|
||
val serverSocket = ServerSocket(port) | ||
val socket = serverSocket.accept() | ||
|
||
toLocalFromRemoteThread = Thread { | ||
Streams.copy(forwarding.getInputStream(port), socket.getOutputStream()) | ||
} | ||
|
||
fromLocalToRemoteThread = Thread { | ||
Streams.copy(socket.getInputStream(), forwarding.getOutboundStream(port)) | ||
} | ||
|
||
toLocalFromRemoteThread.start() | ||
fromLocalToRemoteThread.start() | ||
} | ||
|
||
fun stop() { | ||
toLocalFromRemoteThread.interrupt() | ||
fromLocalToRemoteThread.interrupt() | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/kotlin/com/github/devspaces/gateway/openshift/DevWorkspaces.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright (c) 2024 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package com.github.devspaces.gateway.openshift | ||
|
||
import io.kubernetes.client.openapi.ApiClient | ||
import io.kubernetes.client.openapi.ApiException | ||
import io.kubernetes.client.openapi.apis.CustomObjectsApi | ||
|
||
class DevWorkspaces(private val client: ApiClient) { | ||
@Throws(ApiException::class) | ||
fun list(namespace: String): Any { | ||
val customApi = CustomObjectsApi(client) | ||
return customApi.listNamespacedCustomObject( | ||
"workspace.devfile.io", | ||
"v1alpha2", | ||
namespace, | ||
"devworkspaces", | ||
"false", | ||
false, | ||
"", | ||
"", | ||
"", | ||
-1, | ||
"", | ||
"", | ||
-1, | ||
false | ||
) | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/com/github/devspaces/gateway/openshift/Exec.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2024 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package com.github.devspaces.gateway.openshift | ||
|
||
import io.kubernetes.client.Exec | ||
import io.kubernetes.client.openapi.ApiClient | ||
import io.kubernetes.client.openapi.Configuration | ||
import io.kubernetes.client.openapi.models.V1Pod | ||
import io.kubernetes.client.util.Streams | ||
import java.io.ByteArrayOutputStream | ||
|
||
|
||
// Sample: | ||
// https://github.com/kubernetes-client/java/blob/master/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ExecExample.java | ||
class Exec(private val client: ApiClient) { | ||
fun run(pod: V1Pod, command: Array<String>, container: String): String { | ||
val output = ByteArrayOutputStream() | ||
|
||
Configuration.setDefaultApiClient(client) | ||
val process = Exec().exec(pod, command, container, false, false) | ||
|
||
val copyOutputThread = | ||
Thread { | ||
Streams.copy(process.inputStream, output) | ||
} | ||
copyOutputThread.start() | ||
|
||
process.waitFor() | ||
copyOutputThread.join() | ||
process.destroy() | ||
|
||
return output.toString() | ||
} | ||
} |
Oops, something went wrong.