mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 16:10:05 +01:00
feat(legacy): improve CRD support
This commit is contained in:
parent
29b1140178
commit
26d0351eb8
5 changed files with 134 additions and 45 deletions
|
|
@ -169,7 +169,7 @@ let
|
||||||
config = {
|
config = {
|
||||||
apiVersion = mkOptionDefault "${ct.group}/${ct.version}";
|
apiVersion = mkOptionDefault "${ct.group}/${ct.version}";
|
||||||
kind = mkOptionDefault ct.kind;
|
kind = mkOptionDefault ct.kind;
|
||||||
metadata.name = mkOptionDefault name;
|
metadata.name = mkDefault name;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -384,12 +384,12 @@ in {
|
||||||
|
|
||||||
# custom types created from customResourceDefinitions
|
# custom types created from customResourceDefinitions
|
||||||
kubernetes.customTypes = mkIf cfg.createCustomTypesFromCRDs (
|
kubernetes.customTypes = mkIf cfg.createCustomTypesFromCRDs (
|
||||||
mapAttrsToList (_: crd: {
|
mapAttrsToList (name: crd: {
|
||||||
group = crd.spec.group;
|
group = crd.spec.group;
|
||||||
version = crd.spec.version;
|
version = crd.spec.version;
|
||||||
kind = crd.spec.names.kind;
|
kind = crd.spec.names.kind;
|
||||||
name = crd.spec.names.plural;
|
name = crd.spec.names.plural;
|
||||||
attrName = mkDefault crd.spec.names.plural;
|
attrName = mkOptionDefault name;
|
||||||
}) (cfg.resources.customResourceDefinitions or {})
|
}) (cfg.resources.customResourceDefinitions or {})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
parentModule = module;
|
parentModule = module;
|
||||||
|
globalConfig = config;
|
||||||
|
|
||||||
mkOptionDefault = mkOverride 1001;
|
mkOptionDefault = mkOverride 1001;
|
||||||
|
|
||||||
|
|
@ -120,10 +121,7 @@ in {
|
||||||
namespace = mkOption {
|
namespace = mkOption {
|
||||||
description = "Namespace where to deploy module";
|
description = "Namespace where to deploy module";
|
||||||
type = types.str;
|
type = types.str;
|
||||||
default =
|
default = globalConfig.kubernetes.namespace;
|
||||||
if parentModule != null
|
|
||||||
then parentModule.namespace
|
|
||||||
else "default";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
labels = mkOption {
|
labels = mkOption {
|
||||||
|
|
@ -161,7 +159,8 @@ in {
|
||||||
options.kubernetes.customResources = options.kubernetes.resources;
|
options.kubernetes.customResources = options.kubernetes.resources;
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
kubernetes.api.defaults = mapAttrsToList (attrName: default: let
|
kubernetes = mkMerge [{
|
||||||
|
api.defaults = mapAttrsToList (attrName: default: let
|
||||||
type = head (mapAttrsToList (_: v: v) (filterAttrs (_: type: type.attrName == attrName) config.kubernetes.api.types));
|
type = head (mapAttrsToList (_: v: v) (filterAttrs (_: type: type.attrName == attrName) config.kubernetes.api.types));
|
||||||
in {
|
in {
|
||||||
default = { imports = default; };
|
default = { imports = default; };
|
||||||
|
|
@ -169,7 +168,7 @@ in {
|
||||||
resource = type.name;
|
resource = type.name;
|
||||||
})) config.kubernetes.defaults;
|
})) config.kubernetes.defaults;
|
||||||
|
|
||||||
kubernetes.resources = mkMerge (
|
resources = mkMerge (
|
||||||
mapAttrsToList (name: module:
|
mapAttrsToList (name: module:
|
||||||
mapAttrs' (_: type: let
|
mapAttrs' (_: type: let
|
||||||
moduleDefinition = getModuleDefinition module.module;
|
moduleDefinition = getModuleDefinition module.module;
|
||||||
|
|
@ -177,7 +176,7 @@ in {
|
||||||
moduleResources = module.configuration.kubernetes.api.resources.${type.attrName} or {};
|
moduleResources = module.configuration.kubernetes.api.resources.${type.attrName} or {};
|
||||||
|
|
||||||
moduleConfig =
|
moduleConfig =
|
||||||
if moduleDefinition.prefixResources
|
if moduleDefinition.prefixResources && type.kind != "CustomResourceDefinition"
|
||||||
then prefixResources (moduleToAttrs moduleResources) name
|
then prefixResources (moduleToAttrs moduleResources) name
|
||||||
else moduleToAttrs moduleResources;
|
else moduleToAttrs moduleResources;
|
||||||
in nameValuePair type.attrName
|
in nameValuePair type.attrName
|
||||||
|
|
@ -188,16 +187,16 @@ in {
|
||||||
) config.kubernetes.modules
|
) config.kubernetes.modules
|
||||||
);
|
);
|
||||||
|
|
||||||
# custom resources are now included in normal resources, so just make an alias
|
|
||||||
kubernetes.customResources = mkAliasDefinitions options.kubernetes.resources;
|
|
||||||
|
|
||||||
# create custom types from CRDs was old behavior
|
# create custom types from CRDs was old behavior
|
||||||
kubernetes.createCustomTypesFromCRDs = true;
|
createCustomTypesFromCRDs = true;
|
||||||
|
|
||||||
kubernetes.defaultModuleConfiguration.all = {
|
defaultModuleConfiguration.all = {
|
||||||
_file = head options.kubernetes.defaultModuleConfiguration.files;
|
_file = head options.kubernetes.defaultModuleConfiguration.files;
|
||||||
config.kubernetes.version = mkDefault config.kubernetes.version;
|
config.kubernetes.version = mkDefault config.kubernetes.version;
|
||||||
config.kubernetes.moduleDefinitions = config.kubernetes.moduleDefinitions;
|
config.kubernetes.moduleDefinitions = config.kubernetes.moduleDefinitions;
|
||||||
};
|
};
|
||||||
|
} {
|
||||||
|
resources = mkAliasDefinitions options.kubernetes.customResources;
|
||||||
|
}];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ let
|
||||||
./k8s/submodule.nix
|
./k8s/submodule.nix
|
||||||
./k8s/imports.nix
|
./k8s/imports.nix
|
||||||
./legacy/k8s.nix
|
./legacy/k8s.nix
|
||||||
|
./legacy/crd.nix
|
||||||
./legacy/modules.nix
|
./legacy/modules.nix
|
||||||
./helm/simple.nix
|
./helm/simple.nix
|
||||||
./istio/bookinfo.nix
|
./istio/bookinfo.nix
|
||||||
|
|
|
||||||
89
tests/legacy/crd.nix
Normal file
89
tests/legacy/crd.nix
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
{ options, config, lib, kubenix, pkgs, k8sVersion, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
{
|
||||||
|
imports = with kubenix.modules; [ test k8s legacy ];
|
||||||
|
|
||||||
|
test = {
|
||||||
|
name = "legacy-crd";
|
||||||
|
description = "Simple test tesing kubenix legacy integration with crds crd";
|
||||||
|
assertions = [];
|
||||||
|
};
|
||||||
|
|
||||||
|
kubernetes.version = k8sVersion;
|
||||||
|
kubernetes.namespace = "test";
|
||||||
|
|
||||||
|
kubernetes.moduleDefinitions.secret-claim.module = { config, k8s, module, ... }: {
|
||||||
|
options = {
|
||||||
|
name = mkOption {
|
||||||
|
description = "Name of the secret claim";
|
||||||
|
type = types.str;
|
||||||
|
default = module.name;
|
||||||
|
};
|
||||||
|
|
||||||
|
type = mkOption {
|
||||||
|
description = "Type of the secret";
|
||||||
|
type = types.enum ["Opaque" "kubernetes.io/tls"];
|
||||||
|
default = "Opaque";
|
||||||
|
};
|
||||||
|
|
||||||
|
path = mkOption {
|
||||||
|
description = "Secret path";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
renew = mkOption {
|
||||||
|
description = "Renew time in seconds";
|
||||||
|
type = types.nullOr types.int;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
data = mkOption {
|
||||||
|
type = types.nullOr types.attrs;
|
||||||
|
description = "Data to pass to get secrets";
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
kubernetes.resources.customResourceDefinitions.secret-claims = {
|
||||||
|
kind = "CustomResourceDefinition";
|
||||||
|
apiVersion = "apiextensions.k8s.io/v1beta1";
|
||||||
|
metadata.name = "secretclaims.vaultproject.io";
|
||||||
|
spec = {
|
||||||
|
group = "vaultproject.io";
|
||||||
|
version = "v1";
|
||||||
|
scope = "Namespaced";
|
||||||
|
names = {
|
||||||
|
plural = "secretclaims";
|
||||||
|
kind = "SecretClaim";
|
||||||
|
shortNames = ["scl"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
kubernetes.customResources.secret-claims.claim = {
|
||||||
|
metadata.name = config.name;
|
||||||
|
spec = {
|
||||||
|
inherit (config) type path;
|
||||||
|
} // (optionalAttrs (config.renew != null) {
|
||||||
|
inherit (config) renew;
|
||||||
|
}) // (optionalAttrs (config.data != null) {
|
||||||
|
inherit (config) data;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
kubernetes.modules.myclaim = {
|
||||||
|
module = "secret-claim";
|
||||||
|
configuration.path = "tokens/test";
|
||||||
|
};
|
||||||
|
|
||||||
|
kubernetes.customResources.secret-claims.propagated-claim = {
|
||||||
|
spec = {
|
||||||
|
path = "secrets/test2";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue