Skip to content

Commit

Permalink
Remove old functions from lib
Browse files Browse the repository at this point in the history
  • Loading branch information
arnarg committed Jul 23, 2024
1 parent c3dfb03 commit d46f8b4
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 240 deletions.
10 changes: 0 additions & 10 deletions lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,4 @@ in
kustomize = import ./kustomize.nix params;
helm = import ./helm.nix params;
kube = import ./kube.nix params;

mkApplication = {
name,
namespace,
resources ? {},
YAMLs ? [],
}: {
inherit name namespace;
resources = lib.mkMerge [resources (self.resources.fromManifestYAMLs YAMLs)];
};
})
230 changes: 0 additions & 230 deletions lib/kube.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,234 +107,4 @@ in {
else {}
);
};

/*
Create a Kubernetes namespace manifest. This will create a manifest in
Kubernetes format so if you want to use it for application's resources
it should be then parsed with [lib.resources.fromManifests](#libresourcesfrommanifests).
Type:
namespace :: String -> AttrSet -> AttrSet
Example:
namespace "default" {
labels = {
"pod-security.kubernetes.io/enforce" = "privileged";
};
}
=> {
apiVersion = "v1";
kind = "Namespace";
metadata = {
name = "default";
labels = {
"pod-security.kubernetes.io/enforce" = "privileged";
};
};
}
*/
namespace =
# Name of the namespace manifest to create.
name: {
# Optional annotations to add to the namespace manifest.
# This should be an attribute set.
annotations ? null,
# Optional labels to add to the namespace manifest.
# This should be an attribute set.
labels ? null,
}:
mkManifest {
apiVersion = "v1";
kind = "Namespace";
metadata = {
inherit name annotations labels;
};
};

/*
Create a Kubernetes config map manifest. This will create a manifest in
Kubernetes format so if you want to use it for application's resources
it should be then parsed with [lib.resources.fromManifests](#libresourcesfrommanifests).
Type:
configMap :: String -> AttrSet -> AttrSet
Example:
configMap "my-config" {
namespace = "default";
data."data.txt" = "Hello world!";
}
=> {
apiVersion = "v1";
kind = "ConfigMap";
metadata = {
name = "my-config";
namespace = "default";
};
data = {
"data.txt" = "Hello world!";
};
}
*/
configMap =
# Name of the config map manifest to create.
name: {
# Attribute set of data to put in the config map.
data,
# Optional namespace to add to the config map manifest.
namespace ? null,
# Optional annotations to add to the namespace manifest.
# This should be an attribute set.
annotations ? null,
# Optional labels to add to the namespace manifest.
# This should be an attribute set.
labels ? null,
}:
mkManifest {
inherit data;
apiVersion = "v1";
kind = "ConfigMap";
metadata = {
inherit name namespace annotations labels;
};
};

/*
Create a Kubernetes secret manifest. This will create a manifest in
Kubernetes format so if you want to use it for application's resources
it should be then parsed with [lib.resources.fromManifests](#libresourcesfrommanifests).
!!! danger Danger
Due to the nature of nixidy this resource will be rendered to YAML
and stored in cleartext in git.
Using this resource for actual secret data is discouraged.
Type:
configMap :: String -> AttrSet -> AttrSet
Example:
secret "my-secret" {
namespace = "default";
stringData."data.txt" = "Hello world!";
}
=> {
apiVersion = "v1";
kind = "Secret";
metadata = {
name = "my-secret";
namespace = "default";
};
stringData = {
"data.txt" = "Hello world!";
};
}
*/
secret =
# Name of the secret manifest to create
name: {
# Attribute set of data to put in the config map.
# Values should be base64 encoded.
data ? null,
# Attribute set of data to put in the config map.
# Values should be in cleartext.
stringData ? null,
# Optional namespace to add to the config map manifest.
namespace ? null,
# Optional annotations to add to the namespace manifest.
# This should be an attribute set.
annotations ? null,
# Optional labels to add to the namespace manifest.
# This should be an attribute set.
labels ? null,
}:
mkManifest {
inherit data stringData;
apiVersion = "v1";
kind = "Secret";
metadata = {
inherit name namespace annotations labels;
};
};

/*
Create a Kubernetes service manifest. This will create a manifest in
Kubernetes format so if you want to use it for application's resources
it should be then parsed with [lib.resources.fromManifests](#libresourcesfrommanifests).
Type:
service :: String -> AttrSet -> AttrSet
Example:
service "nginx" {
namespace = "default";
selector.app = "nginx";
ports.http = {
port = 80;
};
}
=> {
apiVersion = "v1";
kind = "Service";
metadata = {
name = "nginx";
namespace = "default";
};
spec = {
type = "ClusterIP"; # Default
selector.app = "nginx";
ports = [
{
name = "http";
port = 80;
protocol = "TCP"; # Default
}
];
};
}
*/
service =
# Name of the service manifest to create.
name: {
# Type of service to create. Defaults to `ClusterIP`.
type ? "ClusterIP",
# Label selector to match pods that this service should target.
# This should be an attribute set.
selector,
# Ports this service should have.
# This should be an attribute set (see example).
ports,
# Optional namespace to add to the config map manifest.
namespace ? null,
# Optional annotations to add to the namespace manifest.
# This should be an attribute set.
annotations ? null,
# Optional labels to add to the namespace manifest.
# This should be an attribute set.
labels ? null,
}: let
defaultPortData = {protocol = "TCP";};

portList =
lib.mapAttrsToList (
n: v:
defaultPortData
// v
// {
name = n;
}
)
ports;
in
mkManifest {
apiVersion = "v1";
kind = "Service";
metadata = {
inherit name namespace annotations labels;
};
spec = {
inherit type selector;
ports = portList;
};
};
}

0 comments on commit d46f8b4

Please sign in to comment.