Skip to content

Commit

Permalink
refactor(etcd-operator): Remove kausal from root element (#480)
Browse files Browse the repository at this point in the history
Instead, declare it explicitly, because it is an implementation detail
that is leaking to the consumers of the libraries, polluting the root
element.

Particularly, this solves one use case, which is importing
`etcd_cluster`:

```
local etcd_cluster = import 'etcd-operator/etcd-cluster.libsonnet';

{
  etcd_cluster: etcd_cluster.etcd_cluster('etcd')
}
```

won't work if kausal is not available on the root element.

To solve that we would need to do:

```
local etcd_cluster = import 'etcd-operator/etcd-cluster.libsonnet';
local k = import 'ksonnet-util/kausal.libsonnet';

{
  etcd_cluster: (k + etcd_cluster).etcd_cluster('etcd')
}
```

For what is worth, that behaviour was not present when importing
'etcd-operator/etcd-operator.libsonnet'.
  • Loading branch information
jvrplmlmn authored Mar 1, 2021
1 parent c3e89e7 commit 815b036
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions etcd-operator/etcd-cluster.libsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
local podAntiAffinity = $.apps.v1.deployment.mixin.spec.template.spec.affinity.podAntiAffinity,
local k = import 'ksonnet-util/kausal.libsonnet',
local podAntiAffinity = k.apps.v1.deployment.mixin.spec.template.spec.affinity.podAntiAffinity,

etcd_cluster(name, size=3, version='3.3.13', env=[]):: {
apiVersion: 'etcd.database.coreos.com/v1beta2',
Expand Down Expand Up @@ -29,8 +30,8 @@
} + (
// Run etcd with the Burstable QoS class, and without a CPU limit
// to avoid CFS throttling (best for low latency)
$.util.resourcesRequests('500m', '512Mi') +
$.util.resourcesLimits(null, '512Mi')
k.util.resourcesRequests('500m', '512Mi') +
k.util.resourcesLimits(null, '512Mi')
),
},
},
Expand Down
1 change: 0 additions & 1 deletion etcd-operator/etcd-operator.libsonnet
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
(import 'ksonnet-util/kausal.libsonnet') +
(import 'operator.libsonnet') +
(import 'etcd-cluster.libsonnet')
15 changes: 8 additions & 7 deletions etcd-operator/operator.libsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
operator: 'quay.io/coreos/etcd-operator:v0.9.4',
},

local policyRule = $.rbac.v1beta1.policyRule,
local k = import 'ksonnet-util/kausal.libsonnet',
local policyRule = k.rbac.v1beta1.policyRule,

operator_rbac:
$.util.rbac('etcd-operator', [
k.util.rbac('etcd-operator', [
policyRule.new() +
policyRule.withApiGroups(['etcd.database.coreos.com']) +
policyRule.withResources(['etcdclusters', 'etcdbackups', 'etcdrestores']) +
Expand All @@ -28,7 +29,7 @@
policyRule.withVerbs(['*']),
]),

local container = $.core.v1.container,
local container = k.core.v1.container,
local env = container.envType,
operator_container::
container.new('operator', $._images.operator) +
Expand All @@ -38,11 +39,11 @@
env.fromFieldPath('MY_POD_NAMESPACE', 'metadata.namespace'),
env.fromFieldPath('MY_POD_NAME', 'metadata.name'),
]) +
container.withPorts([$.core.v1.containerPort.new('http-metrics', 8080)]) +
$.util.resourcesRequests('500m', '200Mi') +
$.util.resourcesLimits('1', '500Mi'),
container.withPorts([k.core.v1.containerPort.new('http-metrics', 8080)]) +
k.util.resourcesRequests('500m', '200Mi') +
k.util.resourcesLimits('1', '500Mi'),

local deployment = $.apps.v1.deployment,
local deployment = k.apps.v1.deployment,

operator_deployment:
deployment.new('etcd-operator', 1, [$.operator_container]) +
Expand Down

0 comments on commit 815b036

Please sign in to comment.