Skip to content

Commit 3c97d7b

Browse files
committed
chore: restructure & get rid of dead_code exclusions
basically all of the logic is now in a chisel_operator lib target, which our entrypoints import from this gets rust_analyzer to handle the dead code warnings properly
1 parent fa63f67 commit 3c97d7b

File tree

10 files changed

+12
-28
lines changed

10 files changed

+12
-28
lines changed

Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,3 @@ hyper-rustls = { version = "0.24.2", features = ["http2", "webpki-roots", "webpk
5858
# tonic = { version = "0.8.3" }
5959
# tracing-opentelemetry = "0.18.0"
6060
# opentelemetry_api = "0.18.0"
61-
62-
[[bin]]
63-
name = "crdgen"
64-
path = "src/crdgen.rs"

src/crdgen.rs renamed to src/bin/crdgen.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1+
use chisel_operator::ops;
12
use kube::CustomResourceExt;
23
use std::fs::File;
34
use std::io::prelude::*;
45

5-
mod cloud;
6-
mod daemon;
7-
mod deployment;
8-
mod error;
9-
mod ops;
10-
116
// todo: Make this a cargo xtask, maybe?
127

138
fn main() {

src/cloud/aws.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use aws_config::{BehaviorVersion, Region};
88
use aws_sdk_ec2::types::{Tag, TagSpecification};
99
use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
1010
use base64::Engine;
11-
use color_eyre::eyre::{anyhow, Error};
11+
use color_eyre::eyre::anyhow;
1212
use k8s_openapi::api::core::v1::Secret;
1313
use schemars::JsonSchema;
1414
use serde::{Deserialize, Serialize};
15-
use tracing::{debug, info, warn};
15+
use tracing::{debug, warn};
1616

1717
const DEFAULT_SIZE: &str = "t2.micro";
1818
const UBUNTU_AMI_SSM_KEY: &str =

src/cloud/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub enum CloudProvider {
1919
}
2020

2121
// This code was actually used, weirdly enough
22-
#[allow(dead_code)]
2322
pub const CHISEL_PORT: u16 = 9090;
2423

2524
#[async_trait]

src/daemon.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use crate::ops::{
5151
EXIT_NODE_NAME_LABEL, EXIT_NODE_PROVISIONER_LABEL,
5252
};
5353
use crate::{deployment::create_owned_deployment, error::ReconcileError};
54-
#[allow(dead_code)]
54+
5555
pub const EXIT_NODE_FINALIZER: &str = "exitnode.chisel-operator.io/finalizer";
5656
pub const SVCS_FINALIZER: &str = "service.chisel-operator.io/finalizer";
5757

@@ -69,7 +69,6 @@ pub const SVCS_FINALIZER: &str = "service.chisel-operator.io/finalizer";
6969
// }
7070

7171
// this is actually used to pass clients around
72-
#[allow(dead_code)]
7372
pub struct Context {
7473
pub client: Client,
7574
}
@@ -130,10 +129,9 @@ async fn check_service_managed(service: &Service) -> bool {
130129

131130
// Let's not use magic values, so we can change this later or if someone wants to fork this for something else
132131

133-
#[allow(dead_code)]
134132
const OPERATOR_CLASS: &str = "chisel-operator.io/chisel-operator-class";
135-
#[allow(dead_code)]
136133
const OPERATOR_MANAGER: &str = "chisel-operator";
134+
137135
#[instrument(skip(ctx))]
138136
async fn select_exit_node_local(
139137
ctx: Arc<Context>,

src/deployment.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ fn convert_service_port(svcport: ServicePort) -> String {
6262
/// The function `generate_remote_arg` is returning a `String`. The `String`
6363
/// contains the formatted remote argument which is a combination of the `lb_ip` and `chisel_port`
6464
/// values obtained from the `node` parameter.
65-
#[allow(dead_code)]
6665
pub fn generate_remote_arg(node: &ExitNode) -> String {
6766
// todo: what about ECDSA keys?
6867

@@ -86,7 +85,6 @@ pub fn generate_remote_arg(node: &ExitNode) -> String {
8685
///
8786
/// a `Result` containing a `Vec` of `String`s. The `Vec` contains arguments for a tunnel, which are
8887
/// generated based on the input `Service`.
89-
#[allow(dead_code)]
9088
pub fn generate_tunnel_args(svc: &Service) -> Result<Vec<String>, ReconcileError> {
9189
// We can unwrap safely since Service is guaranteed to have a name
9290
let service_name = svc.metadata.name.clone().unwrap();

src/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use thiserror::Error;
22

33
#[derive(Error, Debug)]
4-
#[allow(dead_code)] // all these errors are used
54
pub enum ReconcileError {
65
#[error("Kube Error: {0}")]
76
KubeError(#[from] kube::Error),

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub mod cloud;
2+
pub mod daemon;
3+
pub mod deployment;
4+
pub mod error;
5+
pub mod ops;

src/main.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::env;
22

3+
use chisel_operator::daemon;
34
use color_eyre::Result;
45
use tracing::info;
56
// use opentelemetry::sdk::export::metrics::StdoutExporterBuilder;
@@ -10,11 +11,6 @@ use tracing::info;
1011
// use tracing::info;
1112
use tracing_subscriber::{prelude::*, EnvFilter, Registry};
1213
// Main entrypoint for operator
13-
mod cloud;
14-
mod daemon;
15-
mod deployment;
16-
mod error;
17-
mod ops;
1814

1915
// TODO: OpenTelemetry is broken
2016

src/ops.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use kube::{core::ObjectMeta, Api, CustomResource};
1010
use schemars::JsonSchema;
1111
use serde::{Deserialize, Serialize};
1212
use tracing::debug;
13-
#[allow(dead_code)]
13+
1414
pub const EXIT_NODE_NAME_LABEL: &str = "chisel-operator.io/exit-node-name";
1515
pub const EXIT_NODE_PROVISIONER_LABEL: &str = "chisel-operator.io/exit-node-provisioner";
1616

@@ -149,7 +149,6 @@ pub enum ExitNodeProvisionerSpec {
149149
}
150150

151151
impl ExitNodeProvisionerSpec {
152-
#[allow(dead_code)] // this one is actually used lol
153152
pub fn get_inner(self) -> Box<(dyn Provisioner + Send + Sync)> {
154153
// Can we somehow not have to match on this?
155154
match self {
@@ -165,7 +164,6 @@ pub trait ProvisionerSecret {
165164
}
166165

167166
impl ExitNodeProvisioner {
168-
#[allow(dead_code)] // this is used in daemon.rs
169167
pub async fn find_secret(&self) -> Result<Option<Secret>> {
170168
let secret_name = match &self.spec {
171169
ExitNodeProvisionerSpec::DigitalOcean(a) => a.auth.clone(),

0 commit comments

Comments
 (0)