Skip to content
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

WIP MGMT-16426 #79

Closed
wants to merge 14 commits into from
2 changes: 2 additions & 0 deletions run_seed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ use_cert_rules:
BgIejfD1dYW2Fp02z5sF6Pw6vhobpfDYgsTAKNonh5P6NxMiD14eQxYrNJ6DAF0=
-----END CERTIFICATE-----
cluster_rename: new-name:foo.com:some-random-infra-id
hostname: test.hostname
summary_file: summary.yaml
summary_file_clean: summary_redacted.yaml
extend_expiration: true
Expand All @@ -111,6 +112,7 @@ else
--cn-san-replace *.apps.seed.redhat.com:*.apps.new-name.foo.com \
--cn-san-replace 192.168.126.10:192.168.127.11 \
--cluster-rename new-name:foo.com:some-random-infra-id \
--hostname test.hostname \
--summary-file summary.yaml \
--summary-file-clean summary_redacted.yaml \
--extend-expiration
Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub(crate) struct RecertConfig {
pub(crate) static_files: Vec<ConfigPath>,
pub(crate) customizations: Customizations,
pub(crate) cluster_rename: Option<ClusterRenameParameters>,
pub(crate) hostname: Option<String>,
pub(crate) threads: Option<usize>,
pub(crate) regenerate_server_ssh_keys: Option<ConfigPath>,
pub(crate) summary_file: Option<ConfigPath>,
Expand Down Expand Up @@ -231,6 +232,11 @@ impl RecertConfig {
None => None,
};

let hostname = match value.get("hostname") {
Some(value) => Some(value.as_str().context("hostname must be a string")?.to_string()),
None => None,
};

let threads = match value.get("threads") {
Some(value) => Some(
value
Expand Down Expand Up @@ -285,6 +291,7 @@ impl RecertConfig {
force_expire,
},
cluster_rename,
hostname,
threads,
regenerate_server_ssh_keys,
summary_file,
Expand Down Expand Up @@ -326,6 +333,7 @@ impl RecertConfig {
force_expire: cli.force_expire,
},
cluster_rename: cli.cluster_rename,
hostname: cli.hostname,
threads: cli.threads,
regenerate_server_ssh_keys: cli.regenerate_server_ssh_keys.map(ConfigPath::from),
summary_file: cli.summary_file.map(ConfigPath::from),
Expand Down
5 changes: 5 additions & 0 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ pub(crate) struct Cli {
#[clap(long, value_parser = ClusterRenameParameters::cli_parse)]
pub(crate) cluster_rename: Option<ClusterRenameParameters>,

/// If given, the cluster resources that include the hostname will be modified to use this one
/// instead.
#[clap(long)]
pub(crate) hostname: Option<String>,

/// A list of CNs and the private keys to use for their certs. By default, new keys will be
/// generated for all regenerated certificates, this option allows you to use existing keys
/// instead. Must come in pairs of CN and private key file path, separated by a space. For
Expand Down
23 changes: 23 additions & 0 deletions src/ocp_postprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ use std::{collections::HashSet, sync::Arc};

pub(crate) mod cluster_domain_rename;
mod fnv;
pub(crate) mod hostname_rename;

/// Perform some OCP-related post-processing to make some OCP operators happy
pub(crate) async fn ocp_postprocess(
in_memory_etcd_client: &Arc<InMemoryK8sEtcd>,
cluster_rename_params: &Option<ClusterRenameParameters>,
hostname: &Option<String>,
static_dirs: &Vec<ConfigPath>,
static_files: &Vec<ConfigPath>,
) -> Result<()> {
Expand All @@ -47,6 +49,12 @@ pub(crate) async fn ocp_postprocess(
.context("renaming cluster")?;
}

if let Some(hostname) = hostname {
hostname_rename(in_memory_etcd_client, hostname, static_dirs, static_files)
.await
.context("renaming hostname")?;
}

fix_deployment_dep_annotations(
in_memory_etcd_client,
K8sResourceLocation::new(Some("openshift-apiserver"), "Deployment", "apiserver", "v1"),
Expand Down Expand Up @@ -357,3 +365,18 @@ pub(crate) async fn cluster_rename(

Ok(())
}

pub(crate) async fn hostname_rename(
in_memory_etcd_client: &Arc<InMemoryK8sEtcd>,
hostname: &str,
static_dirs: &[ConfigPath],
static_files: &[ConfigPath],
) -> Result<()> {
let etcd_client = in_memory_etcd_client;

hostname_rename::rename_all(etcd_client, hostname, static_dirs, static_files)
.await
.context("renaming all")?;

Ok(())
}
2 changes: 1 addition & 1 deletion src/ocp_postprocess/cluster_domain_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{path::Path, sync::Arc};
mod etcd_rename;
mod filesystem_rename;
pub(crate) mod params;
mod rename_utils;
pub(crate) mod rename_utils;

pub(crate) async fn rename_all(
etcd_client: &Arc<InMemoryK8sEtcd>,
Expand Down
10 changes: 3 additions & 7 deletions src/ocp_postprocess/cluster_domain_rename/filesystem_rename.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use super::{
rename_utils::fix_api_server_arguments,
rename_utils::fix_apiserver_url_file,
rename_utils::fix_kcm_extended_args,
rename_utils::fix_kubeconfig,
rename_utils::fix_oauth_metadata,
rename_utils::{fix_kcm_pod, fix_machineconfig},
use super::rename_utils::{
fix_api_server_arguments, fix_apiserver_url_file, fix_kcm_extended_args, fix_kcm_pod, fix_kubeconfig, fix_machineconfig,
fix_oauth_metadata,
};
use crate::file_utils::{self, commit_file, read_file_to_string};
use anyhow::{self, Context, Result};
Expand Down
Loading
Loading