Skip to content

Commit ecb6cae

Browse files
committed
tag all targets generated by k8s_deploy (#36)
1 parent 2eef5b8 commit ecb6cae

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ When you run `bazel run ///helloworld:mynamespace.apply`, it applies this file i
8686
| ***release_branch_prefix*** | `master` | A git branch name/prefix. Automatically run GitOps while building this branch. See [GitOps and Deployment](#gitops_and_deployment).
8787
| ***deployment_branch*** | `None` | Automatic GitOps output will appear in a branch and PR with this name. See [GitOps and Deployment](#gitops_and_deployment).
8888
| ***gitops_path*** | `cloud` | Path within the git repo where gitops files get generated into
89+
| ***tags*** | `[]` | A list of tags that will be added to all generated bazel targets. Useful for marking targets as manual.
8990
| ***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).
9091

9192

push_oci/push_oci.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def push_oci(
108108
image_digest_tag = False, # buildifier: disable=unused-variable either remove parameter or implement
109109
tag = None,
110110
remote_tags = None, # file with tags to push
111+
tags = [], # bazel tags to add to the push_oci_rule
111112
visibility = None):
112113
if tag:
113114
tags_label = "_{}_write_tags".format(name)
@@ -128,5 +129,6 @@ def push_oci(
128129
image = image,
129130
repository = repository,
130131
remote_tags = remote_tags,
132+
tags = tags,
131133
visibility = visibility,
132134
)

skylib/k8s.bzl

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ show = rule(
6565
executable = True,
6666
)
6767

68-
def _image_pushes(name_suffix, images, image_registry, image_repository, image_digest_tag):
68+
def _image_pushes(name_suffix, images, image_registry, image_repository, image_digest_tag, tags = []):
6969
image_pushes = []
7070

7171
def process_image(image_label, image_alias = None):
@@ -81,6 +81,7 @@ def _image_pushes(name_suffix, images, image_registry, image_repository, image_d
8181
image_digest_tag = image_digest_tag,
8282
registry = image_registry,
8383
repository = image_repository,
84+
tags = tags,
8485
visibility = ["//visibility:public"],
8586
)
8687
if not image_alias:
@@ -92,6 +93,7 @@ def _image_pushes(name_suffix, images, image_registry, image_repository, image_d
9293
name = rule_name + "_alias_" + name_suffix,
9394
alias = image_alias,
9495
pushed_image = rule_name + name_suffix,
96+
tags = tags,
9597
visibility = ["//visibility:public"],
9698
)
9799
return rule_name + "_alias_" + name_suffix
@@ -106,10 +108,6 @@ def _image_pushes(name_suffix, images, image_registry, image_repository, image_d
106108
push = process_image(image)
107109
image_pushes.append(push)
108110
return image_pushes
109-
for image in images:
110-
image_push = process_image(image)
111-
image_pushes.append(image_push)
112-
return image_pushes
113111

114112
def k8s_deploy(
115113
name, # name of the rule is important for gitops, since it will become a part of the target manifest file name in /cloud
@@ -144,6 +142,7 @@ def k8s_deploy(
144142
release_branch_prefix = "main",
145143
start_tag = "{{",
146144
end_tag = "}}",
145+
tags = [], # tags to add to all generated rules.
147146
visibility = None):
148147
""" k8s_deploy
149148
"""
@@ -175,6 +174,7 @@ def k8s_deploy(
175174
image_registry = image_registry + "/mynamespace",
176175
image_repository = image_repository,
177176
image_digest_tag = image_digest_tag,
177+
tags = tags,
178178
)
179179
kustomize(
180180
name = name,
@@ -200,6 +200,7 @@ def k8s_deploy(
200200
image_name_patches = image_name_patches,
201201
image_tag_patches = image_tag_patches,
202202
openapi_path = openapi_path,
203+
tags = tags,
203204
visibility = visibility,
204205
)
205206
kubectl(
@@ -208,6 +209,7 @@ def k8s_deploy(
208209
cluster = cluster,
209210
user = user,
210211
namespace = namespace,
212+
tags = tags,
211213
visibility = visibility,
212214
)
213215
kubectl(
@@ -218,12 +220,14 @@ def k8s_deploy(
218220
push = False,
219221
user = user,
220222
namespace = namespace,
223+
tags = tags,
221224
visibility = visibility,
222225
)
223226
show(
224227
name = name + ".show",
225228
namespace = namespace,
226229
src = name,
230+
tags = tags,
227231
visibility = visibility,
228232
)
229233
else:
@@ -236,6 +240,7 @@ def k8s_deploy(
236240
image_registry = image_registry,
237241
image_repository = image_repository,
238242
image_digest_tag = image_digest_tag,
243+
tags = tags,
239244
)
240245
kustomize(
241246
name = name,
@@ -261,13 +266,15 @@ def k8s_deploy(
261266
image_name_patches = image_name_patches,
262267
image_tag_patches = image_tag_patches,
263268
openapi_path = openapi_path,
269+
tags = tags,
264270
)
265271
kubectl(
266272
name = name + ".apply",
267273
srcs = [name],
268274
cluster = cluster,
269275
user = user,
270276
namespace = namespace,
277+
tags = tags,
271278
visibility = visibility,
272279
)
273280
kustomize_gitops(
@@ -282,12 +289,14 @@ def k8s_deploy(
282289
],
283290
deployment_branch = deployment_branch,
284291
release_branch_prefix = release_branch_prefix,
292+
tags = tags,
285293
visibility = ["//visibility:public"],
286294
)
287295
show(
288296
name = name + ".show",
289297
src = name,
290298
namespace = namespace,
299+
tags = tags,
291300
visibility = visibility,
292301
)
293302

0 commit comments

Comments
 (0)