Compare commits
12 Commits
fix/add_ro
...
528ee8a696
| Author | SHA1 | Date | |
|---|---|---|---|
| 528ee8a696 | |||
| 69a159711a | |||
| b0ad7bb4c4 | |||
| 5f78300d78 | |||
| 2d3c32469c | |||
| 1cec398d4d | |||
| cbbaae2ac8 | |||
| f073b7e5fb | |||
| c84b2413ed | |||
| f83fd09f11 | |||
| c15bd53331 | |||
| 6e6f57e38c |
@@ -1,13 +1,17 @@
|
|||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use k8s_openapi::{
|
use k8s_openapi::{
|
||||||
ClusterResourceScope, NamespaceResourceScope,
|
ClusterResourceScope, NamespaceResourceScope,
|
||||||
api::{apps::v1::Deployment, core::v1::Pod},
|
api::{apps::v1::Deployment, core::v1::Pod},
|
||||||
|
apimachinery::pkg::version::Info,
|
||||||
};
|
};
|
||||||
use kube::{
|
use kube::{
|
||||||
Client, Config, Error, Resource,
|
Client, Config, Discovery, Error, Resource,
|
||||||
api::{Api, AttachParams, DeleteParams, ListParams, Patch, PatchParams, ResourceExt},
|
api::{Api, AttachParams, DeleteParams, ListParams, Patch, PatchParams, ResourceExt},
|
||||||
config::{KubeConfigOptions, Kubeconfig},
|
config::{KubeConfigOptions, Kubeconfig},
|
||||||
core::ErrorResponse,
|
core::ErrorResponse,
|
||||||
|
error::DiscoveryError,
|
||||||
runtime::reflector::Lookup,
|
runtime::reflector::Lookup,
|
||||||
};
|
};
|
||||||
use kube::{api::DynamicObject, runtime::conditions};
|
use kube::{api::DynamicObject, runtime::conditions};
|
||||||
@@ -19,7 +23,7 @@ use log::{debug, error, trace};
|
|||||||
use serde::{Serialize, de::DeserializeOwned};
|
use serde::{Serialize, de::DeserializeOwned};
|
||||||
use serde_json::{Value, json};
|
use serde_json::{Value, json};
|
||||||
use similar::TextDiff;
|
use similar::TextDiff;
|
||||||
use tokio::io::AsyncReadExt;
|
use tokio::{io::AsyncReadExt, time::sleep};
|
||||||
|
|
||||||
#[derive(new, Clone)]
|
#[derive(new, Clone)]
|
||||||
pub struct K8sClient {
|
pub struct K8sClient {
|
||||||
@@ -53,6 +57,17 @@ impl K8sClient {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_apiserver_version(&self) -> Result<Info, Error> {
|
||||||
|
let client: Client = self.client.clone();
|
||||||
|
let version_info: Info = client.apiserver_version().await?;
|
||||||
|
Ok(version_info)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn discovery(&self) -> Result<Discovery, Error> {
|
||||||
|
let discovery: Discovery = Discovery::new(self.client.clone()).run().await?;
|
||||||
|
Ok(discovery)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_resource_json_value(
|
pub async fn get_resource_json_value(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
@@ -153,6 +168,41 @@ impl K8sClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn wait_for_pod_ready(
|
||||||
|
&self,
|
||||||
|
pod_name: &str,
|
||||||
|
namespace: Option<&str>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let mut elapsed = 0;
|
||||||
|
let interval = 5; // seconds between checks
|
||||||
|
let timeout_secs = 120;
|
||||||
|
loop {
|
||||||
|
let pod = self.get_pod(pod_name, namespace).await?;
|
||||||
|
|
||||||
|
if let Some(p) = pod {
|
||||||
|
if let Some(status) = p.status {
|
||||||
|
if let Some(phase) = status.phase {
|
||||||
|
if phase.to_lowercase() == "running" {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if elapsed >= timeout_secs {
|
||||||
|
return Err(Error::Discovery(DiscoveryError::MissingResource(format!(
|
||||||
|
"'{}' in ns '{}' did not become ready within {}s",
|
||||||
|
pod_name,
|
||||||
|
namespace.unwrap(),
|
||||||
|
timeout_secs
|
||||||
|
))));
|
||||||
|
}
|
||||||
|
|
||||||
|
sleep(Duration::from_secs(interval)).await;
|
||||||
|
elapsed += interval;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Will execute a commond in the first pod found that matches the specified label
|
/// Will execute a commond in the first pod found that matches the specified label
|
||||||
/// '{label}={name}'
|
/// '{label}={name}'
|
||||||
pub async fn exec_app_capture_output(
|
pub async fn exec_app_capture_output(
|
||||||
@@ -419,9 +469,12 @@ impl K8sClient {
|
|||||||
.as_str()
|
.as_str()
|
||||||
.expect("couldn't get kind as str");
|
.expect("couldn't get kind as str");
|
||||||
|
|
||||||
let split: Vec<&str> = api_version.splitn(2, "/").collect();
|
let mut it = api_version.splitn(2, '/');
|
||||||
let g = split[0];
|
let first = it.next().unwrap();
|
||||||
let v = split[1];
|
let (g, v) = match it.next() {
|
||||||
|
Some(second) => (first, second),
|
||||||
|
None => ("", first),
|
||||||
|
};
|
||||||
|
|
||||||
let gvk = GroupVersionKind::gvk(g, v, kind);
|
let gvk = GroupVersionKind::gvk(g, v, kind);
|
||||||
let api_resource = ApiResource::from_gvk(&gvk);
|
let api_resource = ApiResource::from_gvk(&gvk);
|
||||||
|
|||||||
@@ -47,6 +47,13 @@ struct K8sState {
|
|||||||
message: String,
|
message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum KubernetesDistribution {
|
||||||
|
OpenshiftFamily,
|
||||||
|
K3sFamily,
|
||||||
|
Default,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum K8sSource {
|
enum K8sSource {
|
||||||
LocalK3d,
|
LocalK3d,
|
||||||
@@ -57,6 +64,7 @@ enum K8sSource {
|
|||||||
pub struct K8sAnywhereTopology {
|
pub struct K8sAnywhereTopology {
|
||||||
k8s_state: Arc<OnceCell<Option<K8sState>>>,
|
k8s_state: Arc<OnceCell<Option<K8sState>>>,
|
||||||
tenant_manager: Arc<OnceCell<K8sTenantManager>>,
|
tenant_manager: Arc<OnceCell<K8sTenantManager>>,
|
||||||
|
flavour: Arc<OnceCell<KubernetesDistribution>>,
|
||||||
config: Arc<K8sAnywhereConfig>,
|
config: Arc<K8sAnywhereConfig>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,6 +170,7 @@ impl K8sAnywhereTopology {
|
|||||||
Self {
|
Self {
|
||||||
k8s_state: Arc::new(OnceCell::new()),
|
k8s_state: Arc::new(OnceCell::new()),
|
||||||
tenant_manager: Arc::new(OnceCell::new()),
|
tenant_manager: Arc::new(OnceCell::new()),
|
||||||
|
flavour: Arc::new(OnceCell::new()),
|
||||||
config: Arc::new(K8sAnywhereConfig::from_env()),
|
config: Arc::new(K8sAnywhereConfig::from_env()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,10 +179,42 @@ impl K8sAnywhereTopology {
|
|||||||
Self {
|
Self {
|
||||||
k8s_state: Arc::new(OnceCell::new()),
|
k8s_state: Arc::new(OnceCell::new()),
|
||||||
tenant_manager: Arc::new(OnceCell::new()),
|
tenant_manager: Arc::new(OnceCell::new()),
|
||||||
|
flavour: Arc::new(OnceCell::new()),
|
||||||
config: Arc::new(config),
|
config: Arc::new(config),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_k8s_distribution(&self) -> Result<&KubernetesDistribution, PreparationError> {
|
||||||
|
self.flavour
|
||||||
|
.get_or_try_init(async || {
|
||||||
|
let client = self.k8s_client().await.unwrap();
|
||||||
|
|
||||||
|
let discovery = client.discovery().await.map_err(|e| {
|
||||||
|
PreparationError::new(format!("Could not discover API groups: {}", e))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let version = client.get_apiserver_version().await.map_err(|e| {
|
||||||
|
PreparationError::new(format!("Could not get server version: {}", e))
|
||||||
|
})?;
|
||||||
|
|
||||||
|
// OpenShift / OKD
|
||||||
|
if discovery
|
||||||
|
.groups()
|
||||||
|
.any(|g| g.name() == "project.openshift.io")
|
||||||
|
{
|
||||||
|
return Ok(KubernetesDistribution::OpenshiftFamily);
|
||||||
|
}
|
||||||
|
|
||||||
|
// K3d / K3s
|
||||||
|
if version.git_version.contains("k3s") {
|
||||||
|
return Ok(KubernetesDistribution::K3sFamily);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(KubernetesDistribution::Default);
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
async fn get_cluster_observability_operator_prometheus_application_score(
|
async fn get_cluster_observability_operator_prometheus_application_score(
|
||||||
&self,
|
&self,
|
||||||
sender: RHOBObservability,
|
sender: RHOBObservability,
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ impl TopologyState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq)]
|
||||||
pub enum DeploymentTarget {
|
pub enum DeploymentTarget {
|
||||||
LocalDev,
|
LocalDev,
|
||||||
Staging,
|
Staging,
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ impl<T: Topology + K8sclient + HelmCommand + Ingress> Interpret<T> for ArgoInter
|
|||||||
let k8s_client = topology.k8s_client().await?;
|
let k8s_client = topology.k8s_client().await?;
|
||||||
let svc = format!("argo-{}", self.score.namespace.clone());
|
let svc = format!("argo-{}", self.score.namespace.clone());
|
||||||
let domain = topology.get_domain(&svc).await?;
|
let domain = topology.get_domain(&svc).await?;
|
||||||
|
// FIXME we now have a way to know if we're running on openshift family
|
||||||
|
|
||||||
let helm_score =
|
let helm_score =
|
||||||
argo_helm_chart_score(&self.score.namespace, self.score.openshift, &domain);
|
argo_helm_chart_score(&self.score.namespace, self.score.openshift, &domain);
|
||||||
|
|
||||||
@@ -160,6 +162,9 @@ global:
|
|||||||
## Used for ingresses, certificates, SSO, notifications, etc.
|
## Used for ingresses, certificates, SSO, notifications, etc.
|
||||||
domain: {domain}
|
domain: {domain}
|
||||||
|
|
||||||
|
securityContext:
|
||||||
|
runAsUser: null
|
||||||
|
|
||||||
# -- Runtime class name for all components
|
# -- Runtime class name for all components
|
||||||
runtimeClassName: ""
|
runtimeClassName: ""
|
||||||
|
|
||||||
@@ -471,6 +476,13 @@ redis:
|
|||||||
# -- Redis name
|
# -- Redis name
|
||||||
name: redis
|
name: redis
|
||||||
|
|
||||||
|
serviceAccount:
|
||||||
|
create: true
|
||||||
|
|
||||||
|
securityContext:
|
||||||
|
runAsUser: null
|
||||||
|
|
||||||
|
|
||||||
## Redis image
|
## Redis image
|
||||||
image:
|
image:
|
||||||
# -- Redis repository
|
# -- Redis repository
|
||||||
|
|||||||
@@ -10,12 +10,11 @@ use crate::{
|
|||||||
data::Version,
|
data::Version,
|
||||||
inventory::Inventory,
|
inventory::Inventory,
|
||||||
modules::application::{
|
modules::application::{
|
||||||
ApplicationFeature, HelmPackage, InstallationError, InstallationOutcome, OCICompliant,
|
features::{ArgoApplication, ArgoHelmScore}, webapp::Webapp, ApplicationFeature, HelmPackage, InstallationError, InstallationOutcome, OCICompliant
|
||||||
features::{ArgoApplication, ArgoHelmScore},
|
|
||||||
},
|
},
|
||||||
score::Score,
|
score::Score,
|
||||||
topology::{
|
topology::{
|
||||||
DeploymentTarget, HelmCommand, K8sclient, MultiTargetTopology, Topology, ingress::Ingress,
|
ingress::Ingress, DeploymentTarget, HelmCommand, K8sclient, MultiTargetTopology, Topology
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,11 +46,11 @@ use crate::{
|
|||||||
/// - ArgoCD to install/upgrade/rollback/inspect k8s resources
|
/// - ArgoCD to install/upgrade/rollback/inspect k8s resources
|
||||||
/// - Kubernetes for runtime orchestration
|
/// - Kubernetes for runtime orchestration
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
pub struct PackagingDeployment<A: OCICompliant + HelmPackage> {
|
pub struct PackagingDeployment<A: OCICompliant + HelmPackage + Webapp> {
|
||||||
pub application: Arc<A>,
|
pub application: Arc<A>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<A: OCICompliant + HelmPackage> PackagingDeployment<A> {
|
impl<A: OCICompliant + HelmPackage + Webapp> PackagingDeployment<A> {
|
||||||
async fn deploy_to_local_k3d(
|
async fn deploy_to_local_k3d(
|
||||||
&self,
|
&self,
|
||||||
app_name: String,
|
app_name: String,
|
||||||
@@ -137,7 +136,7 @@ impl<A: OCICompliant + HelmPackage> PackagingDeployment<A> {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<
|
impl<
|
||||||
A: OCICompliant + HelmPackage + Clone + 'static,
|
A: OCICompliant + HelmPackage + Webapp + Clone + 'static,
|
||||||
T: Topology + HelmCommand + MultiTargetTopology + K8sclient + Ingress + 'static,
|
T: Topology + HelmCommand + MultiTargetTopology + K8sclient + Ingress + 'static,
|
||||||
> ApplicationFeature<T> for PackagingDeployment<A>
|
> ApplicationFeature<T> for PackagingDeployment<A>
|
||||||
{
|
{
|
||||||
@@ -146,10 +145,15 @@ impl<
|
|||||||
topology: &T,
|
topology: &T,
|
||||||
) -> Result<InstallationOutcome, InstallationError> {
|
) -> Result<InstallationOutcome, InstallationError> {
|
||||||
let image = self.application.image_name();
|
let image = self.application.image_name();
|
||||||
let domain = topology
|
|
||||||
|
let domain = if topology.current_target() == DeploymentTarget::Production {
|
||||||
|
self.application.dns()
|
||||||
|
} else {
|
||||||
|
topology
|
||||||
.get_domain(&self.application.name())
|
.get_domain(&self.application.name())
|
||||||
.await
|
.await
|
||||||
.map_err(|e| e.to_string())?;
|
.map_err(|e| e.to_string())?
|
||||||
|
};
|
||||||
|
|
||||||
// TODO Write CI/CD workflow files
|
// TODO Write CI/CD workflow files
|
||||||
// we can autotedect the CI type using the remote url (default to github action for github
|
// we can autotedect the CI type using the remote url (default to github action for github
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ mod feature;
|
|||||||
pub mod features;
|
pub mod features;
|
||||||
pub mod oci;
|
pub mod oci;
|
||||||
mod rust;
|
mod rust;
|
||||||
|
mod webapp;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub use feature::*;
|
pub use feature::*;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use tar::{Builder, Header};
|
|||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
use crate::config::{REGISTRY_PROJECT, REGISTRY_URL};
|
use crate::config::{REGISTRY_PROJECT, REGISTRY_URL};
|
||||||
|
use crate::modules::application::webapp::Webapp;
|
||||||
use crate::{score::Score, topology::Topology};
|
use crate::{score::Score, topology::Topology};
|
||||||
|
|
||||||
use super::{Application, ApplicationFeature, ApplicationInterpret, HelmPackage, OCICompliant};
|
use super::{Application, ApplicationFeature, ApplicationInterpret, HelmPackage, OCICompliant};
|
||||||
@@ -60,6 +61,10 @@ pub struct RustWebapp {
|
|||||||
pub project_root: PathBuf,
|
pub project_root: PathBuf,
|
||||||
pub service_port: u32,
|
pub service_port: u32,
|
||||||
pub framework: Option<RustWebFramework>,
|
pub framework: Option<RustWebFramework>,
|
||||||
|
/// Host name that will be used in production environment.
|
||||||
|
///
|
||||||
|
/// This is the place to put the public host name if this is a public facing webapp.
|
||||||
|
pub dns: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for RustWebapp {
|
impl Application for RustWebapp {
|
||||||
@@ -68,6 +73,12 @@ impl Application for RustWebapp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Webapp for RustWebapp {
|
||||||
|
fn dns(&self) -> String {
|
||||||
|
self.dns.clone()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl HelmPackage for RustWebapp {
|
impl HelmPackage for RustWebapp {
|
||||||
async fn build_push_helm_package(
|
async fn build_push_helm_package(
|
||||||
@@ -257,7 +268,6 @@ impl RustWebapp {
|
|||||||
".harmony_generated",
|
".harmony_generated",
|
||||||
"harmony",
|
"harmony",
|
||||||
"node_modules",
|
"node_modules",
|
||||||
"Dockerfile.harmony",
|
|
||||||
];
|
];
|
||||||
let mut entries: Vec<_> = WalkDir::new(project_root)
|
let mut entries: Vec<_> = WalkDir::new(project_root)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@@ -461,52 +471,53 @@ impl RustWebapp {
|
|||||||
|
|
||||||
let (image_repo, image_tag) = image_url.rsplit_once(':').unwrap_or((image_url, "latest"));
|
let (image_repo, image_tag) = image_url.rsplit_once(':').unwrap_or((image_url, "latest"));
|
||||||
|
|
||||||
|
let app_name = &self.name;
|
||||||
|
let service_port = self.service_port;
|
||||||
// Create Chart.yaml
|
// Create Chart.yaml
|
||||||
let chart_yaml = format!(
|
let chart_yaml = format!(
|
||||||
r#"
|
r#"
|
||||||
apiVersion: v2
|
apiVersion: v2
|
||||||
name: {}
|
name: {chart_name}
|
||||||
description: A Helm chart for the {} web application.
|
description: A Helm chart for the {app_name} web application.
|
||||||
type: application
|
type: application
|
||||||
version: 0.1.0
|
version: 0.2.0
|
||||||
appVersion: "{}"
|
appVersion: "{image_tag}"
|
||||||
"#,
|
"#,
|
||||||
chart_name, self.name, image_tag
|
|
||||||
);
|
);
|
||||||
fs::write(chart_dir.join("Chart.yaml"), chart_yaml)?;
|
fs::write(chart_dir.join("Chart.yaml"), chart_yaml)?;
|
||||||
|
|
||||||
// Create values.yaml
|
// Create values.yaml
|
||||||
let values_yaml = format!(
|
let values_yaml = format!(
|
||||||
r#"
|
r#"
|
||||||
# Default values for {}.
|
# Default values for {chart_name}.
|
||||||
# This is a YAML-formatted file.
|
# This is a YAML-formatted file.
|
||||||
# Declare variables to be passed into your templates.
|
# Declare variables to be passed into your templates.
|
||||||
|
|
||||||
replicaCount: 1
|
replicaCount: 1
|
||||||
|
|
||||||
image:
|
image:
|
||||||
repository: {}
|
repository: {image_repo}
|
||||||
pullPolicy: IfNotPresent
|
pullPolicy: IfNotPresent
|
||||||
# Overridden by the chart's appVersion
|
# Overridden by the chart's appVersion
|
||||||
tag: "{}"
|
tag: "{image_tag}"
|
||||||
|
|
||||||
service:
|
service:
|
||||||
type: ClusterIP
|
type: ClusterIP
|
||||||
port: {}
|
port: {service_port}
|
||||||
|
|
||||||
ingress:
|
ingress:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
tls: true
|
||||||
# Annotations for cert-manager to handle SSL.
|
# Annotations for cert-manager to handle SSL.
|
||||||
annotations:
|
annotations:
|
||||||
# Add other annotations like nginx ingress class if needed
|
# Add other annotations like nginx ingress class if needed
|
||||||
# kubernetes.io/ingress.class: nginx
|
# kubernetes.io/ingress.class: nginx
|
||||||
hosts:
|
hosts:
|
||||||
- host: {}
|
- host: {domain}
|
||||||
paths:
|
paths:
|
||||||
- path: /
|
- path: /
|
||||||
pathType: ImplementationSpecific
|
pathType: ImplementationSpecific
|
||||||
"#,
|
"#,
|
||||||
chart_name, image_repo, image_tag, self.service_port, domain,
|
|
||||||
);
|
);
|
||||||
fs::write(chart_dir.join("values.yaml"), values_yaml)?;
|
fs::write(chart_dir.join("values.yaml"), values_yaml)?;
|
||||||
|
|
||||||
@@ -583,7 +594,11 @@ spec:
|
|||||||
);
|
);
|
||||||
fs::write(templates_dir.join("deployment.yaml"), deployment_yaml)?;
|
fs::write(templates_dir.join("deployment.yaml"), deployment_yaml)?;
|
||||||
|
|
||||||
|
let service_port = self.service_port;
|
||||||
|
|
||||||
// Create templates/ingress.yaml
|
// Create templates/ingress.yaml
|
||||||
|
// TODO get issuer name and tls config from topology as it may be different from one
|
||||||
|
// cluster to another, also from one version to another
|
||||||
let ingress_yaml = format!(
|
let ingress_yaml = format!(
|
||||||
r#"
|
r#"
|
||||||
{{{{- if $.Values.ingress.enabled -}}}}
|
{{{{- if $.Values.ingress.enabled -}}}}
|
||||||
@@ -596,13 +611,11 @@ metadata:
|
|||||||
spec:
|
spec:
|
||||||
{{{{- if $.Values.ingress.tls }}}}
|
{{{{- if $.Values.ingress.tls }}}}
|
||||||
tls:
|
tls:
|
||||||
{{{{- range $.Values.ingress.tls }}}}
|
- secretName: {{{{ include "chart.fullname" . }}}}-tls
|
||||||
- hosts:
|
hosts:
|
||||||
{{{{- range .hosts }}}}
|
{{{{- range $.Values.ingress.hosts }}}}
|
||||||
- {{{{ . | quote }}}}
|
- {{{{ .host | quote }}}}
|
||||||
{{{{- end }}}}
|
{{{{- end }}}}
|
||||||
secretName: {{{{ .secretName }}}}
|
|
||||||
{{{{- end }}}}
|
|
||||||
{{{{- end }}}}
|
{{{{- end }}}}
|
||||||
rules:
|
rules:
|
||||||
{{{{- range $.Values.ingress.hosts }}}}
|
{{{{- range $.Values.ingress.hosts }}}}
|
||||||
@@ -616,12 +629,11 @@ spec:
|
|||||||
service:
|
service:
|
||||||
name: {{{{ include "chart.fullname" $ }}}}
|
name: {{{{ include "chart.fullname" $ }}}}
|
||||||
port:
|
port:
|
||||||
number: {{{{ $.Values.service.port | default {} }}}}
|
number: {{{{ $.Values.service.port | default {service_port} }}}}
|
||||||
{{{{- end }}}}
|
{{{{- end }}}}
|
||||||
{{{{- end }}}}
|
{{{{- end }}}}
|
||||||
{{{{- end }}}}
|
{{{{- end }}}}
|
||||||
"#,
|
"#,
|
||||||
self.service_port
|
|
||||||
);
|
);
|
||||||
fs::write(templates_dir.join("ingress.yaml"), ingress_yaml)?;
|
fs::write(templates_dir.join("ingress.yaml"), ingress_yaml)?;
|
||||||
|
|
||||||
|
|||||||
7
harmony/src/modules/application/webapp.rs
Normal file
7
harmony/src/modules/application/webapp.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
use super::Application;
|
||||||
|
use async_trait::async_trait;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait Webapp: Application {
|
||||||
|
fn dns(&self) -> String;
|
||||||
|
}
|
||||||
20
harmony/src/modules/argocd/discover.rs
Normal file
20
harmony/src/modules/argocd/discover.rs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/// Discover the current ArgoCD setup
|
||||||
|
///
|
||||||
|
/// 1. No argo installed
|
||||||
|
/// 2. Argo installed in current namespace
|
||||||
|
/// 3. Argo installed in different namespace (assuming cluster wide access)
|
||||||
|
///
|
||||||
|
/// For now we will go ahead with this very basic logic, there are many intricacies that can be
|
||||||
|
/// dealt with later, such as multitenant management in a single argo instance, credentials setup t
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
pub trait ArgoCD {
|
||||||
|
async fn ensure_installed() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct CurrentNamespaceArgo;
|
||||||
|
|
||||||
|
|
||||||
|
impl ArgoCD for CurrentNamespaceArgo {
|
||||||
|
}
|
||||||
2
harmony/src/modules/argocd/mod.rs
Normal file
2
harmony/src/modules/argocd/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
mod discover;
|
||||||
|
pub use discover::*;
|
||||||
@@ -17,3 +17,4 @@ pub mod prometheus;
|
|||||||
pub mod storage;
|
pub mod storage;
|
||||||
pub mod tenant;
|
pub mod tenant;
|
||||||
pub mod tftp;
|
pub mod tftp;
|
||||||
|
pub mod argocd;
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ pub mod application_monitoring;
|
|||||||
pub mod grafana;
|
pub mod grafana;
|
||||||
pub mod kube_prometheus;
|
pub mod kube_prometheus;
|
||||||
pub mod ntfy;
|
pub mod ntfy;
|
||||||
|
pub mod okd;
|
||||||
pub mod prometheus;
|
pub mod prometheus;
|
||||||
|
|||||||
149
harmony/src/modules/monitoring/okd/enable_user_workload.rs
Normal file
149
harmony/src/modules/monitoring/okd/enable_user_workload.rs
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
use std::{collections::BTreeMap, sync::Arc};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
data::Version,
|
||||||
|
interpret::{Interpret, InterpretError, InterpretName, InterpretStatus, Outcome},
|
||||||
|
inventory::Inventory,
|
||||||
|
score::Score,
|
||||||
|
topology::{K8sclient, Topology, k8s::K8sClient},
|
||||||
|
};
|
||||||
|
use async_trait::async_trait;
|
||||||
|
use harmony_types::id::Id;
|
||||||
|
use k8s_openapi::api::core::v1::ConfigMap;
|
||||||
|
use kube::api::ObjectMeta;
|
||||||
|
use serde::Serialize;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize)]
|
||||||
|
pub struct OpenshiftUserWorkloadMonitoring {}
|
||||||
|
|
||||||
|
impl<T: Topology + K8sclient> Score<T> for OpenshiftUserWorkloadMonitoring {
|
||||||
|
fn name(&self) -> String {
|
||||||
|
"OpenshiftUserWorkloadMonitoringScore".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_interpret(&self) -> Box<dyn Interpret<T>> {
|
||||||
|
Box::new(OpenshiftUserWorkloadMonitoringInterpret {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize)]
|
||||||
|
pub struct OpenshiftUserWorkloadMonitoringInterpret {}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl<T: Topology + K8sclient> Interpret<T> for OpenshiftUserWorkloadMonitoringInterpret {
|
||||||
|
async fn execute(
|
||||||
|
&self,
|
||||||
|
_inventory: &Inventory,
|
||||||
|
topology: &T,
|
||||||
|
) -> Result<Outcome, InterpretError> {
|
||||||
|
let client = topology.k8s_client().await.unwrap();
|
||||||
|
self.update_cluster_monitoring_config_cm(&client).await?;
|
||||||
|
self.update_user_workload_monitoring_config_cm(&client)
|
||||||
|
.await?;
|
||||||
|
self.verify_user_workload(&client).await?;
|
||||||
|
Ok(Outcome::success(
|
||||||
|
"successfully enabled user-workload-monitoring".to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_name(&self) -> InterpretName {
|
||||||
|
InterpretName::Custom("OpenshiftUserWorkloadMonitoring")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_version(&self) -> Version {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_status(&self) -> InterpretStatus {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_children(&self) -> Vec<Id> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl OpenshiftUserWorkloadMonitoringInterpret {
|
||||||
|
pub async fn update_cluster_monitoring_config_cm(
|
||||||
|
&self,
|
||||||
|
client: &Arc<K8sClient>,
|
||||||
|
) -> Result<Outcome, InterpretError> {
|
||||||
|
let mut data = BTreeMap::new();
|
||||||
|
data.insert(
|
||||||
|
"config.yaml".to_string(),
|
||||||
|
r#"
|
||||||
|
enableUserWorkload: true
|
||||||
|
alertmanagerMain:
|
||||||
|
enableUserAlertmanagerConfig: true
|
||||||
|
"#
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
|
||||||
|
let cm = ConfigMap {
|
||||||
|
metadata: ObjectMeta {
|
||||||
|
name: Some("cluster-monitoring-config".to_string()),
|
||||||
|
namespace: Some("openshift-monitoring".to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
data: Some(data),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
client.apply(&cm, Some("openshift-monitoring")).await?;
|
||||||
|
|
||||||
|
Ok(Outcome::success(
|
||||||
|
"updated cluster-monitoring-config-map".to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn update_user_workload_monitoring_config_cm(
|
||||||
|
&self,
|
||||||
|
client: &Arc<K8sClient>,
|
||||||
|
) -> Result<Outcome, InterpretError> {
|
||||||
|
let mut data = BTreeMap::new();
|
||||||
|
data.insert(
|
||||||
|
"config.yaml".to_string(),
|
||||||
|
r#"
|
||||||
|
alertmanager:
|
||||||
|
enabled: true
|
||||||
|
enableAlertmanagerConfig: true
|
||||||
|
"#
|
||||||
|
.to_string(),
|
||||||
|
);
|
||||||
|
let cm = ConfigMap {
|
||||||
|
metadata: ObjectMeta {
|
||||||
|
name: Some("user-workload-monitoring-config".to_string()),
|
||||||
|
namespace: Some("openshift-user-workload-monitoring".to_string()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
data: Some(data),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
client
|
||||||
|
.apply(&cm, Some("openshift-user-workload-monitoring"))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Outcome::success(
|
||||||
|
"updated openshift-user-monitoring-config-map".to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn verify_user_workload(
|
||||||
|
&self,
|
||||||
|
client: &Arc<K8sClient>,
|
||||||
|
) -> Result<Outcome, InterpretError> {
|
||||||
|
let namespace = "openshift-user-workload-monitoring";
|
||||||
|
let alertmanager_name = "alertmanager-user-workload-0";
|
||||||
|
let prometheus_name = "prometheus-user-workload-0";
|
||||||
|
client
|
||||||
|
.wait_for_pod_ready(alertmanager_name, Some(namespace))
|
||||||
|
.await?;
|
||||||
|
client
|
||||||
|
.wait_for_pod_ready(prometheus_name, Some(namespace))
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
Ok(Outcome::success(format!(
|
||||||
|
"pods: {}, {} ready in ns: {}",
|
||||||
|
alertmanager_name, prometheus_name, namespace
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
1
harmony/src/modules/monitoring/okd/mod.rs
Normal file
1
harmony/src/modules/monitoring/okd/mod.rs
Normal file
@@ -0,0 +1 @@
|
|||||||
|
pub mod enable_user_workload;
|
||||||
@@ -12,9 +12,6 @@ use std::process::Command;
|
|||||||
use crate::modules::k8s::ingress::{K8sIngressScore, PathType};
|
use crate::modules::k8s::ingress::{K8sIngressScore, PathType};
|
||||||
use crate::modules::monitoring::kube_prometheus::crd::grafana_default_dashboard::build_default_dashboard;
|
use crate::modules::monitoring::kube_prometheus::crd::grafana_default_dashboard::build_default_dashboard;
|
||||||
use crate::modules::monitoring::kube_prometheus::crd::rhob_alertmanager_config::RHOBObservability;
|
use crate::modules::monitoring::kube_prometheus::crd::rhob_alertmanager_config::RHOBObservability;
|
||||||
use crate::modules::monitoring::kube_prometheus::crd::rhob_alertmanagers::{
|
|
||||||
Alertmanager, AlertmanagerSpec,
|
|
||||||
};
|
|
||||||
use crate::modules::monitoring::kube_prometheus::crd::rhob_grafana::{
|
use crate::modules::monitoring::kube_prometheus::crd::rhob_grafana::{
|
||||||
Grafana, GrafanaDashboard, GrafanaDashboardSpec, GrafanaDatasource, GrafanaDatasourceConfig,
|
Grafana, GrafanaDashboard, GrafanaDashboardSpec, GrafanaDatasource, GrafanaDatasourceConfig,
|
||||||
GrafanaDatasourceSpec, GrafanaSpec,
|
GrafanaDatasourceSpec, GrafanaSpec,
|
||||||
@@ -25,13 +22,8 @@ use crate::modules::monitoring::kube_prometheus::crd::rhob_monitoring_stack::{
|
|||||||
use crate::modules::monitoring::kube_prometheus::crd::rhob_prometheus_rules::{
|
use crate::modules::monitoring::kube_prometheus::crd::rhob_prometheus_rules::{
|
||||||
PrometheusRule, PrometheusRuleSpec, RuleGroup,
|
PrometheusRule, PrometheusRuleSpec, RuleGroup,
|
||||||
};
|
};
|
||||||
use crate::modules::monitoring::kube_prometheus::crd::rhob_prometheuses::{
|
use crate::modules::monitoring::kube_prometheus::crd::rhob_prometheuses::LabelSelector;
|
||||||
AlertmanagerEndpoints, LabelSelector, PrometheusSpec, PrometheusSpecAlerting,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::modules::monitoring::kube_prometheus::crd::rhob_role::{
|
|
||||||
build_prom_role, build_prom_rolebinding, build_prom_service_account,
|
|
||||||
};
|
|
||||||
use crate::modules::monitoring::kube_prometheus::crd::rhob_service_monitor::{
|
use crate::modules::monitoring::kube_prometheus::crd::rhob_service_monitor::{
|
||||||
ServiceMonitor, ServiceMonitorSpec,
|
ServiceMonitor, ServiceMonitorSpec,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user