mirror of
https://github.com/k8s-at-home/charts.git
synced 2025-01-23 15:39:02 +00:00
[common] version 2.2.0 (#443)
* Add code-server env to values * Bump chart version * [common] - add ingressclass name (#441) * add ingressclassname Signed-off-by: Jon Baker <jonbaker85@gmail.com> * Allow disabling of service links * Update changelog * Update changelog * Set better default for targetPort * Allow for different container / service ports * Fix linting error * Add unit tests * Add unit tests * Add unit tests * Service unit tests * Split CI jobs * Testing CI * Testing CI * Testing CI * Testing CI * Rename test file to match source * Fix newline Co-authored-by: Jon Baker <jonbaker85@gmail.com> Co-authored-by: ᗪєνιη ᗷυнʟ <onedr0p@users.noreply.github.com>
This commit is contained in:
parent
311c9c35bb
commit
52561bd15d
63
.github/workflows/lint-test.yaml
vendored
63
.github/workflows/lint-test.yaml
vendored
@ -3,8 +3,11 @@ name: Lint and Test Charts
|
|||||||
on: pull_request
|
on: pull_request
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint-test:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
changed: ${{ steps.list-changed.outputs.changed }}
|
||||||
|
common: ${{ steps.list-changed.outputs.common }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
@ -41,15 +44,67 @@ jobs:
|
|||||||
run: ct lint --config .github/ct.yaml --excluded-charts ""
|
run: ct lint --config .github/ct.yaml --excluded-charts ""
|
||||||
if: steps.list-changed.outputs.changed == 'true' || steps.list-changed.outputs.common == 'true'
|
if: steps.list-changed.outputs.changed == 'true' || steps.list-changed.outputs.common == 'true'
|
||||||
|
|
||||||
|
unittest:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: lint
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Install Dev tools
|
||||||
|
run: sudo apt-get update && sudo apt-get install -y jq libjq-dev
|
||||||
|
|
||||||
|
- name: Install Helm
|
||||||
|
uses: azure/setup-helm@v1
|
||||||
|
with:
|
||||||
|
version: v3.4.0
|
||||||
|
|
||||||
|
- name: Install Ruby
|
||||||
|
uses: ruby/setup-ruby@v1
|
||||||
|
with:
|
||||||
|
ruby-version: 2.7
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: |
|
||||||
|
export RUBYJQ_USE_SYSTEM_LIBRARIES=1
|
||||||
|
bundle install
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: |
|
||||||
|
bundle exec m -r test/charts
|
||||||
|
|
||||||
|
install:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: lint
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Install Helm
|
||||||
|
uses: azure/setup-helm@v1
|
||||||
|
with:
|
||||||
|
version: v3.4.0
|
||||||
|
|
||||||
|
- uses: actions/setup-python@v2
|
||||||
|
with:
|
||||||
|
python-version: 3.7
|
||||||
|
|
||||||
|
- name: Set up chart-testing
|
||||||
|
uses: helm/chart-testing-action@v2.0.1
|
||||||
|
|
||||||
- name: Create kind cluster
|
- name: Create kind cluster
|
||||||
uses: helm/kind-action@v1.1.0
|
uses: helm/kind-action@v1.1.0
|
||||||
if: steps.list-changed.outputs.changed == 'true' || steps.list-changed.outputs.common == 'true'
|
if: needs.lint.outputs.changed == 'true' || needs.lint.outputs.common == 'true'
|
||||||
|
|
||||||
- name: Run chart-testing (install)
|
- name: Run chart-testing (install)
|
||||||
run: ct install --config .github/ct.yaml
|
run: ct install --config .github/ct.yaml
|
||||||
if: steps.list-changed.outputs.changed == 'true'
|
if: needs.lint.outputs.changed == 'true'
|
||||||
|
|
||||||
- name: Run chart-testing (common-test)
|
- name: Run chart-testing (common-test)
|
||||||
run: |
|
run: |
|
||||||
ct install --config .github/ct.yaml --charts 'charts/common-test'
|
ct install --config .github/ct.yaml --charts 'charts/common-test'
|
||||||
if: steps.list-changed.outputs.common == 'true'
|
if: needs.lint.outputs.common == 'true'
|
||||||
|
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,4 +1,12 @@
|
|||||||
.env
|
# IDE resources
|
||||||
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
|
.devcontainer/
|
||||||
|
|
||||||
|
# Helm resources
|
||||||
charts/*/Chart.lock
|
charts/*/Chart.lock
|
||||||
charts/*/charts
|
charts/*/charts
|
||||||
|
|
||||||
|
# Other rsources
|
||||||
|
.env
|
||||||
|
Gemfile.lock
|
||||||
|
12
Gemfile
Normal file
12
Gemfile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
|
group :test do
|
||||||
|
gem 'm'
|
||||||
|
gem 'minitest'
|
||||||
|
gem 'minitest-implicit-subject'
|
||||||
|
gem 'minitest-reporters'
|
||||||
|
gem 'pry'
|
||||||
|
gem 'ruby-jq'
|
||||||
|
end
|
@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [2.2.0]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Allow serviceLinks to be enabled/disabled.
|
||||||
|
- Support for ingressClassName on apiVersion `networking.k8s.io/v1` by setting `ingress.ingressClassName`.
|
||||||
|
- Added some initial proper unit tests for the `common` chart.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- `service.port.targetPort` is now used in the container spec instead of `service.port.port` if specified. This allows for different service and container ports. (Implements [#465](https://github.com/k8s-at-home/charts/issues/465)).
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Document setting environment variables for code-server add-on in `values.yaml` (Fixes [#436](https://github.com/k8s-at-home/charts/issues/436)).
|
||||||
|
- Set service targetPort to the service port name first if no `targetPort` value is given.
|
||||||
|
|
||||||
## [2.1.0]
|
## [2.1.0]
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
@ -36,6 +53,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
This is the last version before starting this changelog. All sorts of cool stuff was changed, but only `git log` remembers what that was :slightly_frowning_face:
|
This is the last version before starting this changelog. All sorts of cool stuff was changed, but only `git log` remembers what that was :slightly_frowning_face:
|
||||||
|
|
||||||
|
[2.2.0]: https://github.com/k8s-at-home/charts/tree/common-2.2.0/charts/common
|
||||||
|
|
||||||
|
[2.1.0]: https://github.com/k8s-at-home/charts/tree/common-2.1.0/charts/common
|
||||||
|
|
||||||
[2.0.4]: https://github.com/k8s-at-home/charts/tree/common-2.0.4/charts/common
|
[2.0.4]: https://github.com/k8s-at-home/charts/tree/common-2.0.4/charts/common
|
||||||
|
|
||||||
[2.0.0]: https://github.com/k8s-at-home/charts/tree/common-2.0.0/charts/common
|
[2.0.0]: https://github.com/k8s-at-home/charts/tree/common-2.0.0/charts/common
|
||||||
|
@ -2,7 +2,7 @@ apiVersion: v2
|
|||||||
name: common
|
name: common
|
||||||
description: Function library for k8s-at-home charts
|
description: Function library for k8s-at-home charts
|
||||||
type: library
|
type: library
|
||||||
version: 2.1.1
|
version: 2.2.0
|
||||||
keywords:
|
keywords:
|
||||||
- k8s-at-home
|
- k8s-at-home
|
||||||
- common
|
- common
|
||||||
|
@ -26,6 +26,11 @@ metadata:
|
|||||||
{{- toYaml . | nindent 4 }}
|
{{- toYaml . | nindent 4 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
spec:
|
spec:
|
||||||
|
{{- if eq (include "common.capabilities.ingress.apiVersion" $) "networking.k8s.io/v1" }}
|
||||||
|
{{- if $values.ingressClassName }}
|
||||||
|
ingressClassName: {{ $values.ingressClassName }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
{{- if $values.tls }}
|
{{- if $values.tls }}
|
||||||
tls:
|
tls:
|
||||||
{{- range $values.tls }}
|
{{- range $values.tls }}
|
||||||
|
@ -12,7 +12,7 @@ Render all the ports and additionalPorts for a Service object.
|
|||||||
ports:
|
ports:
|
||||||
{{- range $_ := $ports }}
|
{{- range $_ := $ports }}
|
||||||
- port: {{ .port }}
|
- port: {{ .port }}
|
||||||
targetPort: {{ .targetPort | default "http" }}
|
targetPort: {{ .targetPort | default .name | default "http" }}
|
||||||
protocol: {{ .protocol | default "TCP" }}
|
protocol: {{ .protocol | default "TCP" }}
|
||||||
name: {{ .name | default "http" }}
|
name: {{ .name | default "http" }}
|
||||||
{{- if (and (eq $.svcType "NodePort") (not (empty .nodePort))) }}
|
{{- if (and (eq $.svcType "NodePort") (not (empty .nodePort))) }}
|
||||||
|
@ -21,6 +21,7 @@ dnsPolicy: {{ . }}
|
|||||||
dnsConfig:
|
dnsConfig:
|
||||||
{{- toYaml . | nindent 2 }}
|
{{- toYaml . | nindent 2 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
enableServiceLinks: {{ .Values.enableServiceLinks }}
|
||||||
{{- with .Values.initContainers }}
|
{{- with .Values.initContainers }}
|
||||||
initContainers:
|
initContainers:
|
||||||
{{- toYaml . | nindent 2 }}
|
{{- toYaml . | nindent 2 }}
|
||||||
|
@ -32,7 +32,7 @@ Ports included by the controller.
|
|||||||
ports:
|
ports:
|
||||||
{{- range $_ := $ports }}
|
{{- range $_ := $ports }}
|
||||||
- name: {{ .name }}
|
- name: {{ .name }}
|
||||||
containerPort: {{ .port }}
|
containerPort: {{ .targetPort | default .port }}
|
||||||
protocol: {{ .protocol | default "TCP" }}
|
protocol: {{ .protocol | default "TCP" }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
@ -51,6 +51,11 @@ dnsPolicy: ClusterFirst
|
|||||||
# - name: ndots
|
# - name: ndots
|
||||||
# value: "1"
|
# value: "1"
|
||||||
|
|
||||||
|
# Enable/disable the generation of environment variables for services.
|
||||||
|
# See https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#accessing-the-service
|
||||||
|
# for more information.
|
||||||
|
enableServiceLinks: true
|
||||||
|
|
||||||
initContainers: []
|
initContainers: []
|
||||||
|
|
||||||
additionalContainers: []
|
additionalContainers: []
|
||||||
@ -96,13 +101,14 @@ probes:
|
|||||||
service:
|
service:
|
||||||
enabled: true
|
enabled: true
|
||||||
type: ClusterIP
|
type: ClusterIP
|
||||||
# Specify the default port information
|
## Specify the default port information
|
||||||
port:
|
port:
|
||||||
port:
|
port:
|
||||||
# name defaults to http
|
## name defaults to http
|
||||||
name:
|
name:
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
# targetPort defaults to http
|
## targetPort defaults to the service name. If targetPort is specified, this port number
|
||||||
|
## is used in the container definition instead of service.port.port.
|
||||||
targetPort:
|
targetPort:
|
||||||
## Specify the nodePort value for the LoadBalancer and NodePort service types.
|
## Specify the nodePort value for the LoadBalancer and NodePort service types.
|
||||||
## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
|
## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
|
||||||
@ -314,6 +320,10 @@ addons:
|
|||||||
pullPolicy: IfNotPresent
|
pullPolicy: IfNotPresent
|
||||||
tag: 3.7.4
|
tag: 3.7.4
|
||||||
|
|
||||||
|
# Set any environment variables for code-server here
|
||||||
|
env: {}
|
||||||
|
# TZ: UTC
|
||||||
|
|
||||||
# Set codeserver command line arguments
|
# Set codeserver command line arguments
|
||||||
# consider setting --user-data-dir to a persistent location to preserve code-server setting changes
|
# consider setting --user-data-dir to a persistent location to preserve code-server setting changes
|
||||||
args:
|
args:
|
||||||
|
86
test/charts/common-test_spec.rb
Normal file
86
test/charts/common-test_spec.rb
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
require_relative '../test_helper'
|
||||||
|
|
||||||
|
class Test < ChartTest
|
||||||
|
@@chart = Chart.new('charts/common-test')
|
||||||
|
|
||||||
|
describe @@chart.name do
|
||||||
|
describe 'controller type' do
|
||||||
|
it 'defaults to "Deployment"' do
|
||||||
|
assert_nil(resource('StatefulSet'))
|
||||||
|
assert_nil(resource('DaemonSet'))
|
||||||
|
refute_nil(resource('Deployment'))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'accepts "statefulset"' do
|
||||||
|
chart.value controllerType: 'statefulset'
|
||||||
|
assert_nil(resource('Deployment'))
|
||||||
|
assert_nil(resource('DaemonSet'))
|
||||||
|
refute_nil(resource('StatefulSet'))
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'accepts "daemonset"' do
|
||||||
|
chart.value controllerType: 'daemonset'
|
||||||
|
assert_nil(resource('Deployment'))
|
||||||
|
assert_nil(resource('StatefulSet'))
|
||||||
|
refute_nil(resource('DaemonSet'))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'pod replicas' do
|
||||||
|
it 'defaults to 1' do
|
||||||
|
jq('.spec.replicas', resource('Deployment')).must_equal 1
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'accepts integer as value' do
|
||||||
|
chart.value replicas: 3
|
||||||
|
jq('.spec.replicas', resource('Deployment')).must_equal 3
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'ports settings' do
|
||||||
|
default_name = 'http'
|
||||||
|
default_port = 8080
|
||||||
|
|
||||||
|
it 'defaults to name "http" on port 8080' do
|
||||||
|
jq('.spec.ports[0].port', resource('Service')).must_equal default_port
|
||||||
|
jq('.spec.ports[0].targetPort', resource('Service')).must_equal default_name
|
||||||
|
jq('.spec.ports[0].name', resource('Service')).must_equal default_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 default_name
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'port name can be overridden' do
|
||||||
|
values = {
|
||||||
|
service: {
|
||||||
|
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.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]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'targetPort can be overridden' do
|
||||||
|
values = {
|
||||||
|
service: {
|
||||||
|
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].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].name', resource('Deployment')).must_equal default_name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
119
test/test_helper.rb
Normal file
119
test/test_helper.rb
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'json'
|
||||||
|
require 'yaml'
|
||||||
|
require 'open3'
|
||||||
|
|
||||||
|
require 'jq/extend'
|
||||||
|
require 'minitest-implicit-subject'
|
||||||
|
require "minitest/reporters"
|
||||||
|
require 'minitest/autorun'
|
||||||
|
require 'minitest/pride'
|
||||||
|
|
||||||
|
class HelmCompileError < StandardError
|
||||||
|
end
|
||||||
|
|
||||||
|
class HelmDepsError < StandardError
|
||||||
|
end
|
||||||
|
|
||||||
|
class Chart
|
||||||
|
attr_reader :name, :path, :values
|
||||||
|
|
||||||
|
def initialize(chart)
|
||||||
|
@name = chart.split('/').last
|
||||||
|
|
||||||
|
@path = File.expand_path(chart)
|
||||||
|
|
||||||
|
@values = default_values
|
||||||
|
|
||||||
|
update_deps!
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_deps!
|
||||||
|
command = "helm dep update '#{path}'"
|
||||||
|
stdout, stderr, status = Open3.capture3(command)
|
||||||
|
raise HelmDepsError, stderr if status != 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset!
|
||||||
|
@values = default_values
|
||||||
|
@parsed_resources = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def value(value)
|
||||||
|
values.merge!(value)
|
||||||
|
end
|
||||||
|
|
||||||
|
def configure_custom_name(name)
|
||||||
|
@name = name
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute_helm_template!
|
||||||
|
file = Tempfile.new(name)
|
||||||
|
file.write(JSON.parse(values.to_json).to_yaml)
|
||||||
|
file.close
|
||||||
|
|
||||||
|
begin
|
||||||
|
command = "helm template '#{name}' '#{path}' --namespace='default' --values='#{file.path}'"
|
||||||
|
stdout, stderr, status = Open3.capture3(command)
|
||||||
|
|
||||||
|
raise HelmCompileError, stderr if status != 0
|
||||||
|
|
||||||
|
stdout
|
||||||
|
ensure
|
||||||
|
file.unlink
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def parsed_resources
|
||||||
|
@parsed_resources ||= begin
|
||||||
|
output = execute_helm_template!
|
||||||
|
puts output if ENV.fetch('DEBUG', 'false') == 'true'
|
||||||
|
YAML.load_stream(output)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def resources(matcher = nil)
|
||||||
|
return parsed_resources unless matcher
|
||||||
|
|
||||||
|
parsed_resources.select do |r|
|
||||||
|
r >= Hash[matcher.map { |k, v| [k.to_s, v] }]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def default_values
|
||||||
|
{
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class ExtendedMinitest < Minitest::Test
|
||||||
|
extend MiniTest::Spec::DSL
|
||||||
|
end
|
||||||
|
|
||||||
|
class ChartTest < ExtendedMinitest
|
||||||
|
Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
|
||||||
|
|
||||||
|
before do
|
||||||
|
chart.reset!
|
||||||
|
end
|
||||||
|
|
||||||
|
def chart
|
||||||
|
self.class.class_variable_get('@@chart')
|
||||||
|
end
|
||||||
|
|
||||||
|
def resource(name)
|
||||||
|
chart.resources(kind: name).first
|
||||||
|
end
|
||||||
|
|
||||||
|
def jq(matcher, object)
|
||||||
|
value(object.jq(matcher)[0])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class Minitest::Result
|
||||||
|
def name
|
||||||
|
test_name = defined?(@name) ? @name : super
|
||||||
|
test_name.to_s.gsub /\Atest_\d{4,}_/, ""
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user