Skip to content

Commit

Permalink
[Common] Refactor Services (#212)
Browse files Browse the repository at this point in the history
* Refactor All Services

- services (dict, including main service)
- additionalServices (list)

* Add Documentation and standardised questions.yaml layout for services

* Update all existing Apps to 2.0.0

* Fix whiteline error

* fix addons
  • Loading branch information
Kjeld Schouten-Lebbing committed Mar 3, 2021
1 parent ed2abfe commit 6ce336d
Show file tree
Hide file tree
Showing 532 changed files with 2,769 additions and 1,753 deletions.
50 changes: 0 additions & 50 deletions .github/docs/development/questions-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,53 +156,3 @@ They are called general options, because they affect the basic functionalities o
schema:
type: string
```

##### Main Service

Services in Kubernetes (the underlaying framework in TrueNAS SCALE), are (simply put) internal loadbalancers. Besides being load balancers, they are always guaranteed to be reachable by (internal!) DNS name and (in some cases) prevent traffic from reaching your App when the healthcheck isn't finished yet (or is failing).

Every App is required to have a main service, the primary thing that users (or other Apps!) connect with. No mater if it's a webUI, an API, a database connection or something totally else, A service is always required.

Please keep in mind that every App is different, some just have one service (the primary one) and others need more (which get defined in `appAdditionalService`). Every App also uses different ports, so please alter accordingly.

```
- variable: service
group: "Networking"
label: "Configure Service"
schema:
type: dict
attrs:
- variable: type
label: "Service type"
schema:
type: string
default: "ClusterIP"
enum:
- value: "NodePort"
description: "NodePort"
- value: "ClusterIP"
description: "ClusterIP"
show_subquestions_if: "NodePort"
subquestions:
- variable: port
label: "Port configuration"
schema:
type: dict
attrs:
- variable: port
label: "container port"
schema:
type: int
default: 80
editable: false
- variable: nodePort
label: "Node Port to expose for UI"
schema:
type: int
min: 9000
max: 65535
default: 36052
required: true
```

_ Note: Our final main service format has not been fully completed as of yet, this might change the above snipped considerably_
147 changes: 147 additions & 0 deletions .github/docs/development/services.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Services

Every App needs to be exposed to something, either an UI, API or other containers.However with Kubernetes we don't directly connect to the containers running the App, because those might be on another node or there might be multiple "high available" containers for the App. Instead we use what is called `Services`. Services are simply put "Internal Load-Balancers", they also guaranteed to be reachable by (internal!) DNS name and (in some cases) prevent traffic from reaching your App when the healthcheck isn't finished yet (or is failing).

### Two kinds of services

##### Main Service

Every App is required to have a main service, the primary thing that users (or other Apps!) connect with. No mater if it's a webUI, an API, a database connection or something totally else, A service is always required.

Please keep in mind that every App is different, some just have one service (which *ALWAYS* has to be called `main`) and others need more (which each has to have an unique name). Every App also uses different ports, so please alter accordingly.

```
- variable: services
group: "Networking"
label: "Configure Service"
schema:
type: dict
attrs:
- variable: main
label: "Main service"
description: "The Primary service on which the healthcheck runs, often the webUI"
schema:
type: dict
attrs:
- variable: enabled
label: "Enable the service"
schema:
type: boolean
default: true
hidden: true
- variable: type
label: "Service type"
description: "ClusterIP's are only internally available, nodePorts expose the container to the host node System"
schema:
type: string
default: "ClusterIP"
enum:
- value: "nodePort"
description: "NodePort"
- value: "ClusterIP"
description: "ClusterIP"
- variable: port
label: "Port configuration"
schema:
type: dict
attrs:
- variable: protocol
label: "Port Type"
schema:
type: string
default: "TCP"
hidden: true
enum:
- value: TCP
description: "TCP"
- value: "UDP"
description: "UDP"
- variable: port
label: "container port"
schema:
type: int
default: 80
editable: false
hidden: true
- variable: targetport
label: "Internal Service port"
description: "When connecting internally to this App, you'll need this port"
schema:
type: int
default: 80
editable: true
- variable: nodePort
label: "(optional) host nodePort to expose to"
description: "only get used when nodePort is selected"
schema:
type: int
min: 9000
max: 65535
default: 36052
required: true
```

##### Unlimited custom services

in some edgecases users might need or want to have the option to add unlimited custom Services. While we _highly_ suggest not doing so, these services can be added with the following standardised template:

```
- variable: additionalServices
label: "Custom Services"
group: "Networking"
schema:
type: list
default: []
items:
- variable: additionalService
label: "Custom Service"
schema:
type: dict
attrs:
- variable: enabled
label: "Enable the service"
schema:
type: boolean
default: true
hidden: true
- variable: type
label: "Service type"
description: "ClusterIP's are only internally available, nodePorts expose the container to the host node System"
schema:
type: string
default: "ClusterIP"
enum:
- value: "nodePort"
description: "NodePort"
- value: "ClusterIP"
description: "ClusterIP"
- variable: port
label: "Port configuration"
schema:
type: dict
attrs:
- variable: port
label: "container port"
schema:
type: int
default: 80
editable: false
hidden: true
- variable: targetport
label: "Internal Service port"
description: "When connecting internally to this App, you'll need this port"
schema:
type: int
default: 80
editable: true
- variable: nodePort
label: "(optional) host nodePort to expose to"
description: "only get used when nodePort is selected"
schema:
type: int
min: 9000
max: 65535
default: 36052
required: true
```
42 changes: 24 additions & 18 deletions .tools/tests/charts/common-test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,49 +142,55 @@ class Test < ChartTest

it 'port name can be overridden' do
values = {
service: {
port: {
name: 'server'
}
services: {
main: {
port: {
name: 'server'
}
}
}
}
chart.value values
jq('.spec.ports[0].port', resource('Service')).must_equal default_port
jq('.spec.ports[0].targetPort', resource('Service')).must_equal values[:service][:port][:name]
jq('.spec.ports[0].name', resource('Service')).must_equal values[:service][:port][:name]
jq('.spec.ports[0].targetPort', resource('Service')).must_equal values[:services][:main][:port][:name]
jq('.spec.ports[0].name', resource('Service')).must_equal values[:services][:main][:port][:name]
jq('.spec.template.spec.containers[0].ports[0].containerPort', resource('Deployment')).must_equal default_port
jq('.spec.template.spec.containers[0].ports[0].name', resource('Deployment')).must_equal values[:service][:port][:name]
jq('.spec.template.spec.containers[0].ports[0].name', resource('Deployment')).must_equal values[:services][:main][:port][:name]
end

it 'targetPort can be overridden' do
values = {
service: {
port: {
targetPort: 80
}
services: {
main: {
port: {
targetPort: 80
}
}
}
}
chart.value values
jq('.spec.ports[0].port', resource('Service')).must_equal default_port
jq('.spec.ports[0].targetPort', resource('Service')).must_equal values[:service][:port][:targetPort]
jq('.spec.ports[0].targetPort', resource('Service')).must_equal values[:services][:main][:port][:targetPort]
jq('.spec.ports[0].name', resource('Service')).must_equal default_name
jq('.spec.template.spec.containers[0].ports[0].containerPort', resource('Deployment')).must_equal values[:service][:port][:targetPort]
jq('.spec.template.spec.containers[0].ports[0].containerPort', resource('Deployment')).must_equal values[:services][:main][:port][:targetPort]
jq('.spec.template.spec.containers[0].ports[0].name', resource('Deployment')).must_equal default_name
end

it 'targetPort cannot be a named port' do
values = {
service: {
port: {
targetPort: 'test'
}
services: {
main: {
port: {
targetPort: 'test'
}
}
}
}
chart.value values
exception = assert_raises HelmCompileError do
chart.execute_helm_template!
end
assert_match("Our charts do not support named ports for targetPort. (port name #{default_name}, targetPort #{values[:service][:port][:targetPort]})", exception.message)
assert_match("Our charts do not support named ports for targetPort. (port name #{default_name}, targetPort #{values[:services][:main][:port][:targetPort]})", exception.message)
end
end

Expand Down
42 changes: 42 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
GEM
remote: https://rubygems.org/
specs:
ansi (1.5.0)
builder (3.2.4)
coderay (1.1.3)
m (1.5.1)
method_source (>= 0.6.7)
rake (>= 0.9.2.2)
method_source (1.0.0)
mini_portile2 (2.5.0)
minitest (5.14.4)
minitest-implicit-subject (1.4.0)
minitest
minitest-reporters (1.4.3)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
multi_json (1.15.0)
pry (0.14.0)
coderay (~> 1.1)
method_source (~> 1.0)
rake (13.0.3)
ruby-jq (0.2.1)
mini_portile2 (>= 2.2.0)
multi_json
ruby-progressbar (1.11.0)

PLATFORMS
ruby

DEPENDENCIES
m
minitest
minitest-implicit-subject
minitest-reporters
pry
ruby-jq

BUNDLED WITH
2.1.4
6 changes: 0 additions & 6 deletions charts/bazarr/1.6.2/Chart.lock

This file was deleted.

Binary file removed charts/bazarr/1.6.2/charts/common-1.6.2.tgz
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v2
kubeVersion: ">=1.16.0-0"
name: bazarr
version: 1.6.2
version: 2.0.0
upstream_version: 5.2.1
appVersion: v0.9.0.5
description: Bazarr is a companion application to Bazarr and Radarr. It manages and downloads subtitles based on your requirements
Expand All @@ -24,7 +24,7 @@ sources:
dependencies:
- name: common
repository: https://charts.truecharts.org/
version: 1.6.2
version: 2.0.0
# condition:
# tags:
# import-values:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Introduction

![Version: 1.6.2](https://img.shields.io/badge/Version-1.6.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.9.0.5](https://img.shields.io/badge/AppVersion-v0.9.0.5-informational?style=flat-square)
![Version: 1.6.1](https://img.shields.io/badge/Version-1.6.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: v0.9.0.5](https://img.shields.io/badge/AppVersion-v0.9.0.5-informational?style=flat-square)

Bazarr is a companion application to Bazarr and Radarr. It manages and downloads subtitles based on your requirements

Expand All @@ -22,7 +22,7 @@ Kubernetes: `>=1.16.0-0`

| Repository | Name | Version |
|------------|------|---------|
| https://charts.truecharts.org/ | common | 1.6.2 |
| https://charts.truecharts.org/ | common | 1.6.1 |

## Installing the Chart

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Bazarr is a companion application to Bazarr and Radarr. It manages and downloads subtitles based on your requirements

Binary file added charts/bazarr/2.0.0/charts/common-2.0.0.tgz
Binary file not shown.
File renamed without changes.
File renamed without changes.

0 comments on commit 6ce336d

Please sign in to comment.