Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
Make the namespace attribute on k8s_object optional.
Browse files Browse the repository at this point in the history
Only pass the --namespace parameter to kubectl if the namespace attribute
is specified. This will let people specify this in the deployment template
instead.

See #81
  • Loading branch information
ensonic committed Dec 5, 2017
1 parent 1fd1cbb commit d1737c1
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ A rule for interacting with Kubernetes objects.
<p><code>string, optional</code></p>
<p>The namespace on the cluster within which the actions are
performed.</p>
<p><b>If this is omitted, it will default to
<p><b>If this is omitted, it will default to the value specified
in the template or if also unspecified there, to the value
<code>"default"</code>.</b></p>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion k8s/apply.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ function guess_runfiles() {
RUNFILES="${PYTHON_RUNFILES:-$(guess_runfiles)}"

PYTHON_RUNFILES=${RUNFILES} %{resolve_script} | \
kubectl --cluster="%{cluster}" --namespace="%{namespace}" apply -f -
kubectl --cluster="%{cluster}" %{namespace_arg} apply -f -
2 changes: 1 addition & 1 deletion k8s/create.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ RUNFILES="${PYTHON_RUNFILES:-$(guess_runfiles)}"
# TODO(mattmoor): Should we create namespaces that do not exist?

PYTHON_RUNFILES=${RUNFILES} %{resolve_script} | \
kubectl --cluster="%{cluster}" --namespace="%{namespace}" create -f -
kubectl --cluster="%{cluster}" %{namespace_arg} create -f -
3 changes: 1 addition & 2 deletions k8s/delete.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ function guess_runfiles() {

RUNFILES="${PYTHON_RUNFILES:-$(guess_runfiles)}"

kubectl --cluster="%{cluster}" --namespace="%{namespace}" delete \
-f %{unresolved}
kubectl --cluster="%{cluster}" %{namespace_arg} delete k8s/...-f %{unresolved}
4 changes: 2 additions & 2 deletions k8s/describe.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ RUNFILES="${PYTHON_RUNFILES:-$(guess_runfiles)}"

RESOURCE_NAME=$(kubectl create --dry-run -f "%{unresolved}" | cut -d'"' -f 2)

kubectl --cluster="%{cluster}" --namespace="%{namespace}" \
describe %{kind} "${RESOURCE_NAME}"
kubectl --cluster="%{cluster}" %{namespace_arg} describe %{kind} \
"${RESOURCE_NAME}"
5 changes: 4 additions & 1 deletion k8s/object.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ def _common_impl(ctx):
namespace_arg = "$(cat %s)" % _runfiles(ctx, namespace_file)
files += [namespace_file]

if namespace_arg:
namespace_arg = "--namespace=\"" + namespace_arg + "\""

substitutions = {
"%{cluster}": cluster_arg,
"%{namespace}": namespace_arg,
"%{namespace_arg}": namespace_arg,
"%{kind}": ctx.attr.kind,
}

Expand Down
2 changes: 1 addition & 1 deletion k8s/replace.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ function guess_runfiles() {
RUNFILES="${PYTHON_RUNFILES:-$(guess_runfiles)}"

PYTHON_RUNFILES=${RUNFILES} %{resolve_script} | \
kubectl --cluster="%{cluster}" --namespace="%{namespace}" replace -f -
kubectl --cluster="%{cluster}" %{namespace_arg} replace -f -

0 comments on commit d1737c1

Please sign in to comment.