Skip to content

Commit

Permalink
Merge pull request #609 from planetscale/backport-524-to-release-11
Browse files Browse the repository at this point in the history
[release-2.11] Add support for user-defined per-keyspace images
  • Loading branch information
frouioui authored Oct 8, 2024
2 parents 0523c68 + f6ffa05 commit 5ef37db
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 33 deletions.
10 changes: 10 additions & 0 deletions deploy/crds/planetscale.com_vitessclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,16 @@ spec:
type: string
durabilityPolicy:
type: string
images:
properties:
mysqld:
properties:
mysql56Compatible:
type: string
mysql80Compatible:
type: string
type: object
type: object
name:
maxLength: 63
minLength: 1
Expand Down
121 changes: 110 additions & 11 deletions docs/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1418,9 +1418,7 @@ <h3 id="planetscale.com/v2.MysqldImage">MysqldImage
<a href="#planetscale.com/v2.VitessKeyspaceImages">VitessKeyspaceImages</a>)
</p>
<p>
<p>MysqldImage specifies the container image to use for mysqld,
as well as declaring which MySQL flavor setting in Vitess the
image is compatible with.</p>
<p>TODO: Remove this once everything is migrated to MysqldImageNew.</p>
</p>
<table class="table table-striped">
<thead class="thead-dark">
Expand Down Expand Up @@ -1480,6 +1478,52 @@ <h3 id="planetscale.com/v2.MysqldImage">MysqldImage
</tr>
</tbody>
</table>
<h3 id="planetscale.com/v2.MysqldImageNew">MysqldImageNew
</h3>
<p>
(<em>Appears on:</em>
<a href="#planetscale.com/v2.VitessKeyspaceTemplateImages">VitessKeyspaceTemplateImages</a>)
</p>
<p>
<p>MysqldImageNew specifies the container image to use for mysqld,
as well as declaring which MySQL flavor setting in Vitess the
image is compatible with.</p>
<p>TODO: rename this to MysqldImage once MysqldImage is removed.</p>
</p>
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>mysql56Compatible</code></br>
<em>
string
</em>
</td>
<td>
<p>Mysql56Compatible is a container image (including version tag) for mysqld
that&rsquo;s compatible with the Vitess &ldquo;MySQL56&rdquo; flavor setting.</p>
</td>
</tr>
<tr>
<td>
<code>mysql80Compatible</code></br>
<em>
string
</em>
</td>
<td>
<p>Mysql80Compatible is a container image (including version tag) for mysqld
that&rsquo;s compatible with the Vitess &ldquo;MySQL80&rdquo; flavor setting.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="planetscale.com/v2.MysqldSpec">MysqldSpec
</h3>
<p>
Expand Down Expand Up @@ -4738,10 +4782,12 @@ <h3 id="planetscale.com/v2.VitessKeyspace">VitessKeyspace
</em>
</td>
<td>
<p>Images are not customizable by users at the keyspace level because version
skew across the cluster is discouraged except during rolling updates,
in which case this field is automatically managed by the VitessCluster
controller that owns this VitessKeyspace.</p>
<p>Images are inherited from the VitessCluster spec, unless the user has
specified keyspace-level overrides. Version skew across the cluster is
discouraged except during rolling updates, in which case this field is
automatically managed by the VitessCluster controller that owns this
VitessKeyspace, or else when a user has specified a keyspace-level
images on VitessKeyspaceTemplate.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -5525,10 +5571,12 @@ <h3 id="planetscale.com/v2.VitessKeyspaceSpec">VitessKeyspaceSpec
</em>
</td>
<td>
<p>Images are not customizable by users at the keyspace level because version
skew across the cluster is discouraged except during rolling updates,
in which case this field is automatically managed by the VitessCluster
controller that owns this VitessKeyspace.</p>
<p>Images are inherited from the VitessCluster spec, unless the user has
specified keyspace-level overrides. Version skew across the cluster is
discouraged except during rolling updates, in which case this field is
automatically managed by the VitessCluster controller that owns this
VitessKeyspace, or else when a user has specified a keyspace-level
images on VitessKeyspaceTemplate.</p>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -5904,6 +5952,57 @@ <h3 id="planetscale.com/v2.VitessKeyspaceTemplate">VitessKeyspaceTemplate
<p>Annotations can optionally be used to attach custom annotations to the VitessKeyspace object.</p>
</td>
</tr>
<tr>
<td>
<code>images</code></br>
<em>
<a href="#planetscale.com/v2.VitessKeyspaceTemplateImages">
VitessKeyspaceTemplateImages
</a>
</em>
</td>
<td>
<p>For special cases, users may specify per-VitessKeyspace images. An
example: migrating from MySQL 5.7 to MySQL 8.0 via a <code>MoveTables</code>
operation, after which the source keyspace is destroyed.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="planetscale.com/v2.VitessKeyspaceTemplateImages">VitessKeyspaceTemplateImages
</h3>
<p>
(<em>Appears on:</em>
<a href="#planetscale.com/v2.VitessKeyspaceTemplate">VitessKeyspaceTemplate</a>)
</p>
<p>
<p>VitessKeyspaceTemplateImages specifies user-definable container images to
use for this keyspace.</p>
</p>
<table class="table table-striped">
<thead class="thead-dark">
<tr>
<th>Field</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<code>mysqld</code></br>
<em>
<a href="#planetscale.com/v2.MysqldImageNew">
MysqldImageNew
</a>
</em>
</td>
<td>
<p>Mysqld specifies the container image to use for mysqld, as well as
declaring which MySQL flavor setting in Vitess the image is
compatible with. Only one flavor image may be provided at a time.
mysqld running alongside each tablet.</p>
</td>
</tr>
</tbody>
</table>
<h3 id="planetscale.com/v2.VitessKeyspaceTurndownPolicy">VitessKeyspaceTurndownPolicy
Expand Down
14 changes: 13 additions & 1 deletion pkg/apis/planetscale/v2/vitesscluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,21 @@ type VitessImages struct {
MysqldExporter string `json:"mysqldExporter,omitempty"`
}

// MysqldImage specifies the container image to use for mysqld,
// MysqldImageNew specifies the container image to use for mysqld,
// as well as declaring which MySQL flavor setting in Vitess the
// image is compatible with.
//
// TODO: rename this to MysqldImage once MysqldImage is removed.
type MysqldImageNew struct {
// Mysql56Compatible is a container image (including version tag) for mysqld
// that's compatible with the Vitess "MySQL56" flavor setting.
Mysql56Compatible string `json:"mysql56Compatible,omitempty"`
// Mysql80Compatible is a container image (including version tag) for mysqld
// that's compatible with the Vitess "MySQL80" flavor setting.
Mysql80Compatible string `json:"mysql80Compatible,omitempty"`
}

// TODO: Remove this once everything is migrated to MysqldImageNew.
type MysqldImage struct {
// Mysql56Compatible is a container image (including version tag) for mysqld
// that's compatible with the Vitess "MySQL56" flavor setting.
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/planetscale/v2/vitesskeyspace_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,12 @@ func DefaultVitessKeyspaceImages(dst *VitessKeyspaceImages, clusterDefaults *Vit
dst.MysqldExporter = clusterDefaults.MysqldExporter
}
}

// MergeVitessKeyspaceTemplateImages takes non-empty image values from a non-nil src
// and sets them on dst.
func MergeVitessKeyspaceTemplateImages(dst *VitessKeyspaceImages, src *VitessKeyspaceTemplateImages) {
if src.Mysqld != nil {
dst.Mysqld.Mysql56Compatible = src.Mysqld.Mysql56Compatible
dst.Mysqld.Mysql80Compatible = src.Mysqld.Mysql80Compatible
}
}
25 changes: 21 additions & 4 deletions pkg/apis/planetscale/v2/vitesskeyspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ type VitessKeyspaceSpec struct {
// GlobalLockserver are the params to connect to the global lockserver.
GlobalLockserver VitessLockserverParams `json:"globalLockserver"`

// Images are not customizable by users at the keyspace level because version
// skew across the cluster is discouraged except during rolling updates,
// in which case this field is automatically managed by the VitessCluster
// controller that owns this VitessKeyspace.
// Images are inherited from the VitessCluster spec, unless the user has
// specified keyspace-level overrides. Version skew across the cluster is
// discouraged except during rolling updates, in which case this field is
// automatically managed by the VitessCluster controller that owns this
// VitessKeyspace, or else when a user has specified a keyspace-level
// images on VitessKeyspaceTemplate.
Images VitessKeyspaceImages `json:"images,omitempty"`

// ImagePullPolicies are inherited from the VitessCluster spec.
Expand Down Expand Up @@ -178,6 +180,21 @@ type VitessKeyspaceTemplate struct {

// Annotations can optionally be used to attach custom annotations to the VitessKeyspace object.
Annotations map[string]string `json:"annotations,omitempty"`

// For special cases, users may specify per-VitessKeyspace images. An
// example: migrating from MySQL 5.7 to MySQL 8.0 via a `MoveTables`
// operation, after which the source keyspace is destroyed.
Images VitessKeyspaceTemplateImages `json:"images,omitempty"`
}

// VitessKeyspaceTemplateImages specifies user-definable container images to
// use for this keyspace.
type VitessKeyspaceTemplateImages struct {
// Mysqld specifies the container image to use for mysqld, as well as
// declaring which MySQL flavor setting in Vitess the image is
// compatible with. Only one flavor image may be provided at a time.
// mysqld running alongside each tablet.
Mysqld *MysqldImageNew `json:"mysqld,omitempty"`
}

// VitessOrchestratorSpec specifies deployment parameters for vtorc.
Expand Down
36 changes: 36 additions & 0 deletions pkg/apis/planetscale/v2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/controller/vitesscluster/reconcile_keyspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ func newVitessKeyspace(key client.ObjectKey, vt *planetscalev2.VitessCluster, pa
images := planetscalev2.VitessKeyspaceImages{}
planetscalev2.DefaultVitessKeyspaceImages(&images, &vt.Spec.Images)

// Apply user-defined overrides for images.
planetscalev2.MergeVitessKeyspaceTemplateImages(&images, &keyspace.Images)

// Copy parent labels map and add keyspace-specific label.
labels := make(map[string]string, len(parentLabels)+1)
for k, v := range parentLabels {
Expand Down
43 changes: 26 additions & 17 deletions test/endtoend/operator/operator-latest.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down Expand Up @@ -2490,6 +2489,16 @@ spec:
type: string
durabilityPolicy:
type: string
images:
properties:
mysqld:
properties:
mysql56Compatible:
type: string
mysql80Compatible:
type: string
type: object
type: object
name:
maxLength: 63
minLength: 1
Expand Down Expand Up @@ -6318,6 +6327,22 @@ subjects:
- kind: ServiceAccount
name: vitess-operator
---
apiVersion: scheduling.k8s.io/v1
description: Vitess components (vttablet, vtgate, vtctld, etcd)
globalDefault: false
kind: PriorityClass
metadata:
name: vitess
value: 1000
---
apiVersion: scheduling.k8s.io/v1
description: The vitess-operator control plane.
globalDefault: false
kind: PriorityClass
metadata:
name: vitess-operator-control-plane
value: 5000
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -6368,19 +6393,3 @@ spec:
memory: 128Mi
priorityClassName: vitess-operator-control-plane
serviceAccountName: vitess-operator
---
apiVersion: scheduling.k8s.io/v1
description: The vitess-operator control plane.
globalDefault: false
kind: PriorityClass
metadata:
name: vitess-operator-control-plane
value: 5000
---
apiVersion: scheduling.k8s.io/v1
description: Vitess components (vttablet, vtgate, vtctld, etcd)
globalDefault: false
kind: PriorityClass
metadata:
name: vitess
value: 1000

0 comments on commit 5ef37db

Please sign in to comment.