From 831f35aefc925d4800cc7a02d4823a492833a044 Mon Sep 17 00:00:00 2001 From: Max Englander Date: Mon, 22 Jan 2024 23:26:56 -0500 Subject: [PATCH 1/3] Add support for user-defined per-keyspace images Signed-off-by: Max Englander --- .../crds/planetscale.com_vitessclusters.yaml | 22 +++++++++++ docs/api/index.html | 37 +++++++++++++++---- .../planetscale/v2/vitesskeyspace_defaults.go | 20 ++++++++++ .../planetscale/v2/vitesskeyspace_types.go | 18 +++++++-- .../planetscale/v2/zz_generated.deepcopy.go | 1 + .../vitesscluster/reconcile_keyspaces.go | 3 ++ 6 files changed, 89 insertions(+), 12 deletions(-) diff --git a/deploy/crds/planetscale.com_vitessclusters.yaml b/deploy/crds/planetscale.com_vitessclusters.yaml index 5b71c6ff..bb7e9ef1 100644 --- a/deploy/crds/planetscale.com_vitessclusters.yaml +++ b/deploy/crds/planetscale.com_vitessclusters.yaml @@ -1172,6 +1172,28 @@ spec: type: string durabilityPolicy: type: string + images: + properties: + mysqld: + properties: + mariadb103Compatible: + type: string + mariadbCompatible: + type: string + mysql56Compatible: + type: string + mysql80Compatible: + type: string + type: object + mysqldExporter: + type: string + vtbackup: + type: string + vtorc: + type: string + vttablet: + type: string + type: object name: maxLength: 63 minLength: 1 diff --git a/docs/api/index.html b/docs/api/index.html index 0e63a8ed..f8e9736f 100644 --- a/docs/api/index.html +++ b/docs/api/index.html @@ -4770,10 +4770,11 @@

VitessKeyspace -

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.

@@ -5078,6 +5079,7 @@

VitessKeyspaceImages

(Appears on: VitessKeyspaceSpec, +VitessKeyspaceTemplate, VitessShardSpec)

@@ -5557,10 +5559,11 @@

VitessKeyspaceSpec -

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.

@@ -5936,6 +5939,24 @@

VitessKeyspaceTemplate

Annotations can optionally be used to attach custom annotations to the VitessKeyspace object.

+ + +images
+ + +VitessKeyspaceImages + + + + +

Users are encouraged to let the VitessCluster controller automatically +propagate image changes from the VitessCluster to the VitessKeyspace +via rolling updates.

+

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.

+ +

VitessKeyspaceTurndownPolicy diff --git a/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go b/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go index 81189b87..47cca2cf 100644 --- a/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go +++ b/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go @@ -69,3 +69,23 @@ func DefaultVitessKeyspaceImages(dst *VitessKeyspaceImages, clusterDefaults *Vit dst.MysqldExporter = clusterDefaults.MysqldExporter } } + +// MergeVitessKeyspaceImages takes non-empty image values from a non-nil src +// and sets them on dst. +func MergeVitessKeyspaceImages(dst *VitessKeyspaceImages, src *VitessKeyspaceImages) { + if src.Vttablet != "" { + dst.Vttablet = src.Vttablet + } + if src.Vtorc != "" { + dst.Vtorc = src.Vtorc + } + if src.Vtbackup != "" { + dst.Vtbackup = src.Vtbackup + } + if src.Mysqld != nil { + dst.Mysqld = src.Mysqld + } + if dst.MysqldExporter != "" { + dst.MysqldExporter = src.MysqldExporter + } +} diff --git a/pkg/apis/planetscale/v2/vitesskeyspace_types.go b/pkg/apis/planetscale/v2/vitesskeyspace_types.go index 6f4e0ff1..f631343f 100644 --- a/pkg/apis/planetscale/v2/vitesskeyspace_types.go +++ b/pkg/apis/planetscale/v2/vitesskeyspace_types.go @@ -51,10 +51,11 @@ 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. Images VitessKeyspaceImages `json:"images,omitempty"` // ImagePullPolicies are inherited from the VitessCluster spec. @@ -178,6 +179,15 @@ type VitessKeyspaceTemplate struct { // Annotations can optionally be used to attach custom annotations to the VitessKeyspace object. Annotations map[string]string `json:"annotations,omitempty"` + + // Users are encouraged to let the VitessCluster controller automatically + // propagate image changes from the VitessCluster to the VitessKeyspace + // via rolling updates. + // + // 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 VitessKeyspaceImages `json:"images,omitempty"` } // VitessOrchestratorSpec specifies deployment parameters for vtorc. diff --git a/pkg/apis/planetscale/v2/zz_generated.deepcopy.go b/pkg/apis/planetscale/v2/zz_generated.deepcopy.go index b7a8197d..6aa742f6 100644 --- a/pkg/apis/planetscale/v2/zz_generated.deepcopy.go +++ b/pkg/apis/planetscale/v2/zz_generated.deepcopy.go @@ -1999,6 +1999,7 @@ func (in *VitessKeyspaceTemplate) DeepCopyInto(out *VitessKeyspaceTemplate) { (*out)[key] = val } } + in.Images.DeepCopyInto(&out.Images) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VitessKeyspaceTemplate. diff --git a/pkg/controller/vitesscluster/reconcile_keyspaces.go b/pkg/controller/vitesscluster/reconcile_keyspaces.go index 54ef4784..826d4e8e 100644 --- a/pkg/controller/vitesscluster/reconcile_keyspaces.go +++ b/pkg/controller/vitesscluster/reconcile_keyspaces.go @@ -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.MergeVitessKeyspaceImages(&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 { From 5030d17dd298a2411b31773b2d107efb8ec81a2a Mon Sep 17 00:00:00 2001 From: Max Englander Date: Tue, 23 Jan 2024 01:44:01 -0500 Subject: [PATCH 2/3] fix mysqld exporter merging Signed-off-by: Max Englander --- pkg/apis/planetscale/v2/vitesskeyspace_defaults.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go b/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go index 47cca2cf..f659b079 100644 --- a/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go +++ b/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go @@ -85,7 +85,7 @@ func MergeVitessKeyspaceImages(dst *VitessKeyspaceImages, src *VitessKeyspaceIma if src.Mysqld != nil { dst.Mysqld = src.Mysqld } - if dst.MysqldExporter != "" { + if src.MysqldExporter != "" { dst.MysqldExporter = src.MysqldExporter } } From a4207a57a6e79a1871b9ca5f800c4e5082a95ca8 Mon Sep 17 00:00:00 2001 From: Max Englander Date: Wed, 24 Jan 2024 09:25:14 -0500 Subject: [PATCH 3/3] cr: dont propagate mariadb or non-mysqld related images; update comments about version skew Signed-off-by: Max Englander --- .../crds/planetscale.com_vitessclusters.yaml | 12 --- docs/api/index.html | 100 ++++++++++++++++-- .../planetscale/v2/vitesscluster_types.go | 14 ++- .../planetscale/v2/vitesskeyspace_defaults.go | 19 +--- .../planetscale/v2/vitesskeyspace_types.go | 19 ++-- .../planetscale/v2/zz_generated.deepcopy.go | 35 ++++++ .../vitesscluster/reconcile_keyspaces.go | 2 +- 7 files changed, 155 insertions(+), 46 deletions(-) diff --git a/deploy/crds/planetscale.com_vitessclusters.yaml b/deploy/crds/planetscale.com_vitessclusters.yaml index bb7e9ef1..e54649dd 100644 --- a/deploy/crds/planetscale.com_vitessclusters.yaml +++ b/deploy/crds/planetscale.com_vitessclusters.yaml @@ -1176,23 +1176,11 @@ spec: properties: mysqld: properties: - mariadb103Compatible: - type: string - mariadbCompatible: - type: string mysql56Compatible: type: string mysql80Compatible: type: string type: object - mysqldExporter: - type: string - vtbackup: - type: string - vtorc: - type: string - vttablet: - type: string type: object name: maxLength: 63 diff --git a/docs/api/index.html b/docs/api/index.html index f8e9736f..cbf2b048 100644 --- a/docs/api/index.html +++ b/docs/api/index.html @@ -1450,9 +1450,7 @@

MysqldImage VitessKeyspaceImages)

-

MysqldImage specifies the container image to use for mysqld, -as well as declaring which MySQL flavor setting in Vitess the -image is compatible with.

+

TODO: Remove this once everything is migrated to MysqldImageNew.

@@ -1512,6 +1510,52 @@

MysqldImage

+

MysqldImageNew +

+

+(Appears on: +VitessKeyspaceTemplateImages) +

+

+

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.

+

+ + + + + + + + + + + + + + + + + +
FieldDescription
+mysql56Compatible
+ +string + +
+

Mysql56Compatible is a container image (including version tag) for mysqld +that’s compatible with the Vitess “MySQL56” flavor setting.

+
+mysql80Compatible
+ +string + +
+

Mysql80Compatible is a container image (including version tag) for mysqld +that’s compatible with the Vitess “MySQL80” flavor setting.

+

MysqldSpec

@@ -4774,7 +4818,8 @@

VitessKeyspace 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.

+VitessKeyspace, or else when a user has specified a keyspace-level +images on VitessKeyspaceTemplate.

@@ -5079,7 +5124,6 @@

VitessKeyspaceImages

(Appears on: VitessKeyspaceSpec, -VitessKeyspaceTemplate, VitessShardSpec)

@@ -5563,7 +5607,8 @@

VitessKeyspaceSpec 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.

+VitessKeyspace, or else when a user has specified a keyspace-level +images on VitessKeyspaceTemplate.

@@ -5943,15 +5988,12 @@

VitessKeyspaceTemplate images
- -VitessKeyspaceImages + +VitessKeyspaceTemplateImages -

Users are encouraged to let the VitessCluster controller automatically -propagate image changes from the VitessCluster to the VitessKeyspace -via rolling updates.

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.

@@ -5959,6 +6001,42 @@

VitessKeyspaceTemplate +

VitessKeyspaceTemplateImages +

+

+(Appears on: +VitessKeyspaceTemplate) +

+

+

VitessKeyspaceTemplateImages specifies user-definable container images to +use for this keyspace.

+

+ + + + + + + + + + + + + +
FieldDescription
+mysqld
+ + +MysqldImageNew + + +
+

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.

+

VitessKeyspaceTurndownPolicy (string alias)

diff --git a/pkg/apis/planetscale/v2/vitesscluster_types.go b/pkg/apis/planetscale/v2/vitesscluster_types.go index 8bbac586..f796d11b 100644 --- a/pkg/apis/planetscale/v2/vitesscluster_types.go +++ b/pkg/apis/planetscale/v2/vitesscluster_types.go @@ -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. diff --git a/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go b/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go index f659b079..aa5c51d2 100644 --- a/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go +++ b/pkg/apis/planetscale/v2/vitesskeyspace_defaults.go @@ -70,22 +70,11 @@ func DefaultVitessKeyspaceImages(dst *VitessKeyspaceImages, clusterDefaults *Vit } } -// MergeVitessKeyspaceImages takes non-empty image values from a non-nil src +// MergeVitessKeyspaceTemplateImages takes non-empty image values from a non-nil src // and sets them on dst. -func MergeVitessKeyspaceImages(dst *VitessKeyspaceImages, src *VitessKeyspaceImages) { - if src.Vttablet != "" { - dst.Vttablet = src.Vttablet - } - if src.Vtorc != "" { - dst.Vtorc = src.Vtorc - } - if src.Vtbackup != "" { - dst.Vtbackup = src.Vtbackup - } +func MergeVitessKeyspaceTemplateImages(dst *VitessKeyspaceImages, src *VitessKeyspaceTemplateImages) { if src.Mysqld != nil { - dst.Mysqld = src.Mysqld - } - if src.MysqldExporter != "" { - dst.MysqldExporter = src.MysqldExporter + dst.Mysqld.Mysql56Compatible = src.Mysqld.Mysql56Compatible + dst.Mysqld.Mysql80Compatible = src.Mysqld.Mysql80Compatible } } diff --git a/pkg/apis/planetscale/v2/vitesskeyspace_types.go b/pkg/apis/planetscale/v2/vitesskeyspace_types.go index f631343f..1550b242 100644 --- a/pkg/apis/planetscale/v2/vitesskeyspace_types.go +++ b/pkg/apis/planetscale/v2/vitesskeyspace_types.go @@ -55,7 +55,8 @@ type VitessKeyspaceSpec struct { // 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. + // 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. @@ -180,14 +181,20 @@ type VitessKeyspaceTemplate struct { // Annotations can optionally be used to attach custom annotations to the VitessKeyspace object. Annotations map[string]string `json:"annotations,omitempty"` - // Users are encouraged to let the VitessCluster controller automatically - // propagate image changes from the VitessCluster to the VitessKeyspace - // via rolling updates. - // // 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 VitessKeyspaceImages `json:"images,omitempty"` + 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. diff --git a/pkg/apis/planetscale/v2/zz_generated.deepcopy.go b/pkg/apis/planetscale/v2/zz_generated.deepcopy.go index 6aa742f6..4243ff17 100644 --- a/pkg/apis/planetscale/v2/zz_generated.deepcopy.go +++ b/pkg/apis/planetscale/v2/zz_generated.deepcopy.go @@ -421,6 +421,21 @@ func (in *MysqldImage) DeepCopy() *MysqldImage { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MysqldImageNew) DeepCopyInto(out *MysqldImageNew) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MysqldImageNew. +func (in *MysqldImageNew) DeepCopy() *MysqldImageNew { + if in == nil { + return nil + } + out := new(MysqldImageNew) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *MysqldSpec) DeepCopyInto(out *MysqldSpec) { *out = *in @@ -2012,6 +2027,26 @@ func (in *VitessKeyspaceTemplate) DeepCopy() *VitessKeyspaceTemplate { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VitessKeyspaceTemplateImages) DeepCopyInto(out *VitessKeyspaceTemplateImages) { + *out = *in + if in.Mysqld != nil { + in, out := &in.Mysqld, &out.Mysqld + *out = new(MysqldImageNew) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VitessKeyspaceTemplateImages. +func (in *VitessKeyspaceTemplateImages) DeepCopy() *VitessKeyspaceTemplateImages { + if in == nil { + return nil + } + out := new(VitessKeyspaceTemplateImages) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VitessLockserverParams) DeepCopyInto(out *VitessLockserverParams) { *out = *in diff --git a/pkg/controller/vitesscluster/reconcile_keyspaces.go b/pkg/controller/vitesscluster/reconcile_keyspaces.go index 826d4e8e..25136491 100644 --- a/pkg/controller/vitesscluster/reconcile_keyspaces.go +++ b/pkg/controller/vitesscluster/reconcile_keyspaces.go @@ -150,7 +150,7 @@ func newVitessKeyspace(key client.ObjectKey, vt *planetscalev2.VitessCluster, pa planetscalev2.DefaultVitessKeyspaceImages(&images, &vt.Spec.Images) // Apply user-defined overrides for images. - planetscalev2.MergeVitessKeyspaceImages(&images, &keyspace.Images) + planetscalev2.MergeVitessKeyspaceTemplateImages(&images, &keyspace.Images) // Copy parent labels map and add keyspace-specific label. labels := make(map[string]string, len(parentLabels)+1)