package(default_visibility = ["//visibility:public"])

exports_files(["00-crds.yaml"])

load("@io_k8s_repo_infra//defs:pkg.bzl", "pkg_tar")
load("//build:helm.bzl", "helm_tmpl")
load("//build:licensing.bzl", "licensed_file")

RELEASE_NAME = "cert-manager"

RELEASE_NAMESPACE = "cert-manager"

helm_tmpl(
    name = "manifests.helm",
    helm_pkg = "//deploy/charts/cert-manager",
    release_name = RELEASE_NAME,
    release_namespace = RELEASE_NAMESPACE,
    values = {
        # Set creator to "static", so the Helm chart does
        # not add Helm-specific labels to the resources.
        "creator": "static",
        "startupapicheck.enabled": "false",
    },
)

licensed_file(
    name = "cert-manager.crds.yaml",
    src = "//deploy/crds",
)

genrule(
    name = "unlicensed",
    srcs = [
        "//deploy/crds",
        "01-namespace.yaml",
        "manifests.helm",
    ],
    outs = ["unlicensed.yaml"],
    cmd = " ".join([
        "cat",
        "$(location //deploy/crds:crds)",
        "$(location 01-namespace.yaml)",
        "$(location manifests.helm)",
        "> $@",
    ]),
)

licensed_file(
    name = "cert-manager.yaml",
    src = ":unlicensed",
)

pkg_tar(
    name = "manifests",
    srcs = [
        ":cert-manager.crds.yaml",
        ":cert-manager.yaml",
    ],
    extension = "tar.gz",
    mode = "0644",
    package_dir = "manifests",
    strip_prefix = ".",
)

filegroup(
    name = "package-srcs",
    srcs = glob(["**"]),
    tags = ["automanaged"],
    visibility = ["//visibility:private"],
)

filegroup(
    name = "all-srcs",
    srcs = [":package-srcs"],
    tags = ["automanaged"],
    visibility = ["//visibility:public"],
)
