Skip to content

Commit 2322f61

Browse files
committed
use mariadb version status field to determin the actual deployed version
1 parent 93384d6 commit 2322f61

File tree

8 files changed

+76
-26
lines changed

8 files changed

+76
-26
lines changed

apis/vshn/v1/dbaas_vshn_mariadb.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ type VSHNMariaDBStatus struct {
145145
// CurrentInstances tracks the current amount of instances.
146146
// Mainly used to detect if there was a change in instances
147147
CurrentInstances int `json:"currentInstances,omitempty"`
148+
// MariaDBVersion contains the current MariaDB server version
149+
MariaDBVersion string `json:"mariadbVersion,omitempty"`
150+
// InitialMaintenanceRan tracks if the initial maintenance job has been triggered
151+
InitialMaintenanceRan bool `json:"initialMaintenanceRan,omitempty"`
148152
// ResourceStatus represents the observed state of a managed resource.
149153
xpv1.ResourceStatus `json:",inline"`
150154
}

crds/vshn.appcat.vshn.io_vshnmariadbs.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4895,6 +4895,9 @@ spec:
48954895
CurrentInstances tracks the current amount of instances.
48964896
Mainly used to detect if there was a change in instances
48974897
type: integer
4898+
initialMaintenanceRan:
4899+
description: InitialMaintenanceRan tracks if the initial maintenance job has been triggered
4900+
type: boolean
48984901
instanceNamespace:
48994902
description: InstanceNamespace contains the name of the namespace where the instance resides
49004903
type: string
@@ -4935,6 +4938,9 @@ spec:
49354938
type: string
49364939
type: object
49374940
type: array
4941+
mariadbVersion:
4942+
description: MariaDBVersion contains the current MariaDB server version
4943+
type: string
49384944
namespaceConditions:
49394945
items:
49404946
properties:

crds/vshn.appcat.vshn.io_xvshnmariadbs.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5804,6 +5804,10 @@ spec:
58045804
CurrentInstances tracks the current amount of instances.
58055805
Mainly used to detect if there was a change in instances
58065806
type: integer
5807+
initialMaintenanceRan:
5808+
description: InitialMaintenanceRan tracks if the initial maintenance
5809+
job has been triggered
5810+
type: boolean
58075811
instanceNamespace:
58085812
description: InstanceNamespace contains the name of the namespace
58095813
where the instance resides
@@ -5848,6 +5852,9 @@ spec:
58485852
type: string
58495853
type: object
58505854
type: array
5855+
mariadbVersion:
5856+
description: MariaDBVersion contains the current MariaDB server version
5857+
type: string
58515858
namespaceConditions:
58525859
items:
58535860
properties:

pkg/comp-functions/functions/vshnmariadb/files/proxysql.conf.tmpl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ admin_variables=
99
cluster_password="{{ .RootPassword }}"
1010
}
1111

12-
{{ if eq .TLS 1 }}
1312
mysql_variables = {
13+
{{ if eq .TLS 1 }}
1414
ssl_p2s_ca = "/var/lib/proxysql/proxysql-ca.pem"
15+
{{ end }}
16+
server_version = "{{ .MariaDBVersion }}"
1517
}
16-
{{ end }}
1718

1819
mysql_servers =
1920
(

pkg/comp-functions/functions/vshnmariadb/maintenance.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,16 @@ func AddMaintenanceJob(ctx context.Context, comp *vshnv1.VSHNMariaDB, svc *runti
4343

4444
// AddInitialMaintenanceJob creates a one-time job from the CronJob template to run maintenance immediately after provisioning
4545
func AddInitialMaintenanceJob(ctx context.Context, comp *vshnv1.VSHNMariaDB, svc *runtime.ServiceRuntime) *xfnproto.Result {
46-
cronJobName := comp.GetName() + "-maintenancejob"
47-
initialJobName := comp.GetName() + "-initial-maintenance"
48-
49-
observedJob := &batchv1.Job{}
50-
err := svc.GetObservedKubeObject(observedJob, initialJobName)
51-
if err == nil {
52-
// Keep it in the desired state to avoid deletion
53-
errSet := svc.SetDesiredKubeObject(observedJob, initialJobName, runtime.KubeOptionAllowDeletion)
54-
if errSet != nil {
55-
return runtime.NewFatalResult(fmt.Errorf("failed to set desired kube object for existing job: %w", errSet))
56-
}
46+
// Check if initial maintenance has already been triggered
47+
if comp.Status.InitialMaintenanceRan {
5748
return nil
5849
}
5950

51+
cronJobName := comp.GetName() + "-maintenancejob"
52+
initialJobName := comp.GetName() + "-initial-maintenance"
53+
6054
observedCronJob := &batchv1.CronJob{}
61-
err = svc.GetObservedKubeObject(observedCronJob, cronJobName)
55+
err := svc.GetObservedKubeObject(observedCronJob, cronJobName)
6256
if err != nil {
6357
return nil
6458
}
@@ -82,5 +76,12 @@ func AddInitialMaintenanceJob(ctx context.Context, comp *vshnv1.VSHNMariaDB, svc
8276
if errSet != nil {
8377
return runtime.NewFatalResult(fmt.Errorf("failed to set desired kube object: %w", errSet))
8478
}
79+
80+
// Mark that initial maintenance has been triggered
81+
comp.Status.InitialMaintenanceRan = true
82+
if err := svc.SetDesiredCompositeStatus(comp); err != nil {
83+
return runtime.NewWarningResult(fmt.Sprintf("cannot update InitialMaintenanceRan status: %v", err))
84+
}
85+
8586
return nil
8687
}

pkg/comp-functions/functions/vshnmariadb/mariadb_deploy.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"errors"
1010
"fmt"
1111
"io"
12+
"regexp"
1213
"strconv"
1314

1415
xfnproto "github.com/crossplane/function-sdk-go/proto/v1"
@@ -101,6 +102,7 @@ func DeployMariadb(ctx context.Context, comp *vshnv1.VSHNMariaDB, svc *runtime.S
101102
return runtime.NewWarningResult(fmt.Errorf("cannot set custom MariaDB settings: %w", err).Error())
102103
}
103104
}
105+
104106
return nil
105107
}
106108

@@ -117,11 +119,16 @@ func createObjectHelmRelease(ctx context.Context, comp *vshnv1.VSHNMariaDB, svc
117119
return fmt.Errorf("cannot get observed release values: %w", err)
118120
}
119121

120-
_, err = maintenance.SetReleaseVersion(ctx, comp.Spec.Parameters.Service.Version, values, observedValues, []string{"image", "tag"})
122+
versionTag, err := maintenance.SetReleaseVersion(ctx, comp.Spec.Parameters.Service.Version, values, observedValues, []string{"image", "tag"})
121123
if err != nil {
122124
return fmt.Errorf("cannot set mariadb version for release: %w", err)
123125
}
124126

127+
// Extract and update the MariaDB version in status
128+
if err := updateMariaDBVersionFromTag(comp, svc, versionTag); err != nil {
129+
svc.Log.Error(err, "cannot update MariaDB version in status")
130+
}
131+
125132
r, err := newRelease(ctx, svc, values, comp)
126133
if err != nil {
127134
return err
@@ -528,3 +535,25 @@ func getMariaDBRootPassword(secretName string, svc *runtime.ServiceRuntime) ([]b
528535
}
529536
return secret.Data["mariadb-root-password"], nil
530537
}
538+
539+
// updateMariaDBVersionFromTag extracts the semantic version from a tag and appends MariaDB-log suffix
540+
func updateMariaDBVersionFromTag(comp *vshnv1.VSHNMariaDB, svc *runtime.ServiceRuntime, tag string) error {
541+
if tag == "" {
542+
return nil
543+
}
544+
545+
re := regexp.MustCompile(`^(\d+\.\d+\.\d+)`)
546+
matches := re.FindStringSubmatch(tag)
547+
if len(matches) <= 1 {
548+
return nil
549+
}
550+
551+
version := matches[1] + "-MariaDB-log"
552+
if version != comp.Status.MariaDBVersion {
553+
svc.Log.Info("Updating MariaDB version in status", "version", version)
554+
comp.Status.MariaDBVersion = version
555+
return svc.SetDesiredCompositeStatus(comp)
556+
}
557+
558+
return nil
559+
}

pkg/comp-functions/functions/vshnmariadb/proxysql.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ var (
3333
)
3434

3535
type proxySQLConfigParams struct {
36-
CompName string
37-
RootPassword string
38-
Namespace string
39-
TLS int
40-
Users []proxySQLUsers
36+
CompName string
37+
RootPassword string
38+
Namespace string
39+
TLS int
40+
Users []proxySQLUsers
41+
MariaDBVersion string
4142
}
4243

4344
type proxySQLUsers struct {
@@ -119,11 +120,12 @@ func createProxySQLConfig(comp *vshnv1.VSHNMariaDB, svc *runtime.ServiceRuntime,
119120
}
120121

121122
confParams := proxySQLConfigParams{
122-
CompName: comp.GetName(),
123-
RootPassword: string(cd["MARIADB_PASSWORD"]),
124-
Namespace: comp.GetInstanceNamespace(),
125-
Users: userList,
126-
TLS: tls,
123+
CompName: comp.GetName(),
124+
RootPassword: string(cd["MARIADB_PASSWORD"]),
125+
Namespace: comp.GetInstanceNamespace(),
126+
Users: userList,
127+
TLS: tls,
128+
MariaDBVersion: comp.Status.MariaDBVersion,
127129
}
128130

129131
var buf bytes.Buffer

pkg/comp-functions/functions/vshnmariadb/proxysql_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func Test_createProxySQLConfig(t *testing.T) {
5353
svc := commontest.LoadRuntimeFromFile(t, "empty.yaml")
5454
comp := getComp()
5555

56-
expectedHash := "56e11403faab20eb54184eccef557c85"
56+
expectedHash := "1bf00f243388da2aa7ba6b8d14bf7ad3"
5757

5858
hash, err := createProxySQLConfig(comp, svc, false)
5959
assert.NoError(t, err)

0 commit comments

Comments
 (0)