Skip to content

Commit

Permalink
pre and post script can modify the context. to_decimal handlebars mac…
Browse files Browse the repository at this point in the history
…ro and bcrypt_hash support
  • Loading branch information
sebt3 committed Dec 21, 2024
1 parent 5906da6 commit 92e8990
Show file tree
Hide file tree
Showing 32 changed files with 474 additions and 256 deletions.
383 changes: 202 additions & 181 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion agent/scripts/lib/wait.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn vital(lst, duration) {
obj.wait_condition("ClusterAvailable", duration);
} else if ["RedisSentinel"].contains(v.kind) {
log_info(`Waiting for ${v.kind} ${v.namespace}/${v.name} to be available`);
let sts = get_statefulset(v.namespace, `${v.name}--sentinel`);
let sts = get_statefulset(v.namespace, `${v.name}-sentinel`);
sts.wait_available(duration);
} else if ["RedisCluster"].contains(v.kind) {
log_info(`Waiting for ${v.kind} ${v.namespace}/${v.name} to be available`);
Expand Down
12 changes: 9 additions & 3 deletions agent/scripts/system/context.rhai
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import "build_context" as build;
fn run(instance, args) {
let context = build::run(instance, args);
import_run("context_pre", instance, context);
let ctx = import_run("context_system", instance, context);
let ctx = import_run("context_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
ctx = import_run("context_system", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
let extra = import_run("context_extra", instance, context);
context["extra"] = extra;
import_run("context_post", instance, context);
ctx = import_run("context_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
15 changes: 12 additions & 3 deletions agent/scripts/system/delete.rhai
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
fn run(instance, context) {
import_run("delete_pre", instance, context);
let ctx = import_run("delete_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
if is_dir(`${context.package_dir}/systems`) {
import_run("delete_systems", instance, context);
ctx = import_run("delete_systems", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
}
if is_dir(`${context.package_dir}/tofu`) {
context = import_run("delete_tofu", instance, context);
}
if is_dir(`${context.package_dir}/crds`) {
import_run("delete_crds", instance, context);
ctx = import_run("delete_crds", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
}
import_run("delete_post", instance, context);
}
11 changes: 9 additions & 2 deletions agent/scripts/system/delete_crds.rhai
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
fn run(instance, context) {
import_run("delete_crds_pre", instance, context);
let ctx = import_run("delete_crds_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
let api = k8s_resource("CustomResourceDefinition");
if instance.status != () && instance.status.crds != () {
for old in instance.status.crds {
Expand All @@ -20,5 +23,9 @@ fn run(instance, context) {
} catch (e) {}
}
}
import_run("delete_crds_post", instance, context);
ctx = import_run("delete_crds_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
11 changes: 9 additions & 2 deletions agent/scripts/system/delete_systems.rhai
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
fn run(instance, context) {
import_run("delete_systems_pre", instance, context);
let ctx = import_run("delete_systems_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
if instance.status != () && instance.status.systems != () {
let deleted = [];
for old in instance.status.systems {
Expand All @@ -18,5 +21,9 @@ fn run(instance, context) {
d.wait_deleted(60*5);
}
}
import_run("delete_systems_post", instance, context);
ctx = import_run("delete_systems_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
10 changes: 8 additions & 2 deletions agent/scripts/system/delete_tofu.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import "tofu" as tf;
import "tofu_gen" as tfg;

fn run(instance, context) {
import_run("delete_tofu_pre", instance, context);
let ctx = import_run("delete_tofu_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
let orig = instance.get_tfstate();
if orig != "" {
file_write(`${context.package_dir}/tofu/terraform.tfstate`, orig);
}
tfg::gen_files(context);
tf::run_init(`${context.package_dir}/tofu`);
tf::run_destroy(`${context.package_dir}/tofu`);
import_run("delete_tofu_post", instance, context);
ctx = import_run("delete_tofu_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
17 changes: 13 additions & 4 deletions agent/scripts/system/install.rhai
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
fn run(instance, context) {
import_run("install_pre", instance, context);
if is_dir(`${context.package_dir}/crds`) {
let ctx = import_run("install_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
if is_dir(`${context.package_dir}/crds`) {
log_info(`Installing CRDs from ${context.package_dir}/crds from ${instance.metadata.namespace} ${instance.metadata.name}`);
import_run("install_crds", instance, context);
ctx = import_run("install_crds", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
update_k8s_crd_cache();
instance = get_system_instance(instance.metadata.namespace, instance.metadata.name);
}
Expand All @@ -13,7 +19,10 @@ fn run(instance, context) {
}
if is_dir(`${context.package_dir}/systems`) {
log_info(`Installing systems from ${context.package_dir}/systems from ${instance.metadata.namespace} ${instance.metadata.name}`);
import_run("install_systems", instance, context);
ctx = import_run("install_systems", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
instance = get_system_instance(instance.metadata.namespace, instance.metadata.name);
}
import_run("install_post", instance, context);
Expand Down
11 changes: 9 additions & 2 deletions agent/scripts/system/install_crds.rhai
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
fn run(instance, context) {
import_run("install_crds_pre", instance, context);
let ctx = import_run("install_crds_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
let hbs = new_hbs();
hbs.register_partial_dir(`${context.package_dir}/handlebars/partials`);
hbs.register_helper_dir(`${context.package_dir}/handlebars/helpers`);
Expand Down Expand Up @@ -53,5 +56,9 @@ fn run(instance, context) {
}
throw e;
}
import_run("install_crds_post", instance, context);
ctx = import_run("install_crds_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
11 changes: 9 additions & 2 deletions agent/scripts/system/install_systems.rhai
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import "install_from_dir" as dir;
import "wait" as wait;
fn run(instance, context) {
import_run("install_systems_pre", instance, context);
let ctx = import_run("install_systems_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
try {
let applied_objs = dir::install(instance, context, `${context.package_dir}/systems`, true, false);
let added = import_run("install_systems_add", instance, context);
Expand All @@ -27,5 +30,9 @@ fn run(instance, context) {
}
throw e;
}
import_run("install_systems_post", instance, context);
ctx = import_run("install_systems_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
10 changes: 8 additions & 2 deletions agent/scripts/system/install_tofu.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import "tofu" as tf;
import "tofu_gen" as tfg;

fn run(instance, context) {
import_run("install_tofu_pre", instance, context);
ctx = import_run("install_tofu_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
let orig = instance.get_tfstate();
if orig != "" {
file_write(`${context.package_dir}/tofu/terraform.tfstate`, orig);
Expand All @@ -25,6 +28,9 @@ fn run(instance, context) {
}
throw e;
}
import_run("install_tofu_post", instance, context);
ctx = import_run("install_tofu_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
12 changes: 9 additions & 3 deletions agent/scripts/tenant/context.rhai
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import "build_context" as build;
fn run(instance, args) {
let context = build::run(instance, args);
import_run("context_pre", instance, context);
let ctx = import_run("context_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
let name = instance.get_tenant_name();
let nss = instance.get_tenant_namespaces();
context["tenant"] = #{
name: name,
namespaces: nss,
};
let ctx = import_run("context_tenant", instance, context);
ctx = import_run("context_tenant", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
let extra = import_run("context_extra", instance, context);
context["extra"] = extra;
import_run("context_post", instance, context);
ctx = import_run("context_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
24 changes: 18 additions & 6 deletions agent/scripts/tenant/delete.rhai
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
fn run(instance, context) {
import_run("delete_pre", instance, context);
if is_dir(`${context.package_dir}/tofu`) {
context = import_run("delete_tofu", instance, context);
let ctx = import_run("delete_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
if is_dir(`${context.package_dir}/scalables`) {
import_run("delete_scalables", instance, context);
ctx = import_run("delete_scalables", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
}
if is_dir(`${context.package_dir}/tofu`) {
context = import_run("delete_tofu", instance, context);
}
if is_dir(`${context.package_dir}/others`) {
import_run("delete_others", instance, context);
ctx = import_run("delete_others", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
}
if is_dir(`${context.package_dir}/vitals`) {
import_run("delete_vitals", instance, context);
ctx = import_run("delete_vitals", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
}
import_run("delete_post", instance, context);
}
11 changes: 9 additions & 2 deletions agent/scripts/tenant/delete_others.rhai
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
fn run(instance, context) {
import_run("delete_others_pre", instance, context);
let ctx = import_run("delete_others_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
if instance.status != () && instance.status.others != () {
let deleted = [];
for old in instance.status.others {
Expand All @@ -18,5 +21,9 @@ fn run(instance, context) {
d.wait_deleted(60*5);
}
}
import_run("delete_others_post", instance, context);
ctx = import_run("delete_others_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
11 changes: 9 additions & 2 deletions agent/scripts/tenant/delete_scalables.rhai
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
fn run(instance, context) {
import_run("delete_scalables_pre", instance, context);
let ctx = import_run("delete_scalables_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
if instance.status != () && instance.status.scalables != () {
let deleted = [];
for old in instance.status.scalables {
Expand All @@ -18,5 +21,9 @@ fn run(instance, context) {
d.wait_deleted(60*5);
}
}
import_run("delete_scalables_post", instance, context);
ctx = import_run("delete_scalables_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
10 changes: 8 additions & 2 deletions agent/scripts/tenant/delete_tofu.rhai
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import "tofu" as tf;
import "tofu_gen" as tfg;

fn run(instance, context) {
import_run("delete_tofu_pre", instance, context);
let ctx = import_run("delete_tofu_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
let orig = instance.get_tfstate();
if orig != "" {
file_write(`${context.package_dir}/tofu/terraform.tfstate`, orig);
}
tfg::gen_files(context);
tf::run_init(`${context.package_dir}/tofu`);
tf::run_destroy(`${context.package_dir}/tofu`);
import_run("delete_tofu_post", instance, context);
ctx = import_run("delete_tofu_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
11 changes: 9 additions & 2 deletions agent/scripts/tenant/delete_vitals.rhai
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
fn run(instance, context) {
import_run("delete_vitals_pre", instance, context);
let ctx = import_run("delete_vitals_pre", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
if instance.status != () && instance.status.vitals != () {
let deleted = [];
for old in instance.status.vitals {
Expand All @@ -18,5 +21,9 @@ fn run(instance, context) {
d.wait_deleted(60*5);
}
}
import_run("delete_vitals_post", instance, context);
ctx = import_run("delete_vitals_post", instance, context);
if type_of(ctx) == "map" {
context = ctx;
}
context
}
Loading

0 comments on commit 92e8990

Please sign in to comment.