Skip to content

Commit

Permalink
resource error messages (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgerlag authored Sep 19, 2024
1 parent 96add1f commit 8389128
Show file tree
Hide file tree
Showing 15 changed files with 200 additions and 78 deletions.
27 changes: 21 additions & 6 deletions cli/cmd/list.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package cmd

import (
"fmt"
"os"
"reflect"
"sort"

"drasi.io/cli/api"
"drasi.io/cli/service"
"fmt"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"os"
"reflect"
"sort"
"strings"
)

func NewListCommand() *cobra.Command {
Expand Down Expand Up @@ -74,7 +74,22 @@ Example:
for k := 0; k < len(itemStatus); k++ {
statusFieldName := itemStatus[k].String()
statusFields[statusFieldName] = nil
item[statusFieldName] = fmt.Sprintf("%v", reflect.ValueOf(result[i].Status).MapIndex(itemStatus[k]).Elem())
val := reflect.ValueOf(result[i].Status).MapIndex(itemStatus[k])

switch val.Elem().Kind() {
case reflect.Map:
var builder strings.Builder
iter := val.Elem().MapRange()
for iter.Next() {
builder.WriteString(iter.Key().String())
builder.WriteString(" - ")
builder.WriteString(iter.Value().Elem().String())
builder.WriteString("\n")
}
item[statusFieldName] = builder.String()
default:
item[statusFieldName] = fmt.Sprintf(" %v", val.Elem())
}
}
}
items = append(items, item)
Expand Down
12 changes: 6 additions & 6 deletions control-planes/kubernetes_provider/src/actors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use dapr::server::{
utils::DaprJson,
};
use resource_provider_api::models::ResourceRequest;
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::marker;
use tokio::sync::RwLock;

Expand All @@ -29,7 +29,7 @@ pub struct ResourceActor<TSpec, TStatus> {
resource_type: String,
runtime_config: RuntimeConfig,
spec_builder: Box<dyn SpecBuilder<TSpec> + Send + Sync>,
controllers: RwLock<Vec<ResourceController>>,
controllers: RwLock<BTreeMap<String, ResourceController>>,
kube_config: kube::Config,
_owns_tstatus: marker::PhantomData<TStatus>,
}
Expand Down Expand Up @@ -108,7 +108,7 @@ impl<TSpec, TStatus> ResourceActor<TSpec, TStatus> {

let controllers = self.controllers.read().await;

for controller in controllers.iter() {
for (_, controller) in controllers.iter() {
controller.deprovision();
}

Expand Down Expand Up @@ -162,7 +162,7 @@ impl<TSpec, TStatus> ResourceActor<TSpec, TStatus> {
let mut controllers = self.controllers.write().await;
controllers.clear();
for spec in specs {
controllers.push(ResourceController::start(self.kube_config.clone(), spec));
controllers.insert(spec.service_name.clone(), ResourceController::start(self.kube_config.clone(), spec));
}
}

Expand All @@ -172,7 +172,7 @@ impl<TSpec, TStatus> ResourceActor<TSpec, TStatus> {
let mut recievers = Vec::new();

let controllers = self.controllers.read().await;
for controller in controllers.iter() {
for (_, controller) in controllers.iter() {
recievers.push(controller.reconcile());
}

Expand All @@ -185,7 +185,7 @@ impl<TSpec, TStatus> ResourceActor<TSpec, TStatus> {
let mut recievers = Vec::new();

let controllers = self.controllers.read().await;
for controller in controllers.iter() {
for (_, controller) in controllers.iter() {
recievers.push(controller.reconcile());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::{response::IntoResponse, Json};
use dapr::{server::actor::context_client::ActorContextClient};
use dapr_macros::actor;
use resource_provider_api::models::{QueryContainerSpec, QueryContainerStatus};
use std::marker;
use std::{collections::BTreeMap, marker};
use tokio::sync::RwLock;

use super::ResourceActor;
Expand All @@ -29,7 +29,7 @@ impl QueryContainerActor {
resource_type: "querycontainer".to_string(),
runtime_config,
spec_builder: Box::new(QueryContainerSpecBuilder {}),
controllers: RwLock::new(Vec::new()),
controllers: RwLock::new(BTreeMap::new()),
kube_config,
_owns_tstatus: marker::PhantomData,
}
Expand All @@ -39,7 +39,22 @@ impl QueryContainerActor {
let controllers = self.controllers.read().await;
let available = controllers
.iter()
.all(|c| c.status() == ReconcileStatus::Online);
Json(QueryContainerStatus { available })
.all(|c| c.1.status() == ReconcileStatus::Online);

let mut messages = BTreeMap::new();
for (name, controller) in controllers.iter() {
match controller.status() {
ReconcileStatus::Unknown => messages.insert(name.clone(), "Unknown".to_string()),
ReconcileStatus::Offline(msg) => messages.insert(name.clone(), msg),
ReconcileStatus::Online => continue,
};
}

Json(QueryContainerStatus {
available,
messages: Some(messages),

})
}

}
22 changes: 18 additions & 4 deletions control-planes/kubernetes_provider/src/actors/reaction_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::{response::IntoResponse, Json};
use dapr::{server::actor::context_client::ActorContextClient};
use dapr_macros::actor;
use resource_provider_api::models::{ReactionSpec, ReactionStatus};
use std::marker;
use std::{collections::BTreeMap, marker};
use tokio::sync::RwLock;

use super::ResourceActor;
Expand All @@ -29,7 +29,7 @@ impl ReactionActor {
resource_type: "reaction".to_string(),
runtime_config,
spec_builder: Box::new(ReactionSpecBuilder {}),
controllers: RwLock::new(Vec::new()),
controllers: RwLock::new(BTreeMap::new()),
kube_config,
_owns_tstatus: marker::PhantomData,
}
Expand All @@ -40,7 +40,21 @@ impl ReactionActor {
let controllers = self.controllers.read().await;
let available = controllers
.iter()
.all(|c| c.status() == ReconcileStatus::Online);
Json(ReactionStatus { available })
.all(|c| c.1.status() == ReconcileStatus::Online);

let mut messages = BTreeMap::new();
for (name, controller) in controllers.iter() {
match controller.status() {
ReconcileStatus::Unknown => messages.insert(name.clone(), "Unknown".to_string()),
ReconcileStatus::Offline(msg) => messages.insert(name.clone(), msg),
ReconcileStatus::Online => continue,
};
}

Json(ReactionStatus {
available,
messages: Some(messages),

})
}
}
24 changes: 19 additions & 5 deletions control-planes/kubernetes_provider/src/actors/source_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
use axum::{response::IntoResponse, Json};
use dapr::{server::actor::context_client::ActorContextClient};
use dapr_macros::actor;
use resource_provider_api::models::{SourceProviderStatus, SourceSpec, SourceStatus};
use std::{collections::HashMap, marker};
use resource_provider_api::models::{SourceSpec, SourceStatus};
use std::{collections::BTreeMap, marker};
use tokio::sync::RwLock;

use super::ResourceActor;
Expand All @@ -29,7 +29,7 @@ impl SourceActor {
resource_type: "source".to_string(),
runtime_config,
spec_builder: Box::new(SourceSpecBuilder {}),
controllers: RwLock::new(Vec::new()),
controllers: RwLock::new(BTreeMap::new()),
kube_config,
_owns_tstatus: marker::PhantomData,
}
Expand All @@ -39,7 +39,21 @@ impl SourceActor {
let controllers = self.controllers.read().await;
let available = controllers
.iter()
.all(|c| c.status() == ReconcileStatus::Online);
Json(SourceStatus { available })
.all(|c| c.1.status() == ReconcileStatus::Online);

let mut messages = BTreeMap::new();
for (name, controller) in controllers.iter() {
match controller.status() {
ReconcileStatus::Unknown => messages.insert(name.clone(), "Unknown".to_string()),
ReconcileStatus::Offline(msg) => messages.insert(name.clone(), msg),
ReconcileStatus::Online => continue,
};
}

Json(SourceStatus {
available,
messages: Some(messages),

})
}
}
Loading

0 comments on commit 8389128

Please sign in to comment.