Skip to content

Commit 99f8b51

Browse files
chore(monitoring): adding nix package and readme generator
Signed-off-by: Abhilash Shetty <abhilash.shetty@datacore.com>
1 parent 8ee3f91 commit 99f8b51

File tree

10 files changed

+420
-134
lines changed

10 files changed

+420
-134
lines changed

deploy/charts/README.md

Lines changed: 115 additions & 133 deletions
Large diffs are not rendered by default.

deploy/charts/templates/_helpers.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Usage:
8080
{{- range $subchart }}
8181
{{- $values = index $values . }}
8282
{{- end }}
83-
{{- if $values.enabled }} # Add this condition to check if the subchart is enabled
83+
{{- if $values.enabled }}
8484
{{- include $template (dict "Chart" (dict "Name" (last $subchart)) "Values" $values "Release" $dot.Release "Capabilities" $dot.Capabilities) }}
8585
{{- end }}
8686
{{- end }}

nix/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Overview
2+
3+
These are a collection of packages we need, or packages where we
4+
want to control the exact version(s) of.
5+
6+
The packages are imported through the `nix-shell` automatically.
7+
8+
## nix-shell
9+
10+
Build environment including all test and debug dependencies.
11+
It can be run with two arguments:
12+
13+
* `--arg norust true`: to use your own rust toolchain.
14+
* `--arg devrustup true`: to use rustup.

nix/lib/rust.nix

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{ sources ? import ../sources.nix }:
2+
let
3+
pkgs =
4+
import sources.nixpkgs { overlays = [ (import sources.rust-overlay) ]; };
5+
makeRustTarget = platform: pkgs.rust.toRustTargetSpec platform;
6+
static_target = makeRustTarget pkgs.pkgsStatic.stdenv.hostPlatform;
7+
in
8+
rec {
9+
inherit makeRustTarget;
10+
rust_default = { override ? { } }: rec {
11+
nightly_pkg = pkgs.rust-bin.nightly."2023-10-05";
12+
stable_pkg = pkgs.rust-bin.stable."1.72.1";
13+
14+
nightly = nightly_pkg.default.override (override);
15+
stable = stable_pkg.default.override (override);
16+
17+
nightly_src = nightly_pkg.rust-src;
18+
release_src = stable_pkg.rust-src;
19+
};
20+
default = rust_default { };
21+
default_src = rust_default {
22+
override = { extensions = [ "rust-src" ]; };
23+
};
24+
static = { target ? makeRustTarget pkgs.pkgsStatic.stdenv.hostPlatform }: rust_default {
25+
override = { targets = [ "${target}" ]; };
26+
};
27+
hostStatic = rust_default { override = { targets = [ "${makeRustTarget pkgs.pkgsStatic.stdenv.hostPlatform}" ]; }; };
28+
windows_cross = rust_default {
29+
override = { targets = [ "${pkgs.rust.toRustTargetSpec pkgs.pkgsCross.mingwW64.hostPlatform}" ]; };
30+
};
31+
}

nix/lib/sourcer.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{ lib, stdenv, git, sourcer, tag ? "" }:
2+
let
3+
whitelistSource = src: allowedPrefixes:
4+
builtins.path {
5+
filter = (path: type:
6+
(lib.any
7+
(allowedPrefix:
8+
(lib.hasPrefix (toString (src + "/${allowedPrefix}")) path) ||
9+
(type == "directory" && lib.hasPrefix path (toString (src + "/${allowedPrefix}")))
10+
)
11+
allowedPrefixes)
12+
## Remove unwanted files, example:
13+
# && path != (toString (src + "/utils/dependencies/scripts/release.sh"))
14+
);
15+
path = src;
16+
name = "puls8";
17+
};
18+
in
19+
{
20+
inherit whitelistSource;
21+
22+
git-src = whitelistSource ../../. [ ".git" ];
23+
repo-org = whitelistSource ../../mayastor-extensions/dependencies/control-plane/utils/dependencies/scripts [ "git-org-name.sh" ];
24+
}

nix/overlay.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{}:
2+
self: super: {
3+
sourcer = super.callPackage ./lib/sourcer.nix { };
4+
}

nix/sources.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"naersk": {
3+
"branch": "master",
4+
"description": "Build rust crates in Nix. No configuration, no code generation, no IFD. Sandbox friendly. [maintainer: @nmattia]",
5+
"homepage": "",
6+
"owner": "nix-community",
7+
"repo": "naersk",
8+
"rev": "d9a33d69a9c421d64c8d925428864e93be895dcc",
9+
"sha256": "1lhz5haibfnbxwir61mhymxfqfgs2q1nb4rk88va8bpv6j2zlpbv",
10+
"type": "tarball",
11+
"url": "https://github.com/nix-community/naersk/archive/d9a33d69a9c421d64c8d925428864e93be895dcc.tar.gz",
12+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13+
},
14+
"niv": {
15+
"branch": "master",
16+
"description": "Easy dependency management for Nix projects",
17+
"homepage": "https://github.com/nmattia/niv",
18+
"owner": "nmattia",
19+
"repo": "niv",
20+
"rev": "914aba08a26cb10538b84d00d6cfb01c9776d80c",
21+
"sha256": "0gx316gc7prjay5b0cr13x4zc2pdbiwxkfkpjvrlb2rml80lm4pm",
22+
"type": "tarball",
23+
"url": "https://github.com/nmattia/niv/archive/914aba08a26cb10538b84d00d6cfb01c9776d80c.tar.gz",
24+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
25+
},
26+
"nixpkgs": {
27+
"branch": "release-22.11",
28+
"description": "A read-only mirror of NixOS/nixpkgs tracking the released channels. Send issues and PRs to",
29+
"homepage": "https://github.com/NixOS/nixpkgs",
30+
"owner": "NixOS",
31+
"repo": "nixpkgs",
32+
"rev": "ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b",
33+
"sha256": "1xi53rlslcprybsvrmipm69ypd3g3hr7wkxvzc73ag8296yclyll",
34+
"type": "tarball",
35+
"url": "https://github.com/NixOS/nixpkgs/archive/ea4c80b39be4c09702b0cb3b42eab59e2ba4f24b.tar.gz",
36+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
37+
},
38+
"rust-overlay": {
39+
"branch": "master",
40+
"description": "Pure and reproducible nix overlay for binary distributed rust toolchains",
41+
"homepage": "",
42+
"owner": "oxalica",
43+
"repo": "rust-overlay",
44+
"rev": "c0df7f2a856b5ff27a3ce314f6d7aacf5fda546f",
45+
"sha256": "0hm2yznc083bys92h6zrx5lsar5nqphx1h27p7pxz4x7hmilxpsy",
46+
"type": "tarball",
47+
"url": "https://github.com/oxalica/rust-overlay/archive/c0df7f2a856b5ff27a3ce314f6d7aacf5fda546f.tar.gz",
48+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
49+
}
50+
}

nix/sources.nix

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# This file has been generated by Niv.
2+
let
3+
#
4+
# The fetchers. fetch_<type> fetches specs of type <type>.
5+
#
6+
7+
fetch_file = pkgs: spec:
8+
if spec.builtin or true then
9+
builtins_fetchurl { inherit (spec) url sha256; }
10+
else
11+
pkgs.fetchurl { inherit (spec) url sha256; };
12+
13+
fetch_tarball = pkgs: spec:
14+
if spec.builtin or true then
15+
builtins_fetchTarball { inherit (spec) url sha256; }
16+
else
17+
pkgs.fetchzip { inherit (spec) url sha256; };
18+
19+
fetch_git = spec:
20+
builtins.fetchGit {
21+
url = spec.repo;
22+
inherit (spec) rev ref;
23+
};
24+
25+
fetch_builtin-tarball = spec:
26+
builtins.trace ''
27+
WARNING:
28+
The niv type "builtin-tarball" will soon be deprecated. You should
29+
instead use `builtin = true`.
30+
31+
$ niv modify <package> -a type=tarball -a builtin=true
32+
''
33+
builtins_fetchTarball
34+
{ inherit (spec) url sha256; };
35+
36+
fetch_builtin-url = spec:
37+
builtins.trace ''
38+
WARNING:
39+
The niv type "builtin-url" will soon be deprecated. You should
40+
instead use `builtin = true`.
41+
42+
$ niv modify <package> -a type=file -a builtin=true
43+
''
44+
(builtins_fetchurl { inherit (spec) url sha256; });
45+
46+
#
47+
# Various helpers
48+
#
49+
50+
# The set of packages used when specs are fetched using non-builtins.
51+
mkPkgs = sources:
52+
let
53+
sourcesNixpkgs =
54+
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; })
55+
{ };
56+
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
57+
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
58+
in
59+
if builtins.hasAttr "nixpkgs" sources then
60+
sourcesNixpkgs
61+
else if hasNixpkgsPath && !hasThisAsNixpkgsPath then
62+
import <nixpkgs> { }
63+
else
64+
abort ''
65+
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
66+
add a package called "nixpkgs" to your sources.json.
67+
'';
68+
69+
# The actual fetching function.
70+
fetch = pkgs: name: spec:
71+
72+
if !builtins.hasAttr "type" spec then
73+
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
74+
else if spec.type == "file" then
75+
fetch_file pkgs spec
76+
else if spec.type == "tarball" then
77+
fetch_tarball pkgs spec
78+
else if spec.type == "git" then
79+
fetch_git spec
80+
else if spec.type == "builtin-tarball" then
81+
fetch_builtin-tarball spec
82+
else if spec.type == "builtin-url" then
83+
fetch_builtin-url spec
84+
else
85+
abort
86+
"ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
87+
88+
# Ports of functions for older nix versions
89+
90+
# a Nix version of mapAttrs if the built-in doesn't exist
91+
mapAttrs = builtins.mapAttrs or (f: set:
92+
with builtins;
93+
listToAttrs (map
94+
(attr: {
95+
name = attr;
96+
value = f attr set.${attr};
97+
})
98+
(attrNames set)));
99+
100+
# fetchTarball version that is compatible between all the versions of Nix
101+
builtins_fetchTarball = { url, sha256 }@attrs:
102+
let inherit (builtins) lessThan nixVersion fetchTarball;
103+
in
104+
if lessThan nixVersion "1.12" then
105+
fetchTarball { inherit url; }
106+
else
107+
fetchTarball attrs;
108+
109+
# fetchurl version that is compatible between all the versions of Nix
110+
builtins_fetchurl = { url, sha256 }@attrs:
111+
let inherit (builtins) lessThan nixVersion fetchurl;
112+
in
113+
if lessThan nixVersion "1.12" then
114+
fetchurl { inherit url; }
115+
else
116+
fetchurl attrs;
117+
118+
# Create the final "sources" from the config
119+
mkSources = config:
120+
mapAttrs
121+
(name: spec:
122+
if builtins.hasAttr "outPath" spec then
123+
abort
124+
"The values in sources.json should not have an 'outPath' attribute"
125+
else
126+
spec // { outPath = fetch config.pkgs name spec; })
127+
config.sources;
128+
129+
# The "config" used by the fetchers
130+
mkConfig =
131+
{ sourcesFile ? ./sources.json
132+
, sources ? builtins.fromJSON (builtins.readFile sourcesFile)
133+
, pkgs ? mkPkgs sources
134+
}: rec {
135+
# The sources, i.e. the attribute set of spec name to spec
136+
inherit sources;
137+
138+
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
139+
inherit pkgs;
140+
};
141+
in
142+
mkSources (mkConfig { }) // {
143+
__functor = _: settings: mkSources (mkConfig settings);
144+
}

scripts/generate-readme.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPTDIR=$(dirname "$0")
4+
ROOTDIR="$(realpath $SCRIPTDIR/..)"
5+
CHART_DIR="$ROOTDIR/deploy/charts"
6+
README="README.md"
7+
SKIP_GIT=${SKIP_GIT:-}
8+
9+
set -euo pipefail
10+
11+
helm-docs -c "$ROOTDIR" -g "$CHART_DIR" -o $README
12+
13+
14+
if [ -z "$SKIP_GIT" ]; then
15+
git diff --exit-code "$CHART_DIR/$README"
16+
fi

scripts/shell.nix

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{}:
2+
let
3+
sources = import ../nix/sources.nix;
4+
pkgs = import sources.nixpkgs {
5+
overlays = [ (_: _: { inherit sources; }) (import ../nix/overlay.nix { }) ];
6+
};
7+
in
8+
with pkgs;
9+
let
10+
in
11+
mkShell {
12+
name = "helm-scripts-shell";
13+
buildInputs = [
14+
coreutils
15+
git
16+
helm-docs
17+
kubernetes-helm-wrapped
18+
semver-tool
19+
yq-go
20+
];
21+
}

0 commit comments

Comments
 (0)