mirror of
https://github.com/clastix/kamaji.git
synced 2026-02-14 18:10:03 +00:00
fix(datastore): pod template hashing for storage migration (#710)
* fix(datastore): pod template hashing for storage migration Signed-off-by: Dario Tranchitella <dario@tranchitella.eu> * test: ensuring migration works for etcd and postgresql Signed-off-by: Dario Tranchitella <dario@tranchitella.eu> --------- Signed-off-by: Dario Tranchitella <dario@tranchitella.eu>
This commit is contained in:
committed by
GitHub
parent
880a392887
commit
2204fdad63
@@ -5,6 +5,7 @@ metadata:
|
|||||||
labels:
|
labels:
|
||||||
tenant.clastix.io: k8s-130
|
tenant.clastix.io: k8s-130
|
||||||
spec:
|
spec:
|
||||||
|
dataStore: postgresql-bronze
|
||||||
controlPlane:
|
controlPlane:
|
||||||
deployment:
|
deployment:
|
||||||
replicas: 2
|
replicas: 2
|
||||||
|
|||||||
@@ -22,18 +22,18 @@ import (
|
|||||||
"github.com/clastix/kamaji/internal/utilities"
|
"github.com/clastix/kamaji/internal/utilities"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("When migrating a Tenant Control Plane to another datastore", func() {
|
func featureTestMigration(driver string) {
|
||||||
var tcp *kamajiv1alpha1.TenantControlPlane
|
var tcp *kamajiv1alpha1.TenantControlPlane
|
||||||
// Create a TenantControlPlane resource into the cluster
|
// Create a TenantControlPlane resource into the cluster
|
||||||
JustBeforeEach(func() {
|
JustBeforeEach(func() {
|
||||||
// Fill TenantControlPlane object
|
// Fill TenantControlPlane object
|
||||||
tcp = &kamajiv1alpha1.TenantControlPlane{
|
tcp = &kamajiv1alpha1.TenantControlPlane{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: fmt.Sprintf("migrating-%s-etcd", rand.String(5)),
|
Name: fmt.Sprintf("migrating-%s-%s", rand.String(5), driver),
|
||||||
Namespace: "default",
|
Namespace: "default",
|
||||||
},
|
},
|
||||||
Spec: kamajiv1alpha1.TenantControlPlaneSpec{
|
Spec: kamajiv1alpha1.TenantControlPlaneSpec{
|
||||||
DataStore: "etcd-bronze",
|
DataStore: fmt.Sprintf("%s-bronze", driver),
|
||||||
ControlPlane: kamajiv1alpha1.ControlPlane{
|
ControlPlane: kamajiv1alpha1.ControlPlane{
|
||||||
Deployment: kamajiv1alpha1.DeploymentSpec{
|
Deployment: kamajiv1alpha1.DeploymentSpec{
|
||||||
Replicas: pointer.To(int32(1)),
|
Replicas: pointer.To(int32(1)),
|
||||||
@@ -91,7 +91,7 @@ var _ = Describe("When migrating a Tenant Control Plane to another datastore", f
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tcp.Spec.DataStore = "etcd-silver"
|
tcp.Spec.DataStore = fmt.Sprintf("%s-silver", driver)
|
||||||
|
|
||||||
return k8sClient.Update(context.Background(), tcp)
|
return k8sClient.Update(context.Background(), tcp)
|
||||||
}, time.Minute, time.Second).ShouldNot(HaveOccurred())
|
}, time.Minute, time.Second).ShouldNot(HaveOccurred())
|
||||||
@@ -114,11 +114,28 @@ var _ = Describe("When migrating a Tenant Control Plane to another datastore", f
|
|||||||
}
|
}
|
||||||
|
|
||||||
return tcp.Status.Storage.DataStoreName
|
return tcp.Status.Storage.DataStoreName
|
||||||
}, time.Minute, time.Second).Should(BeEquivalentTo("etcd-silver"))
|
}, time.Minute, time.Second).Should(BeEquivalentTo(fmt.Sprintf("%s-silver", driver)))
|
||||||
|
|
||||||
By("checking the presence of the previous Namespace")
|
By("checking the presence of the previous Namespace")
|
||||||
Eventually(func() error {
|
Eventually(func() error {
|
||||||
return tcpClient.Get(context.Background(), types.NamespacedName{Name: ns.GetName()}, &corev1.Namespace{})
|
return tcpClient.Get(context.Background(), types.NamespacedName{Name: ns.GetName()}, &corev1.Namespace{})
|
||||||
}).ShouldNot(HaveOccurred())
|
}).ShouldNot(HaveOccurred())
|
||||||
|
// The Freeze ValidatingWebhookConfiguration should have been removed successfully:
|
||||||
|
// we're checking write operations are allowed.
|
||||||
|
By("checking the changes are newly allowed")
|
||||||
|
Eventually(func() error {
|
||||||
|
var writeNamespace corev1.Namespace
|
||||||
|
writeNamespace.Name = fmt.Sprintf("write-%s-%s", rand.String(5), driver)
|
||||||
|
|
||||||
|
return tcpClient.Create(context.Background(), &writeNamespace)
|
||||||
|
}).ShouldNot(HaveOccurred())
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = Describe("When migrating a Tenant Control Plane to another datastore (etcd)", func() {
|
||||||
|
featureTestMigration("etcd")
|
||||||
|
})
|
||||||
|
|
||||||
|
var _ = Describe("When migrating a Tenant Control Plane to another datastore (postgresql)", func() {
|
||||||
|
featureTestMigration("postgresql")
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func (d Deployment) Build(ctx context.Context, deployment *appsv1.Deployment, te
|
|||||||
d.setLabels(deployment, utilities.MergeMaps(utilities.KamajiLabels(tenantControlPlane.GetName(), "deployment"), tenantControlPlane.Spec.ControlPlane.Deployment.AdditionalMetadata.Labels))
|
d.setLabels(deployment, utilities.MergeMaps(utilities.KamajiLabels(tenantControlPlane.GetName(), "deployment"), tenantControlPlane.Spec.ControlPlane.Deployment.AdditionalMetadata.Labels))
|
||||||
d.setAnnotations(deployment, utilities.MergeMaps(deployment.Annotations, tenantControlPlane.Spec.ControlPlane.Deployment.AdditionalMetadata.Annotations))
|
d.setAnnotations(deployment, utilities.MergeMaps(deployment.Annotations, tenantControlPlane.Spec.ControlPlane.Deployment.AdditionalMetadata.Annotations))
|
||||||
d.setTemplateLabels(&deployment.Spec.Template, utilities.MergeMaps(d.templateLabels(ctx, &tenantControlPlane), tenantControlPlane.Spec.ControlPlane.Deployment.PodAdditionalMetadata.Labels))
|
d.setTemplateLabels(&deployment.Spec.Template, utilities.MergeMaps(d.templateLabels(ctx, &tenantControlPlane), tenantControlPlane.Spec.ControlPlane.Deployment.PodAdditionalMetadata.Labels))
|
||||||
d.setTemplateAnnotations(&deployment.Spec.Template, tenantControlPlane.Spec.ControlPlane.Deployment.PodAdditionalMetadata.Annotations)
|
d.setTemplateAnnotations(&deployment.Spec.Template, utilities.MergeMaps(tenantControlPlane.Spec.ControlPlane.Deployment.PodAdditionalMetadata.Annotations, map[string]string{"storage.kamaji.clastix.io/config": tenantControlPlane.Status.Storage.Config.Checksum}))
|
||||||
d.setNodeSelector(&deployment.Spec.Template.Spec, tenantControlPlane)
|
d.setNodeSelector(&deployment.Spec.Template.Spec, tenantControlPlane)
|
||||||
d.setToleration(&deployment.Spec.Template.Spec, tenantControlPlane)
|
d.setToleration(&deployment.Spec.Template.Spec, tenantControlPlane)
|
||||||
d.setAffinity(&deployment.Spec.Template.Spec, tenantControlPlane)
|
d.setAffinity(&deployment.Spec.Template.Spec, tenantControlPlane)
|
||||||
|
|||||||
Reference in New Issue
Block a user