Skip to content

Commit 9d2e3c1

Browse files
committed
Adding port forward to OKE Pod
1 parent d244350 commit 9d2e3c1

32 files changed

+1478
-90
lines changed

enterprise/cloud.oracle/nbproject/project.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,22 @@
209209
<specification-version>1.48</specification-version>
210210
</run-dependency>
211211
</dependency>
212+
<dependency>
213+
<code-name-base>org.netbeans.api.io</code-name-base>
214+
<build-prerequisite/>
215+
<compile-dependency/>
216+
<run-dependency>
217+
<specification-version>1.29</specification-version>
218+
</run-dependency>
219+
</dependency>
220+
<dependency>
221+
<code-name-base>org.openide.explorer</code-name-base>
222+
<build-prerequisite/>
223+
<compile-dependency/>
224+
<run-dependency>
225+
<specification-version>6.50</specification-version>
226+
</run-dependency>
227+
</dependency>
212228
<dependency>
213229
<code-name-base>org.netbeans.modules.websvc.restlib</code-name-base>
214230
<build-prerequisite/>

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/CloudChildFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*
3232
* @author Jan Horvath
3333
*/
34-
public class CloudChildFactory extends ChildFactory<OCIItem> {
34+
public class CloudChildFactory extends ChildFactory<OCIItem> implements RefreshableKeys {
3535
private static final Logger LOG = Logger.getLogger(CloudChildFactory.class.getName());
3636

3737
private final OCIItem parent;
@@ -81,6 +81,7 @@ protected Node[] createNodesForKey(OCIItem key) {
8181
return new Node[]{nodeProvider.apply(key, session)};
8282
}
8383

84+
@Override
8485
public void refreshKeys() {
8586
refresh(false);
8687
}

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCINode.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import javax.swing.Action;
2727
import org.netbeans.modules.cloud.oracle.items.OCIItem;
2828
import org.openide.nodes.AbstractNode;
29+
import org.openide.nodes.ChildFactory;
2930
import org.openide.nodes.Children;
3031
import org.openide.nodes.Node;
3132
import org.openide.util.ContextAwareAction;
@@ -42,7 +43,7 @@ public class OCINode extends AbstractNode {
4243
private RefreshListener refreshListener;
4344

4445
private final OCIItem item;
45-
private final CloudChildFactory factory;
46+
private final ChildFactory factory;
4647
private final OCISessionInitiator session;
4748

4849
public OCINode(OCIItem item) {
@@ -53,7 +54,11 @@ public OCINode(OCIItem item, OCISessionInitiator session) {
5354
this(new CloudChildFactory(session, item), item, session, Lookups.fixed(item, session));
5455
}
5556

56-
private OCINode(CloudChildFactory factory, OCIItem item, OCISessionInitiator session, Lookup lookup) {
57+
public OCINode(OCIItem item, ChildFactory factory) {
58+
this(factory, item, null, Lookups.singleton(item));
59+
}
60+
61+
private OCINode(ChildFactory factory, OCIItem item, OCISessionInitiator session, Lookup lookup) {
5762
super(Children.create(factory, true), lookup);
5863
setName(item.getName());
5964
this.item = item;
@@ -113,8 +118,8 @@ public static final List<? extends Action> actionsForPath(String path, Lookup lk
113118

114119
public void refresh() {
115120
RequestProcessor.getDefault().post(() -> {
116-
if (factory != null) {
117-
factory.refreshKeys();
121+
if (factory != null && factory instanceof RefreshableKeys) {
122+
((RefreshableKeys) factory).refreshKeys();
118123
}
119124
update(item);
120125
});

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/OCIProfile.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
* Represents an OCI profile. A profile has a user, tenancy and region
6161
* assigned.
6262
*/
63+
@NbBundle.Messages({
64+
"LBL_HomeRegion=Region: {0}"
65+
})
6366
public final class OCIProfile implements OCISessionInitiator {
6467

6568
/**
@@ -178,9 +181,6 @@ public Tenancy getTenancyData() {
178181
* @return Optional {@code OCIItem} describing the Tenancy. If
179182
* Optional.empty() OCI configuration was not found
180183
*/
181-
@NbBundle.Messages({
182-
"LBL_HomeRegion=Region: {0}"
183-
})
184184
public Optional<TenancyItem> getTenancy() {
185185
if (configProvider == null) {
186186
return Optional.empty();
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.modules.cloud.oracle;
20+
21+
/**
22+
*
23+
* @author Jan Horvath
24+
*/
25+
public interface RefreshableKeys {
26+
27+
public void refreshKeys();
28+
29+
}

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/actions/ConfigMapUploader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.netbeans.api.project.ProjectUtils;
2525
import static org.netbeans.modules.cloud.oracle.NotificationUtils.showMessage;
2626
import org.netbeans.modules.cloud.oracle.assets.CloudAssets;
27-
import org.netbeans.modules.cloud.oracle.assets.ConfigMapProvider;
27+
import org.netbeans.modules.cloud.oracle.assets.k8s.ConfigMapProvider;
2828
import org.netbeans.modules.cloud.oracle.assets.Steps;
2929
import org.netbeans.modules.cloud.oracle.compute.ClusterItem;
3030
import org.netbeans.modules.cloud.oracle.steps.CompartmentStep;

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/RootNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class RootNode {
3939

4040
private static Node instance = null;
4141

42-
static synchronized Node instance() {
42+
public static synchronized Node instance() {
4343
if (instance == null) {
4444
instance = new AbstractNode(
4545
Children.create(new AssetsChildren(OCIManager.getDefault().getActiveSession()), true));

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/ConfigMapProvider.java renamed to enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/k8s/ConfigMapProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.netbeans.modules.cloud.oracle.assets;
19+
package org.netbeans.modules.cloud.oracle.assets.k8s;
2020

2121
import io.fabric8.kubernetes.api.model.ConfigMap;
2222
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
@@ -26,6 +26,7 @@
2626
import io.fabric8.kubernetes.client.KubernetesClient;
2727
import java.util.Map;
2828
import java.util.TreeMap;
29+
import org.netbeans.modules.cloud.oracle.assets.PropertiesGenerator;
2930
import org.netbeans.modules.cloud.oracle.compute.ClusterItem;
3031

3132
/**

enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/CreateSecretRotationCronJobCommand.java renamed to enterprise/cloud.oracle/src/org/netbeans/modules/cloud/oracle/assets/k8s/CreateSecretRotationCronJobCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
package org.netbeans.modules.cloud.oracle.assets;
19+
package org.netbeans.modules.cloud.oracle.assets.k8s;
2020

2121
import io.fabric8.kubernetes.api.model.PodTemplateSpec;
2222
import io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder;
@@ -53,6 +53,7 @@
5353
import java.util.concurrent.TimeoutException;
5454
import java.util.function.Supplier;
5555
import org.netbeans.modules.cloud.oracle.NotificationUtils;
56+
import org.netbeans.modules.cloud.oracle.assets.CloudAssets;
5657
import org.netbeans.modules.cloud.oracle.compute.ClusterItem;
5758
import org.openide.util.NbBundle;
5859

@@ -93,7 +94,7 @@ public CompletableFuture<Object> runCommand(String command, List<Object> argumen
9394
}
9495

9596
public CompletableFuture<Object> createSecretRotationCronJob() {
96-
CompletableFuture completableFuture = new CompletableFuture();
97+
CompletableFuture<Object> completableFuture = new CompletableFuture<> ();
9798
this.cluster = CloudAssets.getDefault().getItem(ClusterItem.class);
9899
KubernetesUtils.runWithClient(cluster, client -> {
99100
try {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.netbeans.modules.cloud.oracle.assets.k8s;
20+
21+
import io.fabric8.kubernetes.api.model.Pod;
22+
import io.fabric8.kubernetes.api.model.PodList;
23+
import io.fabric8.kubernetes.api.model.apps.Deployment;
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
import org.netbeans.modules.cloud.oracle.compute.ClusterItem;
27+
import org.netbeans.modules.cloud.oracle.compute.PodItem;
28+
import org.openide.util.NbBundle;
29+
30+
/**
31+
*
32+
* @author Jan Horvath
33+
*/
34+
@NbBundle.Messages({
35+
"ForwardingPorts=Forwarding http://localhost:{0} to a pod {1}"
36+
37+
})
38+
public class KubernetesLoaders {
39+
40+
public static List<PodItem> loadPods(ClusterItem cluster, List<String> deploymentNames) {
41+
final List<PodItem> result = new ArrayList<>();
42+
KubernetesUtils.runWithClient(cluster, client -> {
43+
for (String name : deploymentNames) {
44+
Deployment deployment = client
45+
.apps()
46+
.deployments()
47+
.inNamespace(cluster.getNamespace())
48+
.withName(name)
49+
.get();
50+
if (deployment == null) {
51+
continue;
52+
}
53+
54+
var labelSelector = deployment
55+
.getSpec()
56+
.getSelector()
57+
.getMatchLabels();
58+
59+
PodList podList = client.pods()
60+
.inNamespace(cluster.getNamespace())
61+
.withLabels(labelSelector)
62+
.list();
63+
for (Pod pod : podList.getItems()) {
64+
result.add(new PodItem(cluster,
65+
pod.getMetadata().getNamespace(),
66+
pod.getMetadata().getName()));
67+
}
68+
}
69+
});
70+
return result;
71+
}
72+
73+
}

0 commit comments

Comments
 (0)