Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of bazel tags to rules_gitops #148

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ When you run `bazel run ///helloworld:mynamespace.apply`, it applies this file i
| ***release_branch_prefix*** | `master` | A git branch name/prefix. Automatically run GitOps while building this branch. See [GitOps and Deployment](#gitops_and_deployment).
| ***deployment_branch*** | `None` | Automatic GitOps output will appear in a branch and PR with this name. See [GitOps and Deployment](#gitops_and_deployment).
| ***gitops_path*** | `cloud` | Path within the git repo where gitops files get generated into
| ***tags*** | `[]` | See [Bazel docs on tags](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes).
| ***visibility*** | [Default_visibility](https://docs.bazel.build/versions/master/be/functions.html#package.default_visibility) | Changes the visibility of all rules generated by this macro. See [Bazel docs on visibility](https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes).


Expand Down
1 change: 1 addition & 0 deletions examples/helloworld/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ k8s_deploy(
"service.yaml",
],
namespace = NAMESPACE,
tags = ["release"],
user = USER,
)

Expand Down
14 changes: 13 additions & 1 deletion skylib/k8s.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ show = rule(
executable = True,
)

def _image_pushes(name_suffix, images, image_registry, image_repository, image_repository_prefix, image_digest_tag):
def _image_pushes(name_suffix, images, image_registry, image_repository, image_repository_prefix, image_digest_tag, tags):
image_pushes = []

def process_image(image_label, legacy_name = None):
Expand All @@ -91,6 +91,7 @@ def _image_pushes(name_suffix, images, image_registry, image_repository, image_r
registry = image_registry,
repository = image_repository,
repository_prefix = image_repository_prefix,
tags = tags,
)
return rule_name + name_suffix

Expand Down Expand Up @@ -138,6 +139,7 @@ def k8s_deploy(
release_branch_prefix = "main",
start_tag = "{{",
end_tag = "}}",
tags = [],
visibility = None):
""" k8s_deploy
"""
Expand Down Expand Up @@ -170,6 +172,7 @@ def k8s_deploy(
image_repository = image_repository,
image_repository_prefix = "{BUILD_USER}",
image_digest_tag = image_digest_tag,
tags = tags,
)
kustomize(
name = name,
Expand All @@ -194,6 +197,7 @@ def k8s_deploy(
objects = objects,
image_name_patches = image_name_patches,
image_tag_patches = image_tag_patches,
tags = tags,
visibility = visibility,
)
kubectl(
Expand All @@ -202,6 +206,7 @@ def k8s_deploy(
cluster = cluster,
user = user,
namespace = namespace,
tags = tags,
visibility = visibility,
)
kubectl(
Expand All @@ -212,12 +217,14 @@ def k8s_deploy(
push = False,
user = user,
namespace = namespace,
tags = tags,
visibility = visibility,
)
show(
name = name + ".show",
namespace = namespace,
src = name,
tags = tags,
visibility = visibility,
)
else:
Expand All @@ -231,6 +238,7 @@ def k8s_deploy(
image_repository = image_repository,
image_repository_prefix = image_repository_prefix,
image_digest_tag = image_digest_tag,
tags = tags,
)
kustomize(
name = name,
Expand All @@ -255,13 +263,15 @@ def k8s_deploy(
patches = patches,
image_name_patches = image_name_patches,
image_tag_patches = image_tag_patches,
tags = tags,
)
kubectl(
name = name + ".apply",
srcs = [name],
cluster = cluster,
user = user,
namespace = namespace,
tags = tags,
visibility = visibility,
)
kustomize_gitops(
Expand All @@ -276,12 +286,14 @@ def k8s_deploy(
],
deployment_branch = deployment_branch,
release_branch_prefix = release_branch_prefix,
tags = tags,
visibility = ["//visibility:public"],
)
show(
name = name + ".show",
src = name,
namespace = namespace,
tags = tags,
visibility = visibility,
)

Expand Down