Skip to content

Commit

Permalink
Adjusted to patch source and image fields only when actor is live
Browse files Browse the repository at this point in the history
  • Loading branch information
wangeguo committed Oct 12, 2023
1 parent 91ac4a2 commit 312c843
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 23 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace.package]
version = "0.5.7"
version = "0.5.8"
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/amphitheatre-app/amphitheatre"
Expand Down
14 changes: 7 additions & 7 deletions controllers/src/playbook_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ async fn resolve(playbook: &Playbook, ctx: &Arc<Context>, recorder: &Recorder) -
tracing::debug!("The repositories to be fetched are: {fetches:?}");

for (name, partner) in fetches.iter() {
let actor = resolver::partner::load(&ctx.k8s, &credentials, name, partner)
let character = resolver::partner::load(&ctx.k8s, &credentials, name, partner)
.await
.map_err(Error::ResolveError)?;

let message = "Fetch and add the actor to this playbook";
trace(recorder, message).await.map_err(Error::ResourceError)?;

playbook::add(&ctx.k8s, playbook, actor)
playbook::add(&ctx.k8s, playbook, character)
.await
.map_err(Error::ResourceError)?;
}
Expand Down Expand Up @@ -191,17 +191,17 @@ async fn run(playbook: &Playbook, ctx: &Arc<Context>, recorder: &Recorder) -> Re
let message = format!("Try to refresh an existing Actor {}", name);
trace(recorder, message).await.map_err(Error::ResourceError)?;

let spec = resolver::to_actor(&credentials, character).map_err(Error::ResolveError)?;
let spec = resolver::to_actor(character, &credentials).map_err(Error::ResolveError)?;
actor::update(&ctx.k8s, playbook, &spec)
.await
.map_err(Error::ResourceError)?;
}
false => {
// Create a new actor
trace(recorder, format!("Create new Actor: {}", name))
.await
.map_err(Error::ResourceError)?;
let spec = resolver::to_actor(&credentials, character).map_err(Error::ResolveError)?;
let message = format!("Create new Actor: {}", name);
trace(recorder, message).await.map_err(Error::ResourceError)?;

let spec = resolver::to_actor(character, &credentials).map_err(Error::ResolveError)?;
actor::create(&ctx.k8s, playbook, &spec)
.await
.map_err(Error::ResourceError)?;
Expand Down
23 changes: 14 additions & 9 deletions resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub mod utils;

const CATALOG_REPO_URL: &str = "https://github.com/amphitheatre-app/catalog.git";

/// Load mainfest from catalog and return the actor spec.
/// Load manifest from catalog and return the actor spec.
pub fn load_from_catalog(credentials: &Credentials, name: &str, version: &str) -> Result<CharacterSpec> {
let reference = GitReference {
repo: CATALOG_REPO_URL.to_string(),
Expand All @@ -40,7 +40,7 @@ pub fn load_from_catalog(credentials: &Credentials, name: &str, version: &str) -
load_from_source(credentials, &reference)
}

/// Load mainfest from remote VCS (like github) and return the actor spec.
/// Load manifest from remote VCS (like github) and return the actor spec.
pub fn load_from_source(credentials: &Credentials, reference: &GitReference) -> Result<CharacterSpec> {
let client = ScmClient::init(credentials, &reference.repo).map_err(ResolveError::SCMError)?;

Expand All @@ -59,7 +59,7 @@ pub fn load_from_source(credentials: &Credentials, reference: &GitReference) ->
Ok(CharacterSpec::from(manifest))
}

/// Load mainfest from Kubernetes cluster and return the actor spec.
/// Load manifest from Kubernetes cluster and return the actor spec.
pub async fn load_from_cluster(client: &KubeClient, name: &str) -> Result<CharacterSpec> {
let character = character::get(client, name)
.await
Expand All @@ -68,12 +68,17 @@ pub async fn load_from_cluster(client: &KubeClient, name: &str) -> Result<Charac
}

/// Read Character manifest and return the actor spec.
pub fn to_actor(credentials: &Credentials, manifest: &CharacterSpec) -> Result<ActorSpec> {
let client = ScmClient::init(credentials, &manifest.meta.repository).map_err(ResolveError::SCMError)?;
pub fn to_actor(character: &CharacterSpec, credentials: &Credentials) -> Result<ActorSpec> {
let client = ScmClient::init(credentials, &character.meta.repository).map_err(ResolveError::SCMError)?;

let mut spec = ActorSpec::from(manifest);
spec.source = Some(patches::source(&client, &spec.source.unwrap())?);
spec.image = patches::image(credentials, &spec)?;
let mut actor = ActorSpec::from(character);

Ok(spec)
// Patch the source and image if the actor is not live.
// it will be build with the builders later, so these must be valid.
if !actor.live {
actor.source = Some(patches::source(&client, &actor.source.unwrap())?);
actor.image = patches::image(credentials, &actor)?;
}

Ok(actor)
}
2 changes: 1 addition & 1 deletion resolver/src/preface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
use amp_common::{config::Credentials, resource::CharacterSpec, resource::Preface};
use kube::Client as KubeClient;

/// Load mainfest from different sources and return the actor spec.
/// Load manifest from different sources and return the actor spec.
pub async fn load(client: &KubeClient, credentials: &Credentials, preface: &Preface) -> Result<CharacterSpec> {
if let Some(p) = &preface.registry {
let registry = p.registry.clone().unwrap_or_else(|| "catalog".to_string());
Expand Down

0 comments on commit 312c843

Please sign in to comment.