From 67094431fea89f6dd835d62b7ed8677b3c07597c Mon Sep 17 00:00:00 2001 From: Hubbe Date: Wed, 4 Nov 2020 13:50:12 +0200 Subject: [PATCH] Fix styling and handling of disabled components Filter out null values from disabled components in "items" Fix formatting on thrimshim arguments Use enabled. syntax to check enabled components, as they're essentially variables. --- k8s.jsonnet | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/k8s.jsonnet b/k8s.jsonnet index 2f329ee..93dd405 100644 --- a/k8s.jsonnet +++ b/k8s.jsonnet @@ -182,12 +182,15 @@ }, }, - // The actual manifests. - // These are all deployments. Note that all components work fine if multiple are running + // The actual manifests to output, filtering out "null" from disabled components. + items: [comp for comp in $.components if comp != null], + + // These are all the deployments and services. + // Note that all components work fine if multiple are running // (they may duplicate work, but not cause errors by stepping on each others' toes). - items: [ + components:: [ // The downloader watches the twitch stream and writes the HLS segments to disk - if $.config.enabled["downloader"] then $.deployment("downloader", args=$.config.channels + [ + if $.config.enabled.downloader then $.deployment("downloader", args=$.config.channels + [ "--base-dir", "/mnt", "--qualities", std.join(",", $.config.qualities), "--backdoor-port", std.toString($.config.backdoor_port), @@ -195,7 +198,7 @@ ]), // The restreamer is a http server that fields requests for checking what segments exist // and allows HLS streaming of segments from any requested timestamp - if $.config.enabled["restreamer"] then $.deployment("restreamer", args=[ + if $.config.enabled.restreamer then $.deployment("restreamer", args=[ "--base-dir", "/mnt", "--backdoor-port", std.toString($.config.backdoor_port), "--port", "80", @@ -203,7 +206,7 @@ // The backfiller periodically compares what segments exist locally to what exists on // other nodes. If it finds ones it doesn't have, it downloads them. // It can talk to the database to discover other wubloader nodes, or be given a static list. - if $.config.enabled["backfiller"] then $.deployment("backfiller", args=$.clean_channels + [ + if $.config.enabled.backfiller then $.deployment("backfiller", args=$.clean_channels + [ "--base-dir", "/mnt", "--qualities", std.join(",", $.config.qualities), "--static-nodes", std.join(",", $.config.peers), @@ -215,39 +218,39 @@ // Segment coverage is a monitoring helper that periodically scans available segments // and reports stats. It also creates a "coverage map" image to represent this info. // It puts this in the segment directory where nginx will serve it. - if $.config.enabled["segment_coverage"] then $.deployment("segment-coverage", args=$.clean_channels + [ + if $.config.enabled.segment_coverage then $.deployment("segment-coverage", args=$.clean_channels + [ "--base-dir", "/mnt", "--qualities", std.join(",", $.config.qualities), "--metrics-port", "80", ]), // Thrimshim acts as an interface between the thrimbletrimmer editor and the database // It is needed for thrimbletrimmer to be able to get unedited videos and submit edits - if $.config.enabled["thrimshim"] then $.deployment("thrimshim", args=[ + if $.config.enabled.thrimshim then $.deployment("thrimshim", args=[ "--backdoor-port", std.toString($.config.backdoor_port), "--title-header", $.config.title_header, "--description-footer", $.config.description_footer, - "--upload-locations", std.join(",", [$.config.default_location] + - [location for location in std.objectFields($.config.cutter_config) - if location != $.config.default_location]), + "--upload-locations", std.join(",", [$.config.default_location] + [ + location for location in std.objectFields($.config.cutter_config) + if location != $.config.default_location + ]), $.db_connect, $.clean_channels[0], // use first element as default channel $.config.bustime_start, - ] - ), + ]), // Normally nginx would be responsible for proxying requests to different services, // but in k8s we can use Ingress to do that. However nginx is still needed to serve // static content - segments as well as thrimbletrimmer. - if $.config.enabled["nginx"] then $.deployment("nginx", env=[ + if $.config.enabled.nginx then $.deployment("nginx", env=[ {name: "THRIMBLETRIMMER", value: "true"}, {name: "SEGMENTS", value: "/mnt"}, ]), // Services for all deployments - if $.config.enabled["downloader"] then $.service("downloader"), - if $.config.enabled["backfiller"] then $.service("backfiller"), - if $.config.enabled["nginx"] then $.service("nginx"), - if $.config.enabled["restreamer"] then $.service("restreamer"), - if $.config.enabled["segment_coverage"] then $.service("segment-coverage"), - if $.config.enabled["thrimshim"] then $.service("thrimshim"), + if $.config.enabled.downloader then $.service("downloader"), + if $.config.enabled.backfiller then $.service("backfiller"), + if $.config.enabled.nginx then $.service("nginx"), + if $.config.enabled.restreamer then $.service("restreamer"), + if $.config.enabled.segment_coverage then $.service("segment-coverage"), + if $.config.enabled.thrimshim then $.service("thrimshim"), // Ingress to direct requests to the correct services. { kind: "Ingress",