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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Added

-
- Initial implementation ([#1])

[Unreleased]: https://github.com/projectsyn/component-storage-class/compare/v0.1.0...HEAD
[Unreleased]: https://github.com/projectsyn/component-storage-class/compare/76db758a57b9dc33b95abf0a1bd7a21ce1ac185a...HEAD
[#1]: https://github.com/projectsyn/component-storage-class/pull/1
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ YAMLLINT_CONFIG ?= .yamllint.yml
YAMLLINT_IMAGE ?= docker.io/cytopia/yamllint:latest
YAMLLINT_DOCKER ?= $(DOCKER_CMD) $(DOCKER_ARGS) $(YAMLLINT_IMAGE)

VALE_CMD ?= $(DOCKER_CMD) $(DOCKER_ARGS) --volume "$${PWD}"/docs/modules:/pages vshn/vale:2.1.1
VALE_ARGS ?= --minAlertLevel=error --config=/pages/ROOT/pages/.vale.ini /pages


.PHONY: all
all: lint

.PHONY: lint
lint: lint_jsonnet lint_yaml
lint: lint_jsonnet lint_yaml lint_adoc

.PHONY: lint_jsonnet
lint_jsonnet: $(JSONNET_FILES)
Expand All @@ -33,6 +37,10 @@ lint_jsonnet: $(JSONNET_FILES)
lint_yaml: $(YAML_FILES)
$(YAMLLINT_DOCKER) -f parsable -c $(YAMLLINT_CONFIG) $(YAMLLINT_ARGS) -- $?

.PHONY: lint_adoc
lint_adoc:
$(VALE_CMD) $(VALE_ARGS)

.PHONY: format
format: format_jsonnet

Expand Down
4 changes: 4 additions & 0 deletions class/defaults.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
parameters:
storage_class:
defaults:
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
storageClasses: {}
8 changes: 5 additions & 3 deletions component/main.jsonnet
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// main template for storage-class
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';
local inv = kap.inventory();
// The hiera parameters for the component
local sc = import 'lib/storage-class.libsonnet';

local params = inv.parameters.storage_class;

// Define outputs below
{
[name]:
sc.storageClass(name) + params.storageClasses[name]
for name in std.objectFields(params.storageClasses)
}
53 changes: 53 additions & 0 deletions docs/modules/ROOT/pages/references/parameters.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
= Parameters

The parent key for all of the following parameters is `storage_class`.


== `defaultClass`

[horizontal]
type:: string
default:: undefined

The name of the StorageClass which should be annotated as the https://kubernetes.io/docs/tasks/administer-cluster/change-default-storage-class[default StorageClass].
The provided helper library makes sure that the StorageClass with this name is annotated with `storageclass.kubernetes.io/is-default-class=true`.


== `defaults`

[horizontal]
type:: dictionary
default::
[source,yaml]
----
volumeBindingMode: WaitForFirstConsumer
reclaimPolicy: Delete
----

Defaults to be set on StorageClass objects.
This dictionary can contain any valid https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#storageclass-v1-storage-k8s-io[StorageClass fields].


== `storageClasses`

[horizontal]
type:: dictionary
default:: undefined

A dictionary holding the https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#storageclass-v1-storage-k8s-io[StorageClass fields].
The keys of the dict are used as names for the StorageClass objects.


== Example

[source,yaml]
----
defaults:
allowVolumeExpansion: true
storageClasses:
standard:
parameters:
replication-type: none
type: pd-standard
provisioner: kubernetes.io/gce-pd
----
1 change: 1 addition & 0 deletions docs/modules/ROOT/partials/nav.adoc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* xref:index.adoc[Home]
* xref:references/parameters.adoc[Parameters]
10 changes: 0 additions & 10 deletions lib/storage-class.libjsonnet

This file was deleted.

31 changes: 31 additions & 0 deletions lib/storage-class.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* \file Helper to create StorageClass objects.
*/

local com = import 'lib/commodore.libjsonnet';
local kap = import 'lib/kapitan.libjsonnet';
local kube = import 'lib/kube.libjsonnet';
local inv = kap.inventory();
local storage_class_params = inv.parameters.storage_class;


/**
* \brief Helper to create StorageClass objects.
The `storageclass.kubernetes.io/is-default-class` annotation is automatically set based on `parameters.storage_class.defaultClass`.
Defaults are used from `parameters.storage_class.defaults`.
*
* \arg The name of the StorageClass.
* \return A StorageClass object.
*/
local storageClass(name) = kube._Object('storage.k8s.io/v1', 'StorageClass', name) {
metadata+: {
annotations+: {
[if storage_class_params.defaultClass == name then 'storageclass.kubernetes.io/is-default-class']: 'true',
},
},
} + storage_class_params.defaults;


{
storageClass: storageClass,
}