Skip to content

Commit

Permalink
Refactor to use new schama and custum resource definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
wangeguo committed Sep 25, 2023
1 parent 56d9403 commit 401ba89
Show file tree
Hide file tree
Showing 24 changed files with 328 additions and 160 deletions.
44 changes: 22 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.4.12"
version = "0.5.0"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/amphitheatre-app/amphitheatre"
Expand All @@ -21,7 +21,7 @@ members = [
# https://doc.rust-lang.org/cargo/reference/workspaces.html#the-workspacedependencies-table
[workspace.dependencies]
anyhow = "1.0"
amp-common = { git = "https://github.com/amphitheatre-app/common", tag = "v0.4.1" }
amp-common = { git = "https://github.com/amphitheatre-app/common", tag = "v0.5.0" }
amp-resolver = { path = "resolver" }
amp-resources = { path = "resources" }
async-nats = "0.29.0"
Expand Down
6 changes: 3 additions & 3 deletions apiserver/src/requests/playbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use amp_common::schema::EitherCharacter;
use amp_common::resource::Preface;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

#[derive(Serialize, Deserialize, ToSchema)]
pub struct CreatePlaybookRequest {
pub title: String,
pub description: String,
pub preface: EitherCharacter,
pub description: Option<String>,
pub preface: Preface,
pub live: bool,
}

Expand Down
7 changes: 4 additions & 3 deletions apiserver/src/responses/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use amp_common::schema::Actor;
use amp_common::resource::Actor;
use kube::ResourceExt;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
Expand All @@ -24,15 +24,16 @@ pub struct ActorResponse {
/// The title of the actor.
pub title: String,
/// The description of the actor.
pub description: String,
pub description: Option<String>,
}

impl From<&Actor> for ActorResponse {
fn from(value: &Actor) -> Self {
let description = &value.spec.character.meta.description;
Self {
id: value.name_any(),
title: value.spec.name.clone(),
description: value.spec.description.clone().unwrap_or_default(),
description: description.clone(),
}
}
}
4 changes: 2 additions & 2 deletions apiserver/src/responses/playbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use amp_common::schema::Playbook;
use amp_common::resource::Playbook;
use chrono::{DateTime, Utc};
use kube::ResourceExt;
use serde::{Deserialize, Serialize};
Expand All @@ -37,7 +37,7 @@ impl From<Playbook> for PlaybookResponse {
Self {
id: playbook.name_any(),
title: playbook.spec.title,
description: playbook.spec.description,
description: playbook.spec.description.unwrap_or_default(),
created_at: Utc::now(),
updated_at: Utc::now(),
}
Expand Down
6 changes: 4 additions & 2 deletions apiserver/src/services/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ impl ActorService {
.map_err(|err| ApiError::KubernetesError(err.to_string()))?;

let mut info = HashMap::new();
if let Some(env) = actor.spec.env {
info.insert("environments".to_string(), env);
if let Some(deploy) = actor.spec.character.deploy {
if let Some(env) = deploy.env {
info.insert("environments".to_string(), env);
}
}

Ok(info)
Expand Down
6 changes: 3 additions & 3 deletions apiserver/src/services/playbook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use std::sync::Arc;

use amp_common::schema::{Playbook as PlaybookResource, PlaybookSpec};
use amp_common::resource::{Playbook as PlaybookResource, PlaybookSpec};
use amp_resources::playbook;
use chrono::Utc;
use kube::ResourceExt;
Expand Down Expand Up @@ -67,7 +67,7 @@ impl PlaybookService {
&uuid.to_string(),
PlaybookSpec {
title: req.title.to_string(),
description: req.description.to_string(),
description: req.description.clone(),
namespace: format!("amp-{}", uuid),
preface: req.preface.clone(),
..PlaybookSpec::default()
Expand All @@ -81,7 +81,7 @@ impl PlaybookService {
Ok(PlaybookResponse {
id: playbook.name_any(),
title: playbook.spec.title,
description: playbook.spec.description,
description: playbook.spec.description.unwrap_or_default(),
created_at: Utc::now(),
updated_at: Utc::now(),
})
Expand Down
10 changes: 5 additions & 5 deletions controllers/src/actor_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::sync::Arc;
use std::time::Duration;

use amp_common::docker::{self, registry, DockerConfig};
use amp_common::schema::{Actor, ActorState};
use amp_common::resource::{Actor, ActorState};
use amp_resources::event::trace;
use amp_resources::{actor, builder, deployment, service};
use futures::{future, StreamExt};
Expand Down Expand Up @@ -113,7 +113,7 @@ async fn build(actor: &Actor, ctx: &Arc<Context>, recorder: &Recorder) -> Result
}
};

if registry::exists(&actor.spec.docker_tag(), credential)
if registry::exists(&actor.spec.image, credential)
.await
.map_err(Error::DockerRegistryExistsFailed)?
{
Expand All @@ -130,14 +130,14 @@ async fn build(actor: &Actor, ctx: &Arc<Context>, recorder: &Recorder) -> Result
match builder::exists(&ctx.k8s, actor).await.map_err(Error::ResourceError)? {
true => {
// Build job already exists, update it if there are new changes
let message = format!("Try to refresh an existing build Job {}", actor.spec.build_name());
let message = format!("Try to refresh an existing build Job {}", actor.spec.name());
trace(recorder, message).await.map_err(Error::ResourceError)?;

builder::update(&ctx.k8s, actor).await.map_err(Error::ResourceError)?;
}
false => {
// Create a new build job
let message = format!("Create new build Job: {}", actor.spec.build_name());
let message = format!("Create new build Job: {}", actor.spec.name());
trace(recorder, message).await.map_err(Error::ResourceError)?;

builder::create(&ctx.k8s, actor).await.map_err(Error::ResourceError)?;
Expand Down Expand Up @@ -197,7 +197,7 @@ async fn run(actor: &Actor, ctx: &Arc<Context>, recorder: &Recorder) -> Result<A
}
}

if actor.spec.service_ports().is_some() {
if actor.spec.has_services() {
match service::exists(&ctx.k8s, actor).await.map_err(Error::ResourceError)? {
true => {
// Service already exists, update it if there are new changes
Expand Down
Loading

0 comments on commit 401ba89

Please sign in to comment.