-
Notifications
You must be signed in to change notification settings - Fork 861
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
Adding port forward to OKE Pod #8014
base: master
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,29 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.netbeans.modules.cloud.oracle; | ||
|
||
/** | ||
* | ||
* @author Jan Horvath | ||
*/ | ||
public interface RefreshableKeys { | ||
|
||
public void refreshKeys(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.netbeans.modules.cloud.oracle.assets.k8s; | ||
|
||
import io.fabric8.kubernetes.api.model.Pod; | ||
import io.fabric8.kubernetes.api.model.PodList; | ||
import io.fabric8.kubernetes.api.model.apps.Deployment; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.netbeans.modules.cloud.oracle.compute.ClusterItem; | ||
import org.netbeans.modules.cloud.oracle.compute.PodItem; | ||
import org.openide.util.NbBundle; | ||
|
||
/** | ||
* | ||
* @author Jan Horvath | ||
*/ | ||
@NbBundle.Messages({ | ||
"ForwardingPorts=Forwarding http://localhost:{0} to a pod {1}" | ||
|
||
}) | ||
public class KubernetesLoaders { | ||
|
||
public static List<PodItem> loadPods(ClusterItem cluster, List<String> deploymentNames) { | ||
final List<PodItem> result = new ArrayList<>(); | ||
KubernetesUtils.runWithClient(cluster, client -> { | ||
for (String name : deploymentNames) { | ||
Deployment deployment = client | ||
.apps() | ||
.deployments() | ||
.inNamespace(cluster.getNamespace()) | ||
.withName(name) | ||
.get(); | ||
if (deployment == null) { | ||
continue; | ||
} | ||
|
||
var labelSelector = deployment | ||
.getSpec() | ||
.getSelector() | ||
.getMatchLabels(); | ||
|
||
PodList podList = client.pods() | ||
.inNamespace(cluster.getNamespace()) | ||
.withLabels(labelSelector) | ||
.list(); | ||
for (Pod pod : podList.getItems()) { | ||
result.add(new PodItem(cluster, | ||
pod.getMetadata().getNamespace(), | ||
pod.getMetadata().getName())); | ||
} | ||
} | ||
}); | ||
return result; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.netbeans.modules.cloud.oracle.assets; | ||
package org.netbeans.modules.cloud.oracle.assets.k8s; | ||
|
||
import com.oracle.bmc.Region; | ||
import com.oracle.bmc.http.Priorities; | ||
|
@@ -28,8 +28,6 @@ | |
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.fabric8.kubernetes.api.model.KubernetesResource; | ||
import io.fabric8.kubernetes.api.model.KubernetesResourceList; | ||
import io.fabric8.kubernetes.api.model.batch.v1.CronJob; | ||
import io.fabric8.kubernetes.api.model.batch.v1.CronJobList; | ||
import io.fabric8.kubernetes.client.Config; | ||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.KubernetesClientBuilder; | ||
|
@@ -45,7 +43,6 @@ | |
import org.netbeans.modules.cloud.oracle.OCIManager; | ||
import org.netbeans.modules.cloud.oracle.OCIProfile; | ||
import org.netbeans.modules.cloud.oracle.compute.ClusterItem; | ||
import org.openide.util.Exceptions; | ||
import org.snakeyaml.engine.v2.api.Dump; | ||
import org.snakeyaml.engine.v2.api.DumpSettings; | ||
import org.snakeyaml.engine.v2.api.Load; | ||
|
@@ -57,7 +54,7 @@ | |
*/ | ||
public class KubernetesUtils { | ||
|
||
static void runWithClient(ClusterItem cluster, Consumer<KubernetesClient> consumer) { | ||
public static void runWithClient(ClusterItem cluster, Consumer<KubernetesClient> consumer) { | ||
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. I'd suggest to add some label and use Logger to log start/end of (labelled) operation and some client config info. Could be useful for future debugging. |
||
if (cluster.getConfig() == null) { | ||
cluster.update(); | ||
} | ||
|
@@ -67,8 +64,8 @@ static void runWithClient(ClusterItem cluster, Consumer<KubernetesClient> consum | |
Config config = prepareConfig(cluster.getConfig(), cluster); | ||
try (KubernetesClient client = new KubernetesClientBuilder().withConfig(config).build();) { | ||
consumer.accept(client); | ||
} catch (Exception e) { | ||
Exceptions.printStackTrace(e); | ||
} catch (Throwable t) { | ||
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. No op ? |
||
throw t; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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 org.netbeans.modules.cloud.oracle.assets.k8s; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import org.netbeans.modules.cloud.oracle.compute.PodItem; | ||
import org.openide.awt.ActionID; | ||
import org.openide.awt.ActionRegistration; | ||
import org.openide.util.NbBundle; | ||
|
||
/** | ||
* | ||
* @author Jan Horvath | ||
*/ | ||
@ActionID( | ||
category = "Tools", | ||
id = "org.netbeans.modules.cloud.oracle.actions.PortForwardAction" | ||
) | ||
@ActionRegistration( | ||
displayName = "#PortForward", | ||
asynchronous = true | ||
) | ||
|
||
@NbBundle.Messages({ | ||
"PortForward=Start port forwarding" | ||
}) | ||
public class PortForwardAction implements ActionListener { | ||
private final PodItem pod; | ||
|
||
public PortForwardAction(PodItem pod) { | ||
this.pod = pod; | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
PortForwards.getDefault().startPortForward(pod); | ||
} | ||
|
||
} |
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.
no log / failed (ignored) result to the caller ?