Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datastore): pod template hashing for storage migration #710

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/samples/kamaji_v1alpha1_tenantcontrolplane.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ metadata:
labels:
tenant.clastix.io: k8s-130
spec:
dataStore: postgresql-bronze
controlPlane:
deployment:
replicas: 2
Expand Down
27 changes: 22 additions & 5 deletions e2e/tcp_migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ import (
"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
// Create a TenantControlPlane resource into the cluster
JustBeforeEach(func() {
// Fill TenantControlPlane object
tcp = &kamajiv1alpha1.TenantControlPlane{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("migrating-%s-etcd", rand.String(5)),
Name: fmt.Sprintf("migrating-%s-%s", rand.String(5), driver),
Namespace: "default",
},
Spec: kamajiv1alpha1.TenantControlPlaneSpec{
DataStore: "etcd-bronze",
DataStore: fmt.Sprintf("%s-bronze", driver),
ControlPlane: kamajiv1alpha1.ControlPlane{
Deployment: kamajiv1alpha1.DeploymentSpec{
Replicas: pointer.To(int32(1)),
Expand Down Expand Up @@ -91,7 +91,7 @@ var _ = Describe("When migrating a Tenant Control Plane to another datastore", f
return err
}

tcp.Spec.DataStore = "etcd-silver"
tcp.Spec.DataStore = fmt.Sprintf("%s-silver", driver)

return k8sClient.Update(context.Background(), tcp)
}, time.Minute, time.Second).ShouldNot(HaveOccurred())
Expand All @@ -114,11 +114,28 @@ var _ = Describe("When migrating a Tenant Control Plane to another datastore", f
}

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")
Eventually(func() error {
return tcpClient.Get(context.Background(), types.NamespacedName{Name: ns.GetName()}, &corev1.Namespace{})
}).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")
})
2 changes: 1 addition & 1 deletion internal/builders/controlplane/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.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.setToleration(&deployment.Spec.Template.Spec, tenantControlPlane)
d.setAffinity(&deployment.Spec.Template.Spec, tenantControlPlane)
Expand Down