Skip to content

Commit e312eb7

Browse files
authored
Merge pull request #436 from ivanauth/fix/skip-migrations-deployment-hash
fix: skipMigrations deployments shouldn't claim the real migration hash
2 parents 8475347 + 1b9d660 commit e312eb7

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

pkg/config/config.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,10 +1002,20 @@ func (c *Config) Deployment(migrationHash, secretHash string) *applyappsv1.Deplo
10021002
}
10031003

10041004
// ensure patches don't overwrite anything critical for operator function
1005+
//
1006+
// When migrations are skipped the deployment must not claim the real
1007+
// migration hash: check_migrations treats a deployment carrying the target
1008+
// hash as proof migrations already ran, so stamping the real hash here
1009+
// (overriding unpatchedDeployment's "skipped") causes a later
1010+
// migrations-required reconcile to skip the migration job entirely.
1011+
migrationAnnotation := migrationHash
1012+
if c.SkipMigrations {
1013+
migrationAnnotation = "skipped"
1014+
}
10051015
d.WithName(name).WithNamespace(c.Namespace).WithOwnerReferences(c.ownerRef()).
10061016
WithLabels(metadata.LabelsForComponent(c.Name, metadata.ComponentSpiceDBLabelValue)).
10071017
WithAnnotations(map[string]string{
1008-
metadata.SpiceDBMigrationRequirementsKey: migrationHash,
1018+
metadata.SpiceDBMigrationRequirementsKey: migrationAnnotation,
10091019
})
10101020
d.Spec.Selector.WithMatchLabels(map[string]string{metadata.KubernetesInstanceLabelKey: name})
10111021
d.Spec.Template.

pkg/config/config_test.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,30 @@ func TestDeployment(t *testing.T) {
26542654
secret *corev1.Secret
26552655
wantDeployment *applyappsv1.DeploymentApplyConfiguration
26562656
}{
2657+
{
2658+
name: "migration hash is preserved when migrations are not skipped",
2659+
cluster: v1alpha1.ClusterSpec{
2660+
SecretRef: "test-secret",
2661+
Config: json.RawMessage(`
2662+
{
2663+
"logLevel": "debug",
2664+
"datastoreEngine": "cockroachdb"
2665+
}
2666+
`),
2667+
},
2668+
secret: &corev1.Secret{Data: map[string][]byte{
2669+
"datastore_uri": []byte("uri"),
2670+
"preshared_key": []byte("psk"),
2671+
}},
2672+
wantDeployment: expectedDeployment(func(dep *applyappsv1.DeploymentApplyConfiguration) {
2673+
// migrations not skipped: the deployment must carry the real
2674+
// migration hash so check_migrations can tell it apart from a
2675+
// "skipped" deployment.
2676+
dep.WithAnnotations(map[string]string{
2677+
metadata.SpiceDBMigrationRequirementsKey: "1",
2678+
})
2679+
}),
2680+
},
26572681
{
26582682
name: "container name back compat: smp patch with old name",
26592683
cluster: v1alpha1.ClusterSpec{
@@ -3734,7 +3758,10 @@ func expectedDeployment(apply ...func(dep *applyappsv1.DeploymentApplyConfigurat
37343758
metadata.KubernetesVersionLabelKey: "v1",
37353759
}).
37363760
WithAnnotations(map[string]string{
3737-
metadata.SpiceDBMigrationRequirementsKey: "1",
3761+
// every TestDeployment case below sets skipMigrations: true, so the
3762+
// deployment must advertise "skipped" rather than the real migration
3763+
// hash (otherwise check_migrations would treat it as already migrated).
3764+
metadata.SpiceDBMigrationRequirementsKey: "skipped",
37383765
}).
37393766
WithOwnerReferences(applymetav1.OwnerReference().
37403767
WithName("test").

0 commit comments

Comments
 (0)