Skip to content

Commit

Permalink
use k8 flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nacardin committed Nov 1, 2023
1 parent af648b5 commit 040330d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 16 deletions.
4 changes: 3 additions & 1 deletion crates/fluvio-cluster/src/runtime/local/sc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ impl ScProcess {
ScMode::ReadOnly(path) => {
binary.arg("--read-only").arg(path);
}
ScMode::K8s => {}
ScMode::K8s => {
binary.arg("--k8");
}
};

if let TlsPolicy::Verified(tls) = &self.tls_policy {
Expand Down
34 changes: 21 additions & 13 deletions crates/fluvio-sc/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::io::ErrorKind;
use std::path::PathBuf;
use std::convert::TryFrom;

use clap::Args;
use tracing::info;
use tracing::debug;
use clap::Parser;
Expand All @@ -30,16 +31,11 @@ use crate::config::ScConfig;
type Config = (ScConfig, Option<BasicRbacPolicy>);

/// cli options
#[derive(Debug, Parser, Default)]
#[derive(Debug, Parser)]
#[command(name = "sc-server", about = "Streaming Controller")]
pub struct ScOpt {
/// run in local mode
#[arg(long, conflicts_with_all = &["k8", "read_only"], value_name = "metadata path")]
local: Option<PathBuf>,

/// run on k8
#[arg(long)]
k8: bool,
#[command(flatten)]
run_mode: ScOptRunMode,

#[arg(long)]
/// Address for external service
Expand Down Expand Up @@ -73,10 +69,22 @@ pub struct ScOpt {
/// only allow white list of controllers
#[arg(long)]
white_list: Vec<String>,
}

/// run SC in read only mode
#[arg(long, hide = true, conflicts_with_all = &["auth_policy"])]
read_only: Option<PathBuf>,
#[derive(Debug, Args)]
#[group(required = true, multiple = false)]
pub struct ScOptRunMode {
/// run in local mode
#[arg(long, value_name = "metadata path")]
local: Option<PathBuf>,

/// run on k8
#[arg(long)]
k8: bool,

/// run SC in read only mode
#[arg(long, hide = true)]
read_only: Option<PathBuf>,
}

#[derive(Debug)]
Expand All @@ -88,7 +96,7 @@ pub enum RunMode<'a> {

impl ScOpt {
pub fn mode(&self) -> RunMode<'_> {
match (&self.local, &self.read_only, self.k8) {
match (&self.run_mode.local, &self.run_mode.read_only, self.run_mode.k8) {
(Some(metadata), None, false) => RunMode::Local(metadata),
(None, Some(path), false) => RunMode::ReadOnly(path),
(None, None, true) => RunMode::K8s,
Expand Down Expand Up @@ -117,7 +125,7 @@ impl ScOpt {

config.x509_auth_scopes = self.x509_auth_scopes;
config.white_list = self.white_list.into_iter().collect();
config.read_only_metadata = self.read_only.is_some();
config.read_only_metadata = self.run_mode.read_only.is_some();

// Set Configuration Authorization Policy

Expand Down
2 changes: 1 addition & 1 deletion crates/fluvio-sc/src/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn main_loop(opt: ScOpt) {
let k8_config = K8Config::load().expect("no k8 config founded");
info!(?k8_config, "k8 config");

// if name space is specified, use one from k8 config
// if namespace is default, use one from k8 config
if sc_config.namespace == DEFAULT_NAMESPACE {
let k8_namespace = k8_config.namespace().to_owned();
info!("using {} as namespace from kubernetes config", k8_namespace);
Expand Down
4 changes: 4 additions & 0 deletions crates/fluvio-test-util/setup/environment/k8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ impl EnvironmentDriver for K8EnvironmentDriver {
.save_profile(true)
.hide_spinner(false);

if let Some(ref namespace) = self.option.namespace {
builder.namespace(namespace);
}

if self.option.tls {
let (client, server) = load_tls(&self.option.tls_user());
builder.tls(client, server);
Expand Down
4 changes: 4 additions & 0 deletions crates/fluvio-test-util/test_meta/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,8 @@ pub struct EnvironmentSetup {
/// Expect a test to fail. (fail-> pass. pass or timeout -> fail)
#[arg(long, conflicts_with = "expect_timeout")]
pub expect_fail: bool,

/// K8 namespace
#[arg(long)]
pub namespace: Option<String>,
}
3 changes: 2 additions & 1 deletion k8-util/helm/fluvio-app/templates/sc-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ spec:
{{- toYaml .Values.scPod.extraEnv | nindent 12 }}
{{ end }}
command: ["/fluvio-run", "sc"]
{{ if .Values.tls }}
args:
- --k8
{{ if .Values.tls }}
- --tls
- --enable-client-cert
- --ca-cert
Expand Down

0 comments on commit 040330d

Please sign in to comment.