collect kube versions into a single file

This commit is contained in:
Bryton Hall 2022-08-13 21:39:56 -04:00
parent f251d55857
commit 7fb2bf9578
10 changed files with 25023 additions and 16805 deletions

View file

@ -9,7 +9,7 @@ This project uses [flakes](https://nixos.wiki/wiki/Flakes) so a development envi
nix develop nix develop
where you will find a [devshell](https://numtide.github.io/devshell) prompt (which supports [direnv](https://direnv.net/) so a one-time `direnv allow` at the base of the repo should automate the dev shell process). > **NOTE**: there's also support for [direnv](https://direnv.net/) to automate the dev shell process
## Commits ## Commits
@ -23,15 +23,11 @@ Do try to format the repo with [treefmt](https://github.com/numtide/treefmt) bef
To support a new Kubernetes version: To support a new Kubernetes version:
- Edit [`./jobs/generators/default.nix`](./jobs/generators/default.nix) and add a block for the version under `k8s`; for example: - Edit [`./versions.nix`](./versions.nix) and add a new attribute for the version; for example:
```nix ```nix
{ {
name = "v1.23.nix"; "1.23.0" = "sha256:0jivg8nlxka1y7gzqpcxkmbvhcbxynyrxmjn0blky30q5064wx2a";
path = generateK8S "v1.23" (builtins.fetchurl {
url = "https://github.com/kubernetes/kubernetes/raw/v1.23.0/api/openapi-spec/swagger.json";
sha256 = "0jivg8nlxka1y7gzqpcxkmbvhcbxynyrxmjn0blky30q5064wx2a";
});
} }
``` ```
@ -40,9 +36,6 @@ To support a new Kubernetes version:
nix build '.#jobs.x86_64-linux.generators.k8s' nix build '.#jobs.x86_64-linux.generators.k8s'
cp ./result/* modules/generated/ cp ./result/* modules/generated/
- Add the version in [`./modules/k8s.nix`](./modules/k8s.nix) under `options.kubernetes.version.type`
- Add a new check in [`./flake.nix`](./flake.nix) (e.g., `tests-k8s-1_23`)
## Tests ## Tests
Tests are executed through GitHub actions; see the [workflow definition](../kubenix/.github/workflows/ci.yml) for commands. Tests are executed through GitHub actions; see the [workflow definition](../kubenix/.github/workflows/ci.yml) for commands.

View file

@ -118,15 +118,16 @@
mkK8STests = attrs: mkK8STests = attrs:
(import ./tests {inherit evalModules;}) (import ./tests {inherit evalModules;})
({registry = "docker.io/gatehub";} // attrs); ({registry = "docker.io/gatehub";} // attrs);
in { in
# TODO: access "success" derivation with nice testing utils for nice output {
nginx-example = wasSuccess (mkExamples {}).nginx-deployment.config.testing; # TODO: access "success" derivation with nice testing utils for nice output
tests-k8s-1_19 = wasSuccess (mkK8STests {k8sVersion = "1.19";}); nginx-example = wasSuccess (mkExamples {}).nginx-deployment.config.testing;
tests-k8s-1_20 = wasSuccess (mkK8STests {k8sVersion = "1.20";}); }
tests-k8s-1_21 = wasSuccess (mkK8STests {k8sVersion = "1.21";}); // builtins.listToAttrs (builtins.map (v: {
tests-k8s-1_23 = wasSuccess (mkK8STests {k8sVersion = "1.23";}); name = "test-k8s-${builtins.replaceStrings ["."] ["_"] v}";
tests-k8s-1_24 = wasSuccess (mkK8STests {k8sVersion = "1.24";}); value = wasSuccess (mkK8STests {k8sVersion = v;});
}; })
(import ./versions.nix).versions);
} }
)) ))
// { // {

View file

@ -26,43 +26,20 @@ in {
} }
]; ];
k8s = pkgs.linkFarm "k8s-generated" [ k8s = pkgs.linkFarm "k8s-generated" (
{ builtins.attrValues (
name = "v1.19.nix"; builtins.mapAttrs (
path = generateK8S "v1.19" (builtins.fetchurl { version: sha: let
url = "https://github.com/kubernetes/kubernetes/raw/v1.19.10/api/openapi-spec/swagger.json"; short = builtins.concatStringsSep "." (lib.lists.sublist 0 2 (builtins.splitVersion version));
sha256 = "sha256-ZXxonUAUxRK6rhTgK62ytTdDKCuOoWPwxJmktiKgcJc="; in {
}); name = "v${short}.nix";
} path = generateK8S "v${short}" (builtins.fetchurl {
url = "https://github.com/kubernetes/kubernetes/raw/v${version}/api/openapi-spec/swagger.json";
{ sha256 = sha;
name = "v1.20.nix"; });
path = generateK8S "v1.20" (builtins.fetchurl { }
url = "https://github.com/kubernetes/kubernetes/raw/v1.20.6/api/openapi-spec/swagger.json"; )
sha256 = "sha256-xzVOarQDSomHMimpt8H6MfpiQrLl9am2fDvk/GfLkDw="; (import ../../versions.nix).full
}); )
} );
{
name = "v1.21.nix";
path = generateK8S "v1.21" (builtins.fetchurl {
url = "https://github.com/kubernetes/kubernetes/raw/v1.21.0/api/openapi-spec/swagger.json";
sha256 = "sha256-EoqYTbtaTlzs7vneoNtXUmdnjTM/U+1gYwCiEy0lOcw=";
});
}
{
name = "v1.23.nix";
path = generateK8S "v1.23" (builtins.fetchurl {
url = "https://github.com/kubernetes/kubernetes/raw/v1.23.0/api/openapi-spec/swagger.json";
sha256 = "sha256:0jivg8nlxka1y7gzqpcxkmbvhcbxynyrxmjn0blky30q5064wx2a";
});
}
{
name = "v1.24.nix";
path = generateK8S "v1.24" (builtins.fetchurl {
url = "https://github.com/kubernetes/kubernetes/raw/v1.24.0/api/openapi-spec/swagger.json";
sha256 = "sha256:0fp5hbqk2q0imrfi4mwp1ia0bmn0xnl6hcr07y52q2cp41pmfhqd";
});
}
];
} }

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -8,6 +8,7 @@
... ...
}: }:
with lib; let with lib; let
versions = (import ../versions.nix).versions;
cfg = config.kubernetes; cfg = config.kubernetes;
gvkKeyFn = type: "${type.group}/${type.version}/${type.kind}"; gvkKeyFn = type: "${type.group}/${type.version}/${type.kind}";
@ -272,8 +273,8 @@ in {
options.kubernetes = { options.kubernetes = {
version = mkOption { version = mkOption {
description = "Kubernetes version to use"; description = "Kubernetes version to use";
type = types.enum ["1.19" "1.20" "1.21" "1.23" "1.24"]; type = types.enum versions;
default = "1.24"; default = lib.lists.last versions;
}; };
namespace = mkOption { namespace = mkOption {

24
versions.nix Normal file
View file

@ -0,0 +1,24 @@
let
full = {
"1.19.10" = "sha256-ZXxonUAUxRK6rhTgK62ytTdDKCuOoWPwxJmktiKgcJc=";
"1.20.6" = "sha256-xzVOarQDSomHMimpt8H6MfpiQrLl9am2fDvk/GfLkDw=";
"1.21.0" = "sha256-EoqYTbtaTlzs7vneoNtXUmdnjTM/U+1gYwCiEy0lOcw=";
"1.23.0" = "sha256:0jivg8nlxka1y7gzqpcxkmbvhcbxynyrxmjn0blky30q5064wx2a";
"1.24.0" = "sha256:0fp5hbqk2q0imrfi4mwp1ia0bmn0xnl6hcr07y52q2cp41pmfhqd";
};
in {
inherit full;
# sorted list of major.minor version numbers
# NOTE: avoiding pulling in lib here (not for any good reason)
versions =
map (v: let
arr = builtins.splitVersion v;
in (
builtins.concatStringsSep "."
[
(builtins.elemAt arr 0)
(builtins.elemAt arr 1)
]
))
(builtins.attrNames full);
}