Compare commits

...

18 Commits

18 changed files with 432 additions and 42 deletions

View File

@@ -1,11 +1,11 @@
name: release chart
name: Release Helm Chart
"on":
push:
branches:
- main
paths:
- "charts/ohayodash/**"
- "charts/**/Chart.yaml"
jobs:
release:

3
.gitignore vendored
View File

@@ -150,3 +150,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
charts/**/charts/*
Chart.lock

View File

@@ -1,4 +1,4 @@
FROM python:3.9
FROM python:3.9-alpine
WORKDIR /app
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt

7
LICENSE Normal file
View File

@@ -0,0 +1,7 @@
Copyright 2021 Andrew Williams <andy@tensixtyone.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -1,3 +1,5 @@
# Ohayo Dash
Ohayo Dash is a Kubernetes driven start page and dashboard. All configuration is done by standard Kubernetes objects and ConfigMaps.
Ohayo Dash is a Kubernetes driven start page and dashboard. All configuration is done by standard Kubernetes objects and ConfigMaps.
This is inspired by [Hajimari](https://github.com/toboshii/hajimari) and [SUI](https://github.com/jeroenpardon/sui) projects.

View File

@@ -1,14 +1,14 @@
apiVersion: v2
appVersion: 0.0.1
appVersion: 0.1.2
description: Ohayo Dash is a Kubernetes driven start page and dashboard. All configuration is done by standard Kubernetes objects and ConfigMaps.
name: ohayodash
version: 0.0.1
version: 0.1.2
kubeVersion: ">=1.16.0-0"
keywords:
- ohayodash
- startpage
- dashboard
home: https://github.com/nikdoof/ohayodash/tree/main/charts/hajimari
home: https://github.com/nikdoof/ohayodash/tree/main/charts/ohayodash
sources:
- https://github.com/nikdoof/ohayodash
maintainers:
@@ -17,4 +17,4 @@ maintainers:
dependencies:
- name: common
repository: https://library-charts.k8s-at-home.com
version: 4.0.0
version: 4.2.0

113
charts/ohayodash/README.md Normal file
View File

@@ -0,0 +1,113 @@
# ohayodash
![Version: 0.1.2](https://img.shields.io/badge/Version-0.1.2-informational?style=flat-square) ![AppVersion: 0.1.2](https://img.shields.io/badge/AppVersion-0.1.2-informational?style=flat-square)
Ohayo Dash is a Kubernetes driven start page and dashboard. All configuration is done by standard Kubernetes objects and ConfigMaps.
**This chart is not maintained by the upstream project and any issues with the chart should be raised [here](https://github.com/nikdoof/helm-charts/issues/new/choose)**
## Source Code
* <https://github.com/nikdoof/ohayodash>
## Requirements
Kubernetes: `>=1.16.0-0`
## Dependencies
| Repository | Name | Version |
|------------|------|---------|
| https://library-charts.k8s-at-home.com | common | 4.2.0 |
## TL;DR
```console
helm repo add ohayodash https://nikdoof.github.io/ohayodash/
helm repo update
helm install ohayodash ohayodash/ohayodash
```
## Installing the Chart
To install the chart with the release name `ohayodash`
```console
helm install ohayodash ohayodash/ohayodash
```
## Uninstalling the Chart
To uninstall the `ohayodash` deployment
```console
helm uninstall ohayodash
```
The command removes all the Kubernetes components associated with the chart **including persistent volumes** and deletes the release.
## Configuration
Read through the [values.yaml](./values.yaml) file. It has several commented out suggested values.
Other values may be used from the [values.yaml](https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common/values.yaml) from the [common library](https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common).
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`.
```console
helm install ohayodash \
--set env.TZ="Europe/London"\
ohayodash/ohayodash
```
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart.
```console
helm install ohayodash ohayodash/ohayodash -f values.yaml
```
## Custom configuration
## Values
**Important**: When deploying an application Helm chart you can add more values from our common library chart [here](https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common)
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| env | object | See below | environment variables. |
| env.DATE_FORMAT | string | `"%Y-%m-%d %H:%M"` | Python date format string to use for rendering the date/time |
| env.TZ | string | `"UTC"` | Set the container timezone |
| image.pullPolicy | string | `"Always"` | image pull policy |
| image.repository | string | `"ghcr.io/nikdoof/ohayodash"` | image repository |
| image.tag | string | `"latest"` | image tag |
| ingress.main | object | See values.yaml | Enable and configure ingress settings for the chart under this key. |
| service | object | See values.yaml | Configures service settings for the chart. |
| serviceAccount | object | See below | Configures service account needed for reading k8s ingress objects |
| serviceAccount.create | bool | `true` | Create service account |
## Changelog
All notable changes to this application Helm chart will be documented in this file but does not include changes from our common library. To read those click [here](https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common#changelog).
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### [0.1.2]
#### Added
- Started the Changelog
- Pinned to 0.1.2 rather than latest
#### Changed
- N/A
#### Removed
- N/A
## Support
- Open an [issue](https://github.com/nikdoof/ohayodash/issues/new/choose)
----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.5.0](https://github.com/norwoodj/helm-docs/releases/v1.5.0)

View File

@@ -0,0 +1,143 @@
{{- define "custom.repository.organization" -}}
ohayodash
{{- end -}}
{{- define "custom.repository.url" -}}
https://github.com/nikdoof/ohayodash
{{- end -}}
{{- define "custom.helm.url" -}}
https://nikdoof.github.io/ohayodash/
{{- end -}}
{{- define "custom.helm.path" -}}
{{ template "custom.repository.organization" . }}/{{ template "chart.name" . }}
{{- end -}}
{{- define "custom.notes" -}}
**This chart is not maintained by the upstream project and any issues with the chart should be raised [here](https://github.com/nikdoof/helm-charts/issues/new/choose)**
{{- end -}}
{{- define "custom.requirements" -}}
## Requirements
{{ template "chart.kubeVersionLine" . }}
{{- end -}}
{{- define "custom.dependencies" -}}
## Dependencies
{{ template "chart.requirementsTable" . }}
{{- end -}}
{{- define "custom.install.tldr" -}}
## TL;DR
```console
helm repo add {{ template "custom.repository.organization" . }} {{ template "custom.helm.url" . }}
helm repo update
helm install {{ template "chart.name" . }} {{ template "custom.helm.path" . }}
```
{{- end -}}
{{- define "custom.install" -}}
## Installing the Chart
To install the chart with the release name `{{ template "chart.name" . }}`
```console
helm install {{ template "chart.name" . }} {{ template "custom.helm.path" . }}
```
{{- end -}}
{{- define "custom.uninstall" -}}
## Uninstalling the Chart
To uninstall the `{{ template "chart.name" . }}` deployment
```console
helm uninstall {{ template "chart.name" . }}
```
The command removes all the Kubernetes components associated with the chart **including persistent volumes** and deletes the release.
{{- end -}}
{{- define "custom.configuration.header" -}}
## Configuration
{{- end -}}
{{- define "custom.configuration.readValues" -}}
Read through the [values.yaml](./values.yaml) file. It has several commented out suggested values.
Other values may be used from the [values.yaml](https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common/values.yaml) from the [common library](https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common).
{{- end -}}
{{- define "custom.configuration.example.set" -}}
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`.
```console
helm install {{ template "chart.name" . }} \
--set env.TZ="Europe/London"\
{{ template "custom.helm.path" . }}
```
{{- end -}}
{{- define "custom.configuration.example.file" -}}
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart.
```console
helm install {{ template "chart.name" . }} {{ template "custom.helm.path" . }} -f values.yaml
```
{{- end -}}
{{- define "custom.valuesSection" -}}
## Values
**Important**: When deploying an application Helm chart you can add more values from our common library chart [here](https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common)
{{ template "chart.valuesTable" . }}
{{- end -}}
{{- define "custom.support" -}}
## Support
- Open an [issue](https://github.com/nikdoof/ohayodash/issues/new/choose)
{{- end -}}
{{ template "chart.header" . }}
{{ template "chart.versionBadge" . }}{{ template "chart.typeBadge" . }}{{ template "chart.appVersionBadge" . }}
{{ template "chart.description" . }}
{{ template "custom.notes" . }}
{{ template "chart.sourcesSection" . }}
{{ template "custom.requirements" . }}
{{ template "custom.dependencies" . }}
{{ template "custom.install.tldr" . }}
{{ template "custom.install" . }}
{{ template "custom.uninstall" . }}
{{ template "custom.configuration.header" . }}
{{ template "custom.configuration.readValues" . }}
{{ template "custom.configuration.example.set" . }}
{{ template "custom.configuration.example.file" . }}
{{ template "custom.custom.configuration" . }}
{{ template "custom.valuesSection" . }}
{{ template "custom.changelog" . }}
{{ template "custom.support" . }}
{{ template "helm-docs.versionFooter" . }}
{{ "" }}

View File

@@ -0,0 +1,27 @@
{{- define "custom.changelog.header" -}}
## Changelog
{{- end -}}
{{- define "custom.changelog" -}}
{{ template "custom.changelog.header" . }}
All notable changes to this application Helm chart will be documented in this file but does not include changes from our common library. To read those click [here](https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common#changelog).
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### [0.1.2]
#### Added
- Started the Changelog
- Pinned to 0.1.2 rather than latest
#### Changed
- N/A
#### Removed
- N/A
{{- end -}}

View File

@@ -0,0 +1,7 @@
{{- define "custom.custom.configuration.header" -}}
## Custom configuration
{{- end -}}
{{- define "custom.custom.configuration" -}}
{{ template "custom.custom.configuration.header" . }}
{{- end -}}

View File

@@ -6,7 +6,7 @@ metadata:
labels: {{- include "common.labels" . | nindent 4 }}
rules:
- apiGroups: ["", "extensions", "networking.k8s.io"]
resources: ["ingresses", "namespaces"]
resources: ["ingresses", "namespaces", "configmaps"]
verbs: ["get", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1

View File

@@ -11,13 +11,15 @@ image:
# -- image pull policy
pullPolicy: IfNotPresent
# -- image tag
tag: latest
tag: 0.1.2
# -- environment variables.
# @default -- See below
env:
# -- Set the container timezone
TZ: UTC
# -- Python date format string to use for rendering the date/time
DATE_FORMAT: "%Y-%m-%d %H:%M"
# -- Configures service settings for the chart.
# @default -- See values.yaml

View File

@@ -1,44 +1,59 @@
from flask import Blueprint, render_template, abort
from jinja2 import TemplateNotFound
import datetime
import logging
import os
import zoneinfo
import kubernetes
import yaml
from flask import Blueprint, render_template, jsonify
ANNOTATION_BASE = 'ohayodash.github.io'
base = Blueprint('base', __name__, template_folder='templates')
def get_k8s_applications():
kubernetes.config.load_kube_config()
v1 = kubernetes.client.NetworkingV1Api()
ret = v1.list_ingress_for_all_namespaces(watch=False)
results = []
for ingress in ret.items:
def get_k8s_applications() -> list:
"""Get all ingresses from the cluster and produce a application list."""
if 'KUBERNETES_SERVICE_HOST' in os.environ:
kubernetes.config.load_incluster_config()
else:
kubernetes.config.load_kube_config()
api = kubernetes.client.NetworkingV1Api()
# Skip if
if f'{ANNOTATION_BASE}/enable' not in ingress.metadata.annotations or \
ingress.metadata.annotations[f'{ANNOTATION_BASE}/enable'] == 'false':
applications = []
for ingress in api.list_ingress_for_all_namespaces(watch=False).items:
# Skip if not enabled
enable_annotation = '{0}/enable'.format(ANNOTATION_BASE)
if enable_annotation not in ingress.metadata.annotations:
continue
if ingress.metadata.annotations[enable_annotation] == 'false':
continue
values = {
# Set to some basic values from the ingress
application_values = {
'name': ingress.metadata.name,
'namespace': ingress.metadata.namespace,
'url': f'https://{ingress.spec.rules[0].host}',
'url': 'https://{0}'.format(ingress.spec.rules[0].host),
'show_url': False,
}
for key in ingress.metadata.annotations:
# Read annotations and override the values if defined
for key, value in ingress.metadata.annotations.items():
if key.startswith(ANNOTATION_BASE):
val = key.split('/')[1]
values[val] = ingress.metadata.annotations[key]
annotation_key = key.split('/')[1]
application_values[annotation_key] = value
results.append(values)
return sorted(results, key=lambda i: i['appName'])
applications.append(application_values)
return sorted(applications, key=lambda item: item['name'])
def get_bookmarks():
kubernetes.config.load_kube_config()
def get_bookmarks() -> list:
"""Get all 'bookmark' ConfigMaps from the cluster and produce a bookmark list."""
if 'KUBERNETES_SERVICE_HOST' in os.environ:
kubernetes.config.load_incluster_config()
else:
kubernetes.config.load_kube_config()
v1 = kubernetes.client.CoreV1Api()
ret = v1.list_config_map_for_all_namespaces(watch=False)
@@ -46,11 +61,11 @@ def get_bookmarks():
for cm in ret.items:
# Skip if
if not cm.metadata.annotations or f'{ANNOTATION_BASE}/bookmarks' not in cm.metadata.annotations:
if not cm.metadata.annotations or '{0}/bookmarks'.format(ANNOTATION_BASE) not in cm.metadata.annotations:
continue
data = yaml.safe_load(cm.data['bookmarks'])
for bookmark in data:
bookmark_data = yaml.safe_load(cm.data['bookmarks'])
for bookmark in bookmark_data:
if 'group' not in bookmark:
group = 'default'
else:
@@ -62,10 +77,43 @@ def get_bookmarks():
return bookmarks
def get_greeting() -> tuple:
"""Generate the greeting string based on the defined timezone."""
try:
tz = zoneinfo.ZoneInfo(os.environ.get('TZ', 'UTC'))
except zoneinfo.ZoneInfoNotFound:
logging.warning('Timezone {0} is invalid, using UTC'.format(os.environ.get('TZ', 'UTC')))
tz = zoneinfo.ZoneInfo('UTC')
current_time = datetime.datetime.now(tz)
if 0 < current_time.hour < 12:
return 'おはようございます!', "Thats 'Good morning' in Japanese"
elif current_time.hour >= 19:
return 'こんばんは', "Thats 'Good evening' in Japanese"
return 'こんにちは', "Thats 'Good day' in Japanese"
@base.app_template_filter()
def format_datetime(value, format='medium'):
return value.strftime(os.environ.get('DATE_FORMAT', '%Y-%m-%d %H:%M')) # noqa: WPS323
@base.route('/')
def index():
return render_template(f'index.j2', **{
'now': datetime.datetime.utcnow(),
'applications': get_k8s_applications(),
'bookmarks': get_bookmarks(),
})
return render_template('index.j2',
greeting=get_greeting(),
now=datetime.datetime.utcnow(),
applications=get_k8s_applications(),
bookmarks=get_bookmarks(),
)
@base.route('/api/applications')
def applications():
return jsonify(get_k8s_applications())
@base.route('/api/bookmarks')
def bookmarks():
return jsonify(get_bookmarks())

View File

@@ -2,7 +2,7 @@
<html lang="en">
<head>
<title>{{ title | default("Hajimari") }}</title>
<title>{{ title | default("おはよう!") }}</title>
<meta charset="utf-8">
<meta http-equiv="Default-Style" content="">
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
@@ -52,8 +52,8 @@
</section>
<section id="header">
<h1>{{ greeting | default("Welcome")}}</h1>
<h2>{{ now }}</h2>
<h1><span title="{{ greeting[1] }}">{{ greeting[0] | default("Welcome")}}</span></h1>
<h2>{{ now | format_datetime }}</h2>
</section>
{% if applications %}
@@ -63,7 +63,7 @@
{% for app in applications %}
<div class="apps_item">
<div class="apps_icon">
<span class="iconify icon" data-icon="mdi-{{ app.icon | default("application") }}"></span>
<a href="{{ app.url }}"><span class="iconify icon" data-icon="mdi-{{ app.icon | default("application") }}"></span></a>
</div>
<div class="apps_text">
<a href="{{ app.url }}">{{ app.name }}</a>

4
pyproject.toml Normal file
View File

@@ -0,0 +1,4 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

1
requirements-dev.txt Normal file
View File

@@ -0,0 +1 @@
wheel

30
setup.cfg Normal file
View File

@@ -0,0 +1,30 @@
[metadata]
name = ohayodash
version = 0.1.2
description = A Kubernetes driven start page and dashboard. All configuration is done by standard Kubernetes objects and ConfigMaps.
long_description = file: README.md, LICENSE
license = MIT
license_file = LICENSE
classifiers =
Framework :: Flask
License :: OSI Approved :: MIT License
Programming Language :: Python :: 3
Programming Language :: Python :: 3.9
[options]
zip_safe = False
packages = ohayodash
install_requires =
flask
kubernetes
pyyaml
gunicorn
[flake8]
format = wemake
ignore = E501
max-line-length = 120
exclude = setup.py
[darglint]
docstring_style=sphinx

3
setup.py Normal file
View File

@@ -0,0 +1,3 @@
from setuptools import setup
setup()