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

Setting new ip to etcd member #161

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/k8s_etcd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::cluster_crypto::locations::K8sResourceLocation;
use crate::etcd_encoding;
use anyhow::{bail, Context, Result};
use anyhow::{bail, ensure, Context, Result};
use etcd_client::{Client as EtcdClient, GetOptions};
use futures_util::future::join_all;
use serde_json::Value;
Expand Down Expand Up @@ -176,6 +176,36 @@ impl InMemoryK8sEtcd {
self.deleted_keys.lock().await.insert(key.to_string());
Ok(())
}

pub(crate) async fn update_member(&self, value: String) -> Result<()> {
let etcd_client = self.etcd_client.as_ref().context("etcd client not configured")?;

let members_list = etcd_client
.cluster_client()
.member_list()
.await
.context("listing etcd members list")?;

tsorya marked this conversation as resolved.
Show resolved Hide resolved
let members = members_list.members();

ensure!(
members.len() == 1,
"single-node must have exactly one etcd member, found {}",
members.len()
);

ensure!(
!etcd_client
.cluster_client()
.member_update(members[0].id(), vec![value.clone()])
.await
.context("updating etcd member")?
.members()
.is_empty(),
"no members in update response"
);
Ok(())
}
}

fn is_too_many_requests_error(delete_response: &std::prelude::v1::Result<etcd_client::DeleteResponse, etcd_client::Error>) -> bool {
Expand Down
2 changes: 2 additions & 0 deletions src/ocp_postprocess/ip_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,7 @@ async fn fix_etcd_resources(etcd_client: &Arc<InMemoryK8sEtcd>, ip: &str) -> Res
.await
.context("fixing oauth apiserver deployment")?;

etcd_rename::fix_etcd_member(etcd_client, ip).await.context("fixing etcd member")?;

Ok(original_ip)
}
11 changes: 11 additions & 0 deletions src/ocp_postprocess/ip_rename/etcd_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
use anyhow::{bail, ensure, Context, Result};
use futures_util::future::join_all;
use serde_json::Value;
use std::net::Ipv6Addr;
use std::sync::Arc;

pub(crate) async fn fix_openshift_apiserver_configmap(etcd_client: &Arc<InMemoryK8sEtcd>, ip: &str) -> Result<String> {
Expand Down Expand Up @@ -448,6 +449,16 @@ pub(crate) async fn fix_networks_cluster(etcd_client: &Arc<InMemoryK8sEtcd>, ip:
Ok(())
}

pub(crate) async fn fix_etcd_member(etcd_client: &Arc<InMemoryK8sEtcd>, ip: &str) -> Result<()> {
let mut update = format!("https://{}:2380", ip).to_string();
if ip.parse::<Ipv6Addr>().is_ok() {
update = format!("https://[{}]:2380", ip).to_string();
}

etcd_client.update_member(update).await.context("failed to update etcd member")?;
Ok(())
}

fn replace_etcd_servers(cluster: &mut Value, original_ip: &str, ip: &str) -> Result<()> {
let observed_config = cluster.pointer_mut("/spec/observedConfig").context("no /spec/observedConfig")?;

Expand Down
Loading