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

breaking: rename assets #69

Merged
merged 13 commits into from
Sep 25, 2023
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
run: |
k3d image import hirosystems/stacks-devnet-api:ci -c k3d-kube
kubectl create namespace devnet
kubectl create configmap stacks-devnet-api-conf --from-file=./Config.toml --namespace devnet
kubectl create configmap stacks-devnet-api --from-file=./Config.toml --namespace devnet
kubectl apply -f ./templates/ci/stacks-devnet-api.template.yaml
echo "sleep for 30 sec"
sleep 30
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ metadata:
name: stacks-devnet-api
namespace: devnet
spec:
serviceAccountName: stacks-devnet-api-service-account
serviceAccountName: stacks-devnet-api
containers:
- command:
- ./stacks-devnet-api
name: stacks-devnet-api-container
name: stacks-devnet-api
- image: quay.io/hirosystems/stacks-devnet-api:latest
- imagePullPolicy: Always
+ image: stacks-devnet-api:latest
Expand Down Expand Up @@ -83,9 +83,9 @@ When the service has been deployed to your Kubernetes cluster, it should be reac
"bitcoin_chain_tip": 116
}
```
- `GET/POST localhost:8477/api/v1/network/<network-id>/stacks-node/*` - Forwards `*` to the underlying stacks node pod of the devnet. If not all devnet assets exist for the given namespace, a 404 error will be returned.
- `GET/POST localhost:8477/api/v1/network/<network-id>/stacks-blockchain/*` - Forwards `*` to the underlying stacks node pod of the devnet. If not all devnet assets exist for the given namespace, a 404 error will be returned.
- `GET/POST localhost:8477/api/v1/network/<network-id>/bitcoin-node/*` - Forwards `*` to the underlying bitcoin node pod of the devnet. If not all devnet assets exist for the given namespace, a 404 error will be returned.
- `GET/POST localhost:8477/api/v1/network/<network-id>/stacks-api/*` - Forwards `*` to the underlying stacks api pod of the devnet. If not all devnet assets exist for the given namespace, a 404 error will be returned.
- `GET/POST localhost:8477/api/v1/network/<network-id>/stacks-blockchain-api/*` - Forwards `*` to the underlying stacks api pod of the devnet. If not all devnet assets exist for the given namespace, a 404 error will be returned.

## Bugs and feature requests

Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy-api.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kubectl --context kind-kind create namespace devnet
kubectl --context kind-kind create configmap stacks-devnet-api-conf --from-file=./Config.toml --namespace devnet && \
kubectl --context kind-kind create configmap stacks-devnet-api --from-file=./Config.toml --namespace devnet && \
kubectl --context kind-kind apply -f ./templates/stacks-devnet-api.template.yaml
10 changes: 5 additions & 5 deletions scripts/get-logs.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
kubectl --context kind-kind logs stacks-node --namespace $1 > ./logs/stacks-node.txt & \
kubectl --context kind-kind logs stacks-api --namespace $1 -c stacks-api-container > ./logs/stacks-api.txt & \
kubectl --context kind-kind logs stacks-api --namespace $1 -c stacks-api-postgres > ./logs/stacks-api-postgres.txt & \
kubectl --context kind-kind logs bitcoind-chain-coordinator --namespace $1 -c bitcoind-container > ./logs/bitcoin-node.txt & \
kubectl --context kind-kind logs bitcoind-chain-coordinator --namespace $1 -c chain-coordinator-container > ./logs/chain-coordinator.txt
kubectl --context kind-kind logs stacks-blockchain --namespace $1 > ./logs/stacks-blockchain.txt & \
kubectl --context kind-kind logs stacks-blockchain-api --namespace $1 -c stacks-blockchain-api > ./logs/stack-blockchains-api.txt & \
kubectl --context kind-kind logs stacks-blockchain-api --namespace $1 -c postgres > ./logs/stacks-blockchain-api-pg.txt & \
kubectl --context kind-kind logs bitcoind-chain-coordinator --namespace $1 -c bitcoind > ./logs/bitcoin-node.txt & \
kubectl --context kind-kind logs bitcoind-chain-coordinator --namespace $1 -c chain-coordinator > ./logs/chain-coordinator.txt
2 changes: 1 addition & 1 deletion scripts/redeploy-api.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
kubectl --context kind-kind delete configmap stacks-devnet-api-conf --namespace devnet & \
kubectl --context kind-kind delete configmap stacks-devnet-api --namespace devnet & \
kubectl --context kind-kind delete pod stacks-devnet-api --namespace devnet && \
./scripts/deploy-api.sh
10 changes: 5 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,27 @@ impl StacksDevnetConfig {
.parse::<u16>()
.unwrap();
devnet_config.stacks_node_p2p_port =
get_service_port(StacksDevnetService::StacksNode, ServicePort::P2P)
get_service_port(StacksDevnetService::StacksBlockchain, ServicePort::P2P)
.unwrap()
.parse::<u16>()
.unwrap();
devnet_config.stacks_node_rpc_port =
get_service_port(StacksDevnetService::StacksNode, ServicePort::RPC)
get_service_port(StacksDevnetService::StacksBlockchain, ServicePort::RPC)
.unwrap()
.parse::<u16>()
.unwrap();
devnet_config.stacks_api_port =
get_service_port(StacksDevnetService::StacksApi, ServicePort::API)
get_service_port(StacksDevnetService::StacksBlockchainApi, ServicePort::API)
.unwrap()
.parse::<u16>()
.unwrap();
devnet_config.stacks_api_events_port =
get_service_port(StacksDevnetService::StacksApi, ServicePort::Event)
get_service_port(StacksDevnetService::StacksBlockchainApi, ServicePort::Event)
.unwrap()
.parse::<u16>()
.unwrap();
devnet_config.postgres_port =
get_service_port(StacksDevnetService::StacksApi, ServicePort::DB)
get_service_port(StacksDevnetService::StacksBlockchainApi, ServicePort::DB)
.unwrap()
.parse::<u16>()
.unwrap();
Expand Down
56 changes: 27 additions & 29 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,9 @@ impl StacksDevnetApiK8sManager {
namespace: &str,
) -> Result<StacksV2InfoResponse, DevNetError> {
let client = HttpClient::new();
let url = get_service_url(namespace, StacksDevnetService::StacksNode);
let port = get_service_port(StacksDevnetService::StacksNode, ServicePort::RPC).unwrap();
let url = get_service_url(namespace, StacksDevnetService::StacksBlockchain);
let port =
get_service_port(StacksDevnetService::StacksBlockchain, ServicePort::RPC).unwrap();
let url = format!("http://{}:{}/v2/info", url, port);

let context = format!("NAMESPACE: {}", namespace);
Expand Down Expand Up @@ -548,8 +549,8 @@ impl StacksDevnetApiK8sManager {
chain_info,
) = try_join4(
self.get_pod_status_info(&namespace, StacksDevnetPod::BitcoindNode),
self.get_pod_status_info(&namespace, StacksDevnetPod::StacksNode),
self.get_pod_status_info(&namespace, StacksDevnetPod::StacksApi),
self.get_pod_status_info(&namespace, StacksDevnetPod::StacksBlockchain),
self.get_pod_status_info(&namespace, StacksDevnetPod::StacksBlockchainApi),
self.get_stacks_v2_info(&namespace),
)
.await?;
Expand Down Expand Up @@ -832,13 +833,6 @@ impl StacksDevnetApiK8sManager {
)
.await?;

self.deploy_configmap(
StacksDevnetConfigmap::Namespace,
&namespace,
Some(vec![("NAMESPACE".into(), namespace.clone())]),
)
.await?;

self.deploy_configmap(
StacksDevnetConfigmap::ProjectManifest,
&namespace,
Expand Down Expand Up @@ -931,8 +925,8 @@ impl StacksDevnetApiK8sManager {
block_reward_recipient = "{}"
# microblock_attempt_time_ms = 15000
"#,
get_service_port(StacksDevnetService::StacksNode, ServicePort::RPC).unwrap(),
get_service_port(StacksDevnetService::StacksNode, ServicePort::P2P).unwrap(),
get_service_port(StacksDevnetService::StacksBlockchain, ServicePort::RPC).unwrap(),
get_service_port(StacksDevnetService::StacksBlockchain, ServicePort::P2P).unwrap(),
stacks_miner_secret_key_hex,
stacks_miner_secret_key_hex,
devnet_config.stacks_node_wait_time_for_microblocks,
Expand Down Expand Up @@ -979,15 +973,16 @@ impl StacksDevnetApiK8sManager {

stacks_conf.push_str(&format!(
r#"
# Add stacks-api as an event observer
# Add stacks-blockchain-api as an event observer
[[events_observer]]
endpoint = "{}:{}"
retry_count = 255
include_data_events = false
events_keys = ["*"]
"#,
get_service_url(&namespace, StacksDevnetService::StacksApi),
get_service_port(StacksDevnetService::StacksApi, ServicePort::Event).unwrap(),
get_service_url(&namespace, StacksDevnetService::StacksBlockchainApi),
get_service_port(StacksDevnetService::StacksBlockchainApi, ServicePort::Event)
.unwrap(),
));

stacks_conf.push_str(&format!(
Expand Down Expand Up @@ -1046,16 +1041,16 @@ impl StacksDevnetApiK8sManager {
};

self.deploy_configmap(
StacksDevnetConfigmap::StacksNode,
StacksDevnetConfigmap::StacksBlockchain,
&namespace,
Some(vec![("Stacks.toml".into(), stacks_conf)]),
)
.await?;

self.deploy_pod(StacksDevnetPod::StacksNode, &namespace)
self.deploy_pod(StacksDevnetPod::StacksBlockchain, &namespace)
.await?;

self.deploy_service(StacksDevnetService::StacksNode, namespace)
self.deploy_service(StacksDevnetService::StacksBlockchain, namespace)
.await?;

Ok(())
Expand All @@ -1068,19 +1063,22 @@ impl StacksDevnetApiK8sManager {
("POSTGRES_DB".into(), "stacks_api".into()),
]);
self.deploy_configmap(
StacksDevnetConfigmap::StacksApiPostgres,
StacksDevnetConfigmap::StacksBlockchainApiPg,
&namespace,
Some(stacks_api_pg_env),
)
.await?;

// configmap env vars for api conatainer
let stacks_node_host = get_service_url(&namespace, StacksDevnetService::StacksNode);
let rpc_port = get_service_port(StacksDevnetService::StacksNode, ServicePort::RPC).unwrap();
let api_port = get_service_port(StacksDevnetService::StacksApi, ServicePort::API).unwrap();
let stacks_node_host = get_service_url(&namespace, StacksDevnetService::StacksBlockchain);
let rpc_port =
get_service_port(StacksDevnetService::StacksBlockchain, ServicePort::RPC).unwrap();
let api_port =
get_service_port(StacksDevnetService::StacksBlockchainApi, ServicePort::API).unwrap();
let event_port =
get_service_port(StacksDevnetService::StacksApi, ServicePort::Event).unwrap();
let db_port = get_service_port(StacksDevnetService::StacksApi, ServicePort::DB).unwrap();
get_service_port(StacksDevnetService::StacksBlockchainApi, ServicePort::Event).unwrap();
let db_port =
get_service_port(StacksDevnetService::StacksBlockchainApi, ServicePort::DB).unwrap();
let stacks_api_env = Vec::from([
("STACKS_CORE_RPC_HOST".into(), stacks_node_host),
("STACKS_BLOCKCHAIN_API_DB".into(), "pg".into()),
Expand All @@ -1101,19 +1099,19 @@ impl StacksDevnetApiK8sManager {
("STACKS_API_LOG_LEVEL".into(), "debug".into()),
]);
self.deploy_configmap(
StacksDevnetConfigmap::StacksApi,
StacksDevnetConfigmap::StacksBlockchainApi,
&namespace,
Some(stacks_api_env),
)
.await?;

self.deploy_pvc(StacksDevnetPvc::StacksApi, &namespace)
self.deploy_pvc(StacksDevnetPvc::StacksBlockchainApiPg, &namespace)
.await?;

self.deploy_pod(StacksDevnetPod::StacksApi, &namespace)
self.deploy_pod(StacksDevnetPod::StacksBlockchainApi, &namespace)
.await?;

self.deploy_service(StacksDevnetService::StacksApi, &namespace)
self.deploy_service(StacksDevnetService::StacksBlockchainApi, &namespace)
.await?;

Ok(())
Expand Down
24 changes: 11 additions & 13 deletions src/resources/configmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,26 @@ use strum_macros::EnumIter;
#[derive(EnumIter, Debug)]
pub enum StacksDevnetConfigmap {
BitcoindNode,
StacksNode,
StacksApi,
StacksApiPostgres,
StacksBlockchain,
StacksBlockchainApi,
StacksBlockchainApiPg,
DeploymentPlan,
Devnet,
ProjectDir,
Namespace,
ProjectManifest,
}

impl fmt::Display for StacksDevnetConfigmap {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
StacksDevnetConfigmap::BitcoindNode => write!(f, "bitcoind-conf"),
StacksDevnetConfigmap::StacksNode => write!(f, "stacks-node-conf"),
StacksDevnetConfigmap::StacksApi => write!(f, "stacks-api-conf"),
StacksDevnetConfigmap::StacksApiPostgres => write!(f, "stacks-api-postgres-conf"),
StacksDevnetConfigmap::DeploymentPlan => write!(f, "deployment-plan-conf"),
StacksDevnetConfigmap::Devnet => write!(f, "devnet-conf"),
StacksDevnetConfigmap::ProjectDir => write!(f, "project-dir-conf"),
StacksDevnetConfigmap::Namespace => write!(f, "namespace-conf"),
StacksDevnetConfigmap::ProjectManifest => write!(f, "project-manifest-conf"),
StacksDevnetConfigmap::BitcoindNode => write!(f, "bitcoind"),
StacksDevnetConfigmap::StacksBlockchain => write!(f, "stacks-blockchain"),
StacksDevnetConfigmap::StacksBlockchainApi => write!(f, "stacks-blockchain-api"),
StacksDevnetConfigmap::StacksBlockchainApiPg => write!(f, "stacks-blockchain-api-pg"),
StacksDevnetConfigmap::DeploymentPlan => write!(f, "deployment-plan"),
StacksDevnetConfigmap::Devnet => write!(f, "devnet"),
StacksDevnetConfigmap::ProjectDir => write!(f, "project-dir"),
StacksDevnetConfigmap::ProjectManifest => write!(f, "project-manifest"),
}
}
}
8 changes: 4 additions & 4 deletions src/resources/pod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ use strum_macros::EnumIter;
#[derive(EnumIter, Debug)]
pub enum StacksDevnetPod {
BitcoindNode,
StacksNode,
StacksApi,
StacksBlockchain,
StacksBlockchainApi,
}

impl fmt::Display for StacksDevnetPod {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
StacksDevnetPod::BitcoindNode => write!(f, "bitcoind-chain-coordinator"),
StacksDevnetPod::StacksNode => write!(f, "stacks-node"),
StacksDevnetPod::StacksApi => write!(f, "stacks-api"),
StacksDevnetPod::StacksBlockchain => write!(f, "stacks-blockchain"),
StacksDevnetPod::StacksBlockchainApi => write!(f, "stacks-blockchain-api"),
}
}
}
4 changes: 2 additions & 2 deletions src/resources/pvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use strum_macros::EnumIter;

#[derive(EnumIter, Debug)]
pub enum StacksDevnetPvc {
StacksApi,
StacksBlockchainApiPg,
}

impl fmt::Display for StacksDevnetPvc {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
StacksDevnetPvc::StacksApi => write!(f, "stacks-api-pvc"),
StacksDevnetPvc::StacksBlockchainApiPg => write!(f, "stacks-blockchain-api-pg"),
}
}
}
28 changes: 14 additions & 14 deletions src/resources/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use strum_macros::EnumIter;
#[derive(EnumIter, Debug, Clone, PartialEq)]
pub enum StacksDevnetService {
BitcoindNode,
StacksNode,
StacksApi,
StacksBlockchain,
StacksBlockchainApi,
}

pub enum ServicePort {
Expand All @@ -21,9 +21,9 @@ pub enum ServicePort {
impl fmt::Display for StacksDevnetService {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
StacksDevnetService::BitcoindNode => write!(f, "bitcoind-chain-coordinator-service"),
StacksDevnetService::StacksNode => write!(f, "stacks-node-service"),
StacksDevnetService::StacksApi => write!(f, "stacks-api-service"),
StacksDevnetService::BitcoindNode => write!(f, "bitcoind-chain-coordinator"),
StacksDevnetService::StacksBlockchain => write!(f, "stacks-blockchain"),
StacksDevnetService::StacksBlockchainApi => write!(f, "stacks-blockchain-api"),
}
}
}
Expand All @@ -34,21 +34,21 @@ pub fn get_service_port(service: StacksDevnetService, port_type: ServicePort) ->
(StacksDevnetService::BitcoindNode, ServicePort::P2P) => Some("18444".into()),
(StacksDevnetService::BitcoindNode, ServicePort::Ingestion) => Some("20445".into()),
(StacksDevnetService::BitcoindNode, ServicePort::Control) => Some("20446".into()),
(StacksDevnetService::StacksNode, ServicePort::RPC) => Some("20443".into()),
(StacksDevnetService::StacksNode, ServicePort::P2P) => Some("20444".into()),
(StacksDevnetService::StacksApi, ServicePort::API) => Some("3999".into()),
(StacksDevnetService::StacksApi, ServicePort::Event) => Some("3700".into()),
(StacksDevnetService::StacksApi, ServicePort::DB) => Some("5432".into()),
(StacksDevnetService::StacksBlockchain, ServicePort::RPC) => Some("20443".into()),
(StacksDevnetService::StacksBlockchain, ServicePort::P2P) => Some("20444".into()),
(StacksDevnetService::StacksBlockchainApi, ServicePort::API) => Some("3999".into()),
(StacksDevnetService::StacksBlockchainApi, ServicePort::Event) => Some("3700".into()),
(StacksDevnetService::StacksBlockchainApi, ServicePort::DB) => Some("5432".into()),
(_, _) => None,
}
}

pub fn get_user_facing_port(service: StacksDevnetService) -> Option<String> {
match service {
StacksDevnetService::BitcoindNode | StacksDevnetService::StacksNode => {
StacksDevnetService::BitcoindNode | StacksDevnetService::StacksBlockchain => {
get_service_port(service, ServicePort::RPC)
}
StacksDevnetService::StacksApi => get_service_port(service, ServicePort::API),
StacksDevnetService::StacksBlockchainApi => get_service_port(service, ServicePort::API),
}
}

Expand All @@ -59,8 +59,8 @@ pub fn get_service_url(namespace: &str, service: StacksDevnetService) -> String
pub fn get_service_from_path_part(path_part: &str) -> Option<StacksDevnetService> {
match path_part {
"bitcoin-node" => Some(StacksDevnetService::BitcoindNode),
"stacks-node" => Some(StacksDevnetService::StacksNode),
"stacks-api" => Some(StacksDevnetService::StacksApi),
"stacks-blockchain" => Some(StacksDevnetService::StacksBlockchain),
"stacks-blockchain-api" => Some(StacksDevnetService::StacksBlockchainApi),
_ => None,
}
}
Loading
Loading