mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-11 23:50:06 +01:00
flake: format
This commit is contained in:
parent
eb3ec20f46
commit
baa1a6c949
16 changed files with 86 additions and 72 deletions
|
|
@ -1,8 +1,8 @@
|
|||
{ kubenix ? import ../../../.. }:
|
||||
{kubenix ? import ../../../..}:
|
||||
kubenix.evalModules.${builtins.currentSystem} {
|
||||
module = { kubenix, ... }: {
|
||||
module = {kubenix, ...}: {
|
||||
# instead of defining everything inline, let's import it
|
||||
imports = [ ./module.nix ];
|
||||
imports = [./module.nix];
|
||||
|
||||
# annotate the generated resources with a project name
|
||||
kubenix.project = "example";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{ kubenix, ... }: {
|
||||
imports = [ kubenix.modules.k8s ];
|
||||
{kubenix, ...}: {
|
||||
imports = [kubenix.modules.k8s];
|
||||
|
||||
kubernetes.resources = {
|
||||
deployments.nginx.spec = {
|
||||
|
|
@ -51,10 +51,12 @@
|
|||
|
||||
services.nginx.spec = {
|
||||
selector.app = "nginx";
|
||||
ports = [{
|
||||
name = "http";
|
||||
port = 80;
|
||||
}];
|
||||
ports = [
|
||||
{
|
||||
name = "http";
|
||||
port = 80;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{ kubenix ? import ../../../.. }:
|
||||
{kubenix ? import ../../../..}:
|
||||
kubenix.evalModules.${builtins.currentSystem} {
|
||||
module = { kubenix, ... }: {
|
||||
imports = [ kubenix.modules.helm ];
|
||||
module = {kubenix, ...}: {
|
||||
imports = [kubenix.modules.helm];
|
||||
kubernetes.helm.releases.example = {
|
||||
chart = kubenix.lib.helm.fetch {
|
||||
repo = "https://charts.bitnami.com/bitnami";
|
||||
|
|
|
|||
|
|
@ -1,10 +1,15 @@
|
|||
{ kubenix ? import ../../../.. }:
|
||||
{kubenix ? import ../../../..}:
|
||||
kubenix.evalModules.${builtins.currentSystem} {
|
||||
module = { kubenix, config, pkgs, ... }: {
|
||||
imports = with kubenix.modules; [ k8s docker ];
|
||||
module = {
|
||||
kubenix,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}: {
|
||||
imports = with kubenix.modules; [k8s docker];
|
||||
docker = {
|
||||
registry.url = "docker.somewhere.io";
|
||||
images.example.image = pkgs.callPackage ./image.nix { };
|
||||
images.example.image = pkgs.callPackage ./image.nix {};
|
||||
};
|
||||
kubernetes.resources.pods.example.spec.containers = {
|
||||
custom.image = config.docker.images.example.path;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
{ dockerTools, nginx }:
|
||||
{
|
||||
dockerTools,
|
||||
nginx,
|
||||
}:
|
||||
dockerTools.buildLayeredImage {
|
||||
name = "nginx";
|
||||
contents = [ nginx ];
|
||||
contents = [nginx];
|
||||
extraCommands = ''
|
||||
mkdir -p etc
|
||||
chmod u+w etc
|
||||
|
|
@ -9,9 +12,9 @@ dockerTools.buildLayeredImage {
|
|||
echo "nginx:x:1000:nginx" > etc/group
|
||||
'';
|
||||
config = {
|
||||
Cmd = [ "nginx" "-c" "/etc/nginx/nginx.conf" ];
|
||||
Cmd = ["nginx" "-c" "/etc/nginx/nginx.conf"];
|
||||
ExposedPorts = {
|
||||
"80/tcp" = { };
|
||||
"80/tcp" = {};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{ kubenix ? import ../../../.. }:
|
||||
{kubenix ? import ../../../..}:
|
||||
kubenix.evalModules.${builtins.currentSystem} {
|
||||
module = { kubenix, ... }: {
|
||||
imports = [ ./module.nix ];
|
||||
module = {kubenix, ...}: {
|
||||
imports = [./module.nix];
|
||||
|
||||
kubenix.project = "multi-namespace-example";
|
||||
kubernetes.version = "1.24";
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@
|
|||
|
||||
kubernetes = lib.mkMerge [
|
||||
# Use instance name as namespace
|
||||
{ namespace = name; }
|
||||
{namespace = name;}
|
||||
# Create namespace object
|
||||
{ resources.namespaces.${name} = {}; }
|
||||
{resources.namespaces.${name} = {};}
|
||||
# All resources defined here will use the above namespace
|
||||
args.kubernetes
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
# let's creata a function whose only input is the kubenix package
|
||||
{ kubenix ? import ../../../.. }:
|
||||
{kubenix ? import ../../../..}:
|
||||
# evalModules is our main entrypoint
|
||||
kubenix.evalModules.${builtins.currentSystem} {
|
||||
# to it, we pass a module that accepts a (different) kubenix object
|
||||
module = { kubenix, ... }: {
|
||||
module = {kubenix, ...}: {
|
||||
# in order to define options, we need to import their definitions
|
||||
imports = [ kubenix.modules.k8s ];
|
||||
imports = [kubenix.modules.k8s];
|
||||
# now we have full access to define Kubernetes resources
|
||||
kubernetes.resources.pods = {
|
||||
# "example" is the name of our pod
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{ kubenix ? import ../../../.. }:
|
||||
{kubenix ? import ../../../..}:
|
||||
kubenix.evalModules.${builtins.currentSystem} {
|
||||
module = { kubenix, ... }: {
|
||||
imports = [ kubenix.modules.k8s ];
|
||||
module = {kubenix, ...}: {
|
||||
imports = [kubenix.modules.k8s];
|
||||
kubernetes.resources.secrets.example.stringData = {
|
||||
password = "ref+file:///path/to/secret";
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,17 @@
|
|||
{ kubenix ? import ../../../.. }:
|
||||
{kubenix ? import ../../../..}:
|
||||
kubenix.evalModules.x86_64-linux {
|
||||
module = { kubenix, ... }: {
|
||||
imports = [ kubenix.modules.testing ];
|
||||
module = {kubenix, ...}: {
|
||||
imports = [kubenix.modules.testing];
|
||||
testing = {
|
||||
tests = [ ./test.nix ];
|
||||
common = [{
|
||||
features = [ "k8s" ];
|
||||
options = {
|
||||
kubernetes.version = "1.24";
|
||||
};
|
||||
}];
|
||||
tests = [./test.nix];
|
||||
common = [
|
||||
{
|
||||
features = ["k8s"];
|
||||
options = {
|
||||
kubernetes.version = "1.24";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
{ kubenix, test, ... }: {
|
||||
imports = [ kubenix.modules.test ];
|
||||
{
|
||||
kubenix,
|
||||
test,
|
||||
...
|
||||
}: {
|
||||
imports = [kubenix.modules.test];
|
||||
|
||||
test = {
|
||||
name = "example";
|
||||
|
|
|
|||
12
flake.nix
12
flake.nix
|
|
@ -13,19 +13,13 @@
|
|||
};
|
||||
};
|
||||
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
...
|
||||
} @ inputs:
|
||||
outputs = inputs @ {self, ...}:
|
||||
(inputs.flake-utils.lib.eachDefaultSystem (
|
||||
system: let
|
||||
pkgs = import inputs.nixpkgs {
|
||||
overlays = [
|
||||
self.overlays.default
|
||||
];
|
||||
config.allowUnsupportedSystem = true;
|
||||
inherit system;
|
||||
overlays = [self.overlays.default];
|
||||
config.allowUnsupportedSystem = true;
|
||||
};
|
||||
|
||||
inherit (pkgs) lib;
|
||||
|
|
|
|||
|
|
@ -170,21 +170,25 @@ with lib; let
|
|||
else
|
||||
# make it an attribute set of submodules if only x-kubernetes-patch-merge-key is present, or
|
||||
# x-kubernetes-patch-merge-key == x-kubernetes-list-map-keys.
|
||||
if hasAttr "properties" swagger.definitions.${refDefinition property.items} &&
|
||||
hasAttr "name" swagger.definitions.${refDefinition property.items}.properties
|
||||
if
|
||||
hasAttr "properties" swagger.definitions.${refDefinition property.items}
|
||||
&& hasAttr "name" swagger.definitions.${refDefinition property.items}.properties
|
||||
then let
|
||||
mergeKey = "name";
|
||||
in {
|
||||
type = requiredOrNot (coerceAttrsOfSubmodulesToListByKey (refDefinition property.items) mergeKey (if hasAttr "x-kubernetes-list-map-keys" property then property."x-kubernetes-list-map-keys" else []));
|
||||
type = requiredOrNot (coerceAttrsOfSubmodulesToListByKey (refDefinition property.items) mergeKey (
|
||||
if hasAttr "x-kubernetes-list-map-keys" property
|
||||
then property."x-kubernetes-list-map-keys"
|
||||
else []
|
||||
));
|
||||
apply = attrsToList;
|
||||
}
|
||||
|
||||
else {
|
||||
type =
|
||||
if (refDefinition property.items) == _name
|
||||
then types.unspecified # do not allow self-referential values
|
||||
else requiredOrNot (types.listOf (submoduleOf definitions (refDefinition property.items)));
|
||||
}
|
||||
else {
|
||||
type =
|
||||
if (refDefinition property.items) == _name
|
||||
then types.unspecified # do not allow self-referential values
|
||||
else requiredOrNot (types.listOf (submoduleOf definitions (refDefinition property.items)));
|
||||
}
|
||||
# in other case it only references a simple type
|
||||
else {
|
||||
type = requiredOrNot (types.listOf (mapType property.items));
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ with lib;
|
|||
# kubernetes version to template chart for
|
||||
kubeVersion ? null,
|
||||
# whether to include CRD
|
||||
includeCRDs ? false
|
||||
includeCRDs ? false,
|
||||
}: let
|
||||
valuesJsonFile = builtins.toFile "${name}-values.json" (builtins.toJSON values);
|
||||
in
|
||||
|
|
@ -31,7 +31,7 @@ with lib;
|
|||
${optionalString (kubeVersion != null) "--kube-version ${kubeVersion}"} \
|
||||
${optionalString (namespace != null) "--namespace ${namespace}"} \
|
||||
${optionalString (values != {}) "-f ${valuesJsonFile}"} \
|
||||
${optionalString (includeCRDs) "--include-crds"} \
|
||||
${optionalString includeCRDs "--include-crds"} \
|
||||
${chart} >resources.yaml
|
||||
|
||||
# split multy yaml file into multiple files
|
||||
|
|
|
|||
|
|
@ -82,13 +82,13 @@ in {
|
|||
};
|
||||
|
||||
includeCRDs = mkOption {
|
||||
description = ''
|
||||
description = ''
|
||||
Whether to include CRDs.
|
||||
|
||||
Warning: Always including CRDs here is dangerous and can break CRs in your cluster as CRDs may be updated unintentionally.
|
||||
An interactive `helm install` NEVER updates CRDs, only installs them when they are not existing.
|
||||
See https://github.com/helm/community/blob/aa8e13054d91ee69857b13149a9652be09133a61/hips/hip-0011.md
|
||||
|
||||
|
||||
Only set this to true if you know what you are doing and are manually checking the included CRDs for breaking changes whenever updating the Helm chart.
|
||||
'';
|
||||
type = types.bool;
|
||||
|
|
|
|||
|
|
@ -335,12 +335,12 @@ in {
|
|||
customTypes = mkOption {
|
||||
description = "Custom resource types to make API for";
|
||||
example = {
|
||||
helmchartconfig = {
|
||||
attrName = "helmchartconfig";
|
||||
kind = "HelmChartConfig";
|
||||
version = "v1";
|
||||
group = "helm.cattle.io";
|
||||
};
|
||||
helmchartconfig = {
|
||||
attrName = "helmchartconfig";
|
||||
kind = "HelmChartConfig";
|
||||
version = "v1";
|
||||
group = "helm.cattle.io";
|
||||
};
|
||||
};
|
||||
type =
|
||||
coerceListOfSubmodulesToAttrs
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue