Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/models/microservice_model'
Expand All @@ -26,4 +26,40 @@ class MicroservicesController < ModelController
def initialize
@model_class = OpenC3::MicroserviceModel
end

def traefik
result = {}
result['http'] = {}
http = result['http']
http['routers'] = {}
routers = http['routers']
http['services'] = {}
services = http['services']
models = OpenC3::MicroserviceModel.all
models.each do |microservice_name, microservice|
prefix = microservice['prefix']
ports = microservice['ports']
if prefix and ports[0][0]
port = ports[0][0].to_i
prefix = '/' + prefix unless prefix[0] == '/'
if ENV['KUBERNETES_SERVICE_HOST']
url = "http://#{microservice_name.downcase.gsub('__', '-').gsub('_', '-')}-service:#{port}"
else
url = "http://openc3-operator:#{port}"
end
service_name = microservice_name
router_name = microservice_name
services[service_name] = {}
services[service_name]['loadBalancer'] = {}
services[service_name]['loadBalancer']['passHostHeader'] = false
services[service_name]['loadBalancer']['servers'] = []
services[service_name]['loadBalancer']['servers'] << {"url" => url}
routers[router_name] = {}
routers[router_name]['rule'] = "PathPrefix(`#{prefix}`)"
routers[router_name]['service'] = service_name
routers[router_name]['priority'] = 20
end
end
render :json => result
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# All changes Copyright 2022, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
# This file may also be used under the terms of a commercial license
# if purchased from OpenC3, Inc.

require 'openc3/models/tool_model'
Expand Down
1 change: 1 addition & 0 deletions openc3-cosmos-cmd-tlm-api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@

get "/time" => "time#get_current"
get "map.json" => "tools#importmap"
get "/traefik" => "microservices#traefik"

post "/redis/exec" => "redis#execute_raw"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ VARIABLE templated_int_name TEMPLATED_INT
VARIABLE demo_tool_name Demo
VARIABLE example_microservice_name openc3-example
VARIABLE templated_microservice_name openc3-templated
VARIABLE example_host openc3-operator
VARIABLE example_port 9999
VARIABLE templated_host openc3-operator
VARIABLE templated_port 5025
VARIABLE inst_router_port 7779
VARIABLE log_retain_time 172800
Expand Down Expand Up @@ -78,6 +76,8 @@ VARIABLE reduced_log_retain_time 2592000
<% end %>

<% if include_example and include_example_int %>
# This expression builds the correct hostname for Open Source or Enterprise Edition in Kubernetes
<% example_host = ENV['KUBERNETES_SERVICE_HOST'] ? "#{scope}-user-#{example_microservice_name.downcase.gsub('__', '-').gsub('_', '-')}-service" : "openc3-operator" %>
INTERFACE <%= example_int_name %> example_interface.rb <%= example_host %> <%= example_port %>
PROTOCOL WRITE MyRejectProtocol
MAP_TARGET <%= example_target_name %>
Expand All @@ -86,6 +86,8 @@ VARIABLE reduced_log_retain_time 2592000
<% end %>

<% if include_templated and include_templated_int %>
# This expression builds the correct hostname for Open Source or Enterprise Edition in Kubernetes
<% templated_host = ENV['KUBERNETES_SERVICE_HOST'] ? "#{scope}-user-#{templated_microservice_name.downcase.gsub('__', '-').gsub('_', '-')}-service" : "openc3-operator" %>
INTERFACE <%= templated_int_name %> templated_interface.rb <%= templated_host %> <%= templated_port %> <%= templated_port %> 5.0 nil TEMPLATE 0xA 0xA
MAP_TARGET <%= templated_target_name %>
DONT_CONNECT
Expand Down
1 change: 0 additions & 1 deletion openc3-redis/users.acl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ user healthcheck on nopass -@all +cluster|info +ping
user openc3 on >openc3password allkeys allchannels -@all +@read +@write +@pubsub +@connection +@transaction +info
user scriptrunner on >scriptrunnerpassword resetkeys resetchannels ~running-script* ~*script-locks ~*script-breakpoints ~*openc3_log_messages &_action_cable_internal &script-api:* -@all +@read +@write +@pubsub +@hash +@connection
user admin on >adminpassword +@admin
user traefik on >traefikpassword allchannels ~traefik* -@all +@admin +@read +@pubsub
user default off
8 changes: 3 additions & 5 deletions openc3-traefik/traefik-allow-http.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ http:
providers:
file:
filename: /etc/traefik/traefik.yaml
redis:
endpoints:
- "openc3-redis:6379"
username: "traefik"
password: "traefikpassword"
http:
endpoint: "http://openc3-cosmos-cmd-tlm-api:2901/openc3-api/traefik"
pollInterval: "5s"
accessLog: {}
# api:
# dashboard: true
Expand Down
8 changes: 3 additions & 5 deletions openc3-traefik/traefik-dev-base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,9 @@ http:
providers:
file:
filename: /etc/traefik/traefik.yaml
redis:
endpoints:
- "openc3-redis:6379"
username: "traefik"
password: "traefikpassword"
http:
endpoint: "http://openc3-cosmos-cmd-tlm-api:2901/openc3-api/traefik"
pollInterval: "5s"
accessLog: {}
# api:
# dashboard: true
Expand Down
8 changes: 3 additions & 5 deletions openc3-traefik/traefik-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ http:
providers:
file:
filename: /etc/traefik/traefik.yaml
redis:
endpoints:
- "openc3-redis:6379"
username: "traefik"
password: "traefikpassword"
http:
endpoint: "http://openc3-cosmos-cmd-tlm-api:2901/openc3-api/traefik"
pollInterval: "5s"
accessLog: {}
# api:
# dashboard: true
Expand Down
8 changes: 3 additions & 5 deletions openc3-traefik/traefik-letsencrypt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,9 @@ http:
providers:
file:
filename: /etc/traefik/traefik.yaml
redis:
endpoints:
- "openc3-redis:6379"
username: "traefik"
password: "traefikpassword"
http:
endpoint: "http://openc3-cosmos-cmd-tlm-api:2901/openc3-api/traefik"
pollInterval: "5s"
accessLog: {}
# api:
# dashboard: true
Expand Down
8 changes: 3 additions & 5 deletions openc3-traefik/traefik-ssl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,9 @@ http:
providers:
file:
filename: /etc/traefik/traefik.yaml
redis:
endpoints:
- "openc3-redis:6379"
username: "traefik"
password: "traefikpassword"
http:
endpoint: "http://openc3-cosmos-cmd-tlm-api:2901/openc3-api/traefik"
pollInterval: "5s"
accessLog: {}
# api:
# dashboard: true
Expand Down
8 changes: 3 additions & 5 deletions openc3-traefik/traefik.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,9 @@ http:
providers:
file:
filename: /etc/traefik/traefik.yaml
redis:
endpoints:
- "openc3-redis:6379"
username: "traefik"
password: "traefikpassword"
http:
endpoint: "http://openc3-cosmos-cmd-tlm-api:2901/openc3-api/traefik"
pollInterval: "5s"

accessLog: {}
# api:
Expand Down
3 changes: 0 additions & 3 deletions openc3/lib/openc3/models/microservice_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
require 'openc3/top_level'
require 'openc3/models/model'
require 'openc3/models/metric_model'
require 'openc3/models/traefik_model'
require 'openc3/utilities/bucket'

module OpenC3
Expand Down Expand Up @@ -225,7 +224,6 @@ def deploy(gem_path, variables, validate_only: false)
end
end
unless validate_only
TraefikModel.register_route(microservice_name: @name, port: @ports[0][0], prefix: @prefix) if @ports[0] and ports[0][0] and @prefix
ConfigTopic.write({ kind: 'created', type: 'microservice', name: @name, plugin: @plugin }, scope: @scope)
end
end
Expand All @@ -235,7 +233,6 @@ def undeploy
@bucket.list_objects(bucket: ENV['OPENC3_CONFIG_BUCKET'], prefix: prefix).each do |object|
@bucket.delete_object(bucket: ENV['OPENC3_CONFIG_BUCKET'], key: object.key)
end
TraefikModel.unregister_route(microservice_name: @name, port: @ports[0][0], prefix: @prefix) if @ports[0] and ports[0][0] and @prefix
ConfigTopic.write({ kind: 'deleted', type: 'microservice', name: @name, plugin: @plugin }, scope: @scope)
rescue Exception => error
Logger.error("Error undeploying microservice model #{@name} in scope #{@scope} due to #{error}")
Expand Down
4 changes: 3 additions & 1 deletion openc3/lib/openc3/models/plugin_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module OpenC3
class PluginModel < Model
PRIMARY_KEY = 'openc3_plugins'
# Reserved VARIABLE names. See local_mode.rb: update_local_plugin()
RESERVED_VARIABLE_NAMES = ['target_name', 'microservice_name']
RESERVED_VARIABLE_NAMES = ['target_name', 'microservice_name', 'scope']

attr_accessor :variables
attr_accessor :plugin_txt_lines
Expand Down Expand Up @@ -198,6 +198,8 @@ def self.install_phase2(plugin_hash, scope:, gem_file_path: nil, validate_only:
tf.close
plugin_txt_path = tf.path
variables = plugin_hash['variables']
variables ||= {}
variables['scope'] = scope
if File.exist?(plugin_txt_path)
parser = OpenC3::ConfigParser.new("https://openc3.com")

Expand Down
47 changes: 0 additions & 47 deletions openc3/lib/openc3/models/traefik_model.rb

This file was deleted.

12 changes: 6 additions & 6 deletions openc3/spec/models/plugin_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ module OpenC3

# Just stub the instance deploy method
expect(GemModel).to receive(:install).and_return(nil)
expect_any_instance_of(ToolModel).to receive(:deploy).with(anything, {}, validate_only: false).and_return(nil)
expect_any_instance_of(TargetModel).to receive(:deploy).with(anything, {}, validate_only: false).and_return(nil)
expect_any_instance_of(ToolModel).to receive(:deploy).with(anything, {"scope" => 'DEFAULT'}, validate_only: false).and_return(nil)
expect_any_instance_of(TargetModel).to receive(:deploy).with(anything, {"scope" => 'DEFAULT'}, validate_only: false).and_return(nil)
plugin_model = PluginModel.install_phase2({"name" => "name", "variables" => {}, "plugin_txt_lines" => plugin_txt_lines}, scope: "DEFAULT")
expect(plugin_model['needs_dependencies']).to eql true
end
Expand Down Expand Up @@ -255,8 +255,8 @@ module OpenC3

# Just stub the instance deploy method
expect(GemModel).to receive(:install).and_return(nil)
expect_any_instance_of(ToolModel).to receive(:deploy).with(anything, {}, validate_only: false).and_return(nil)
expect_any_instance_of(TargetModel).to receive(:deploy).with(anything, {}, validate_only: false).and_return(nil)
expect_any_instance_of(ToolModel).to receive(:deploy).with(anything, {"scope" => 'DEFAULT'}, validate_only: false).and_return(nil)
expect_any_instance_of(TargetModel).to receive(:deploy).with(anything, {"scope" => 'DEFAULT'}, validate_only: false).and_return(nil)
plugin_model = PluginModel.install_phase2({"name" => "name", "variables" => {}, "plugin_txt_lines" => plugin_txt_lines}, scope: "DEFAULT")
expect(plugin_model['needs_dependencies']).to eql true
end
Expand Down Expand Up @@ -285,8 +285,8 @@ module OpenC3

# Just stub the instance deploy method
expect(GemModel).to receive(:install).and_return(nil)
expect_any_instance_of(ToolModel).to receive(:deploy).with(anything, {}, validate_only: false).and_return(nil)
expect_any_instance_of(TargetModel).to receive(:deploy).with(anything, {}, validate_only: false).and_return(nil)
expect_any_instance_of(ToolModel).to receive(:deploy).with(anything, {"scope" => 'DEFAULT'}, validate_only: false).and_return(nil)
expect_any_instance_of(TargetModel).to receive(:deploy).with(anything, {"scope" =>'DEFAULT'}, validate_only: false).and_return(nil)
plugin_model = PluginModel.install_phase2({"name" => "name", "variables" => {}, "plugin_txt_lines" => plugin_txt_lines}, scope: "DEFAULT")
expect(plugin_model['needs_dependencies']).to eql true
end
Expand Down