Skip to content

Commit

Permalink
[etcd] Bump go package to v3.5.3
Browse files Browse the repository at this point in the history
Upgrading etcd golang libraries to the version that mitigates a critical
issue which leds to data corruption --> https://github.com/ahrtr/etcd-issues/tree/master/issues/13766

Signed-off-by: dntosas <[email protected]>
  • Loading branch information
dntosas committed Apr 14, 2022
1 parent 70c9771 commit 5adc0a2
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@

# Writing a ClusterClass

A ClusterClass becomes more useful and valuable when it can be used to create many Cluster of a similar
shape. The goal of this document is to explain how ClusterClasses can be written in a way that they are
A ClusterClass becomes more useful and valuable when it can be used to create many Cluster of a similar
shape. The goal of this document is to explain how ClusterClasses can be written in a way that they are
flexible enough to be used in as many Cluster as possible by supporting variants of the same base Cluster shape.

**Table of Contents**

* [Basic ClusterClass](#basic-clusterclass)
* [ClusterClass with MachineHealthChecks](#clusterclass-with-machinehealthchecks)
* [ClusterClass with patches](#clusterclass-with-patches)
* [Advanced features of ClusterClass with patches](#advanced-features-of-clusterclass-with-patches)
* [MachineDeployment variable overrides](#machinedeployment-variable-overrides)
* [Builtin variables](#builtin-variables)
* [Complex variable types](#complex-variable-types)
* [Using variable values in JSON patches](#using-variable-values-in-json-patches)
* [Optional patches](#optional-patches)
- [Writing a ClusterClass](#writing-a-clusterclass)
- [Basic ClusterClass](#basic-clusterclass)
- [ClusterClass with MachineHealthChecks](#clusterclass-with-machinehealthchecks)
- [ClusterClass with patches](#clusterclass-with-patches)
- [Advanced features of ClusterClass with patches](#advanced-features-of-clusterclass-with-patches)
- [MachineDeployment variable overrides](#machinedeployment-variable-overrides)
- [Builtin variables](#builtin-variables)
- [Complex variable types](#complex-variable-types)
- [Using variable values in JSON patches](#using-variable-values-in-json-patches)
- [Optional patches](#optional-patches)

## Basic ClusterClass

The following example shows a basic ClusterClass. It contains templates to shape the control plane,
infrastructure and workers of a Cluster. When a Cluster is using this ClusterClass, the templates
The following example shows a basic ClusterClass. It contains templates to shape the control plane,
infrastructure and workers of a Cluster. When a Cluster is using this ClusterClass, the templates
are used to generate the objects of the managed topology of the Cluster.

```yaml
Expand Down Expand Up @@ -65,9 +66,9 @@ spec:
namespace: default
```
The following example shows a Cluster using this ClusterClass. In this case a `KubeadmControlPlane`
with the corresponding `DockerMachineTemplate`, a `DockerCluster` and a `MachineDeployment` with
the corresponding `KubeadmConfigTemplate` and `DockerMachineTemplate` will be created. This basic
The following example shows a Cluster using this ClusterClass. In this case a `KubeadmControlPlane`
with the corresponding `DockerMachineTemplate`, a `DockerCluster` and a `MachineDeployment` with
the corresponding `KubeadmConfigTemplate` and `DockerMachineTemplate` will be created. This basic
ClusterClass is already very flexible. Via the topology on the Cluster the following can be configured:
* `.spec.topology.version`: the Kubernetes version of the Cluster
* `.spec.topology.controlPlane`: ControlPlane replicas and their metadata
Expand All @@ -86,7 +87,7 @@ spec:
replicas: 3
metadata:
labels:
cpLabel: cpLabelValue
cpLabel: cpLabelValue
annotations:
cpAnnotation: cpAnnotationValue
workers:
Expand All @@ -103,10 +104,10 @@ spec:
```

Best practices:
* The ClusterClass name should be generic enough to make sense across multiple clusters, i.e. a
* The ClusterClass name should be generic enough to make sense across multiple clusters, i.e. a
name which corresponds to a single Cluster, e.g. "my-cluster", is not recommended.
* Try to keep the ClusterClass names short and consistent (if you publish multiple ClusterClasses).
* As a ClusterClass usually evolves over time and you might want to rebase Clusters from one version
* As a ClusterClass usually evolves over time and you might want to rebase Clusters from one version
of a ClusterClass to another, consider including a version suffix in the ClusterClass name.
For more information about changing a ClusterClass please see: [Changing a ClusterClass].
* Prefix the templates used in a ClusterClass with the name of the ClusterClass.
Expand All @@ -133,8 +134,8 @@ For more details please see: [clusterctl alpha topology plan].

## ClusterClass with MachineHealthChecks

`MachineHealthChecks` can be configured in the ClusterClass for the control plane and for a
MachineDeployment class. The following configuration makes sure a `MachineHealthCheck` is
`MachineHealthChecks` can be configured in the ClusterClass for the control plane and for a
MachineDeployment class. The following configuration makes sure a `MachineHealthCheck` is
created for the control plane and for every `MachineDeployment` using the `default-worker` class.

```yaml
Expand Down Expand Up @@ -173,20 +174,20 @@ spec:

## ClusterClass with patches

As shown above, basic ClusterClasses are already very powerful. But there are cases where
more powerful mechanisms are required. Let's assume you want to manage multiple Clusters
with the same ClusterClass, but they require different values for a field in one of the
As shown above, basic ClusterClasses are already very powerful. But there are cases where
more powerful mechanisms are required. Let's assume you want to manage multiple Clusters
with the same ClusterClass, but they require different values for a field in one of the
referenced templates of a ClusterClass.

A concrete example would be to deploy Clusters with different registries. In this case,
every cluster needs a Cluster-specific value for `.spec.kubeadmConfigSpec.clusterConfiguration.imageRepository`
A concrete example would be to deploy Clusters with different registries. In this case,
every cluster needs a Cluster-specific value for `.spec.kubeadmConfigSpec.clusterConfiguration.imageRepository`
in `KubeadmControlPlane`. Use cases like this can be implemented with ClusterClass patches.

**Defining variables in the ClusterClass**

The following example shows how variables can be defined in the ClusterClass.
A variable definition specifies the name and the schema of a variable and if it is
required. The schema defines how a variable is defaulted and validated. It supports
A variable definition specifies the name and the schema of a variable and if it is
required. The schema defines how a variable is defaulted and validated. It supports
a subset of the schema of CRDs. For more information please see the [godoc](https://doc.crds.dev/github.com/kubernetes-sigs/cluster-api/cluster.x-k8s.io/ClusterClass/v1beta1#spec-variables-schema-openAPIV3Schema).

```yaml
Expand All @@ -211,17 +212,17 @@ spec:

<h1>Supported types</h1>

The following basic types are supported: `string`, `integer`, `number` and `boolean`. We are also
The following basic types are supported: `string`, `integer`, `number` and `boolean`. We are also
supporting complex types, please see the [complex variables](#complex-variables) section.

</aside>

**Defining patches in the ClusterClass**

The variable can then be used in a patch to set a field on a template referenced in the ClusterClass.
The `selector` specifies on which template the patch should be applied. `jsonPatches` specifies which JSON
patches should be applied to that template. In this case we set the `imageRepository` field of the
`KubeadmControlPlaneTemplate` to the value of the variable `imageRepository`. For more information
The `selector` specifies on which template the patch should be applied. `jsonPatches` specifies which JSON
patches should be applied to that template. In this case we set the `imageRepository` field of the
`KubeadmControlPlaneTemplate` to the value of the variable `imageRepository`. For more information
please see the [godoc](https://doc.crds.dev/github.com/kubernetes-sigs/cluster-api/cluster.x-k8s.io/ClusterClass/v1beta1#spec-patches-definitions).

```yaml
Expand Down Expand Up @@ -252,7 +253,7 @@ spec:

* Only fields below `/spec` can be patched.
* Only `add`, `remove` and `replace` operations are supported.
* It's only possible to append and prepend to arrays. Insertions at a specific index are
* It's only possible to append and prepend to arrays. Insertions at a specific index are
not supported.
* Be careful, appending or prepending an array variable to an array leads to a nested array
(for more details please see this [issue](https://github.com/kubernetes-sigs/cluster-api/issues/5944)).
Expand All @@ -261,7 +262,7 @@ spec:

**Setting variable values in the Cluster**

After creating a ClusterClass with a variable definition, the user can now provide a value for
After creating a ClusterClass with a variable definition, the user can now provide a value for
the variable in the Cluster as in the example below.

```yaml
Expand Down Expand Up @@ -378,19 +379,19 @@ spec:

### Builtin variables

In addition to variables specified in the ClusterClass, the following builtin variables can be
In addition to variables specified in the ClusterClass, the following builtin variables can be
referenced in patches:
- `builtin.cluster.{name,namespace}`
- `builtin.cluster.topology.{version,class}`
- `builtin.cluster.network.{serviceDomain,services,pods,ipFamily}`
- `builtin.controlPlane.{replicas,version,name}`
- Please note, these variables are only available when patching control plane or control plane
- Please note, these variables are only available when patching control plane or control plane
machine templates.
- `builtin.controlPlane.machineTemplate.infrastructureRef.name`
- Please note, these variables are only available when using a control plane with machines and
- Please note, these variables are only available when using a control plane with machines and
when patching control plane or control plane machine templates.
- `builtin.machineDeployment.{replicas,version,class,name,topologyName}`
- Please note, these variables are only available when patching the templates of a MachineDeployment
- Please note, these variables are only available when patching the templates of a MachineDeployment
and contain the values of the current `MachineDeployment` topology.
- `builtin.machineDeployment.{infrastructureRef.name,bootstrap.configRef.name}`
- Please note, these variables are only available when patching the templates of a MachineDeployment
Expand Down Expand Up @@ -418,8 +419,8 @@ spec:

**Tips & Tricks**

Builtin variables can be used to dynamically calculate image names. The version used in the patch
will always be the same as the one we set in the corresponding MachineDeployment (works the same way
Builtin variables can be used to dynamically calculate image names. The version used in the patch
will always be the same as the one we set in the corresponding MachineDeployment (works the same way
with `.builtin.controlPlane.version`).

```yaml
Expand Down Expand Up @@ -451,7 +452,7 @@ spec:
### Complex variable types

Variables can also be objects, maps and arrays. An object is specified with the type `object` and
by the schemas of the fields of the object. A map is specified with the type `object` and the schema
by the schemas of the fields of the object. A map is specified with the type `object` and the schema
of the map values. An array is specified via the type `array` and the schema of the array items.

```yaml
Expand All @@ -466,9 +467,9 @@ spec:
schema:
openAPIV3Schema:
type: object
properties:
properties:
# Schema of the url field.
url:
url:
type: string
# Schema of the noProxy field.
noProxy:
Expand Down Expand Up @@ -527,7 +528,7 @@ spec:
**Tips & Tricks**

Complex variables can be used to make references in templates configurable, e.g. the `identityRef` used in `AzureCluster`.
Of course it's also possible to only make the name of the reference configurable, including restricting the valid values
Of course it's also possible to only make the name of the reference configurable, including restricting the valid values
to a pre-defined enum.

```yaml
Expand All @@ -551,7 +552,7 @@ spec:

### Using variable values in JSON patches

We already saw above that it's possible to use variable values in JSON patches. It's also
We already saw above that it's possible to use variable values in JSON patches. It's also
possible to calculate values via Go templating or to use hard-coded values.

```yaml
Expand All @@ -570,11 +571,11 @@ spec:
- op: add
path: /spec/template/spec/kubeadmConfigSpec/clusterConfiguration/etcd
valueFrom:
# This template is first rendered with Go templating, then parsed by
# This template is first rendered with Go templating, then parsed by
# a YAML/JSON parser and then used as value of the JSON patch.
# For example, if the variable etcdImageTag is set to `3.5.1-0` the
# For example, if the variable etcdImageTag is set to `3.5.3-0` the
# .../clusterConfiguration/etcd field will be set to:
# {"local": {"imageTag": "3.5.1-0"}}
# {"local": {"imageTag": "3.5.3-0"}}
template: |
local:
imageTag: {{ .etcdImageTag }}
Expand Down Expand Up @@ -606,7 +607,7 @@ Templates can be used to implement defaulting behavior during JSON patch value c
constant default value which can be specified in the schema is not enough.
```yaml
valueFrom:
# If .vnetName is set, it is used. Otherwise, we will use `{{.builtin.cluster.name}}-vnet`.
# If .vnetName is set, it is used. Otherwise, we will use `{{.builtin.cluster.name}}-vnet`.
template: "{{ if .vnetName }}{{.vnetName}}{{else}}{{.builtin.cluster.name}}-vnet{{end}}"
```
When writing templates, a subset of functions from [the sprig library](http://masterminds.github.io/sprig/) can be used to
Expand All @@ -615,8 +616,8 @@ for a given input are allowed (e.g. `upper` or `max` can be used, while `now` or

### Optional patches

Patches can also be conditionally enabled. This can be done by configuring a Go template via `enabledIf`.
The patch is then only applied if the Go template evaluates to `true`. In the following example the `httpProxy`
Patches can also be conditionally enabled. This can be done by configuring a Go template via `enabledIf`.
The patch is then only applied if the Go template evaluates to `true`. In the following example the `httpProxy`
patch is only applied if the `httpProxy` variable is set (and not empty).

```yaml
Expand All @@ -635,7 +636,7 @@ spec:
- name: httpProxy
enabledIf: "{{ if .httpProxy }}true{{end}}"
definitions:
...
...
```

**Tips & Tricks**:
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.10.1
github.com/valyala/fastjson v1.6.3
go.etcd.io/etcd/api/v3 v3.5.1
go.etcd.io/etcd/client/v3 v3.5.1
go.etcd.io/etcd/api/v3 v3.5.3
go.etcd.io/etcd/client/v3 v3.5.3
golang.org/x/net v0.0.0-20211209124913-491a49abca63
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
google.golang.org/grpc v1.43.0
Expand Down Expand Up @@ -117,7 +117,7 @@ require (
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_golang v1.11.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.28.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
Expand All @@ -132,7 +132,7 @@ require (
github.com/subosito/gotenv v1.2.0 // indirect
github.com/vincent-petithory/dataurl v1.0.0 // indirect
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.1 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.3 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3O
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.11.0 h1:HNkLOAEQMIDv/K+04rukrLx6ch7msSRwf3/SASFAGtQ=
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_golang v1.11.1 h1:+4eQaD7vAZ6DsfsxB15hbE0odUjGI5ARs9yskGu1v4s=
github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down Expand Up @@ -700,14 +702,20 @@ go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4=
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM=
go.etcd.io/etcd/api/v3 v3.5.1/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
go.etcd.io/etcd/api/v3 v3.5.3 h1:QmhsZfmMpCT6M7EwRVSPJFfKOOGgo+MeUDfSZngfeso=
go.etcd.io/etcd/api/v3 v3.5.3/go.mod h1:5GB2vv4A4AOn3yk7MftYGHkUfGtDHnEraIjym4dYz5A=
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/pkg/v3 v3.5.1 h1:XIQcHCFSG53bJETYeRJtIxdLv2EWRGxcfzR8lSnTH4E=
go.etcd.io/etcd/client/pkg/v3 v3.5.1/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/pkg/v3 v3.5.3 h1:QvFISaDSofVNt2sWwM1lJLHNZNjkuJjYOU+cIYBQcoQ=
go.etcd.io/etcd/client/pkg/v3 v3.5.3/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
go.etcd.io/etcd/client/v2 v2.305.1/go.mod h1:pMEacxZW7o8pg4CrFE7pquyCJJzZvkvdD2RibOCCCGs=
go.etcd.io/etcd/client/v3 v3.5.0/go.mod h1:AIKXXVX/DQXtfTEqBryiLTUXwON+GuvO6Z7lLS/oTh0=
go.etcd.io/etcd/client/v3 v3.5.1 h1:oImGuV5LGKjCqXdjkMHCyWa5OO1gYKCnC/1sgdfj1Uk=
go.etcd.io/etcd/client/v3 v3.5.1/go.mod h1:OnjH4M8OnAotwaB2l9bVgZzRFKru7/ZMoS46OtKyd3Q=
go.etcd.io/etcd/client/v3 v3.5.3 h1:2Yli1O50DkVHrEvli5CbrRJJCdqymxNAgY67D5r3WwI=
go.etcd.io/etcd/client/v3 v3.5.3/go.mod h1:S9LzGLV7Kh1Rg85nMVMjloLdUSMu+wvZZXPcUXDQ2Ds=
go.etcd.io/etcd/pkg/v3 v3.5.0/go.mod h1:UzJGatBQ1lXChBkQF0AuAtkRQMYnHubxAEYIrC3MSsE=
go.etcd.io/etcd/raft/v3 v3.5.0/go.mod h1:UFOHSIvO/nKwd4lhkwabrTD3cqW5yVyYYf/KlD00Szc=
go.etcd.io/etcd/server/v3 v3.5.0/go.mod h1:3Ah5ruV+M+7RZr0+Y/5mNLwC+eQlni+mQmOVdCRJoS4=
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/config/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ variables:
KUBERNETES_VERSION: "v1.23.4"
KUBERNETES_VERSION_UPGRADE_FROM: "v1.22.7"
KUBERNETES_VERSION_UPGRADE_TO: "v1.23.4"
ETCD_VERSION_UPGRADE_TO: "3.5.1-0"
ETCD_VERSION_UPGRADE_TO: "3.5.3-0"
COREDNS_VERSION_UPGRADE_TO: "v1.8.6"
DOCKER_SERVICE_DOMAIN: "cluster.local"
IP_FAMILY: "IPv4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
openAPIV3Schema:
type: string
default: ""
example: "3.5.1-0"
example: "3.5.3-0"
description: "etcdImageTag is the tag for the etcd image."
- name: coreDNSImageTag
required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
openAPIV3Schema:
type: string
default: ""
example: "3.5.1-0"
example: "3.5.3-0"
description: "etcdImageTag sets the tag for the etcd image."
- name: coreDNSImageTag
required: true
Expand Down

0 comments on commit 5adc0a2

Please sign in to comment.