Skip to content

Commit

Permalink
dependabot & adjustment (#2)
Browse files Browse the repository at this point in the history
* feat(deps): bump dependencies version

Signed-off-by: widnyana <wid@widnyana.web.id>

* feat(deps): adjustment
make adjustment based on dependency updates

Signed-off-by: widnyana <wid@widnyana.web.id>

* chore(make): ensure nightly toolchain installed

Signed-off-by: widnyana <wid@widnyana.web.id>

---------

Signed-off-by: widnyana <wid@widnyana.web.id>
  • Loading branch information
widnyana authored Oct 9, 2024
1 parent 7427457 commit 348e5d3
Show file tree
Hide file tree
Showing 9 changed files with 1,131 additions and 704 deletions.
1,739 changes: 1,087 additions & 652 deletions Cargo.lock

Large diffs are not rendered by default.

33 changes: 12 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,45 @@ exclude = [".github/*", ".vscode/*", "target", "bin"]


[dependencies]
anyhow = "1.0.71"
anyhow = "1.0.89"
prettytable-rs = "0.10.0"
thiserror = "1.0.39"
tracing = "0.1.37"
thiserror = "1.0.64"
tracing = "0.1.40"

[dependencies.clap]
version = "4.1.8"
features = [
"cargo",
"suggestions",
"usage",
"std",
"error-context",
"derive",
"color",
]
version = "4.5.20"
features = ["cargo", "suggestions", "usage", "std", "error-context", "derive", "color", "wrap_help"]
optional = false
default-features = false

[dependencies.k8s-openapi]
version = "0.18.0"
features = ["v1_24"]
version = "0.23.0"
features = ["v1_30"]
optional = false

[dependencies.kube]
version = "0.82.2"
version = "0.95.0"
features = ["client", "oauth", "gzip", "openssl-tls", "runtime", "derive"]
optional = false
default-features = true

[dependencies.openssl]
version = "0.10.48"
version = "0.10.66"
features = ["vendored"]
optional = false

[dependencies.tokio]
version = "1.26.0"
version = "1.40.0"
features = ["full"]
optional = false

[dependencies.tracing-bunyan-formatter]
version = "0.3.6"
version = "0.3.9"
features = []
optional = false

[dependencies.tracing-subscriber]
version = "0.3.16"
version = "0.3.18"
features = ["env-filter"]
optional = false

Expand All @@ -85,6 +77,5 @@ path = "src/main.rs"
name = "kubectl-ports"
bench = false
doc = false
plugin = false
proc-macro = false
required-features = []
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ lint:
lint-fix:
@cargo fix


fmt-dep:
@rustup toolchain install nightly-x86_64-unknown-linux-gnu
@rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt


## Run format
fmt:
fmt: fmt-dep
@cargo +nightly fmt

## Analyse for unsafe usage - `cargo install cargo-geiger`
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# The default profile includes rustc, rust-std, cargo, rust-docs, rustfmt and clippy.
# https://rust-lang.github.io/rustup/concepts/profiles.html
profile = "default"
channel = "1.68.0"
channel = "1.81.0"
components = [ "rustfmt", "clippy" ]
4 changes: 4 additions & 0 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub async fn render_pod_as_table(data: &Vec<Resource>) {
table.set_format(get_table_format());

let row_titles = row![
bc->"Kind",
bc->"Namespace",
bc->"Pod Name",
bc->"Container name",
Expand All @@ -47,6 +48,7 @@ pub async fn render_pod_as_table(data: &Vec<Resource>) {
for p in d.ports.clone() {
#[allow(clippy::string_to_string)]
let c = vec![
cell!(d.kind),
cell!(d.namespace),
cell!(d.name),
cell!(p.container_name.clone()),
Expand All @@ -73,6 +75,7 @@ pub async fn render_svc_as_table(svcs: &Vec<ServiceResource>) {
bc->"Target Port",
bc->"Exposed Port",
bc->"Node Port",
bc->"External Traffic Policy",
];
table.set_titles(row_titles);

Expand All @@ -88,6 +91,7 @@ pub async fn render_svc_as_table(svcs: &Vec<ServiceResource>) {
cell!(format!("{}/{}", p.target_port, p.protocol)),
cell!(format!("{}/{}", p.exposed_port, p.protocol)),
cell!(format!("{}/{}", p.node_port, p.protocol)),
cell!(svc.external_traffic_policy),
];
table.add_row(Row::new(c));
}
Expand Down
14 changes: 5 additions & 9 deletions src/extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use k8s_openapi::api::core::v1::{
use kube::{
api::ObjectList,
Client,
ResourceExt,
};
use tracing::{
error,
Expand Down Expand Up @@ -49,8 +48,8 @@ async fn process_ports_from_pods(
for pod in pods.into_iter().filter(is_scheduled) {
let mut tmp = Resource::new(
"pod".to_string(),
pod.name_any(),
pod.namespace().clone().unwrap_or_default(),
pod.metadata.name.unwrap_or_else(|| String::from("unknown")),
pod.metadata.namespace.unwrap_or_else(|| String::from("unknown")),
);

let spec = pod.spec.as_ref();
Expand All @@ -61,8 +60,6 @@ async fn process_ports_from_pods(
tmp.ports.push(ContainerPort {
container_name: container.name.clone(),
container_port: port.container_port,
host_ip: port.host_ip.unwrap_or_default(),
host_port: port.host_port.unwrap_or_default(),
name: port.name.unwrap_or_default(),
protocol: port.protocol.unwrap_or("TCP".to_string()),
});
Expand Down Expand Up @@ -95,8 +92,8 @@ async fn process_ports_from_svcs(
out: &mut Vec<ServiceResource>,
) -> Result<(), AppError> {
for svc in svcs {
let name = svc.name_any();
let namespace = svc.namespace().unwrap_or_default();
let name = svc.metadata.name.unwrap_or_else(|| String::from("unknown"));
let namespace = svc.metadata.namespace.unwrap_or_else(|| String::from("unknown"));

let svc_spec = if let Some(ss) = svc.spec.as_ref() {
ss.clone()
Expand All @@ -109,12 +106,11 @@ async fn process_ports_from_svcs(
};

let mut tmp = ServiceResource::new(
"service".to_string(),
name.clone(),
namespace.clone(),
svc_spec.type_.unwrap_or_default(),
svc_spec.cluster_ip.unwrap_or_default(),
svc_spec.external_traffic_policy.unwrap_or_default(),
svc_spec.external_traffic_policy.unwrap_or_else(|| String::from("n/a")),
);
let ports = match svc_spec.ports.as_ref() {
None => {
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ fn init_tracing() {

let formatting_layer =
BunyanFormattingLayer::new(env!("CARGO_CRATE_NAME").to_owned(), std::io::stderr);

let subscriber = Registry::default()
.with(EnvFilter::from_default_env())
.with(JsonStorageLayer)
Expand Down
23 changes: 14 additions & 9 deletions src/opts.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
use clap::{
crate_authors,
Parser,
ValueEnum,
};

#[derive(Parser, Debug)]
#[clap(
// global_settings(&[AppSettings::ColoredHelp, AppSettings::VersionlessSubcommands]),
author = env!("CARGO_PKG_HOMEPAGE"), about, version, long_about = None
author = crate_authors!(),
name = env!("CARGO_PKG_NAME"),
version = env!("CARGO_PKG_VERSION"),
about = "Show exposed container ports in the cluster.",
long_about = "This tool allows you to easily view exposed container ports in your Kubernetes cluster. It provides a quick overview of which ports are open on your pods and services, helping you to monitor and troubleshoot your cluster's network configuration.
Features:
- List exposed ports for pods and services
- Filter results by namespace
- Support for custom kubeconfig contexts
- Detailed output including container names, port numbers, and protocols
Use this tool to quickly identify open ports, verify your service configurations, and ensure your cluster's network setup meets your expectations and security requirements."
)]
pub struct CliOpts {
/// The name of the kubeconfig context to use
Expand All @@ -33,11 +46,3 @@ pub enum Kind {
Service,
Svc,
}
// impl Kind {
// pub fn as_str(&self) -> &'static str {
// match self {
// Kind::Pod => "pod",
// Kind::Service => "svc",
// }
// }
// }
11 changes: 0 additions & 11 deletions src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ pub struct ContainerPort {

pub container_port: i32,

/// What host IP to bind the external port to.
pub host_ip: String,

/// Number of port to expose on the host. If specified, this must be a valid
/// port number, 0 \< x \< 65536. If HostNetwork is specified, this must
/// match ContainerPort. Most containers do not need this.
pub host_port: i32,

/// If specified, this must be an IANA_SVC_NAME and unique within the pod.
/// Each named port in a pod must have a unique name. Name for the port that
/// can be referred to by services.
Expand Down Expand Up @@ -39,7 +31,6 @@ impl Resource {
#[derive(Debug, Clone)]
pub struct ServiceResource {
pub kind: String,
pub name: String,
pub namespace: String,
pub svc_type: String,
Expand All @@ -50,15 +41,13 @@ pub struct ServiceResource {

impl ServiceResource {
pub fn new(
kind: String,
name: String,
ns: String,
svc_type: String,
cluster_ip: String,
external_traffic_policy: String,
) -> ServiceResource {
ServiceResource {
kind,
name,
namespace: ns,
svc_type,
Expand Down

0 comments on commit 348e5d3

Please sign in to comment.